Example #1
0
void RUNTX(TPSVCINFO *p_svc)
{
    int first=1;
    UBFH *p_ub = (UBFH *)p_svc->data;
    char buf[1024];

    p_ub = (UBFH *)tprealloc ((char *)p_ub, Bsizeof (p_ub) + 4096);

    if (SUCCEED!=Bget(p_ub, T_STRING_FLD, 0, buf, 0))
    {
        NDRX_LOG(log_error, "TESTERROR: Failed to get T_STRING_FLD: %s",
                                          Bstrerror(Berror));
        tpreturn (TPFAIL, 0L, NULL, 0L, 0L);
    }
    
    if (SUCCEED!=__write_to_tx_file(buf))
    {
        NDRX_LOG(log_error, "TESTERROR: Failed to call __write_to_tx_file()");
        tpreturn (TPFAIL, 0L, NULL, 0L, 0L);
    }
    
    /* Return OK */
    tpreturn (TPSUCCESS, 0L, (char *)p_ub, 0L, 0L);
}
Example #2
0
/**
 * Initialize clock diff.
 * @param call
 * @return 
 */
public int br_calc_clock_diff(command_call_t *call)
{
    int ret=SUCCEED;
    n_timer_t our_time;
    cmd_br_time_sync_t *their_time = (cmd_br_time_sync_t *)call;
    
    /* So we have their time let timer lib, to get diff */
    n_timer_reset(&our_time);
    
    
    G_bridge_cfg.timediff = n_timer_diff(&their_time->time, &our_time);
    NDRX_LOG(log_warn, "Monotonic clock time correction between us "
            "and node %d is: %ld msec", 
            call->caller_nodeid, G_bridge_cfg.timediff);
    
    return ret;
}
Example #3
0
/**
 * Basic init data structure allocator
 * @param subtype
 * @param len
 * @return
 */
public char	* TPINIT_tpalloc (typed_buffer_descr_t *descr, long len)
{
    char *ret=NULL;
    char fn[] = "UBF_tpalloc";

    /* Allocate UBF buffer */
    ret=malloc(sizeof(TPINIT));

    if (NULL==ret)
    {
        NDRX_LOG(log_error, "%s: Failed to allocate TPINIT buffer!", fn);
        _TPset_error_fmt(TPEOS, "TPINIT failed to allocate: %d bytes", sizeof(TPINIT));
        goto out;
    }

out:
    return ret;
}
Example #4
0
/**
 * Push our node on call stack.
 * @param call
 * @return 
 */
public int br_tpcall_pushstack(tp_command_call_t *call)
{
    int ret=SUCCEED;
    char us = (char)G_bridge_cfg.nodeid;
    int len = strlen(call->callstack);
    
    if (len+1>CONF_NDRX_NODEID_COUNT)
    {
        NDRX_LOG(log_error, "Stack too deep! TODO: Reply with SYSERR back to caller!");
        FAIL_OUT(ret);
    }
    
    /* We are OK, just stack us */
    call->callstack[len] = us;
    call->callstack[len+1] = EOS;
    
    br_dump_nodestack(call->callstack, "Stack after node push");
out:
    return ret;
}
Example #5
0
/**
 * Dump node stack
 * @param stack
 */
public void br_dump_nodestack(char *stack, char *msg)
{
    int i=0;
    int nodeid;
    char node_stack_str[CONF_NDRX_NODEID_COUNT*4];
    node_stack_str[0] = EOS;
    char tmp[10];
    int len = strlen(stack);

    for (i=0; i<len; i++)
    {
        nodeid = stack[i];
        if (i+1!=len)
            sprintf(tmp, "%d->", nodeid);
        else
            sprintf(tmp, "%d", nodeid);
        strcat(node_stack_str, tmp);
    }
    NDRX_LOG(log_error, "%s: [%s]", msg, node_stack_str);

}
Example #6
0
/**
 * Internal initialization.
 * Here we will:
 * - Determine server name (binary)
 * - Determine client ID (1,2,3,4,5, etc...) (flag -i <num>)
 * @param argc
 * @param argv
 * @return  SUCCEED/FAIL
 */
