Example #1
0
/**
 * Do initialization
 */
int tpsvrinit(int argc, char **argv)
{
    char svcnm[16];
    int i;
    int ret = SUCCEED;
    NDRX_LOG(log_debug, "tpsvrinit called");
    
    
    if (SUCCEED!=tpopen())
    {
        NDRX_LOG(log_error, "TESTERROR: tpopen() fail: %d:[%s]", 
                                            tperrno, tpstrerror(tperrno));
        ret=FAIL;
        goto out;
    }

    if (SUCCEED!=tpadvertise("RUNTX", RUNTX))
    {
        NDRX_LOG(log_error, "Failed to initialize RUNTX!");
    }
    
    if (SUCCEED!=tpadvertise("RUNTXFAIL", RUNTXFAIL))
    {
        NDRX_LOG(log_error, "Failed to initialize RUNTXFAIL!");
    }

    if (SUCCEED!=tpadvertise("NOTRANFAIL", NOTRANFAIL))
    {
        NDRX_LOG(log_error, "Failed to initialize NOTRANFAIL!");
    }
    
out:
    return ret;
}
Example #2
0
/**
 * Initialize the application
 * @param argc	argument count
 * @param argv	argument values
 * @return SUCCEED/FAIL
 */
int init(int argc, char** argv)
{
	int ret = SUCCEED;

	TP_LOG(log_info, "Initialising...");

	if (SUCCEED!=tpinit(NULL))
	{
		TP_LOG(log_error, "Failed to Initialise: %s", 
			tpstrerror(tperrno));
		ret = FAIL;
		goto out;
	}
	

	
	/* Advertise our service */
	if (SUCCEED!=tpadvertise(msg_service(), USERREGSV))
	{
		TP_LOG(log_error, "Failed to initialise USERREGSV_UBF!");
		ret=FAIL;
		goto out;
	}	

out:

	
	return ret;
}
Example #3
0
/**
 * Do de-initialization
 */
void tpsvrdone(void)
{
    NDRX_LOG(log_debug, "tpsvrdone called");
    if (SUCCEED!=tpclose())
    {
        NDRX_LOG(log_error, "TESTERROR: tpclose() fail: %d:[%s]", 
                                            tperrno, tpstrerror(tperrno));
    }
}
Example #4
0
void GenericTuxedoClient::allocFieldBuffer(FieldMode fm) throw (BufferHandlingException)
{
	if (fm != PARM_IN && fm != PARM_OUT && fm != PARM_INOUT) {
		throw BufferHandlingException(
			"O modo do parametro deve ser PARM_IN, PARM_OUT ou PARM_INOUT");
	}

	if ((fm & PARM_IN) == PARM_IN) {
		iFieldBuffer = (FBFR_1632 *) tpalloc(FMLTYPE_1632, NULL, getBuffNeededSpace(PARM_IN));
		if (iFieldBuffer == NULL)
			throw BufferHandlingException(tpstrerror(tperrno));
	}

	if ((fm & PARM_OUT) == PARM_OUT) {
		oFieldBuffer = (FBFR_1632 *) tpalloc(FMLTYPE_1632, NULL, getBuffNeededSpace(PARM_OUT));
		if (oFieldBuffer == NULL)
			throw BufferHandlingException(tpstrerror(tperrno));
	}
}
Example #5
0
/**
 * Call the client process monitor with command
 * @return
 */
private int call_cpm(char *svcnm, char *cmd, char *tag, char *subsect)
{
    UBFH *p_ub = (UBFH *)tpalloc("UBF", NULL, CPM_DEF_BUFFER_SZ);
    int ret=SUCCEED;
    long rsplen;
    char output[CPM_OUTPUT_SIZE];
    
    /* Setup the call buffer... */
    if (NULL==p_ub)
    {
        NDRX_LOG(log_error, "Failed to alloc FB!");        
        FAIL_OUT(ret);
    }
    
    if (SUCCEED!=Bchg(p_ub, EX_CPMTAG, 0, tag, 0L))
    {
        NDRX_LOG(log_error, "Failed to set EX_CPMCOMMAND to %s!", tag);        
        FAIL_OUT(ret);
    }
    
    if (SUCCEED!=Bchg(p_ub, EX_CPMSUBSECT, 0, subsect, 0L))
    {
        NDRX_LOG(log_error, "Failed to set EX_CPMSUBSECT to %s!", subsect);        
        FAIL_OUT(ret);
    }
    
    if (SUCCEED!=Bchg(p_ub, EX_CPMCOMMAND, 0, cmd, 0L))
    {
        NDRX_LOG(log_error, "Failed to set EX_CPMCOMMAND to %s!", cmd);
        FAIL_OUT(ret);
    }
    
    /* Call the client admin */
    if (FAIL==(ret=tpcall(svcnm, (char *)p_ub, 0L, (char **)&p_ub, &rsplen, 0L)))
    {
        fprintf(stderr, "%s\n", tpstrerror(tperrno));
    }
    
    /* print the stuff we got from CPM. */
    if (SUCCEED==Bget(p_ub, EX_CPMOUTPUT, 0, (char *)output, 0L))
    {
        fprintf(stdout, "%s\n", output);
    }

out:

    if (NULL!=p_ub)
    {
        tpfree((char *)p_ub);
    }

    return ret;
}
Example #6
0
/**
 * Service entry
 * @return SUCCEED/FAIL
 */
