// File: /workspace/github_cpp_makefile_star2_O1/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, %ebx       # imm = 0xFFFFFFFF
movq %rsp, %r14
movq 0x9bf9(%rip), %r15      # 0xffb0
leaq 0x534d(%rip), %rbp      # 0xb70b
movl $0x1, %edi
xorl %esi, %esi
callq 0x4440
testl %eax, %eax
jne 0x6596
movl %ebx, 0x4(%rsp)
movl %ebx, (%rsp)
leaq 0x4(%rsp), %rdi
movq %r14, %rsi
callq 0x66ec
movl %eax, %r12d
testb %al, %al
je 0x6568
callq 0x69f2
movl %eax, %r13d
leaq 0x9f54(%rip), %rax      # 0x10354
cmpl $0x2, (%rax)
jl 0x64c5
movl $0x17, %edx
movq %r15, %rdi
leaq 0x5074(%rip), %rsi      # 0xb48c
callq 0x4310
movl $0x15, %edx
movq %r15, %rdi
leaq 0x5078(%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 0x505e(%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 0x5045(%rip), %rsi      # 0xb4d0
callq 0x4310
testb %r13b, %r13b
leaq 0x5050(%rip), %rsi      # 0xb4ea
leaq 0x5045(%rip), %rax      # 0xb4e6
cmovneq %rax, %rsi
movzbl %r13b, %edx
orq $0x2, %rdx
movq %r15, %rdi
callq 0x4310
movl $0x1, %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4310
testb %r13b, %r13b
je 0x64eb
movq 0x9e67(%rip), %rdi      # 0x10338
movq (%rdi), %rax
movl $0x1, %r13d
movl $0x2, %esi
movl $0x1, %edx
callq *0x40(%rax)
xorl %eax, %eax
jmp 0x64f9
cmpl $0x0, (%rsp)
jle 0x6535
movb $0x1, %al
movl $0x3, %r13d
movq 0x9e38(%rip), %rdi      # 0x10338
movq (%rdi), %rcx
movq 0x40(%rcx), %rcx
movzbl %al, %edx
movl %r13d, %esi
callq *%rcx
xorl %edi, %edi
xorl %esi, %esi
callq 0x4440
testl %eax, %eax
jne 0x65f5
movl $0x384, %edi            # imm = 0x384
callq 0x41f0
testb %r12b, %r12b
jne 0x63be
jmp 0x6568
cmpl $0x0, 0x4(%rsp)
movq 0x9df7(%rip), %rdi      # 0x10338
movq (%rdi), %rax
movq 0x40(%rax), %rcx
jle 0x655e
movl $0x1, %esi
movl $0x1, %edx
callq *%rcx
movl $0x2, %r13d
jmp 0x64e7
xorl %eax, %eax
movl $0x3, %r13d
jmp 0x6507
movq 0x9a41(%rip), %rdi      # 0xffb0
leaq 0x4f77(%rip), %rsi      # 0xb4ed
movl $0x3b, %edx
callq 0x4310
callq 0x66a8
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 0x4ec2(%rip), %rsi      # 0xb475
leaq 0x4ed1(%rip), %rdx      # 0xb48b
leaq 0x8(%rsp), %rdi
callq 0x5e88
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x5be8
xorl %ebp, %ebp
leaq 0x910c(%rip), %rsi      # 0xf6f0
movq 0x99b5(%rip), %rdx      # 0xffa0
movq %r14, %rdi
callq 0x4520
jmp 0x6652
movl $0x10, %edi
callq 0x4140
movq %rax, %r14
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x4e63(%rip), %rsi      # 0xb475
leaq 0x4e72(%rip), %rdx      # 0xb48b
leaq 0x8(%rsp), %rdi
callq 0x5e88
callq 0x4030
movl (%rax), %edx
movb $0x1, %bpl
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x5be8
xorl %ebp, %ebp
leaq 0x90ad(%rip), %rsi      # 0xf6f0
movq 0x9956(%rip), %rdx      # 0xffa0
movq %r14, %rdi
callq 0x4520
jmp 0x669f
jmp 0x668f
jmp 0x665a
jmp 0x6676
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x667c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42c0
jmp 0x667c
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x6692
movq %r14, %rdi
callq 0x41e0
jmp 0x6692
jmp 0x668f
jmp 0x668f
movq %rax, %rbx
callq 0x66a8
movq %rbx, %rdi
callq 0x4550
movq %rax, %rdi
callq 0x5b9e
nop