#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

#include "log.h"
#include "trace_api.h"

void cb(trace_ret_t ret, void *arg)
{
    printf("reply valaue:%u\n", ret);
}


int main(int argc, char **argv)
{
    printf("1111\n");
   
    SYSLOG_INIT("test-client");
    trace_client_init();

    printf("argc num:%d\n", argc);
    int count = 1;
    if (argc >= 2) {
        count = atoi(argv[1]);
    }

    int async = 1;
    if (argc >= 3) {
        async = atoi(argv[2]);
    }
    
    for (int i = 0; i < count; i++) {
    
        trace_policy_t trace1 = {0};
        
        //trace1.src.addr.ip4.s_addr = i;
        trace1.dst.addr.ip4.s_addr = i;
        //memset(&trace1, 0, sizeof(trace1));
        trace1.src.family = TRACE_FAMILY_IP4;
        trace1.dst.family = TRACE_FAMILY_IP4;
        trace1.protocol = 30;

        if (async == 1) {
            printf("async exec\n");
            trace_async_exec(&trace1, cb, NULL);
        } else if (async == 2) {
            printf("exec no reply\n");
            trace_exec_no_reply(&trace1);
        } else {
            printf("sync exec\n");
            trace_sync_exec(&trace1);
            printf("sync final\n");
        }
        printf("send success\n");
    }

    //policy_client_exit();
    if (async != 3) {
        sleep(10);
    }
    trace_client_exit();

    return 0;
}