void USERREGSV (TPSVCINFO *p_svc)
{
    int ret = SUCCEED;
    int rsp = 0;
    Message_t msg;
    long len;
    char * buf = p_svc->data;

    memset(&msg, 0, sizeof(msg));
    
    /* allocate some stuff for more data to put in  */
    
    len = tptypes(p_svc->data, NULL, NULL) + 1024;
    
    if (NULL==(buf = tprealloc(buf, len)))
    {
	TP_LOG(log_error, "Failed reallocate buffer to size %d: %s", 
                len, tpstrerror(tperrno));
	ret=FAIL;
	goto out;
    }

    if (SUCCEED != parse_msg(&msg, buf, len))
    {
	TP_LOG(log_error, "Failed to parse msg");
	ret=FAIL;
	goto out;
	    
    }
    
    msg.rsp.rspstatus = 100;
    strcpy(msg.rsp.rsprspmsg, "User successfully registered");
    
    if(SUCCEED != msg_build(&msg, &buf, &len))
    {
	TP_LOG(log_error, "Failed to build msg");
	ret=FAIL;
	goto out;
    }

out:

    tpreturn(  ret==SUCCEED?TPSUCCESS:TPFAIL,
            0L,
            buf,
            0L,
            0L);


}
Example #7
0
void GenericTuxedoClient::connect(const string &srvAddr, const string &srvPort)
throw(TPConnectionException)
{
	// codigo que da tpinit no Tuxedo sem nenhuma autenticacao
	// NOTA: sobrecarregar este metodo para os casos possiveis de autenticacao

	if (connected)
		throw TPConnectionException("Ja esta conectado ao TP Monitor");

	if (! srvAddr.empty() && ! srvPort.empty()) {
		checkEnvVar("WSNADDR", "//" + srvAddr + ":" + srvPort);
	}

    if (tpinit((TPINIT *)NULL) < 0)
		throw TPConnectionException(
			string("Falha na conexao ao TP Monitor - ").append(tpstrerror(tperrno)));

	connected = true;
}
Example #8
0
int
main(int argc, char* argv[])
{
	DB *dbp3;
	DBT key, data;
	TPINIT *initBuf;
        FBFR *replyBuf;
	long replyLen;
	int ch, ret, i;
	char *target;
	char *home = HOME;
	u_int32_t flags = DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN |
	  DB_INIT_LOCK | DB_CREATE | DB_THREAD | DB_RECOVER | DB_REGISTER;
	u_int32_t dbflags = DB_CREATE | DB_THREAD;

	progname = argv[0];

	initBuf = NULL;
        ret = 0;
        replyBuf = NULL;
        replyLen = 1024;

	while ((ch = getopt(argc, argv, "v")) != EOF)
		switch (ch) {
		case 'v':
			verbose = 1;
			break;
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	if (verbose)
		printf("%s: called\n", progname);

	if (tpinit((TPINIT *)NULL) == -1)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpinit() OK\n", progname);

	/* Create the DB environment. */
	if ((ret = db_env_create(&dbenv, 0)) != 0 ||
	    (ret = dbenv->open(dbenv, home, flags, 0)) != 0) {
		fprintf(stderr,
		    "%s: %s: %s\n", progname, home, db_strerror(ret));
		goto err;
	}
	dbenv->set_errfile(dbenv, stderr);
	if (verbose)
		printf("%s: opened %s OK\n", progname, home);

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));

        /* Allocate reply buffer. */
	if ((replyBuf = (FBFR*)tpalloc("FML32", NULL, replyLen)) 
	    == NULL) 
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"FML32\"), reply buffer OK\n", 
		    progname);
	for (i = 0; i < 2; i++) {
        	if (tpbegin(10L, 0L) == -1)
			goto tuxedo_err;
		if (verbose)
			printf("%s: tpbegin() OK\n", progname);

		if (tpcall("TestTxn1", NULL, 0L, (char **)&replyBuf, 
		    &replyLen, TPSIGRSTRT) == -1) 
			goto tuxedo_err;

        	/* This call will timeout. */
        	tpcall("TestTxn2", NULL, 0L, (char **)&replyBuf, &replyLen, 
            	    TPSIGRSTRT);
        	if (tperrno != TPETIME)
	        	goto tuxedo_err;

		if (i == 0) {
			if (tpabort(0L) == -1)
				goto tuxedo_err;
			if (verbose)
				printf("%s: tpabort() OK\n", progname);
		} else {
		  	/* Commit will fail due to the time out. */
			tpcommit(0L);
			if (tperrno != TPEABORT)
				goto tuxedo_err;
			if (verbose)
				printf("%s: tpcommit() OK\n", progname);
		}


		ret = check_data(dbenv, TABLE1, dbenv, TABLE2, progname);
	}

	if (0) {
tuxedo_err:	fprintf(stderr, "%s: TUXEDO ERROR: %s (code %d)\n",
		    progname, tpstrerror(tperrno), tperrno);
		goto err;
	}
	if (0) {
err:		ret = EXIT_FAILURE;
	}

	if (replyBuf != NULL)
		tpfree((char *)replyBuf);
	if (dbenv != NULL)
		(void)dbenv->close(dbenv, 0);

	tpterm();
	if (verbose)
		printf("%s: tpterm() OK\n", progname);

 	if (verbose && ret == 0)
		printf("%s: test passed.\n", progname);
	else if (verbose)
 		printf("%s: test failed.\n", progname);
	return (ret);
}
Example #9
0
/**
 * Build outgoing message
 * @param[in] msg full message to send
 * @param[out] outbuf output buffer/XATMI allocated
 * @param[out] olen output buffer len
 * @return SUCCEED/FAIL
 */
