// File: /workspace/github_cpp_makefile_star2_O2/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 0xed34(%rip), %rax      # 0x152c5
movzbl (%rax), %eax
movq %rax, 0x8(%rsp)
leaq 0x65b0(%rip), %rax      # 0xcb50
movzwl (%rax), %esi
leaq 0x64a6(%rip), %rdi      # 0xca50
leaq 0x110(%rsp), %rdx
pushq $0x32
popq %rcx
callq 0x2665
movl %eax, 0x4(%rsp)
cmpl $-0x1, %eax
je 0x67c5
leaq 0xed12(%rip), %r14      # 0x152e0
movl 0xed04(%rip), %eax      # 0x152d8
testl %eax, %eax
je 0x67bc
movslq 0xecf1(%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), %r12d
movl 0x30(%rdx,%r14), %r10d
movl 0x34(%rdx,%r14), %r15d
movl 0x38(%rdx,%r14), %r11d
movl %eax, 0xec90(%rip)      # 0x152d8
movl 0x3c(%rdx,%r14), %ebp
movl $0x0, %eax
cmovgel %eax, %esi
movl %esi, 0xec79(%rip)      # 0x152d4
movl 0x40(%rdx,%r14), %r13d
movl 0x44(%rdx,%r14), %ebx
cmpl $0x8, %r8d
ja 0x67a1
pushq $0xf
popq %rax
btl %r8d, %eax
jb 0x66c3
movq %rdi, 0x10(%rsp)
movq %rcx, 0x18(%rsp)
movl $0x1c0, %eax            # imm = 0x1C0
btl %r8d, %eax
jae 0x6708
movq 0x8(%rsp), %rax
leaq 0x56f7(%rip), %rcx      # 0xbd90
movq 0x20(%rcx,%rax,8), %rdx
movl $0xc8, %esi
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rcx
xorl %eax, %eax
pushq 0x10(%rsp)
pushq 0x20(%rsp)
callq 0x2320
addq $0x10, %rsp
jmp 0x6762
movq 0x8(%rsp), %rax
movq %rcx, %r11
leaq 0x56be(%rip), %rcx      # 0xbd90
movq (%rcx,%rax,8), %rdx
movl $0xc8, %esi
movq %rdi, %rbx
leaq 0x40(%rsp), %rdi
pushq $0x1
popq %rcx
xorl %eax, %eax
pushq %r15
pushq %r10
pushq %r12
pushq 0x38(%rsp)
pushq 0x48(%rsp)
pushq 0x58(%rsp)
pushq %rbx
pushq %r11
callq 0x2320
addq $0x40, %rsp
jmp 0x6762
movq 0x8(%rsp), %rax
leaq 0x567c(%rip), %rcx      # 0xbd90
movq 0x10(%rcx,%rax,8), %rdx
subq $0x8, %rsp
movl $0xc8, %esi
leaq 0x48(%rsp), %rdi
pushq $0x1
popq %rcx
xorl %eax, %eax
pushq %rbx
pushq %r13
pushq %rbp
pushq %r11
pushq %r15
pushq %r10
pushq %r12
pushq 0x60(%rsp)
pushq 0x70(%rsp)
pushq 0x80(%rsp)
pushq 0x90(%rsp)
pushq 0x70(%rsp)
pushq 0x80(%rsp)
callq 0x2320
addq $0x70, %rsp
testl %eax, %eax
jle 0x65ce
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x20d0
movl 0x4(%rsp), %edi
movq %rbx, %rsi
movl %eax, %edx
pushq $0x5
popq %rcx
callq 0x2979
pushq $0x3
popq %rdi
leaq 0x18de(%rip), %rsi      # 0x8070
movq %rbx, %rdx
xorl %eax, %eax
callq 0x247c
jmp 0x65ce
movl $0xc8, %edx
leaq 0x40(%rsp), %rdi
leaq 0x1e27(%rip), %rsi      # 0x85d9
callq 0x553a
jmp 0x65ce
movl 0x4(%rsp), %edi
callq 0x2370
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq