// File: /workspace/github_cpp_makefile_star2_O2/enbock[P]Warp10Server/ulib/src/EventDispatcher.cpp
// Function: u::EventDispatcher::dispatchEvent(u::Event*)
Event* EventDispatcher::dispatchEvent(Event *event)
{
	lock();

	Vector<Callback>* pVec = getEventVector(event->_type);
	if(pVec != null)
	{
		Vector<Callback> vec = *pVec;
		unlock();

		int64 i=0, l = vec.size();
		for(i=0; i<l; i++)
		{
			Callback cb = vec.at(i);
			trace(
				"DispatchEvent: " + *(event->_type)
				+ "\033[36m -> "+cb.toString()
			);
			Event* ev = event->clone();
			ev->_target = this;
			cb.arg = ev;

			if(ThreadSystem::create(&cb) == false)
			{
				// thread system is terminating
				ev->destroy();
			}
		}

		return event;
	}
	else
	{
		trace(
			"\033[32mNo listener for " + *event->type()
			+ " on target "+ toString() + "."
		);
	}
	unlock();
	return event;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
movq %rdi, %r12
callq 0x407cb6
movq 0x38(%rbx), %rsi
movq %r12, %rdi
callq 0x4065c2
testq %rax, %rax
je 0x4069c7
leaq 0x58(%rsp), %rdi
movq %rax, %rsi
callq 0x406e2e
movq %r12, 0x8(%rsp)
movq %r12, %rdi
callq 0x407c72
leaq 0x90(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0x58
popq %rcx
cqto
idivq %rcx
xorl %ebp, %ebp
testq %rax, %rax
cmovleq %rbp, %rax
movq %rax, 0x10(%rsp)
leaq 0x120(%rsp), %r13
leaq 0x38(%rsp), %r12
cmpq %rbp, 0x10(%rsp)
je 0x4069b8
leaq 0x90(%rsp), %rdi
movq %rbp, %rsi
callq 0x406d9a
movq %r13, %rdi
movq %rax, %rsi
callq 0x40567e
movq $0x60d6a0, %rdi         # imm = 0x60D6A0
leaq 0x18f7b0(%rip), %rsi    # 0x596079
callq 0x474850
movq %rax, %r15
movq 0x38(%rbx), %rdx
addq $0x38, %rdx
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
leaq 0x18f8ec(%rip), %rsi    # 0x5961d7
callq 0x405bdd
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
leaq 0x18f8e8(%rip), %rdx    # 0x5961e7
callq 0x404ec5
leaq 0xc8(%rsp), %rdi
movq %r13, %rsi
callq 0x40573a
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
leaq 0x100(%rsp), %rdx
callq 0x405951
movq %r15, %rdi
movq %r12, %rsi
callq 0x4870d0
movq %rax, %rdi
leaq 0x18f747(%rip), %rsi    # 0x596085
callq 0x474850
movq %rax, %rdi
callq 0x474130
movq %r12, %rdi
callq 0x484750
leaq 0xc8(%rsp), %rdi
callq 0x404ab8
leaq 0x18(%rsp), %rdi
callq 0x484750
leaq 0xa8(%rsp), %rdi
callq 0x484750
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x20(%rax)
movq %rax, %r15
movq 0x8(%rsp), %rax
movq %rax, 0x40(%r15)
movq %r15, 0x170(%rsp)
movq %r13, %rdi
callq 0x409408
testb %al, %al
jne 0x4069a8
movq (%r15), %rax
movq %r15, %rdi
callq *(%rax)
movq %r13, %rdi
callq 0x407db8
incq %rbp
jmp 0x406895
leaq 0x58(%rsp), %rdi
callq 0x406cee
jmp 0x406aba
movq $0x60d6a0, %rdi         # imm = 0x60D6A0
leaq 0x18f6a4(%rip), %rsi    # 0x596079
callq 0x474850
movq %rax, %r14
movq %rbx, %rdi
callq 0x4059fe
leaq 0x38(%rax), %rdx
leaq 0x18f801(%rip), %rsi    # 0x5961f1
leaq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x405bdd
leaq 0x18f803(%rip), %rdx    # 0x596207
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x404ec5
movq (%r12), %rax
leaq 0x120(%rsp), %rdi
movq %r12, %rsi
callq *0x18(%rax)
leaq 0x158(%rsp), %rdx
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x405951
leaq 0x1939ac(%rip), %rdx    # 0x59a3ed
leaq 0xc8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x404ec5
leaq 0xc8(%rsp), %rsi
movq %r14, %rdi
callq 0x4870d0
leaq 0x18f61b(%rip), %rsi    # 0x596085
movq %rax, %rdi
callq 0x474850
movq %rax, %rdi
callq 0x474130
leaq 0xc8(%rsp), %rdi
callq 0x484750
leaq 0x58(%rsp), %rdi
callq 0x484750
leaq 0x120(%rsp), %rdi
callq 0x404ab8
leaq 0x38(%rsp), %rdi
callq 0x484750
leaq 0x18(%rsp), %rdi
callq 0x484750
movq %r12, %rdi
callq 0x407c72
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x406af5
movq %rax, %rbx
jmp 0x406aff
movq %rax, %rbx
jmp 0x406b0c
movq %rax, %rbx
jmp 0x406b16
jmp 0x406b35
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x484750
leaq 0x58(%rsp), %rdi
callq 0x484750
leaq 0x120(%rsp), %rdi
callq 0x404ab8
leaq 0x38(%rsp), %rdi
callq 0x484750
leaq 0x18(%rsp), %rdi
callq 0x484750
jmp 0x406b87
jmp 0x406b3a
jmp 0x406b3a
movq %rax, %rbx
jmp 0x406b63
movq %rax, %rbx
jmp 0x406b59
movq %rax, %rbx
jmp 0x406b4c
movq %rax, %rbx
jmp 0x406b7d
movq %rax, %rbx
jmp 0x406b70
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x484750
leaq 0xc8(%rsp), %rdi
callq 0x404ab8
leaq 0x18(%rsp), %rdi
callq 0x484750
leaq 0xa8(%rsp), %rdi
callq 0x484750
leaq 0x120(%rsp), %rdi
callq 0x407db8
leaq 0x58(%rsp), %rdi
callq 0x406cee
movq %rbx, %rdi
callq 0x4b5490
nop