// File: jandoerntlein[P]wire/src/main.cpp
// Function: main
int main( int argc, char** argv )
{
    std::cout << "--- Wire Test ---" << std::endl;

    Button B;
    Light  L1;
    Light  L2;

    B.toggle.connect( &Light::Toggle, &L1 );
    B.toggle.connect( &Light::Toggle, &L2 );
    B.changeColor.connect( &Light::setColor, &L1 );
    B.changeColor.connect( &Light::setColor, &L2 );
    B.range.connect( &Light::setRange, &L1 );
    B.toggle(); // toggles all connected lights
    B.changeColor( 17 );
    B.toggle();
    B.range( 17.f, 19.f );

    std::cout << "--- Disconnect Test ---" << std::endl;

    B.toggle.disconnect();
    B.toggle.connect( &Light::Toggle, &L2 );
    B.toggle();    

    std::cout << "--- DirectWire Test ---" << std::endl;

    Light  L3;
    Light  L4;
    enum { PORT0, PORT1 };

    B.direct_toggle.connect( PORT0, &Light::Toggle, &L3 );
    B.direct_toggle.connect( PORT1, &Light::Toggle, &L4 );
    B.direct_ChangeColor.connect( PORT0, &Light::setColor, &L3 );
    B.direct_ChangeColor.connect( PORT1, &Light::setColor, &L4 );
    B.direct_toggle( PORT0 ); // toggles only light connected to PORT0
    B.direct_toggle( PORT1 );
    B.direct_ChangeColor( PORT0, 1337 );
    B.direct_ChangeColor( PORT1, 42 );
    B.direct_toggle( PORT0 );
    B.direct_toggle( PORT1 );

    std::cout << "--- End Test ---" << std::endl;

    return 0;
}

