// File: /workspace/github_c_makefile_star2_O2/soso7885[P]OPCUA_example/demo_src/server_method.c
// Function: main
int main(int argc, char** argv) {
    signal(SIGINT, stopHandler); /* catches ctrl-c */

    /* initialize the server */
    UA_ServerConfig config = UA_ServerConfig_standard;
    UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664);
    config.networkLayers = &nl;
    config.networkLayersSize = 1;
    UA_Server *server = UA_Server_new(config);

    //EXAMPLE 1
    /* add the method node with the callback */
    UA_Argument inputArguments;
    UA_Argument_init(&inputArguments);
    inputArguments.arrayDimensionsSize = 0;
    inputArguments.arrayDimensions = NULL;
    inputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
    inputArguments.description = UA_LOCALIZEDTEXT("en_US", "A String");
    inputArguments.name = UA_STRING("MyInput");
    inputArguments.valueRank = -1;

    UA_Argument outputArguments;
    UA_Argument_init(&outputArguments);
    outputArguments.arrayDimensionsSize = 0;
    outputArguments.arrayDimensions = NULL;
    outputArguments.dataType = UA_TYPES[UA_TYPES_STRING].typeId;
    outputArguments.description = UA_LOCALIZEDTEXT("en_US", "A String");
    outputArguments.name = UA_STRING("MyOutput");
    outputArguments.valueRank = -1;
        
    UA_MethodAttributes helloAttr;
    UA_MethodAttributes_init(&helloAttr);
    helloAttr.description = UA_LOCALIZEDTEXT("en_US","Say `Hello World`");
    helloAttr.displayName = UA_LOCALIZEDTEXT("en_US","Hello World");
    helloAttr.executable = true;
    helloAttr.userExecutable = true;
    UA_Server_addMethodNode(server, UA_NODEID_NUMERIC(1,62541),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT),
                            UA_QUALIFIEDNAME(1, "hello world"), 
                            helloAttr, &helloWorldMethod, NULL,
                            1, &inputArguments, 1, &outputArguments, NULL);

    //END OF EXAMPLE 1

    //EXAMPLE 2
    /* add another method node: output argument as 1d Int32 array*/
    // define input arguments
    UA_Argument_init(&inputArguments);
    inputArguments.arrayDimensionsSize = 1;
    UA_UInt32 * pInputDimensions = UA_UInt32_new();
    pInputDimensions[0] = 5;
    inputArguments.arrayDimensions = pInputDimensions;
    inputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
    inputArguments.description = UA_LOCALIZEDTEXT("en_US",
                    "input an array with 5 elements, type int32");
    inputArguments.name = UA_STRING("int32 value");
    inputArguments.valueRank = 1;

    // define output arguments
    UA_Argument_init(&outputArguments);
    outputArguments.arrayDimensionsSize = 1;
    UA_UInt32 * pOutputDimensions = UA_UInt32_new();
    pOutputDimensions[0] = 5;
    outputArguments.arrayDimensions = pOutputDimensions;
    outputArguments.dataType = UA_TYPES[UA_TYPES_INT32].typeId;
    outputArguments.description = UA_LOCALIZEDTEXT("en_US", "increment each array index");
    outputArguments.name = UA_STRING("output is the array, each index is incremented by one");
    outputArguments.valueRank = 1;

    
    UA_MethodAttributes incAttr;
    UA_MethodAttributes_init(&incAttr);
    incAttr.description = UA_LOCALIZEDTEXT("en_US","1dArrayExample");
    incAttr.displayName = UA_LOCALIZEDTEXT("en_US","1dArrayExample");
    incAttr.executable = true;
    incAttr.userExecutable = true;
    UA_Server_addMethodNode(server, UA_NODEID_STRING(1, "IncInt32ArrayValues"),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
                            UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), 
                            UA_QUALIFIEDNAME(1, "IncInt32ArrayValues"),
                            incAttr, &IncInt32ArrayValuesMethod, NULL,
                            1, &inputArguments, 1, &outputArguments, NULL);
    //END OF EXAMPLE 2

    /* If out methodnode is part of an instantiated object, we never had
       the opportunity to define the callback... we could do that now
    */
    UA_Server_setMethodNode_callback(server, UA_NODEID_NUMERIC(1,62541), &fooBarMethod, NULL);
    
    //END OF EXAMPLE 3
    /* start server */
    UA_StatusCode retval = UA_Server_run(server, &running);

    /* ctrl-c received -> clean up */
    UA_UInt32_delete(pInputDimensions);
    UA_UInt32_delete(pOutputDimensions);
    UA_Server_delete(server);
    nl.deleteMembers(&nl);

    return (int)retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x578, %rsp            # imm = 0x578