int msg_build(Message_t *msg, char **outbuf, long *olen)
{
    int ret = SUCCEED;
    msgbuilder_t *p = M_msgflds;
    short *p_short;
    long *p_long;
    void *fld_ptr;
    char *p_string_el;
    char tmpbuf[64];
    char tmpbuf2[64];
    xmlDocPtr   newDoc;
    xmlNodePtr  rootNode;
    short *p_items;
    int i;
    xmlChar *xmlDocInMemory = NULL;
    int		size = 0;
    
    /* Alloc STRING into obuf */
    if (NULL==*outbuf)
    {
        *outbuf = tpalloc("STRING", NULL, MAX_BUFSZ);
    }
    
    if (NULL==*outbuf)
    {
       TP_LOG(log_error, "Failed to alloc %d bytes: %s", 
			MAX_BUFSZ, tpstrerror(tperrno)); 
       ret=FAIL;
       goto out;
    }
    
    /* start libxml2 XML doc */
    
    newDoc = xmlNewDoc( BAD_CAST XML_VERSION );
    rootNode = xmlNewNode(NULL, BAD_CAST "user");
    xmlDocSetRootElement(newDoc, rootNode);
            
    while (0!=p->tag[0])
    {
        fld_ptr = (char *)msg + p->msgoffs + p->elmoffs;
                
        switch (p->elmtyp)
        {
            case MSG_SHORT:
                p_short =  (short *)fld_ptr;
                snprintf(tmpbuf, sizeof(tmpbuf), "%hd", *p_short);
                xmlNewTextChild( rootNode, NULL, BAD_CAST p->tag, BAD_CAST tmpbuf );
                break;
            case MSG_LONG:
                p_long =  (long *)fld_ptr;
                snprintf(tmpbuf, sizeof(tmpbuf), "%ld", *p_long);
                xmlNewTextChild( rootNode, NULL, BAD_CAST p->tag, BAD_CAST tmpbuf );
                break;
            case MSG_STRING:
                xmlNewTextChild( rootNode, NULL, BAD_CAST p->tag, 
                        BAD_CAST ((char *)fld_ptr) );
                break;
            case MSG_ARRAY_SHORT:
                
                p_items = (short *)((char *)msg + p->msgoffs + p->itmoffs);
                
                for (i=0; i<*p_items; i++)
                {
                    p_short = (short *)( (char *)fld_ptr + i*sizeof(short));
                    snprintf(tmpbuf, sizeof(tmpbuf), "%hd", *p_short);
                    
                    snprintf(tmpbuf2, sizeof(tmpbuf), "%s_%d", p->tag, i);
                    xmlNewTextChild( rootNode, NULL, BAD_CAST tmpbuf2, 
                            BAD_CAST tmpbuf );
                }
                
                break;
            case MSG_ARRAY_STRING:
                
                p_items = (short *)((char *)msg + p->msgoffs + p->itmoffs);
                
                for (i=0; i<*p_items; i++)
                {
                    /* calculate string array element location */
                    p_string_el = (char *)fld_ptr + i*MAX_STR;
                    
                    snprintf(tmpbuf2, sizeof(tmpbuf), "%s_%d", p->tag, i);
                    xmlNewTextChild( rootNode, NULL, BAD_CAST tmpbuf2, 
                            BAD_CAST p_string_el );
                }
                
                break;
            default:
                TP_LOG(log_error, "Unknown element type %d tag: [%s]!", 
                        p->elmtyp, p->tag);
                ret=FAIL;
                goto out;
                break;
        }
        
        p++;
    }
    
    /* build xmldoc, copy to outbuf, specify size */
    xmlDocDumpMemory( newDoc, &xmlDocInMemory, &size );
    strncpy(*outbuf, xmlDocInMemory, size);
    (*outbuf)[size] = 0;
    *olen = size+1;
    xmlFree(xmlDocInMemory);
    
    TP_LOG(log_debug, "got XML [%s]", *outbuf);
    
out:
    if (NULL != newDoc)
    {
        xmlFreeDoc( newDoc );
    }
    return ret;
}
Example #10
0
  const char *atmi_exception::what() const throw(){
#else
  const char *atmi_exception::what() const noexcept {
#endif

    return (_what.size() > 0 ) ? _what.c_str() : _message.c_str();
  }

#if __cplusplus < 201103L
  const char *atmi_exception::message() throw () {
#else
  const char *atmi_exception::message() const noexcept {
#endif

    return _message.c_str();
  }


  // unix_exception ----------------------------------------
  //

  unix_exception::unix_exception (): _error(errno), atmi_exception(strerror (errno)) {
  }

  int unix_exception::error () const {

    return _error;
  }

  // buffer_exception ---------------------------------------
  //

  buffer_exception::buffer_exception (): _error(Ferror32), atmi_exception("FML buffer error occured.") {
  }

  int buffer_exception::error () const {

    return _error;
  }

  const char *buffer_exception::error_message () const {

    return Fstrerror32 ( _error );
  }

  // tuxedo_exception --------------------------------------
  //

  const char *tuxedo_exception::error_detail () const {
    return tpstrerrordetail(_detail, 0);
  }

  const char *tuxedo_exception::error_message () const {

    return tpstrerror ( _error );
  }


  // /Q related exceptions ---------------------------------------------------------
  //
  // diagnostic exception -----------------------------------
  //

  const char *diagnostic_exception::diagnostic_message () const {
    switch ( _diagno ) {
      case QMEINVAL:
        return "QMEINVAL: An invalid flag value was specified.";

      case QMEBADRMID:
        return "QMEBADRMID: An invalid resource manager identifier was specified.";

      case QMENOTOPEN:
        return "QMENOTOPEN: The resource manager is not currently open.";

      case QMETRAN:
        return "QMETRAN: Failed to start transaction to enqueue/dequeue a message.";

      case QMEBADMSGID:
        return "QMEBADMSGID: An invalid message identifier was specified.";

      case QMESYSTEM:
        return "QMESYSTEM: A system error occurred. The exact nature of the error is written to a log file.";

      case QMEOS:
        return "QMEOS: An operating system error occurred.";

      case QMEABORTED:
        return "QMEABORTED: The operation was aborted.";

      case QMEPROTO:
        return "QMEPROTO: An enqueue was done when the transaction state was not active.";

      case QMEBADQUEUE:
        return "QMEBADQUEUE: An invalid or deleted queue name was specified.";

      case QMENOSPACE:
        return "QMENOSPACE: insufficient resource, such as no space on the queue.";

      case QMERELEASE:
        return "QMERELEASE: System does not support a newer feature.";

      case QMESHARE:
        return "QMESHARE: The queue is already opened for exclusive read and/or write.";

      default:
        return "Never heard about this diagno !!??";
    }
  }
}
Example #11
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 #12
0
int
main(int argc, char* argv[])
{
	DB *dbp2;
	DBT key, data;
	FBFR *buf, *replyBuf;
	HDbRec rec;
	TPINIT *initBuf;
        DB_ENV *dbenv2, *dbenv1;
	long len, replyLen, seqNo;
	int ch, cnt, cnt_abort, cnt_commit, cnt_server1, i, ret;
	char *target;
	char *home = HOME;
	u_int32_t flags = DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_TXN |
	  DB_INIT_LOCK | DB_CREATE | DB_RECOVER | DB_REGISTER;
	u_int32_t dbflags = DB_CREATE;

	progname = argv[0];

	dbenv2 = dbenv1  = NULL;
	dbp2 = NULL;
	buf = replyBuf = NULL;
	initBuf = NULL;
	cnt = 1000;
	cnt_abort = cnt_commit = cnt_server1 = 0;

	while ((ch = getopt(argc, argv, "n:v")) != EOF)
		switch (ch) {
		case 'n':
			cnt = atoi(optarg);
			break;
		case 'v':
			verbose = 1;
			break;
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	if (verbose)
		printf("%s: called\n", progname);

	/* Seed random number generator. */
	srand((u_int)(time(NULL) | getpid()));

	if (tpinit((TPINIT *)NULL) == -1)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpinit() OK\n", progname);

	/* Allocate init buffer */
	if ((initBuf = (TPINIT *)tpalloc("TPINIT", NULL, TPINITNEED(0))) == 0)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"TPINIT\") OK\n", progname);

	/* Create the DB environment. */
	if ((ret = db_env_create(&dbenv2, 0)) != 0 ||
	    (ret = dbenv2->open(dbenv2, home, flags, 0)) != 0) {
		fprintf(stderr,
		    "%s: %s: %s\n", progname, home, db_strerror(ret));
		goto err;
	}
	dbenv2->set_errfile(dbenv2, stderr);
	if (verbose)
		printf("%s: opened %s OK\n", progname, home);

	/* 
	 * Open table #2 -- Data is inserted into table 1 using XA
	 * transactions, and inserted into table 2 using regular transactions.
	 */
	if ((ret = db_create(&dbp2, dbenv2, 0)) != 0 ||
	    (ret = dbp2->open(dbp2,
	    NULL, TABLE2, NULL, DB_BTREE, dbflags, 0660)) != 0) {
		fprintf(stderr,
		    "%s: %s %s\n", progname, TABLE2, db_strerror(ret));
		goto err;
	}
	if (verbose)
		printf("%s: opened %s OK\n", progname, TABLE2);

	/* Allocate send buffer. */
	len = Fneeded(1, 3 * sizeof(long));
	if ((buf = (FBFR*)tpalloc("FML32", NULL, len)) == 0)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"FML32\"), send buffer OK\n", progname);

	/* Allocate reply buffer. */
	replyLen = 1024;
	if ((replyBuf = (FBFR*)tpalloc("FML32", NULL, replyLen)) == NULL)
		goto tuxedo_err;
	if (verbose)
		printf("%s: tpalloc(\"FML32\"), reply buffer OK\n", progname);

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));
	for (rec.SeqNo = 1, i = 0; i < cnt; ++i, ++rec.SeqNo) {
		GetTime(&rec.Ts);

		if (Fchg(buf, SEQ_NO, 0, (char *)&rec.SeqNo, 0) == -1)
			goto tuxedo_fml_err;
		if (verbose)
			printf("%s: Fchg(), sequence number OK\n", progname);
		if (Fchg(buf, TS_SEC, 0, (char *)&rec.Ts.Sec, 0) == -1)
			goto tuxedo_fml_err;
		if (verbose)
			printf("%s: Fchg(), seconds OK\n", progname);
		if (Fchg(buf, TS_USEC, 0, (char *)&rec.Ts.Usec, 0) == -1)
			goto tuxedo_fml_err;
		if (verbose)
			printf("%s: Fchg(), microseconds OK\n", progname);

		if (tpbegin(60L, 0L) == -1)
			goto tuxedo_err;
		if (verbose)
			printf("%s: tpbegin() OK\n", progname);

		/* Randomly send half of our requests to each server. */
		if (rand() % 2 > 0) {
			++cnt_server1;
			target = "TestTxn1";
		} else
			target = "TestTxn2";
		if (tpcall(target, (char *)buf,
		    0L, (char **)&replyBuf, &replyLen, TPSIGRSTRT) == -1)
			goto tuxedo_err;
		/* Commit for a return value of 0, otherwise abort. */
		if (tpurcode == 0) {
			++cnt_commit;
			if (verbose)
				printf("%s: txn success\n", progname);

			if (tpcommit(0L) == -1)
				goto abort;
			if (verbose)
				printf("%s: tpcommit() OK\n", progname);

			/*
			 * Store a copy of the key/data pair into table #2
			 * on success, we'll compare table #1 and table #2
			 * after the run finishes.
			 */
			seqNo = rec.SeqNo;
			key.data = &seqNo;
			key.size = sizeof(seqNo);
			data.data = &seqNo;
			data.size = sizeof(seqNo);
			if ((ret =
			    dbp2->put(dbp2, NULL, &key, &data, 0)) != 0) {
				fprintf(stderr, "%s: DB->put: %s %s\n",
				    progname, TABLE2, db_strerror(ret));
				goto err;
			}
		} else {
 abort:			++cnt_abort;
			if (verbose)
				printf("%s: txn failure\n", progname);

			if (tpabort(0L) == -1)
				goto tuxedo_err;
			if (verbose)
				printf("%s: tpabort() OK\n", progname);
		}
	}

	printf("%s: %d requests: %d committed, %d aborted\n",
	    progname, cnt, cnt_commit, cnt_abort);
	printf("%s: %d sent to server #1, %d sent to server #2\n",
	    progname, cnt_server1, cnt - cnt_server1);

	/* Check that database 1 and database 2 are identical. */
	if (dbp2 != NULL)
		(void)dbp2->close(dbp2, 0);
	dbp2 = NULL;
	if ((ret = db_env_create(&dbenv1, 0)) != 0 ||
	    (ret = dbenv1->open(dbenv1, "../data", flags, 0)) != 0) 
		goto err;
	ret = check_data(dbenv1, TABLE1, dbenv2, TABLE2, progname);

	if (0) {
tuxedo_err:	fprintf(stderr, "%s: TUXEDO ERROR: %s (code %d)\n",
		    progname, tpstrerror(tperrno), tperrno);
		goto err;
	}
	if (0) {
tuxedo_fml_err:	fprintf(stderr, "%s: FML ERROR: %s (code %d)\n",
		    progname, Fstrerror(Ferror), Ferror);
	}
	if (0) {
err:		ret = EXIT_FAILURE;
	}

	if (replyBuf != NULL)
		tpfree((char *)replyBuf);
	if (buf != NULL)
		tpfree((char *)buf);
	if (initBuf != NULL)
		tpfree((char *)initBuf);
	if (dbp2 != NULL)
		(void)dbp2->close(dbp2, 0);
	if (dbenv1 != NULL)
		(void)dbenv1->close(dbenv1, 0);
	if (dbenv2 != NULL)
		(void)dbenv2->close(dbenv2, 0);

	tpterm();
	if (verbose)
		printf("%s: tpterm() OK\n", progname);

	return (ret);
}
Example #13
0
void GenericTuxedoClient::run(const string &svcName)
throw(TPFatalException,BufferHandlingException)
{
	if (! connected)
		throw TPFatalException("Nao conectado ao TP Monitor");


	try {
		allocFieldBuffer(PARM_IN);
		allocFieldBuffer(PARM_OUT);
	} catch (BufferHandlingException ex) {
		cout << ex.what();
		throw;
	}

	long succCount = 0, failCount = 0;
	int consecFails = 0;

	while (true) {
		try {
			int result;
			long sizeOfOutBuffer;
			ostringstream fmt;

			populateInputFieldBuffer();
#ifdef _MY_DEBUG
			cout << "svcName=" << svcName.c_str() << "\n";
			cout << "iFieldBuffer: INICIO\n";
			Fprint_1632(iFieldBuffer);
			cout << "iFieldBuffer: FINAL\n";
#endif
			result = tpcall(const_cast<char *>(svcName.c_str()),
							reinterpret_cast<char *>(iFieldBuffer),
							0,
							reinterpret_cast<char **>(&oFieldBuffer),
							&sizeOfOutBuffer,
							TPSIGRSTRT || TPNOTIME);

#ifdef _SHOW_OUTPUT
			cout << "oFieldBuffer: INICIO\n";
			Fprint_1632(oFieldBuffer);
			cout << "oFieldBuffer: FINAL\n";
#endif

			if (result < 0) {
				if (tperrno == TPESVCFAIL || tperrno == TPETIME) {
					if (maxConsecFails > 0 && consecFails >= maxConsecFails) {
						disconnect();
						deleteFieldBuffer(PARM_INOUT);
						fmt << (succCount + failCount + 1) << ": "
							 << "Numero maximo de erros consecutivos chegou ao limite("
							 << maxConsecFails << ")\n";
						break;
					}
					failCount++;
					consecFails++;
					if (tperrno == TPESVCFAIL)
						fmt << "ERRO DE NEGOCIO\n";
					else /* if (tperrno == TPETIME) */
						fmt << "TEMPO ESGOTADO\n";

				} else {
//					cout << tpstrerror(tperrno) << endl;
					fmt.clear();
					fmt << "Erro fatal em run(): " << tpstrerror(tperrno);
					disconnect();
					deleteFieldBuffer(PARM_INOUT);
					throw TPFatalException(fmt.str());
				}
			} else {
				succCount++;
				consecFails = 0;
//				fmt << "OK\n";
			}

			if (!quietMode) {
				if (batchMode) cout << "** " << (succCount + failCount) << ": ";
				cout << fmt.str();
				fmt.str("");
			}

			retrieveOutputFields();
#ifdef _SHOW_OUTPUT
//			showFields(PARM_OUT);
			showFields(PARM_INOUT);
#endif

			if (batchMode && ! endOfBatch) {
				cout << endl;
				recycleOutputFields();
				continue;
			}

			break;
		} catch (...) {
			throw;
		}
	}

	if (batchMode && ! quietMode) {
		cout << "\nEstatisticas de " << svcName << endl;
		cout << "\nCasos de sucesso : " << succCount << endl;
		cout << "Casos de erro    : " << failCount << endl;
	}

	deleteFieldBuffer(PARM_INOUT);
}
Example #14
0
void GenericTuxedoClient::retrieveOutputFields(void) throw (BufferHandlingException)
{
	FLDID_1632  fldId;
	FLDOCC_1632 fldOcc;
	FLDLEN_1632 fldLen;

/*
		cout << "oFieldBuffer possui " << Fnum(oFieldBuffer) << " campos\n";

		FLDID fieldid;
		FLDOCC occurrence;
		char val[1000];
		FLDLEN len;

		for( fieldid=FIRSTFLDID, len=sizeof(val);
			 Fnext(oFieldBuffer, &fieldid, &occurrence, val, &len) > 0;
			 len=sizeof(val))
		{
			cout << Fname(fieldid) << "(" << fieldid << ":" << occurrence << ") = [";
			cout << string(val,len) << "]\n";
		}
*/

#ifdef _DEBUG
		cout << "\n\nDISPLAY em retrieveOutputFields: INICIO\n";
		Fprint_1632(oFieldBuffer);
		cout << "DISPLAY em retrieveOutputFields: FINAL\n";
#endif

	for (FieldRepMap::iterator it1 = outFieldsMap.begin();
		 it1 != outFieldsMap.end(); it1++)
	{
		// força a limpeza da lista de valores do campo
		fldId = it1->first;
//		it1->second.erase(it1->second.begin(),it1->second.end());
		it1->second.clear();
		fldOcc = Foccur_1632(oFieldBuffer, fldId);

		if (fldOcc < 0) throw BufferHandlingException(tpstrerror(tperrno));
		if (fldOcc == 0) continue;

		for (FLDOCC_1632 occ = 0; occ < fldOcc; occ++) {

			ostringstream fmt;
			char *value;

			if((value = Ffind_1632(oFieldBuffer, fldId, occ, &fldLen)) == NULL)
				throw BufferHandlingException(tpstrerror(tperrno));

			switch(Fldtype_1632(fldId)) {
			case FLD_SHORT:

				fmt << reinterpret_cast<short *>(value);
				break;

			case FLD_LONG:

				fmt << reinterpret_cast<long *>(value);
				break;

			case FLD_CHAR:

				fmt << reinterpret_cast<char *>(value);
				break;

			case FLD_FLOAT:

				fmt << reinterpret_cast<float *>(value);
				break;

			case FLD_DOUBLE:

				fmt << reinterpret_cast<double *>(value);
				break;

			case FLD_STRING:
			case FLD_CARRAY:

				fmt << string(value, fldLen);
				break;

			}

			it1->second.push_back(FieldAttr(fldLen, fmt.str()));

			if (batchMode && it1->first == batchCtrlField && fmt.str() == valueToStopBatch)
				endOfBatch = true;
		}
	}
}
Example #15
0
void GenericTuxedoClient::populateInputFieldBuffer(void)
throw(BufferNotFieldedException,BufferHandlingException,InvalidNumberFormatException)
{
	if (! Fielded_1632(iFieldBuffer)) {
		throw BufferNotFieldedException("Buffer FML nao inicializado");
	}

	clearFieldBuffer(PARM_IN);

	for (FieldRepMap::iterator it1 = inFieldsMap.begin();
		 it1 != inFieldsMap.end(); it1++)
	{
		// Popula o buffer com as ocorrĂȘncias do campo atual
		for (FieldAttrVector::iterator it2 = it1->second.begin();
			 it2 != it1->second.end(); it2++)
		{
			int result;
			istringstream fmt;

			fmt.str(it2->getValue());

			switch(Fldtype_1632(it1->first)) {

			case FLD_SHORT:
			{
				short value;
				try {
					fmt >> value;
				} catch(...) {
					throw InvalidNumberFormatException("Valor invalido para o tipo short: " + fmt.str());
				}
				result = Fappend_1632(iFieldBuffer, it1->first,
								 reinterpret_cast<char *>(&value),
								 (FLDLEN_1632) 0);
				break;
			}

			case FLD_LONG:
			{
				long value;
				try {
					fmt >> value;
				} catch(...) {
					throw InvalidNumberFormatException("Valor invalido para o tipo long: " + fmt.str());
				}
				result = Fappend_1632(iFieldBuffer, it1->first,
								 reinterpret_cast<char *>(&value),
								 (FLDLEN_1632) 0);
				break;
			}

			case FLD_CHAR:
			{
				char value;
				try {
					fmt >> value;
				} catch(...) {
					throw InvalidNumberFormatException("Valor invalido para o tipo char: " + fmt.str());
				}
				result = Fappend_1632(iFieldBuffer, it1->first,
								 reinterpret_cast<char *>(&value),
								 (FLDLEN_1632) 0);
				break;
			}

			case FLD_FLOAT:
			{
				float value;
				try {
					fmt >> value;
				} catch(...) {
					throw InvalidNumberFormatException("Valor invalido para o tipo float: " + fmt.str());
				}
				result = Fappend_1632(iFieldBuffer, it1->first,
								 reinterpret_cast<char *>(&value),
								 (FLDLEN_1632) 0);
				break;
			}

			case FLD_DOUBLE:
			{
				double value;
				try {
					fmt >> value;
				} catch(...) {
					throw InvalidNumberFormatException("Valor invalido para o tipo double: " + fmt.str());
				}
				result = Fappend_1632(iFieldBuffer, it1->first,
								 reinterpret_cast<char *>(&value),
								 (FLDLEN_1632) 0);
				break;
			}

			case FLD_STRING:

				result = Fappend_1632(iFieldBuffer, it1->first,
								 const_cast<char *>(it2->getValue().c_str()),
								 (FLDLEN_1632) 0);
				break;

			case FLD_CARRAY:

				result = Fappend_1632(iFieldBuffer, it1->first,
								 const_cast<char *>(it2->getValue().c_str()),
								 (FLDLEN_1632) it2->getValue().size());
				break;

			}

			if (result < 0)
				throw BufferHandlingException(tpstrerror(tperrno));

		}
		Findex_1632(iFieldBuffer, 0);
	}
}
Example #16
0
/**
 * Real processing starts here.
 * @param argc
 * @param argv
 * @return
 */