// Assembly:
subq $0x1c8, %rsp            # imm = 0x1C8
movl $0x0, 0x1c4(%rsp)
movl %edi, 0x1c0(%rsp)
movq %rsi, 0x1b8(%rsp)
movq 0x10d00(%rip), %rdi     # 0x12fd8
leaq 0x9d61(%rip), %rsi      # 0xc040
callq 0x20c0
movq %rax, %rdi
movq 0x10cda(%rip), %rsi     # 0x12fc8
callq 0x20f0
leaq 0x100(%rsp), %rdi
callq 0x2760
leaq 0xf4(%rsp), %rdi
callq 0x27c0
jmp 0x230f
leaq 0xd8(%rsp), %rdi
callq 0x27c0
jmp 0x231e
leaq 0x52b(%rip), %rax       # 0x2850
movq %rax, 0xc8(%rsp)
movq $0x0, 0xd0(%rsp)
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
leaq 0x100(%rsp), %rdi
leaq 0xf4(%rsp), %rcx
callq 0x27f0
jmp 0x2360
leaq 0x4e9(%rip), %rax       # 0x2850
movq %rax, 0xb8(%rsp)
movq $0x0, 0xc0(%rsp)
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
leaq 0x100(%rsp), %rdi
leaq 0xd8(%rsp), %rcx
callq 0x27f0
jmp 0x23a2
leaq 0x118(%rsp), %rdi
leaq 0x5bf(%rip), %rax       # 0x2970
movq %rax, 0xa8(%rsp)
movq $0x0, 0xb0(%rsp)
movq 0xa8(%rsp), %rsi
movq 0xb0(%rsp), %rdx
leaq 0xf4(%rsp), %rcx
callq 0x2910
jmp 0x23e4
leaq 0x118(%rsp), %rdi
leaq 0x57d(%rip), %rax       # 0x2970
movq %rax, 0x98(%rsp)
movq $0x0, 0xa0(%rsp)
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
leaq 0xd8(%rsp), %rcx
callq 0x2910
jmp 0x2426
leaq 0x130(%rsp), %rdi
leaq 0x60b(%rip), %rax       # 0x2a40
movq %rax, 0x88(%rsp)
movq $0x0, 0x90(%rsp)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
leaq 0xf4(%rsp), %rcx
callq 0x29e0
jmp 0x2468
leaq 0x100(%rsp), %rdi
callq 0x2ae0
jmp 0x2477
leaq 0x118(%rsp), %rdi
movl $0x11, %esi
callq 0x2b50
jmp 0x248b
leaq 0x100(%rsp), %rdi
callq 0x2ae0
jmp 0x249a
leaq 0x130(%rsp), %rdi
movss 0x9b5a(%rip), %xmm0     # 0xc004
movss 0x9b56(%rip), %xmm1     # 0xc008
callq 0x2bd0
jmp 0x24b9
movq 0x10b18(%rip), %rdi     # 0x12fd8
leaq 0x9b8b(%rip), %rsi      # 0xc052
callq 0x20c0
movq %rax, 0x18(%rsp)
jmp 0x24d3
movq 0x18(%rsp), %rdi
movq 0x10ae9(%rip), %rsi     # 0x12fc8
callq 0x20f0
jmp 0x24e6
leaq 0x100(%rsp), %rdi
callq 0x2c60
jmp 0x24f5
leaq 0x354(%rip), %rax       # 0x2850
movq %rax, 0x78(%rsp)
movq $0x0, 0x80(%rsp)
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
leaq 0x100(%rsp), %rdi
leaq 0xd8(%rsp), %rcx
callq 0x27f0
jmp 0x2531
leaq 0x100(%rsp), %rdi
callq 0x2ae0
jmp 0x2540
movq 0x10a91(%rip), %rdi     # 0x12fd8
leaq 0x9b1c(%rip), %rsi      # 0xc06a
callq 0x20c0
movq %rax, 0x10(%rsp)
jmp 0x255a
movq 0x10(%rsp), %rdi
movq 0x10a62(%rip), %rsi     # 0x12fc8
callq 0x20f0
jmp 0x256d
leaq 0x6c(%rsp), %rdi
callq 0x27c0
jmp 0x2579
leaq 0x60(%rsp), %rdi
callq 0x27c0
jmp 0x2585
leaq 0x148(%rsp), %rdi
leaq 0x2bc(%rip), %rax       # 0x2850
movq %rax, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x50(%rsp), %rdx
movq 0x58(%rsp), %rcx
xorl %esi, %esi
leaq 0x6c(%rsp), %r8
callq 0x2c70
jmp 0x25ba
leaq 0x148(%rsp), %rdi
leaq 0x287(%rip), %rax       # 0x2850
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movl $0x1, %esi
leaq 0x60(%rsp), %r8
callq 0x2c70
jmp 0x25f2
leaq 0x180(%rsp), %rdi
leaq 0x36f(%rip), %rax       # 0x2970
movq %rax, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
xorl %esi, %esi
leaq 0x6c(%rsp), %r8
callq 0x2cf0
jmp 0x2627
leaq 0x180(%rsp), %rdi
leaq 0x33a(%rip), %rax       # 0x2970
movq %rax, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
movl $0x1, %esi
leaq 0x60(%rsp), %r8
callq 0x2cf0
jmp 0x265f
leaq 0x148(%rsp), %rdi
xorl %esi, %esi
callq 0x2d70
jmp 0x2670
leaq 0x148(%rsp), %rdi
movl $0x1, %esi
callq 0x2d70
jmp 0x2684
leaq 0x180(%rsp), %rdi
xorl %esi, %esi
movl $0x539, %edx            # imm = 0x539
callq 0x2dc0
jmp 0x269a
leaq 0x180(%rsp), %rdi
movl $0x1, %esi
movl $0x2a, %edx
callq 0x2dc0
jmp 0x26b3
leaq 0x148(%rsp), %rdi
xorl %esi, %esi
callq 0x2d70
jmp 0x26c4
leaq 0x148(%rsp), %rdi
movl $0x1, %esi
callq 0x2d70
jmp 0x26d8
movq 0x108f9(%rip), %rdi     # 0x12fd8
leaq 0x999c(%rip), %rsi      # 0xc082
callq 0x20c0
movq %rax, 0x8(%rsp)
jmp 0x26f2
movq 0x8(%rsp), %rdi
movq 0x108ca(%rip), %rsi     # 0x12fc8
callq 0x20f0
jmp 0x2705
movl $0x0, 0x1c4(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x2e10
movl 0x1c4(%rsp), %eax
addq $0x1c8, %rsp            # imm = 0x1C8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x2e10
movq 0xe8(%rsp), %rdi
callq 0x2160
nopw (%rax,%rax)