// File: Stygain[P]bandwidth-monitor/src/interface.cpp
// Function: InterfaceDetailWindow::Update()
void InterfaceDetailWindow::Update()
{
	werase(this->win);
	wborder(this->win, 0, 0, 0, 0, 0, 0, 0, 0);

	char interfaceDetailOptionString[interfaceDetailOptionStringSize];
	for (int i = 0; i < IDO_END; ++i)
	{
		getInterfaceDetailOptionString((InterfaceDetailOption)i, interfaceDetailOptionString);
		if (i == this->activeItem)
		{
			wattron(this->win, COLOR_PAIR(HEADER_ACTIVE_COLOR));
		}
		mvwprintw(this->win, i + 1, 1, "%s", interfaceDetailOptionString);
		if (i == this->activeItem)
		{
			wattroff(this->win, COLOR_PAIR(HEADER_ACTIVE_COLOR));
		}
	}
	// TODO get max width of IDO strings
	mvwprintw(this->win, 1, 25, "State: %s", this->interface->operstate);

	if (this->interface->wireless)
	{
		mvwprintw(this->win, 2, 25, "Link Quality: %d", this->interface->linkQual);
		mvwprintw(this->win, 3, 25, "Level Quality: %d", this->interface->levelQual);
		mvwprintw(this->win, 4, 25, "Noise Quality: %d", this->interface->noiseQual);
	}

	char r_bpsUnit[3] = "B";
	int r_bps = this->interface->r_bps;
	if (r_bps > 1000)
	{
		r_bps = (int)(r_bps / 1000);
		strcpy(r_bpsUnit, "KB");
	}
	if (r_bps > 1000)
	{
		r_bps = (int)(r_bps / 1000);
		strcpy(r_bpsUnit, "MB");
	}
	if (r_bps > 1000)
	{
		r_bps = (int)(r_bps / 1000);
		strcpy(r_bpsUnit, "GB");
	}

	char t_bpsUnit[3] = "B";
	int t_bps = this->interface->t_bps;
	if (t_bps > 1000)
	{
		t_bps = (int)(t_bps / 1000);
		strcpy(t_bpsUnit, "KB");
	}
	if (t_bps > 1000)
	{
		t_bps = (int)(t_bps / 1000);
		strcpy(t_bpsUnit, "MB");
	}
	if (t_bps > 1000)
	{
		t_bps = (int)(t_bps / 1000);
		strcpy(t_bpsUnit, "GB");
	}
	mvwprintw(this->win, 1, 50, "Recv: %d %sps", r_bps, r_bpsUnit);
	mvwprintw(this->win, 2, 50, "Send: %d %sps", t_bps, t_bpsUnit);

	wrefresh(this->win);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq (%rax), %rdi
callq 0x3060
movq -0x50(%rbp), %rax
movq (%rax), %rdi
xorl %r9d, %r9d
movl %r9d, %esi
movl %r9d, %edx
movl %r9d, %ecx
movl %r9d, %r8d
movl $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x10(%rsp)
callq 0x31e0
movl $0x0, -0x34(%rbp)
cmpl $0x2, -0x34(%rbp)
jge 0x13231
movl -0x34(%rbp), %edi
leaq -0x30(%rbp), %rsi
callq 0x12080
movq -0x50(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x20(%rcx), %eax
jne 0x131dc
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl $0x400, %esi            # imm = 0x400
xorl %eax, %eax
movl %eax, %edx
callq 0x31a0
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x34(%rbp), %esi
addl $0x1, %esi
leaq -0x30(%rbp), %r8
movl $0x1, %edx
leaq 0x34a8(%rip), %rcx      # 0x166a1
movb $0x0, %al
callq 0x30d0
movq -0x50(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x20(%rcx), %eax
jne 0x13221
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl $0x400, %esi            # imm = 0x400
xorl %eax, %eax
movl %eax, %edx
callq 0x3420
jmp 0x13223
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x131a5
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %r8
addq $0x78, %r8
movl $0x1, %esi
movl $0x19, %edx
leaq 0x3449(%rip), %rcx      # 0x1669a
movb $0x0, %al
callq 0x30d0
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
testb $0x1, 0x8c(%rax)
je 0x132e7
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %rax
movl 0x90(%rax), %r8d
movl $0x2, %esi
movl $0x19, %edx
leaq 0x3418(%rip), %rcx      # 0x166a4
movb $0x0, %al
callq 0x30d0
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %rax
movl 0x94(%rax), %r8d
movl $0x3, %esi
movl $0x19, %edx
leaq 0x33ff(%rip), %rcx      # 0x166b5
movb $0x0, %al
callq 0x30d0
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %rax
movl 0x98(%rax), %r8d
movl $0x4, %esi
movl $0x19, %edx
leaq 0x33e7(%rip), %rcx      # 0x166c7
movb $0x0, %al
callq 0x30d0
movq -0x50(%rbp), %rax
movw 0x329b(%rip), %cx       # 0x1658d
movw %cx, -0x37(%rbp)
movb 0x3293(%rip), %cl       # 0x1658f
movb %cl, -0x35(%rbp)
movq 0x18(%rax), %rax
movl 0x9c(%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x3e8, -0x3c(%rbp)     # imm = 0x3E8
jle 0x13333
movl -0x3c(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
leaq -0x37(%rbp), %rdi
leaq 0x3336(%rip), %rsi      # 0x16664
callq 0x32d0
cmpl $0x3e8, -0x3c(%rbp)     # imm = 0x3E8
jle 0x1335a
movl -0x3c(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
leaq -0x37(%rbp), %rdi
leaq 0x3312(%rip), %rsi      # 0x16667
callq 0x32d0
cmpl $0x3e8, -0x3c(%rbp)     # imm = 0x3E8
jle 0x13381
movl -0x3c(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
leaq -0x37(%rbp), %rdi
leaq 0x32ee(%rip), %rsi      # 0x1666a
callq 0x32d0
movq -0x50(%rbp), %rax
movw 0x3204(%rip), %cx       # 0x16590
movw %cx, -0x3f(%rbp)
movb 0x31fc(%rip), %cl       # 0x16592
movb %cl, -0x3d(%rbp)
movq 0x18(%rax), %rax
movl 0xa0(%rax), %eax
movl %eax, -0x44(%rbp)
cmpl $0x3e8, -0x44(%rbp)     # imm = 0x3E8
jle 0x133cd
movl -0x44(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
leaq -0x3f(%rbp), %rdi
leaq 0x329c(%rip), %rsi      # 0x16664
callq 0x32d0
cmpl $0x3e8, -0x44(%rbp)     # imm = 0x3E8
jle 0x133f4
movl -0x44(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
leaq -0x3f(%rbp), %rdi
leaq 0x3278(%rip), %rsi      # 0x16667
callq 0x32d0
cmpl $0x3e8, -0x44(%rbp)     # imm = 0x3E8
jle 0x1341b
movl -0x44(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
leaq -0x3f(%rbp), %rdi
leaq 0x3254(%rip), %rsi      # 0x1666a
callq 0x32d0
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x3c(%rbp), %r8d
leaq -0x37(%rbp), %r9
movl $0x1, %esi
movl $0x32, %edx
leaq 0x329e(%rip), %rcx      # 0x166d9
movb $0x0, %al
callq 0x30d0
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movl -0x44(%rbp), %r8d
leaq -0x3f(%rbp), %r9
movl $0x2, %esi
movl $0x32, %edx
leaq 0x3285(%rip), %rcx      # 0x166e7
movb $0x0, %al
callq 0x30d0
movq -0x50(%rbp), %rax
movq (%rax), %rdi
callq 0x3390
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)