int ndrx_main(int argc, char** argv)
{
    int ret=SUCCEED;

    /* do internal initialization, get configuration, request for admin q */
    ret=ndrx_init(argc, argv);
    
    /*
     * Initialize services
     */
    if (SUCCEED==ret)
    {
        ret=tpsvrinit(argc, argv);
    }

    /*
     * Push the services out!
     */
    if (SUCCEED==ret)
    {
        ret=build_advertise_list();
    }

    if (SUCCEED==ret)
    {
        /* initialize the library */
        ret=initialize_atmi_library();
    }
    
    /*
     * Open the queues
     */
    if (SUCCEED==ret)
    {
        ret=sv_open_queue();
    }
    
    /* Do lib updates after Q open... */
    if (SUCCEED==ret)
    {
        ret=tp_internal_init_upd_replyq(G_server_conf.service_array[1]->q_descr,
                G_server_conf.service_array[1]->listen_q);
    }
    
    if (SUCCEED==ret)
    {
        /* As we can run even witout ndrxd, then we ingore the result of send op */
        report_to_ndrxd();
    }

    /* run process here! */
    if (SUCCEED==ret)
    {
        ret=sv_wait_for_request();
    }

    /* finish up. */
    tpsvrdone();

    un_initialize();
    /*
     * Print error message on exit. 
     */
    if (SUCCEED!=ret)
    {
        printf("Error: %s\n", tpstrerror(tperrno));
    }
    
    fprintf(stderr, "Server exit: %d, id: %d\n", ret, G_srv_id);

    return ret;
}
Example #17
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;
}