int ndrx_init(int argc, char** argv)
{
    int ret=SUCCEED;
    extern char *optarg;
    extern int optind, optopt, opterr;
    int c;
    int dbglev;
    char *p;
    char key[NDRX_MAX_KEY_SIZE]={EOS};

    /* set pre-check values */
    memset(&G_server_conf, 0, sizeof(G_server_conf));
    /* Set default advertise all */
    G_server_conf.advertise_all = 1;
    G_server_conf.time_out = FAIL;
    
    /* Load common atmi library environment variables */
    if (SUCCEED!=ndrx_load_common_env())
    {
        NDRX_LOG(log_error, "Failed to load common env");
        ret=FAIL;
        goto out;
    }
    
    /* Parse command line, will use simple getopt */
    while ((c = getopt(argc, argv, "h?:D:i:k:e:rs:t:N--")) != FAIL)
    {
        switch(c)
        {
            case 'k':
                /* just ignore the key... */
                strcpy(key, optarg);
                break;
            case 's':
                ret=parse_svc_arg(optarg);
                break;
            case 'D': /* Not used. */
                dbglev = atoi(optarg);
                NDRX_DBG_SETLEV(dbglev);
                break;
            case 'i': /* server id */
                /*fprintf(stderr, "got -i: %s\n", optarg);*/
                G_server_conf.srv_id = atoi(optarg);
                break;
            case 'N':
                /* Do not advertise all services */
                G_server_conf.advertise_all = 0;
                break;
            case 'r': /* Not used. */
                /* Not sure actually what does this mean, but ok, lets have it. */
                G_server_conf.log_work = 1;
                break;
            case 'e':
            {
                FILE *f;
                strcpy(G_server_conf.err_output, optarg);

                /* Open error log, OK? */
                if (NULL!=(f=fopen(G_server_conf.err_output, "a")))
                {
                    /* Redirect stdout & stderr to error file */
                    close(1);
                    close(2);
                    dup(fileno(f));
                    dup(fileno(f));
                }
                else
                {
                    NDRX_LOG(log_error, "Failed to open error file: [%s]",
                            G_server_conf.err_output);
                }
            }
                break;
            case 't':
                /* Looks liek */
                G_server_conf.time_out = atoi(optarg);
                break;
            case 'h': case '?':
                fprintf(stderr, "usage: %s [-D dbglev] -i server_id [-N - do "
                        "not advertise servers]"
                        " [-sSERVER:ALIAS] [-sSERVER]\n",
                                argv[0]);
                goto out;
                break;
            /* add support for s */
        }
    }
    
    /* Override the timeout with system value, if FAIL i.e. -t was not present */
    if (FAIL==G_server_conf.time_out)
    {
        /* Get timeout */
        if (NULL!=(p=getenv("NDRX_TOUT")))
        {
            G_server_conf.time_out = atoi(p);
        }
        else
        {
            _TPset_error_msg(TPEINVAL, "Error: Missing evn param: NDRX_TOUT, "
                    "cannot determine default timeout!");
            ret=FAIL;
            goto out;
        }
    }

    NDRX_LOG(log_debug, "Using comms timeout: %d",
                                    G_server_conf.time_out);

    /* Validate the configuration */
    if (G_server_conf.srv_id<1)
    {
        _TPset_error_msg(TPEINVAL, "Error: server ID (-i) must be >= 1");
        ret=FAIL;
        goto out;
    }
    
    /*
     * Extract the binary name
     */
    p=strrchr(argv[0], '/');
    if (NULL!=p)
    {
        strncpy(G_server_conf.binary_name, p+1, MAXTIDENT);
    }
    else
    {
        strncpy(G_server_conf.binary_name, argv[0], MAXTIDENT);
    }

    G_server_conf.binary_name[MAXTIDENT] = EOS;

    /*
     * Read queue prefix (This is mandatory to have)
     */

    if (NULL==(p=getenv("NDRX_QPREFIX")))
    {
        _TPset_error_msg(TPEINVAL, "Env NDRX_QPREFIX not set");
        ret=FAIL;
        goto out;
    }
    else
    {
        strcpy(G_server_conf.q_prefix, p);
    }

    G_srv_id = G_server_conf.srv_id;
    
    /* Defaut number of events supported by e-poll */
    G_server_conf.max_events = 1;
    
out:
    return ret;
}
Example #7
0
/*
 * Do the test call to the server
 */
int main(int argc, char** argv) {

    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
    long rsplen;
    int i;
    int ret=SUCCEED;

    
    CBadd(p_ub, T_DOUBLE_FLD, "5", 0, BFLD_STRING);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);

    /* Do it many times...! */
    for (i=0; i<9900; i++)
    {
        ret=tppost("EVX.TEST", (char*)p_ub, 0L, TPSIGRSTRT);
        NDRX_LOG(log_debug, "dispatched events: %d", ret);
        if (ret!=6)
        {
            NDRX_LOG(log_error, "Applied event count is not 6 (which is %d)", ret);
            ret=FAIL;
            goto out;
        }
        else
        {
            NDRX_LOG(log_debug, "6 dispatches - OK");
        }
        
        if (i % 1000 == 0)
        {
            /* let services to flush the stuff... */
            NDRX_LOG(log_debug, "Dispatched %d - sleeping", i);
            sleep(10);
        }
    }

    ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);

    if (3!=ret)
    {
        NDRX_LOG(log_error, "TESTERROR: First post of TEST2EV did not return 3 (%d) ",
                                    ret);
        ret=FAIL;
        goto out;
    }
    sleep(10); /* << because server may not complete the unsubscribe! */
    ret=tppost("TEST2EV", (char*)p_ub, 0L, TPSIGRSTRT);
    if (0!=ret)
    {
        NDRX_LOG(log_error, "TESTERROR: Second post of TEST2EV did not return 0 (%d) ",
                                    ret);
        ret=FAIL;
        goto out;
    }