leaq 0x567(%rip), %rsi       # 0x17ae
pushq $0x2
popq %rdi
callq 0x10c0
movq 0x2d8a(%rip), %rsi      # 0x3fe0
leaq -0x440(%rbp), %rbx
movl $0x160, %edx            # imm = 0x160
movq %rbx, %rdi
callq 0x10b0
movq 0x2d7f(%rip), %rax      # 0x3ff0
movl 0x10(%rax), %ecx
leaq -0x2a0(%rbp), %r12
movl %ecx, -0x30(%r12)
movups (%rax), %xmm0
movaps %xmm0, -0x40(%r12)
movl -0x30(%r12), %eax
movl %eax, 0x10(%rsp)
movaps -0x40(%r12), %xmm0
movups %xmm0, (%rsp)
leaq -0x168(%rbp), %r14
movq %r14, %rdi
movl $0x4118, %esi           # imm = 0x4118
callq 0x1060
movq %r14, 0xf8(%rbx)
pushq $0x1
popq %rax
movq %rax, 0xf0(%rbx)
pushq $0x2c
popq %rcx
movq %rsp, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x1030
movq %rax, -0x30(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r12)
movups %xmm0, -0x8(%r12)
movups %xmm0, -0x18(%r12)
andq $0x0, 0x18(%r12)
movq 0x2ce0(%rip), %rax      # 0x3fd8
movups 0x1b8(%rax), %xmm0
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x30(%r12)
movq 0x1c8(%rax), %r14
movq %r14, -0x20(%r12)
leaq 0xcee(%rip), %rbx       # 0x200a
movq %r12, %rdi
movq %rbx, %rsi
callq 0x17d8
leaq 0xce5(%rip), %rdi       # 0x2013
callq 0x1810
movq %rax, -0x40(%r12)
movq %rdx, -0x38(%r12)
orl $-0x1, -0x18(%r12)
leaq -0x240(%rbp), %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r13)
andq $0x0, 0x18(%r13)
movups %xmm0, -0x8(%r13)
movups %xmm0, -0x18(%r13)
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x30(%r13)
movq %r14, -0x20(%r13)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x17d8
leaq 0xc9b(%rip), %rdi       # 0x201b
callq 0x1810
movq %rax, -0x40(%r13)
movq %rdx, -0x38(%r13)
orl $-0x1, -0x18(%r13)
leaq -0x1f8(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x18(%rdi)
movaps %xmm0, 0x8(%rdi)
movaps %xmm0, -0x8(%rdi)
movaps %xmm0, -0x18(%rdi)
movaps %xmm0, -0x28(%rdi)
andq $0x0, 0x28(%rdi)
leaq 0xc68(%rip), %rsi       # 0x2024
callq 0x17d8
leaq -0x218(%rbp), %rbx
leaq 0xc67(%rip), %rsi       # 0x2036
movq %rbx, %rdi
callq 0x17d8
movw $0x101, %ax             # imm = 0x101
movw %ax, 0x48(%rbx)
movw $0x1, %ax
movw %ax, -0x118(%rbp)
movw $0x1, %cx
movabsq $0xf44d00000000, %rax   # imm = 0xF44D00000000
movq %rax, -0x114(%rbp)
andw $0x0, -0x100(%rbp)
movabsq $0x5500000000, %rax     # imm = 0x5500000000
andw $0x0, -0xe8(%rbp)
movq %rax, -0xfc(%rbp)
movabsq $0x2f00000000, %rax     # imm = 0x2F00000000
movq %rax, -0xe4(%rbp)
movw %cx, -0xd0(%rbp)
leaq 0xc03(%rip), %rdi       # 0x2042
callq 0x1810
movq %rax, -0xc8(%rbp)
movq %rdx, -0xc0(%rbp)
leaq 0x60(%rsp), %rdi
pushq $0xb
popq %rcx
leaq -0x220(%rbp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %rdx, 0x58(%rsp)
movups -0xd0(%rbp), %xmm0
movups %xmm0, 0x48(%rsp)
movq -0xd8(%rbp), %rax
movq %rax, 0x40(%rsp)
movups -0xe8(%rbp), %xmm0
movups %xmm0, 0x30(%rsp)
movq -0xf0(%rbp), %rax
movq %rax, 0x28(%rsp)
movups -0x100(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x108(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x118(%rbp), %xmm0
movups %xmm0, (%rsp)
leaq -0x280(%rbp), %rbx
movq %rbx, 0xb8(%rsp)
andq $0x0, 0xc0(%rsp)
leaq 0x34d(%rip), %rsi       # 0x1828
leaq -0x2e0(%rbp), %r15
movq -0x30(%rbp), %rdi
xorl %edx, %edx
pushq $0x1
popq %rcx
movq %r15, %r8
movq %rcx, %r9
movq %rcx, %r14
callq 0x1040
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%r15)
movaps %xmm0, (%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x50(%r15)
movq %r14, 0x30(%r15)
callq 0x18d8
movq %rax, -0x40(%rbp)
pushq $0x5
popq %rcx
movl %ecx, (%rax)
movq %rax, 0x38(%r15)
movq 0x2aa2(%rip), %rax      # 0x3fd8
movups 0xc8(%rax), %xmm0
movaps %xmm0, -0x130(%rbp)
movaps %xmm0, 0x10(%r15)
movq 0xd8(%rax), %r14
movq %r14, 0x20(%r15)
leaq 0xaf3(%rip), %rsi       # 0x204e
movq %r12, %rdi
callq 0x17d8
leaq 0xb0f(%rip), %rdi       # 0x2079
callq 0x1810
movq %rax, (%r15)
movq %rdx, 0x8(%r15)
pushq $0x1
popq %rax
movl %eax, 0x28(%r15)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rbx)
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, 0x20(%rbx)
movaps %xmm0, 0x40(%rbx)
movaps %xmm0, 0x50(%rbx)
pushq $0x1
popq %rax
movq %rax, 0x30(%rbx)
callq 0x18d8
movq %rax, %r12
pushq $0x5
popq %rax
movl %eax, (%r12)
movq %r12, 0x38(%rbx)
movaps -0x130(%rbp), %xmm0
movaps %xmm0, 0x10(%rbx)
movq %r14, 0x20(%rbx)
leaq 0xabe(%rip), %rsi       # 0x2085
movq %r13, %rdi
callq 0x17d8
leaq 0xaca(%rip), %rdi       # 0x20a0
callq 0x1810
movq %rax, (%rbx)
movq %rdx, 0x8(%rbx)
pushq $0x1
popq %rax
movl %eax, 0x28(%rbx)
leaq -0x198(%rbp), %rdi
xorps %xmm0, %xmm0
movaps %xmm0, 0x18(%rdi)
movaps %xmm0, 0x8(%rdi)
movaps %xmm0, -0x8(%rdi)
movaps %xmm0, -0x18(%rdi)
movaps %xmm0, -0x28(%rdi)
andq $0x0, 0x28(%rdi)
leaq 0xac4(%rip), %r13       # 0x20d6
movq %r13, %rsi
callq 0x17d8
leaq -0x1b8(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x17d8
movw $0x101, %ax             # imm = 0x101
movw %ax, 0x48(%r14)
movw $0x1, %r14w
movw %r14w, -0x58(%rbp)
movl $0x3, -0x54(%rbp)
leaq 0xa98(%rip), %rdi       # 0x20e5
callq 0x1810
movq %rax, -0x50(%rbp)
movq %rdx, -0x48(%rbp)
andw $0x0, -0xb8(%rbp)
movabsq $0x5500000000, %rcx     # imm = 0x5500000000
movq %rcx, -0xb4(%rbp)
andw $0x0, -0xa0(%rbp)
movabsq $0x2f00000000, %rcx     # imm = 0x2F00000000
movq %rcx, -0x9c(%rbp)
movw %r14w, -0x88(%rbp)
movq %rax, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
leaq 0x60(%rsp), %rdi
leaq -0x1c0(%rbp), %rsi
pushq $0xb
popq %rcx
rep  movsq (%rsi), %es:(%rdi)
movq %rdx, 0x58(%rsp)
movups -0x88(%rbp), %xmm0
movups %xmm0, 0x48(%rsp)
movq -0x90(%rbp), %rax
movq %rax, 0x40(%rsp)
movups -0xa0(%rbp), %xmm0
movups %xmm0, 0x30(%rsp)
movq -0xa8(%rbp), %rax
movq %rax, 0x28(%rsp)
movups -0xb8(%rbp), %xmm0
movups %xmm0, 0x18(%rsp)
movq -0x48(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x58(%rbp), %xmm0
movups %xmm0, (%rsp)
andq $0x0, 0xc0(%rsp)
movq %rbx, 0xb8(%rsp)
leaq 0x1d6(%rip), %rsi       # 0x18ee
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
pushq $0x1
popq %rcx
movq %r15, %r8
movq %rcx, %r9
callq 0x1040
movw %r14w, -0x70(%rbp)
movabsq $0xf44d00000000, %rax   # imm = 0xF44D00000000
movq %rax, -0x6c(%rbp)
movq -0x60(%rbp), %rax
movq %rax, 0x10(%rsp)
movups -0x70(%rbp), %xmm0
movups %xmm0, (%rsp)
leaq 0x1e3(%rip), %rsi       # 0x193d
movq %rbx, %rdi
xorl %edx, %edx
callq 0x1100
leaq 0x293d(%rip), %rsi      # 0x40a8
movq %rbx, %rdi
callq 0x10d0
movl %eax, %r14d
movq -0x40(%rbp), %rdi
callq 0x19ed
movq %r12, %rdi
callq 0x19ed
movq %rbx, %rdi
callq 0x1120
leaq -0x168(%rbp), %rdi
callq *0x30(%rdi)
movl %r14d, %eax
addq $0x578, %rsp            # imm = 0x578
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq