// File: /workspace/github_cpp_makefile_star2_O1/qian-jiahong[P]uvncrep017-ws/repeaterevents.cpp
// Function: doEventWork()
static int doEventWork(void)
{
    char eventMessageToListener[MAX_EVENT_MSG_LEN];
    connectionEvent *connEv;
    sessionEvent *sessEv;
    startEndEvent *seEv;
    int eventNum;
    repeaterEvent ev;
    int connection;
    char eventListenerIp[MAX_IP_LEN];
    int msgLen;
    int formatStrInd;
    
    if (useHttpForEventListener) {
    	formatStrInd = 1;
    }
    else {
    	formatStrInd = 0;
    }
    
    connection = openConnectionToEventListener(eventListenerHost, eventListenerPort, eventListenerIp, MAX_IP_LEN);  
    if (-1 != connection) {
        while(!isFifoEmpty()) {
            ev = eventFifo[fifoTailInd];
            itemsInFifo--;
            fifoTailInd = advanceFifoIndex(fifoTailInd);
        
            eventNum = ev.eventNum;
    
            switch (eventNum) {
                case VIEWER_CONNECT:
                    //Fall through
                case VIEWER_DISCONNECT:
                    //Fall through
                case SERVER_CONNECT:
                    //Fall through
                case SERVER_DISCONNECT:
                    connEv = (connectionEvent *) ev.extraInfo;
                    msgLen = snprintf(eventMessageToListener, MAX_EVENT_MSG_LEN, 
                        formatStrings[0][formatStrInd],
                        REP_EVENT_VERSION, eventNum, ev.timeStamp, ev.repeaterProcessId, 
                        connEv -> tableIndex, connEv -> code, connEv -> connMode, connEv->peerIp.a,
                        connEv->peerIp.b, connEv->peerIp.c, connEv->peerIp.d);  
                    break;
            
                case VIEWER_SERVER_SESSION_START:
                    //Fall through
                case VIEWER_SERVER_SESSION_END:
                    sessEv = (sessionEvent *) ev.extraInfo;
                    msgLen = snprintf(eventMessageToListener, MAX_EVENT_MSG_LEN, 
                        formatStrings[1][formatStrInd],
                        REP_EVENT_VERSION, eventNum, ev.timeStamp, ev.repeaterProcessId, 
                        sessEv -> serverTableIndex, sessEv -> viewerTableIndex, sessEv -> code, sessEv -> connMode, 
                        sessEv->serverIp.a, sessEv->serverIp.b, sessEv->serverIp.c, sessEv->serverIp.d,
                        sessEv->viewerIp.a, sessEv->viewerIp.b, sessEv->viewerIp.c, sessEv->viewerIp.d);  
                    break;
            
                case REPEATER_STARTUP:
                    //Fall through
                case REPEATER_SHUTDOWN:
                    //Fall through
                case REPEATER_HEARTBEAT:
                    seEv = (startEndEvent *) ev.extraInfo;
                    msgLen = snprintf(eventMessageToListener, MAX_EVENT_MSG_LEN, 
                        formatStrings[2][formatStrInd],
                        REP_EVENT_VERSION, eventNum, ev.timeStamp, ev.repeaterProcessId, 
                        seEv -> maxSessions);  
                    break;
            
                default:
                    msgLen = 0;
                    strlcpy(eventMessageToListener, "\n", MAX_EVENT_MSG_LEN);
                    break;
            }

            if (msgLen > 0) { 
                writeExact(connection, eventMessageToListener, 
                    strlen(eventMessageToListener), TIMEOUT_5SECS);
                    
                debug(LEVEL_3, "%s", eventMessageToListener);
            }
        }
    
        close(connection);
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
leaq 0xe959(%rip), %rax      # 0x152c5
movzbl (%rax), %eax
movq %rax, 0x8(%rsp)
leaq 0x61d5(%rip), %rax      # 0xcb50
movzwl (%rax), %esi
leaq 0x60cb(%rip), %rdi      # 0xca50
leaq 0x110(%rsp), %rdx
movl $0x32, %ecx
callq 0x360f
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x6bb2
movl 0xe92e(%rip), %eax      # 0x152d8
testl %eax, %eax
je 0x6ba9
leaq 0xe927(%rip), %r14      # 0x152e0
movslq 0xe914(%rip), %rcx      # 0x152d4
imulq $0x78, %rcx, %rdx
decl %eax
leal 0x1(%rcx), %esi
cmpq $0x1f3, %rcx            # imm = 0x1F3
movl (%rdx,%r14), %r8d
movq 0x8(%rdx,%r14), %r9
movl 0x10(%rdx,%r14), %ecx
movl 0x14(%rdx,%r14), %edi
movl 0x18(%rdx,%r14), %r10d
movq %r10, 0x38(%rsp)
movq 0x1c(%rdx,%r14), %r10
movq %r10, 0x30(%rsp)
movl 0x24(%rdx,%r14), %r10d
movq %r10, 0x28(%rsp)
movl 0x28(%rdx,%r14), %r10d
movq %r10, 0x20(%rsp)
movl 0x2c(%rdx,%r14), %r13d
movl 0x30(%rdx,%r14), %r10d
movl 0x34(%rdx,%r14), %r15d
movl 0x38(%rdx,%r14), %r11d
movl %eax, 0xe8b3(%rip)      # 0x152d8
movl 0x3c(%rdx,%r14), %r12d
movl $0x0, %eax
cmovgel %eax, %esi
movl %esi, 0xe89c(%rip)      # 0x152d4
movl 0x40(%rdx,%r14), %ebp
movl 0x44(%rdx,%r14), %ebx
cmpl $0x8, %r8d
ja 0x6b49
movl $0xf, %eax
btl %r8d, %eax
jb 0x6aa4
movq %rdi, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl $0x1c0, %eax            # imm = 0x1C0
btl %r8d, %eax
jae 0x6aeb
movq 0x8(%rsp), %rax
leaq 0x5318(%rip), %rcx      # 0xbd90
movq 0x20(%rcx,%rax,8), %rdx
movl $0xc8, %esi
leaq 0x40(%rsp), %rdi
movl $0x1, %ecx
xorl %eax, %eax
pushq 0x10(%rsp)
pushq 0x20(%rsp)
callq 0x2310
addq $0x10, %rsp
jmp 0x6b61
movq 0x8(%rsp), %rax
movq %rcx, %r11
leaq 0x52dd(%rip), %rcx      # 0xbd90
movq (%rcx,%rax,8), %rdx
movl $0xc8, %esi
movq %rdi, %rbx
leaq 0x40(%rsp), %rdi
movl $0x1, %ecx
xorl %eax, %eax
pushq %r15
pushq %r10
pushq %r13
pushq 0x38(%rsp)
pushq 0x48(%rsp)
pushq 0x58(%rsp)
pushq %rbx
pushq %r11
callq 0x2310
addq $0x40, %rsp
jmp 0x6b61
movq 0x8(%rsp), %rax
leaq 0x5299(%rip), %rcx      # 0xbd90
movq 0x10(%rcx,%rax,8), %rdx
subq $0x8, %rsp
movl $0xc8, %esi
leaq 0x48(%rsp), %rdi
movl $0x1, %ecx
xorl %eax, %eax
pushq %rbx
pushq %rbp
pushq %r12
pushq %r11
pushq %r15
pushq %r10
pushq %r13
pushq 0x60(%rsp)
pushq 0x70(%rsp)
pushq 0x80(%rsp)
pushq 0x90(%rsp)
pushq 0x70(%rsp)
pushq 0x80(%rsp)
callq 0x2310
addq $0x70, %rsp
jmp 0x6b61
movl $0xc8, %edx
leaq 0x40(%rsp), %rdi
leaq 0x1a7f(%rip), %rsi      # 0x85d9
callq 0x5844
xorl %eax, %eax
testl %eax, %eax
jle 0x6b9b
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x20d0
movl 0x4(%rsp), %edi
movq %rbx, %rsi
movl %eax, %edx
movl $0x5, %ecx
callq 0x3971
movl $0x3, %edi
leaq 0x14df(%rip), %rsi      # 0x8070
movq %rbx, %rdx
xorl %eax, %eax
callq 0x355c
movl 0xe737(%rip), %eax      # 0x152d8
testl %eax, %eax
jne 0x69b9
movl 0x4(%rsp), %edi
callq 0x2360
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq