// File: /workspace/github_cpp_makefile_star2_O3/merelin[P]mediasmartserverd/src/update_monitor.cpp
// Function: UpdateMonitor::MonitorThreadProc(void*)
void* UpdateMonitor::MonitorThreadProc(void* /*arg*/)
{
	pthread_cleanup_push(MonitorThreadCleanupHandler, NULL);
	while(true)
	{
		if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0)
		{
			throw ErrnoException("pthread_setcancelstate");
		}
		int update_count = -1, security_update_count = -1;
		if(!GetUpdateStatus(&update_count, &security_update_count))
		{
			break;
		}
		bool reboot_required = IsRebootRequired();
		if (verbose > 1)
		{
			std::cout << "--- Update Monitor ---\n";
			std::cout << "  Updates          : " << update_count << "\n"; 
			std::cout << "  Security Updates : " << security_update_count << "\n";
			std::cout << "  Reboot Required  : " << (reboot_required ? "YES" : "NO") << "\n";
		}
		if (reboot_required)
		{
			//Red
			leds_->SetSystemLed(LED_RED, true);
			leds_->SetSystemLed(LED_BLUE, false);
		}
		else if (security_update_count > 0)
		{
			//Purple
			leds_->SetSystemLed(LED_BLUE | LED_RED, true);
		}
		else if (update_count > 0)
		{
			//Blue
			leds_->SetSystemLed(LED_BLUE, true);
			leds_->SetSystemLed(LED_RED, false);
		}
		else //Nothing
		{
			//Off
			leds_->SetSystemLed(LED_BLUE | LED_RED, false);
		}
		if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
		{
			throw ErrnoException("pthread_setcancelstate");
		}
		sleep(900); //Sleep 15 minutes. //A cancellation point.
	}
	std::cout << "Update monitor thread stopped from within monitoring loop.\n";
	pthread_cleanup_pop(1); //Remove handler and execute it.
	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
leaq 0x4(%rsp), %rbx
movq %rsp, %r14
movq 0x9be9(%rip), %r15      # 0xffb0
leaq 0x533d(%rip), %rbp      # 0xb70b
movl $0x1, %edi
xorl %esi, %esi
callq 0x4440
testl %eax, %eax
jne 0x659d
movl %r13d, 0x4(%rsp)
movl %r13d, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x66f0
testb %al, %al
je 0x656f
callq 0x69f6
movl %eax, %r12d
leaq 0x9f47(%rip), %rax      # 0x10354
cmpl $0x2, (%rax)
jl 0x64d2
movl $0x17, %edx
movq %r15, %rdi
leaq 0x5067(%rip), %rsi      # 0xb48c
callq 0x4310
movl $0x15, %edx
movq %r15, %rdi
leaq 0x506b(%rip), %rsi      # 0xb4a4
callq 0x4310
movl 0x4(%rsp), %esi
movq %r15, %rdi
callq 0x4530
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4310
movl $0x15, %edx
movq %r15, %rdi
leaq 0x5051(%rip), %rsi      # 0xb4ba
callq 0x4310
movl (%rsp), %esi
movq %r15, %rdi
callq 0x4530
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x4310
movl $0x15, %edx
movq %r15, %rdi
leaq 0x5038(%rip), %rsi      # 0xb4d0
callq 0x4310
testb %r12b, %r12b
leaq 0x5043(%rip), %rsi      # 0xb4ea
leaq 0x5038(%rip), %rax      # 0xb4e6
cmovneq %rax, %rsi
movzbl %r12b, %edx
orq $0x2, %rdx
movq %r15, %rdi
callq 0x4310
movl $0x1, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4310
testb %r12b, %r12b
je 0x64f8
movq 0x9e5a(%rip), %rdi      # 0x10338
movq (%rdi), %rax
movl $0x1, %r12d
movl $0x2, %esi
movl $0x1, %edx
callq *0x40(%rax)
xorl %eax, %eax
jmp 0x6506
cmpl $0x0, (%rsp)
jle 0x653c
movb $0x1, %al
movl $0x3, %r12d
movq 0x9e2b(%rip), %rdi      # 0x10338
movq (%rdi), %rcx
movq 0x40(%rcx), %rcx
movzbl %al, %edx
movl %r12d, %esi
callq *%rcx
xorl %edi, %edi
xorl %esi, %esi
callq 0x4440
testl %eax, %eax
jne 0x65fc
movl $0x384, %edi            # imm = 0x384
callq 0x41f0
jmp 0x63ce
cmpl $0x0, 0x4(%rsp)
movq 0x9df0(%rip), %rdi      # 0x10338
movq (%rdi), %rax
movq 0x40(%rax), %rcx
jle 0x6565
movl $0x1, %esi
movl $0x1, %edx
callq *%rcx
movl $0x2, %r12d
jmp 0x64f4
xorl %eax, %eax
movl $0x3, %r12d
jmp 0x6514
movq 0x9a3a(%rip), %rdi      # 0xffb0
leaq 0x4f70(%rip), %rsi      # 0xb4ed
movl $0x3b, %edx
callq 0x4310
callq 0x66ac
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x4140
movq %rax, %r14
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4ebb(%rip), %rsi      # 0xb475
leaq 0x4eca(%rip), %rdx      # 0xb48b
leaq 0x8(%rsp), %rdi
callq 0x5e90
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x5be6
xorl %ebp, %ebp
leaq 0x9195(%rip), %rsi      # 0xf780
movq 0x99ae(%rip), %rdx      # 0xffa0
movq %r14, %rdi
callq 0x4520
jmp 0x6659
movl $0x10, %edi
callq 0x4140
movq %rax, %r14
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4e5c(%rip), %rsi      # 0xb475
leaq 0x4e6b(%rip), %rdx      # 0xb48b
leaq 0x8(%rsp), %rdi
callq 0x5e90
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x5be6
xorl %ebp, %ebp
leaq 0x9136(%rip), %rsi      # 0xf780
movq 0x994f(%rip), %rdx      # 0xffa0
movq %r14, %rdi
callq 0x4520
jmp 0x66a3
jmp 0x6693
jmp 0x6661
jmp 0x6682
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x667b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42c0
testb %bpl, %bpl
jne 0x6685
jmp 0x6696
movq %rax, %rbx
movq %r14, %rdi
callq 0x41e0
jmp 0x6696
jmp 0x6693
jmp 0x6693
movq %rax, %rbx
callq 0x66ac
movq %rbx, %rdi
callq 0x4550
movq %rax, %rdi
callq 0x5b9c
nop