int main(int argc, char *argv[]) { char *sendbuf, *rcvbuf; long sendlen, rcvlen; char svcname[16]; int ret; if(argc != 3) { (void) fprintf(stderr, "arg:clientpetri servname sendbuf"); exit(1); } /* 作为tuxedo客户端连入tuxedo System */ if (tpinit((TPINIT *) NULL) == -1) { (void) fprintf(stderr, "Tpinit failed "); exit(1); } sendlen = strlen(argv[2]); /* 使用tpalloc申请string类型buffer作为请求和应答buffer */ if((sendbuf = (char *) tpalloc("STRING", NULL, sendlen+1)) == NULL) { (void) fprintf(stderr,"Error allocating send buffer "); tpterm(); exit(1); } if((rcvbuf = (char *) tpalloc("STRING", NULL, 1024*2)) == NULL) { (void) fprintf(stderr,"Error allocating receive buffer "); tpfree(sendbuf); tpterm(); exit(1); } (void) strcpy(svcname, argv[1]); (void) strcpy(sendbuf, argv[2]); /* 同步调用服务 */ ret = tpcall(svcname, (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0); if(ret == -1) { (void) fprintf(stderr, "Can't send request to service "); (void) fprintf(stderr, "Tperrno = %d ", tperrno); tpfree(sendbuf); tpfree(rcvbuf); tpterm(); exit(1); } (void) fprintf(stdout, "Returned string is: %s ", rcvbuf); /* 使用tpfree释放申请的请求和应答buffer空间 */ tpfree(sendbuf); tpfree(rcvbuf); /* 使用tpterm离开tuxedo System */ tpterm(); return(0); }
void BAR(TPSVCINFO * svcinfo) #endif { test_req_t *req = (test_req_t *) svcinfo->data; test_req_t *resp = (test_req_t *) tpalloc((char*) "X_C_TYPE", (char*) "test_req", 0); product_t *p = products; btlogger_debug( "TxLog %s service %s running", __FUNCTION__, TXTEST_SVC_NAME); resp->status = -1; inject_fault(O_XA_COMMIT, req->txtype); for (p = products; p->id != -1; p++) { if (req->prod == p->id) { int rv; strncpy(req->db, p->dbname, sizeof(req->db)); btlogger_debug("TxLog Service %s %4d: prod=%8s (id=%d) op=%c tx=0x%x data=%s", TXTEST_SVC_NAME, req->id, p->pname, p->id, req->op, req->txtype, req->data); rv = p->access(req, resp); btlogger_debug("TxLog Service %s %4d: resp->status=%d rv=%d", TXTEST_SVC_NAME, req->id, resp->status, rv); break; } } tpreturn(TPSUCCESS, resp->status, (char *) resp, sizeof (test_req_t), 0); }
/*********************************************************************** 交易: CLIENT_LOGIN 功能:远程监控客户端连接主监控时调用 输入参数: iHostID(客户端主机ID, 对应WF_HOSTINFO.HOST_ID) --客户端守护进程启动时建议默认根据hostname取ID sSysUserName(Unix 用户名) 返回值: iLogID(登录ID; -1登录失败) sMsg(错误信息. 当iLogID == -1时有效) ----------------------------------------------------------------------*/ void CLIENT_LOGIN(TPSVCINFO *rqst) { TParseBuff ParaList; char *sQqstBuf; sQqstBuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); int iLen = rqst->len; memcpy(sQqstBuf, rqst->data, iLen); sQqstBuf[iLen] = 0; TrimHeadNull(sQqstBuf,iLen); int iRet = ParaList.parseBuff(sQqstBuf); if (!iRet){ ParaList.reset(); ParaList.setLogID(-1); //输入参数不合法,登录失败 ParaList.addMsg("登录主监控守护时输入参数不合法!"); ParaList.getBuiltStr(sQqstBuf); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } //lock the signal. LockSafe(g_pShmTable->m_iClientLock,0); g_pShmTable->ClientReqInfo.m_iHostID = ParaList.getHostID(); ParaList.getSysUserName(g_pShmTable->ClientReqInfo.m_sSysUserName); g_pShmTable->ClientReqInfo.m_iStatus = REQ_CLIENT_LOGIN; ParaList.reset(); int iTimeOut = 0; while(g_pShmTable->ClientReqInfo.m_iStatus == REQ_CLIENT_LOGIN) { //wait... usleep(USLEEP_LONG); if (iTimeOut++ > TIME_OUT) { ParaList.setLogID(-1); //time out,failed ParaList.addMsg("登录主监控超时!"); ParaList.getBuiltStr(sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } } //主守护进程处理后的状态可能有: //SERVER_ACCEPT MAX_CLIENT_NUM SERVER_REJECT if (g_pShmTable->ClientReqInfo.m_iStatus == SERVER_ACCEPT){ ParaList.setLogID(g_pShmTable->ClientReqInfo.m_iIndex); } else if (g_pShmTable->ClientReqInfo.m_iStatus == MAX_CLIENT_NUM) { ParaList.setLogID(-1); ParaList.addMsg("远程守护监控连接达到最大限制!"); } else { ParaList.setLogID(-1); ParaList.addMsg(g_pShmTable->ClientReqInfo.m_sMsgBuf); } ParaList.getBuiltStr(sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); }
int main(int argc, char **argv) { int tpstatus; char *retbuf; char type[20]; char subtype[20]; long retbufsize; char *sbuf; long sbufsize; long callflags; int i; for (i = 0; i < 10; i++) { callflags = 0L; sbufsize = 29; sbuf = tpalloc("X_OCTET", 0, sbufsize); memset(sbuf, 0, sbufsize); strcpy(sbuf, "THIS IS YOUR CLIENT SPEAKING"); retbufsize = 15; retbuf = tpalloc("X_OCTET", 0, retbufsize); memset(retbuf, 0, retbufsize); // tptypes tptypes(sbuf, type, subtype); // tpcall btlogger((char*) "Calling tpcall with input: %s", sbuf); tpstatus = tpcall("FOOAPP", sbuf, sbufsize, (char **) &retbuf, &retbufsize, callflags); btlogger( (char*) "Called tpcall with length: %d output: %s and status: %d and tperrno: %d", retbufsize, retbuf, tpstatus, tperrno); if (tpstatus == -1 && tperrno == TPENOENT) { tpfree(sbuf); tpfree(retbuf); return -1; } tpfree(sbuf); tpfree(retbuf); } return 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)); } }
/** * 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; }
int main(int argc, char** argv) { char *sendbuf = NULL; sendbuf = (char *) tpalloc("CARRAY", NULL, 1024); if(sendbuf == NULL) { (void) fprintf(stderr, "Error allocating send buffer\n"); return -1; } tpfree(sendbuf); }
void FOOAPP(TPSVCINFO * svcinfo) { char* buffer; int sendlen; btlogger((char*) "bar called - svc: %s data %s len: %d flags: %d", svcinfo->name, svcinfo->data, svcinfo->len, svcinfo->flags); sendlen = 15; buffer = tpalloc("X_OCTET", 0, sendlen); strcpy(buffer, "BAR SAYS HELLO"); tpreturn(TPSUCCESS, 0, buffer, sendlen, 0); }
/*********************************************************************** 交易: SEND_REMOTEMSG 功能:远程监控发送一个应用程序状态和输出信息到主监控 输入参数: iLogID(登录ID) iHostID(主机ID) iProecessID iProcessCnt cState(进程状态) iMainGuardIndex <sMsg=str_msg>... 返回值: iResult(0-失败, 1-成功) ----------------------------------------------------------------------*/ void SEND_REMOTEMSG(TPSVCINFO *rqst) { TParseBuff ParaList; char *sQqstBuf; sQqstBuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); int iLen = rqst->len; memcpy(sQqstBuf, rqst->data, iLen); sQqstBuf[iLen] = 0; TrimHeadNull(sQqstBuf,iLen); int iRet = ParaList.parseBuff(sQqstBuf); if (!iRet){ ParaList.reset(); ParaList.setResult(0); //输入参数不合法 ParaList.addMsg("输入参数不合法!"); ParaList.getBuiltStr(sQqstBuf); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } //lock the signal. LockSafe(g_pShmTable->m_iClientLock,0); g_pShmTable->ClientReqInfo.m_iHostID = ParaList.getHostID(); g_pShmTable->ClientReqInfo.m_iIndex = ParaList.getLogID(); //g_pShmTable->ClientReqInfo.m_cState = ParaList.getState(); //strcpy(g_pShmTable->ClientReqInfo.m_sMsgBuf,ParaList.getBuiltMsg()); strcpy(g_pShmTable->ClientReqInfo.m_sMsgBuf,sQqstBuf); g_pShmTable->ClientReqInfo.m_iStatus = REQ_SEND_REMOTEMSG; ParaList.reset(); int iTimeOut = 0; while(g_pShmTable->ClientReqInfo.m_iStatus == REQ_SEND_REMOTEMSG) { //wait... usleep(USLEEP_LONG); if (iTimeOut++ > TIME_OUT) { ParaList.setResult(0); //time out,failed ParaList.addMsg("输出消息超时!"); ParaList.getBuiltStr(sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } } //主守护进程处理后的状态可能有: // CLIENT_LOG_DEAD REMOTEMSG_SENT if (g_pShmTable->ClientReqInfo.m_iStatus == REMOTEMSG_SENT) { ParaList.setResult(1); } else if (g_pShmTable->ClientReqInfo.m_iStatus == CLIENT_LOG_DEAD) { ParaList.setResult(0); ParaList.addMsg("client log dead."); } else { ParaList.setResult(0); ParaList.addMsg("Failed. Unknown reason."); } ParaList.getBuiltStr(sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); }
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); }
/*********************************************************************** 交易: GET_COMMAND 功能:远程监控客户端获取其需要执行的指令时调用 输入参数: iLogID(登录ID) iHostID(主机ID) 返回值: iResult (0-失败, 1-有操作指令, 2-当前无指令) iOperation (1-start, 2-stop, 3-ChangeStatus, 4-Refresh) iProcessID (指令操作的进程号) iStaffID iPlanID cState sMsg (iResult=0时存放失败信息; ) ----------------------------------------------------------------------*/ void GET_COMMAND(TPSVCINFO *rqst) { TParseBuff ParaList; char *sQqstBuf; sQqstBuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); int iLen = rqst->len; memcpy(sQqstBuf, rqst->data, iLen); sQqstBuf[iLen] = 0; TrimHeadNull(sQqstBuf,iLen); DEFINE_QUERY(qry); qry.commit(); qry.close(); int iRet = ParaList.parseBuff(sQqstBuf); if (!iRet){ ParaList.reset(); ParaList.setResult(0); ParaList.addMsg("输入参数不合法!"); ParaList.getBuiltStr(sQqstBuf); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } //lock signal LockSafe(g_pShmTable->m_iClientLock,0); g_pShmTable->ClientReqInfo.m_iHostID = ParaList.getHostID(); g_pShmTable->ClientReqInfo.m_iIndex = ParaList.getLogID(); g_pShmTable->ClientReqInfo.m_iStatus = REQ_GET_COMMAND; ParaList.reset(); int iTimeOut = 0; while(g_pShmTable->ClientReqInfo.m_iStatus == REQ_GET_COMMAND) { //wait... usleep(USLEEP_LONG); if (iTimeOut++ > TIME_OUT) { ParaList.setResult(0); //time out ParaList.addMsg("获取指令超时!"); ParaList.getBuiltStr(sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } } //主守护进程处理后的状态可能有: //REQ_COMMAND_RECV CLIENT_LOG_DEAD REQ_NO_COMMAND if (g_pShmTable->ClientReqInfo.m_iStatus == REQ_COMMAND_RECV){ ParaList.setResult(1); ParaList.setOperation(g_pShmTable->ClientReqInfo.m_iOperation); ParaList.setProcessID(g_pShmTable->ClientReqInfo.m_iProcessID); ParaList.setStaffID(g_pShmTable->ClientReqInfo.m_iStaffID); ParaList.setPlanID(g_pShmTable->ClientReqInfo.m_iPlanID); ParaList.setState(g_pShmTable->ClientReqInfo.m_cState); } else if (g_pShmTable->ClientReqInfo.m_iStatus == CLIENT_LOG_DEAD){ ParaList.setResult(0); ParaList.addMsg("Err: CLIENT_LOG_DEAD"); } else if (g_pShmTable->ClientReqInfo.m_iStatus == REQ_NO_COMMAND){ ParaList.setResult(2); } else { ParaList.setResult(0); ParaList.addMsg("Err: Unknown reason."); } ParaList.getBuiltStr(sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); }
/*********************************************************************** 交易: ACK_COMMAND 功能:返回指令执行后的结果信息(在GET_COMMAND后调用) 输入参数: iLogID(登录ID) iHostID(主机ID) iProcessID(指令操作的进程ID) iOperation(指令动作) (1-start, 2-stop, 3-ChangeStatus, 4-Refresh) iResult(0-失败, 1-成功) 指令的执行情况 sMsg(指令执行返回的文本信息) 返回值: iResult(0-失败, 1-成功) 交易的执行情况 //iMainGuardIndex(当指令为启动指令时,标识远程应用进程在主监控守护主机AppInfo中的下标) sMsg (失败原因) ----------------------------------------------------------------------*/ void ACK_COMMAND(TPSVCINFO *rqst) { TParseBuff ParaList; char *sQqstBuf; sQqstBuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); int iLen = rqst->len; memcpy(sQqstBuf, rqst->data, iLen); sQqstBuf[iLen] = 0; TrimHeadNull(sQqstBuf,iLen); int iRet = ParaList.parseBuff(sQqstBuf); if (!iRet){ ParaList.reset(); ParaList.setResult(0); //输入参数不合法 ParaList.addMsg("输入参数不合法!"); ParaList.getBuiltStr(sQqstBuf); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } //lock the signal. LockSafe(g_pShmTable->m_iClientLock,0); g_pShmTable->ClientReqInfo.m_iHostID = ParaList.getHostID(); g_pShmTable->ClientReqInfo.m_iIndex = ParaList.getLogID(); g_pShmTable->ClientReqInfo.m_iProcessID = ParaList.getProcessID(); g_pShmTable->ClientReqInfo.m_iResult = ParaList.getResult(); g_pShmTable->ClientReqInfo.m_iOperation = ParaList.getOperation(); strcpy(g_pShmTable->ClientReqInfo.m_sMsgBuf,ParaList.getMsg()); g_pShmTable->ClientReqInfo.m_iStatus = REQ_ACK_COMMAND; ParaList.reset(); int iTimeOut = 0; while(g_pShmTable->ClientReqInfo.m_iStatus == REQ_ACK_COMMAND) { //wait... usleep(USLEEP_LONG); if (iTimeOut++ > TIME_OUT) { ParaList.setResult(0); //time out,failed ParaList.addMsg("返回指令执行结果超时!"); ParaList.getBuiltStr(sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); } } //主守护进程处理后的状态可能有: // CLIENT_LOG_DEAD ACK_COMMAND_END if (g_pShmTable->ClientReqInfo.m_iStatus == ACK_COMMAND_END) { ParaList.setResult(1); //ParaList.setMainGuardIndex(g_pShmTable->ClientReqInfo.m_iMainGuardIndex); //ParaList.addMsg("已获取到iMainGuardIndex"); } else if (g_pShmTable->ClientReqInfo.m_iStatus == CLIENT_LOG_DEAD) { ParaList.setResult(0); ParaList.addMsg("client log dead."); } else { ParaList.setResult(0); ParaList.addMsg("Failed. Unknown reason."); } ParaList.getBuiltStr(sQqstBuf); TWfLog::log(0,"server_client send ACK_COMMAND_END msg:%s",sQqstBuf); UnlockSafe(g_pShmTable->m_iClientLock,0); tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); }
//using namespace std; int main(int argc, char *argv[]) { FBFR32 *sendbuf, *rcvbuf; long ret, numread = 0; char sOrderListID[13]={0}; char sAreaCode[10]={0}; char sInXML[MAX_XML_SIZE]; char sOutXML[MAX_XML_SIZE]; char sFileName[30]; long lResult; char sErrMsg[1000]; struct timeb tp1,tp2; memset(sOutXML, 0, MAX_XML_SIZE); memset(sErrMsg, 0, 1000); memset(sFileName, 0, 30); strcpy(sFileName, (char*)argv[1]); printf("you input fileName is <%s>\n", sFileName); FILE *fp; if((fp = fopen(sFileName, "r")) == NULL) { printf("can't open file: %s\n", sFileName); return 0; } numread = fread(sInXML, sizeof(char), MAX_XML_SIZE, fp); printf("read size is %d\n", numread); fclose(fp); long rcvlen = 0L; if ((sendbuf = (FBFR32*)tpalloc("FML32", NULL,MAX_XML_SIZE ))==NULL) { printf("分配发送buff error\n"); } if ((rcvbuf = (FBFR32*)tpalloc("FML32", NULL, MAX_XML_SIZE))==NULL) { printf("分配接收buff error\n"); } rcvlen = Fsizeof32(rcvbuf); //初始化 //if ((ret=tpinit((TPINIT * )NULL))<0) if ((ret=tpinit(NULL))<0) { printf( "tpinit fail\n"); tpfree((char *)sendbuf); tpfree((char *)rcvbuf); return -1; } Fchg32(sendbuf, IN_XML, 0, (char *)&sInXML, 0L); ftime(&tp1); ret=tpcall("POWER_CTL_RUN",(char*)sendbuf,0L,(char**)&rcvbuf,&rcvlen,0L); ftime(&tp2); if (Fgets32(rcvbuf, OUT_XML, 0, sOutXML) == -1) { printf( " OUT_XML error \n"); } if (Fget32(rcvbuf, IRESULT, 0, (char*)&lResult, 0) == -1) { printf( " IRESULT error \n"); } if (Fgets32(rcvbuf, SMSG, 0, sErrMsg) == -1) { printf( " SMSG error \n"); } printf("InXML is %s\n", sInXML); printf("OutXML is : %s\n", sOutXML); printf("Result is : %ld\n", lResult); printf("ErrMsg is : %s\n", sErrMsg); printf(" 用时: %d ms\n", tp2.time*1000+tp2.millitm - tp1.time*1000 -tp1.millitm ); return 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; }
void P_CHANGE_STATUS(TPSVCINFO *rqst) { long ltransID=0; int iRet=0; char swsnaddr[30]; FBFR32 *sendbuf; FBFR32 *recvbuf; char *sendstring; char *sendbuf2=NULL; int iLen = rqst->len; long i; sendstring = new char[iLen]; memset(sendstring,'\0',iLen); sendbuf2 = (char *) tpalloc("STRING", NULL, MAX_CMAMSG_LEN); //char *rcvbuf = NULL; //char *sendbuf = NULL; long lRecLen = 0; char cRouteKey[30]; char tmpBuff[30]; memset(swsnaddr,0,sizeof(swsnaddr)); //rcvbuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); //sendbuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); if ((sendbuf = (FBFR32 *)tpalloc("FML32",NULL,MAX_CMAMSG_LEN)) == NULL) { sprintf(sendbuf2,"<iResult=1><sMsg=sendbuf err>"); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } if ((recvbuf = (FBFR32 *)tpalloc("FML32",NULL,MAX_CMAMSG_LEN)) == NULL) { sprintf(sendbuf2,"<iResult=1><sMsg=recvbuf err>"); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } //int iLen = rqst->len; memcpy(sendstring, rqst->data, iLen); sendstring[iLen] = 0; TrimHeadNull(sendstring,iLen); ::PETRI::P_RECVBUFF.reset(); ::PETRI::P_RECVBUFF.parseBuff(sendstring); ltransID = ::PETRI::P_RECVBUFF.getTransitionID(); TOCIQuery query (::PETRI::P_DB.getDB()); try { string sql = "select b.wsnaddr from P_TRANSITION_HOST_INFO a, WF_HOST_WSNADDR b where a.wsnaddr_id = b.wsnaddr_id and a.transition_id = :TRANSID"; query.close(); query.setSQL(sql.c_str()); query.setParameter("TRANSID",ltransID); query.open(); while(query.next()) { strcpy( swsnaddr,query.field(0).asString() ); } query.close(); string sql2 = "select HOST_AREA||HOST_DOMAIN from P_TRANSITION_HOST_INFO where transition_id = :TRANSID"; query.close(); query.setSQL(sql2.c_str()); query.setParameter("TRANSID",ltransID); query.open(); while(query.next()) { strcpy( tmpBuff,query.field(0).asString()); } query.close(); query.commit(); }catch (TOCIException & toe){ sprintf(sendbuf2,"<iResult=1><sMsg=get WSNADDR err:%s>",toe.getErrMsg()); query.close(); query.commit(); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } catch(...) { sprintf(sendbuf2,"<iResult=1><sMsg=get WSNADDR other err>"); query.close(); query.commit(); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } if(0 == swsnaddr[0]){ sprintf(sendbuf2,"<iResult=1><sMsg=Transition have no WSNADDR >"); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } /* iRet = setenv("WSNADDR",swsnaddr,1); if( -1 == iRet){ sprintf(rcvbuf,"<iResult=1><sMsg=set WSNADDR fail>"); tpfree(sendbuf); tpreturn(TPSUCCESS,0L,rcvbuf,strlen(rcvbuf),0L); }; */ strcpy(cRouteKey, tmpBuff); //iRet = Fchg32(&sendbuf,ROUTE_KEY,0,(char*)cRouteKey,(FLDLEN32)10); iRet = Fchg32(sendbuf,ROUTE_KEY,0,(char *)cRouteKey,0); if(iRet < 0) { userlog("cRouteKey=[%s],iRet=[%d]",cRouteKey,iRet); sprintf(sendbuf2,"<iResult=1><sMsg=cslfput to ROUTE_KEY is error>"); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } iRet = Fchg32(sendbuf,SEND_STRING,0,(char *)sendstring,0); if(iRet < 0) { userlog("sendstring=[%s],iRet=[%d]",sendstring,iRet); sprintf(sendbuf2,"<iResult=1><sMsg=cslfput to SEND_STRING is error>"); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } iRet = tpcall("P_C_S_LOCAL",(char *)sendbuf,0,(char **)&recvbuf,&lRecLen,0); if (iRet < 0){ sprintf(sendbuf2,"<iResult=1><sMsg=call localsvc err,tperrno:%d>",tperrno); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } tpfree((char *)sendbuf); sprintf(sendbuf2,"<iResult=0><sMsg=you tpcall success>"); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); }
void P_GET_TRANSINFO(TPSVCINFO *rqst) { long drawID = 0; int iRet = 0; char swsnaddr[30]; char *allrcvbuf = NULL; char *rcvbuf = NULL; FBFR32 *sendbuf; FBFR32 *recvbuf; char *sendstring; char *sendbuf2=NULL; int iLen = rqst->len; long i; sendstring = new char[iLen]; memset(sendstring,'\0',iLen); sendbuf2 = (char *) tpalloc("STRING", NULL, MAX_CMAMSG_LEN); //char *sendbuf = NULL; long lRecLen = 0; string s_rcvbuff; char cRouteKey[30]; char tmpBuff[30]; memset(swsnaddr,0,sizeof(swsnaddr)); allrcvbuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); //rcvbuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); if ((sendbuf = (FBFR32 *)tpalloc("FML32",NULL,MAX_CMAMSG_LEN)) == NULL) { sprintf(sendbuf2,"<iResult=1><sMsg=sendbuf err>"); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } if ((recvbuf = (FBFR32 *)tpalloc("FML32",NULL,MAX_CMAMSG_LEN)) == NULL) { sprintf(sendbuf2,"<iResult=1><sMsg=recvbuf err>"); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } //sendbuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); memset(sendstring,0,MAX_CMAMSG_LEN); s_rcvbuff.clear(); memcpy(sendstring, rqst->data, iLen); sendstring[iLen] = 0; TrimHeadNull(sendstring,iLen); ::PETRI::P_RECVBUFF.reset(); ::PETRI::P_RECVBUFF.parseBuff(sendstring); drawID = (long) ::PETRI::P_RECVBUFF.getDrawID(); vector<long> transList; transList.clear(); TOCIQuery query (::PETRI::P_DB.getDB()); try { string sql = "SELECT TRANSITION_ID FROM P_TRANSITION_ATTR WHERE DRAW_ID= :DRAWID AND EXE_STATE = 'R'"; query.close(); query.setSQL(sql.c_str()); query.setParameter("DRAWID",drawID); query.open(); while(query.next()) { transList.push_back(query.field(0).asLong()); } query.close(); query.commit(); } catch (TOCIException& toe) { query.close(); query.commit(); sprintf(sendbuf2,"<iResult=1><sMsg=Get Transition of The Draw Error! %s>",toe.getErrMsg()); tpfree(rcvbuf); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } catch (...) { query.close(); query.commit(); sprintf(sendbuf2,"<iResult=1><sMsg=Get Transition of The Draw Error!> other error"); tpfree(rcvbuf); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); }; if (0 == transList.size()){ memset(sendbuf2,0,MAX_CMAMSG_LEN); tpfree(rcvbuf); tpfree((char *)sendbuf); query.commit(); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } for (int idx = 0;idx <transList.size();idx ++ ) { try { string sql = "select b.wsnaddr from P_TRANSITION_HOST_INFO a, WF_HOST_WSNADDR b where a.wsnaddr_id = b.wsnaddr_id and a.transition_id = :TRANSID"; query.close(); query.setSQL(sql.c_str()); query.setParameter("TRANSID",transList[idx]); query.open(); while(query.next()) { strcpy( swsnaddr,query.field(0).asString() ); } query.close(); string sql2 = "select HOST_AREA||HOST_DOMAIN from P_TRANSITION_HOST_INFO where transition_id = :TRANSID"; query.close(); query.setSQL(sql2.c_str()); query.setParameter("TRANSID",transList[idx]); query.open(); while(query.next()) { strcpy( tmpBuff,query.field(0).asString()); } query.close(); query.commit(); }catch (TOCIException & toe){ sprintf(sendbuf2,"<iResult=1><lTransitionID=%ld><sMsg=get WSNADDR err:%s>",transList[idx],toe.getErrMsg()); query.close(); query.commit(); } catch(...) { sprintf(sendbuf2,"<iResult=1><lTransitionID=%ld><sMsg=get WSNADDR other err>",transList[idx]); query.close(); query.commit(); } if(0 == swsnaddr[0]){ sprintf(sendbuf2,"<iResult=1><lTransitionID=%ld><sMsg=Transition have no WSNADDR >",transList[idx]); } /* iRet = setenv("WSNADDR",swsnaddr,1); if( -1 == iRet){ sprintf(rcvbuf,"<iResult=1><lTransitionID=%ld><sMsg=set WSNADDR fail>",transList[idx]); }; */ sprintf(sendbuf2,"<lTransitionID=%ld>%s\0",transList[idx],sendstring); strcpy(cRouteKey, tmpBuff); //iRet = cslfput(&sendbuf,ROUTE_KEY,0,cRouteKey); //iRet = Fchg32(&sendbuf,ROUTE_KEY,0,(char*)cRouteKey,(FLDLEN32)10); strcpy(cRouteKey, tmpBuff); iRet = Fchg32(sendbuf,ROUTE_KEY,0,(char *)cRouteKey,0); //iRet = Fchg32((FBFR32*)(&sendbuf),ROUTE_KEY,0,(char*)cRouteKey,(FLDLEN32)20); if(iRet < 0) { userlog("cRouteKey=[%s],iRet=[%d]",cRouteKey,iRet); sprintf(sendbuf2,"<iResult=1><sMsg=cslfput to ROUTE_KEY is error>\0"); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } iRet = Fchg32(sendbuf,SEND_STRING,0,(char *)sendbuf2,0); if(iRet < 0) { userlog("sendstring=[%s],iRet=[%d]",sendstring,iRet); sprintf(sendbuf2,"<iResult=1><sMsg=cslfput to SEND_STRING is error>\0"); tpfree((char *)sendbuf); tpreturn(TPSUCCESS,0L,sendbuf2,MAX_CMAMSG_LEN,0L); } iRet = tpcall("P_G_T_LOCAL",(char *)sendbuf,0,(char **)&recvbuf,&lRecLen,0); if (iRet < 0){ sprintf(sendbuf2,"<iResult=1><lTransitionID=%ld><sMsg=call localsvc err,tperrno:%d>\0",transList[idx],tperrno); } userlog(sendbuf2); s_rcvbuff = s_rcvbuff + "$" + sendbuf2; } sprintf (allrcvbuf,"%s\0",s_rcvbuff.c_str()); tpfree((char *)sendbuf); tpfree((char *)rcvbuf); tpreturn(TPSUCCESS,0L,allrcvbuf,MAX_CMAMSG_LEN,0L); }
/* * 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; }
/* * 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; }
/************************************* * 功能: 分配缓冲区 * * 参数: type: 缓冲区类型 * * size: 缓冲区长度 * * 返回值: * * <>NULL 缓冲区地址 * * =NULL 失败 * **************************************/ char * cslalloc(char *type ,long size) { return(tpalloc(type,NULL,size)); }
/** * 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; }
void P_C_S_LOCAL(TPSVCINFO *rqst) { char *sQqstBuf; //sQqstBuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); //int iLen = rqst->len; //memcpy(sQqstBuf, rqst->data, iLen); sQqstBuf = tpalloc("STRING",NULL,MAX_CMAMSG_LEN); int iRet = 0; FBFR32 *recvbuf = NULL; //recvbuf=(FBFR32 *) tpalloc("FML32",NULL,MAX_CMAMSG_LEN); FBFR32 *sendbuf = NULL; sendbuf=(FBFR32 *)tpalloc("FML32",NULL,MAX_CMAMSG_LEN); int iLen = rqst->len; //memcpy(sQqstBuf, rqst->data, iLen); //memcpy(recvbuf, rqst->data, iLen); recvbuf=(FBFR32 *)rqst->data; Fget32(recvbuf, SEND_STRING, 0, sQqstBuf, 0); //sQqstBuf[iLen] = 0; TrimHeadNull(sQqstBuf,iLen); ::PETRI::P_CMDMSG->mtype = (long)pid; sprintf(::PETRI::P_CMDMSG->mbody,"<iNeedAck=1>%s\0",sQqstBuf); while ( ::PETRI::P_MQ.ackMQ.receive(pid) ) { userlog("%ld,%s\n",::PETRI::P_ACKMSG->mtype,::PETRI::P_ACKMSG->mbody); }; if(!(::PETRI::P_MQ.cmdMQ.send())) { tpfree((char *)recvbuf); memset(sQqstBuf,0,MAX_CMAMSG_LEN); strcpy(sQqstBuf,"<iResult=1><sMsg=MQ Send Fail>"); iRet = Fchg32(recvbuf,SEND_STRING,0,(char *)sQqstBuf,0); if( iRet > 0 ) tpreturn(TPSUCCESS,0L,(char *)recvbuf,strlen(sQqstBuf),0L); else userlog("P_F_LOCAL Error sQqstBuf!"); } int iTime=0; bool ifAck = false; while ( iTime++ < WAIT_TIME ) { if (::PETRI::P_MQ.ackMQ.receive(pid)) { ifAck = true; break; } sleep(1); } if (ifAck) { strcpy(sQqstBuf,::PETRI::P_ACKMSG->mbody); userlog(::PETRI::P_ACKMSG->mbody); } /* else { while ( ::PETRI::P_MQ.cmdMQ.receive(pid) ){}; strcpy(sQqstBuf,"<iResult=1><sMsg=schd order send OK,wait result timeOut>"); } */ //strcpy(sQqstBuf,"OK"); //tpfree((char *)recvbuf); char sTemp[10]="OK"; //iRet = Fchg32(recvbuf,SEND_STRING,0,(char *)sQqstBuf,0); iRet = Fchg32(sendbuf,SEND_STRING,0,(char *)sTemp,0); userlog("iRet=[%d]",iRet); tpreturn(TPSUCCESS,0L,(char *)sendbuf,MAX_CMAMSG_LEN,0); //tpreturn(TPSUCCESS,0L,sQqstBuf,strlen(sQqstBuf),0L); }
void svr_next_command(struct tpclient *c) { svriowait(c, tpalloc(0, 0, 1), command, "command"); }
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); }