out:


    if (ret>=0)
        ret=SUCCEED;


    return ret;
}
Example #8
0
/**
 * Do de-initialization
 */
void NDRX_INTEGRA(tpsvrdone)(void)
{
    NDRX_LOG(log_debug, "tpsvrdone called");
}
Example #9
0
/*
 * Do the test call to the server
 */
int main(int argc, char** argv) {

    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
    long rsplen;
    int i;
    int ret=SUCCEED;
    double d;
    double dv = 55.66;
    int cd;
    long revent;
    int received = 0;
    char tmp[126];

    
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 1", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 2", 0);
    Badd(p_ub, T_STRING_FLD, "THIS IS TEST FIELD 3", 0);


    if (FAIL==(cd=tpconnect("CONVSV", (char *)p_ub, 0L, TPRECVONLY)))
    {
            NDRX_LOG(log_error, "TESTSV connect failed!: %s",
                                    tpstrerror(tperrno));
            ret=FAIL;
            goto out;
    }

    /* Recieve the stuff back */
    NDRX_LOG(log_debug, "About to tprecv!");

    while (SUCCEED==tprecv(cd, (char **)&p_ub, 0L, 0L, &revent))
    {
        received++;
        NDRX_LOG(log_debug, "MSG RECEIVED OK!");
    }
    

    /* If we have event, we would like to become recievers if so */
    if (TPEEVENT==tperrno)
    {
        received++;
        sprintf(tmp, "CLT: %d", received);
        
        Badd(p_ub, T_STRING_FLD, tmp, 0L);
        if (TPEV_SENDONLY==revent)
        {
            int i=0;
            /* Start the sending stuff now! */
            for (i=0; i<100 && SUCCEED==ret; i++)
            {
                ret=tpsend(cd, (char *)p_ub, 0L, 0L, &revent);
            }
        }
    }

    /* Now give the control to the server, so that he could finish up */
    if (FAIL==tpsend(cd, NULL, 0L, TPRECVONLY, &revent))
    {
        NDRX_LOG(log_debug, "Failed to give server control!!");
        ret=FAIL;
        goto out;
    }

    NDRX_LOG(log_debug, "Get response from tprecv!");
    Bfprint(p_ub, stderr);

    /* Wait for return from server */
    ret=tprecv(cd, (char **)&p_ub, 0L, 0L, &revent);
    NDRX_LOG(log_error, "tprecv failed with revent=%ld", revent);

    if (FAIL==ret && TPEEVENT==tperrno && TPEV_SVCSUCC==revent)
    {
        NDRX_LOG(log_error, "Service finished with TPEV_SVCSUCC!");
        ret=SUCCEED;
    }
    
    if (SUCCEED!=tpterm())
    {
        NDRX_LOG(log_error, "tpterm failed with: %s", tpstrerror(tperrno));
        ret=FAIL;
        goto out;
    }
    
out:
    return ret;
}
Example #10
0
/*
 * Do the test call to the server
 */
int main(int argc, char** argv) {

    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, 1024);
    long rsplen;
    int ret=SUCCEED;
    char buf[128]={EOS};
    
    if (0==strcmp(argv[1], "DOADV"))
    {
        if (FAIL == tpcall("DOADV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
        {
            NDRX_LOG(log_error, "TESTERROR: DOADV failed: %s", tpstrerror(tperrno));
            ret=FAIL;
            goto out;
        }
    }
    else if (0==strcmp(argv[1], "UNADV"))
    {
        if (FAIL == tpcall("UNADV", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
        {
            NDRX_LOG(log_error, "TESTERROR: UNADV failed: %s", tpstrerror(tperrno));
            ret=FAIL;
            goto out;
        }
    }
    else if (0==strcmp(argv[1], "TEST"))
    {
        if (FAIL == tpcall("TESTSVFN", (char *)p_ub, 0L, (char **)&p_ub, &rsplen,0))
        {
            NDRX_LOG(log_error, "TESTSVFN failed: %s", tpstrerror(tperrno));
            ret=FAIL;
            goto out;
        }
        /* Verify the data */
        if (FAIL==Bget(p_ub, T_STRING_FLD, 0, (char *)buf, 0))
        {
            NDRX_LOG(log_debug, "Failed to get T_STRING_FLD[0]");
            ret=FAIL;
            goto out;
        }
        else if (0!=strcmp(buf, "THIS IS TEST - OK!"))
        {
            NDRX_LOG(log_debug, "Call test failed");
            ret=FAIL;
            goto out;
        }
    }
    else
    {
        NDRX_LOG(log_error, "ERROR: Invalid command, valid ones are: DOADV, UNADV, TEST");
                
        ret=FAIL;
        goto out;
    }

out:
    /* Terminate the session */
    tpterm();

    return ret;
}