📄 tux_cli.c
字号:
/***************************
tux_cli.c
***************************
/*+****************************************************************
**********
*
*
* COPYRIGHT (c) 1997 BY
*
* DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS.
*
* ALL RIGHTS RESERVED.
*
*
*
* THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED *
* ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE *
* INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER *
* COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY *
* OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY *
* TRANSFERRED.
*
*
*
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE *
* AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT *
* CORPORATION.
*
*
*
* DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS *
* SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
*
*
*
*
*
* Updated November 20, 2001 - Susan Georgson
*
* Converted tpcc_fct.c file to tux_cli.c
*
* Changed transaction monitor from DB Web Connector to Tuxedo
*
*******************************************************************
*********/
/*
*
*
* Modification history:
*
*
* 08/01/2002 Andrew Bond, HP
* - Conversion to run under Linux
*
*/
#include <stdlib.h> /* stg - added for change to Tuxedo */
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include <oci.h>
#include <ocidfn.h>
#include <ociapr.h>
#include <tpccstruct.h>
#include <oracle_db8.h>
#include <tpccapi.h>
#include <tpccerr.h>
#include <tpcc.h>
#include <pthread.h>
/* tuxedo include files */
#include <atmi.h>
#ifdef FFE_DEBUG
# include <crtdbg.h>
#endif
#define TOTAL_ADMIN_CONNECTIONS 1
#define FILENAMESIZE 256
static pthread_key_t initkey;
static pthread_once_t initkey_once = PTHREAD_ONCE_INIT;
static void doinit(void)
{
pthread_key_create(&initkey, NULL);
}
/* Returns non-zero if thread has been initialized already. */
static int IsInited(void)
{
void *p;
pthread_once(&initkey_once, doinit);
p = pthread_getspecific(initkey);
return (p == NULL);
}
static void NowInited(void)
{
pthread_setspecific(initkey, (void *)1); /* non-NULL value. */
}
/* stg - IsTuxInit is added to check if Tuxedo has been initialized
*/
/* If Tuxedo has not been initialized, then Tuxedo is initialized during */
/* this function. */
/*
* FUNCTION int IsTuxInit
*/
int IsTuxInit()
{
TPINIT *tpinitbuf;
int retcode = -1;
int count = 0;
static int num_tpinits = 0;
#if (DEBUG == 1)
fprintf(MyLogFile, "Entering IsTuxInit\n");
fflush(MyLogFile);
#endif
if(IsInited())
{
while(count < 20)
{
if(NULL == (tpinitbuf = (TPINIT *) tpalloc("TPINIT",NULL,sizeof(TPINIT))))
{
TPCCErr("error with tpalloc - %d - %d",tperrno,count);
}
else
{
tpinitbuf->flags |= TPMULTICONTEXTS;
itoa(++num_tpinits, tpinitbuf->cltname);
retcode = tpinit(tpinitbuf);
#if (DEBUG == 1)
fprintf(MyLogFile, "Back from tpinit, retcode=%d\n",retcode);
fflush(MyLogFile);
#endif
if(-1 != retcode)
{
NowInited();
tpfree((char*)tpinitbuf);
break;
}
else
{
TPCCErr("error with TPINIT - %s (%d) -%d\n\t\t..%s..",tpstrerror(tperrno),
tperrno,count,tpstrerrordetail( tperrordetail( 0 ), 0));
tpfree((char*)tpinitbuf);
}
}
count++;
if(count > 50)
{
retcode = -1;
TPCCErr("exceeded 50 trys in TPINIT");
}
sleep(10);
}
/*
sleep(50);
*/
if( -1 != retcode)
return ERR_DB_SUCCESS;
else
return(retcode);
}
return ERR_DB_SUCCESS;
}
/* stg - end IsTuxInit function */
/* FUNCTION: void DELIErrorMessage(int iError)
*
* PURPOSE: This function writes an error message to the error
log file.
*
* ARGUMENTS: int iError error id to be logged
*
* RETURNS: None
*
* COMMENTS: None
*
*/
void DELIErrorMessage(int iError)
{
int ii;
for( ii = 0; errorMsgs[ii].szMsg[0]; ii++ )
{
if ( iError == errorMsgs[ii].iError )
{
TPCCErr( "*Error(%d): %s\r\n", iError, errorMsgs[ii].szMsg );
return;
}
}
TPCCErr( "*Error(%d): Unknown Error.\r\n", iError );
return;
}
int TPCCDelivery( pDeliveryData pDelivery)
{
int retcode;
struct timezone tz;
time( &pDelivery->queue_time );
gettimeofday(&pDelivery->tbegin, &tz);
retcode = TPCCDeliveryDeferred(pDelivery);
if ( ERR_DB_PENDING != retcode )
{
if( ERR_DB_SUCCESS != retcode)
{
/* send a flag to the reducer to mark an error on the delivery */
pDelivery->queue_time = 1;
DELIErrorMessage(retcode);
}
}
return ERR_DB_SUCCESS;
}
/* stg - begin Tuxedo change of TPCCDelivery Deferred */
/*
* FUNCTION int TPCCDelivery
*/
int TPCCDeliveryDeferred( pDeliveryData ppDelivery )
{
int retcode = ERR_DB_SUCCESS;
pDeliveryData retptr;
int dysiz = sizeof(DeliveryData);
#if (DEBUG == 1)
fprintf(MyLogFile, "Entering TPCCDeliveryDeferred\n");
fflush(MyLogFile);
#endif
/* check to see that the database is connected. */
if( ERR_DB_SUCCESS != IsTuxInit() )
{
TPCCErr("IsTuxInit - delivery ");
return ERR_DB_ERROR;
}
/* allocate memory and copy over data */
if(NULL == ( retptr= (pDeliveryData) tpalloc("CARRAY", NULL,dysiz)))
{
TPCCErr("tp alloc in delivery");
return ERR_DB_ERROR;
}
memcpy( retptr, ppDelivery, dysiz);
/* Call tuxedo for Delivery */
retcode = tpacall("dy_transaction", (char*)retptr,dysiz,TPNOREPLY|TPSIGRSTRT|TPNOTIME);
if( -1 == retcode )
{
TPCCErr("tpcall - delivery: %d", tperrno);
tpfree((char*) retptr);
return ERR_DB_ERROR;
}
/*
memcpy(ppDelivery, retptr, dysiz);
*/
tpfree((char*) retptr);
return ERR_DB_SUCCESS;
}
/* stg - end Tuxedo change of TPCCDelivery Deferred */
/* stg - begin Tuxedo change of TPCCNewOrder */
/*
* FUNCTION int TPCCNewOrder
*/
int TPCCNewOrder( pNewOrderData ppNewOrder )
{
int retcode = ERR_DB_SUCCESS;
pNewOrderData retptr;
int nosiz = sizeof(NewOrderData);
#if (DEBUG == 1)
fprintf(MyLogFile, "Entering TPCCNewOrder\n");
fflush(MyLogFile);
#endif
/* check to see that the database is connected. */
if( ERR_DB_SUCCESS != IsTuxInit() )
{
TPCCErr("IsTuxInit - new order: %d ", tperrno);
return ERR_DB_ERROR;
}
/* allocate memory and copy over data */
if(NULL == ( retptr= (pNewOrderData) tpalloc("CARRAY", NULL,nosiz)))
{
TPCCErr("tp alloc in neworder: %d ", tperrno);
return ERR_DB_ERROR;
}
memcpy( retptr, ppNewOrder, nosiz);
/* Call tuxedo for New Order */
retcode = tpcall("no_transaction", (char *)retptr, nosiz,
(char**)&retptr, (long *)&nosiz,TPSIGRSTRT|TPNOTIME);
if( -1 == retcode )
{
TPCCErr("tpcall - new order: %d", tperrno);
tpfree((char*) retptr);
return ERR_DB_ERROR;
}
memcpy(ppNewOrder, retptr, nosiz);
tpfree((char*) retptr);
return ERR_DB_SUCCESS;
}
/* stg - end Tuxedo change of TPCCNewOrder */
/* stg - begin Tuxedo change of TPCCOrderStatus */
/*
* FUNCTION int TPCCOrderStatus
*/
int TPCCOrderStatus( pOrderStatusData ppOrderStatus )
{
int retcode = ERR_DB_SUCCESS;
pOrderStatusData retptr;
int ossiz = sizeof(OrderStatusData);
#if (DEBUG == 1)
fprintf(MyLogFile, "Entering TPCCOrderStatus\n");
fflush(MyLogFile);
#endif
/* check to see that the database is connected. */
if( ERR_DB_SUCCESS != IsTuxInit() )
{
TPCCErr("IsTuxInit - order status");
return ERR_DB_ERROR;
}
/* allocate memory and copy over data */
if(NULL == ( retptr= (pOrderStatusData) tpalloc("CARRAY", NULL,ossiz)))
{
TPCCErr("tp alloc in order status: %d", tperrno);
return ERR_DB_ERROR;
}
memcpy( retptr, ppOrderStatus, ossiz);
/* Call tuxedo for Order Status */
retcode = tpcall("os_transaction", (char *)retptr, ossiz,
(char**)&retptr, (long *)&ossiz,TPSIGRSTRT|TPNOTIME);
#if (DEBUG == 1)
fprintf(MyLogFile, "TPCCOrderStatus:tpcall returned $d\n",retcode);
fflush(MyLogFile);
#endif
if( -1 == retcode )
{
TPCCErr("tpcall - order status");
tpfree((char*) retptr);
return ERR_DB_ERROR;
}
memcpy(ppOrderStatus, retptr, ossiz);
tpfree((char*) retptr);
return ERR_DB_SUCCESS;
}
/* stg - end Tuxedo change of TPCCOrderStatus */
/* stg - begin Tuxedo change of TPCCPayment */
/*
* FUNCTION int TPCCPayment
*/
int TPCCPayment( pPaymentData ppPayment )
{
int retcode = ERR_DB_SUCCESS;
pPaymentData retptr;
long ptsiz = sizeof(PaymentData);
#if (DEBUG == 1)
fprintf(MyLogFile, "Entering TPCCPayment\n");
fflush(MyLogFile);
#endif
/* check to see that the database is connected. */
if( ERR_DB_SUCCESS != IsTuxInit() )
{
TPCCErr("IsTuxInit - payment ");
return ERR_DB_ERROR;
}
/* allocate memory and copy over data */
if(NULL == ( retptr= (pPaymentData) tpalloc("CARRAY", NULL,ptsiz)))
{
TPCCErr("tp alloc in payment");
return ERR_DB_ERROR;
}
memcpy( retptr, ppPayment, ptsiz);
/* Call tuxedo for Payment */
retcode = tpcall("pt_transaction", (char *)retptr, ptsiz,
(char**)&retptr, &ptsiz,TPSIGRSTRT|TPNOTIME);
if( -1 == retcode )
{
TPCCErr("tpcall - payment: %d ", tperrno);
tpfree((char*) retptr);
return ERR_DB_ERROR;
}
memcpy(ppPayment, retptr, ptsiz);
tpfree((char*) retptr);
return ERR_DB_SUCCESS;
}
/* stg - end Tuxedo change of TPCCPayment */
/* stg - begin Tuxedo change of TPCCStockLevel */
/*
* FUNCTION int TPCCStockLevel
*/
int TPCCStockLevel( pStockLevelData ppStockLevel )
{
int retcode = ERR_DB_SUCCESS;
pStockLevelData retptr;
int slsiz = sizeof(StockLevelData);
#if (DEBUG == 1)
fprintf(MyLogFile, "Entering TPCCStockLevel\n");
fflush(MyLogFile);
#endif
/* check to see that the database is connected. */
if( ERR_DB_SUCCESS != IsTuxInit() )
{
TPCCErr("IsTuxInit - stock level ");
return ERR_DB_ERROR;
}
/* allocate memory and copy over data */
if(NULL == ( retptr= (pStockLevelData) tpalloc("CARRAY", NULL,slsiz)))
{
TPCCErr("tp alloc in stock level");
return ERR_DB_ERROR;
}
memcpy( retptr, ppStockLevel, slsiz);
/* Call tuxedo for Stock Level */
retcode = tpcall("sl_transaction", (char *)retptr, slsiz,
(char**)&retptr, (long *)&slsiz,TPSIGRSTRT|TPNOTIME);
if( -1 == retcode )
{
TPCCErr("tpcall - stock level: %d", tperrno);
tpfree((char*) retptr);
return ERR_DB_ERROR;
}
memcpy(ppStockLevel, retptr, slsiz);
tpfree((char*) retptr);
return ERR_DB_SUCCESS;
}
/* stg - end Tuxedo change of TPCCStockLevel */
/*
**++
** FUNCTION NAME: TPCCStartup
**--
*/
int TPCCStartup()
{
return ERR_SUCCESS;
}
/*
**++
** FUNCTION NAME: TPCCConnect
**--
*/
int TPCCConnect( pLoginData pLogin )
{
if( 0 != strcmp( pLogin->szServer, gszServer ))
return ERR_SERVER_MISMATCH;
if( 0 != strcmp( pLogin->szDatabase, gszDatabase ))
return ERR_DATABASE_MISMATCH;
if( 0 != strcmp( pLogin->szUser, gszUser ))
return ERR_USER_MISMATCH;
if( 0 != strcmp( pLogin->szPassword, gszPassword ))
return ERR_PASSWORD_MISMATCH;
return ERR_DB_SUCCESS;
}
/*
**++
** FUNCTION NAME: TPCCDisconnect
**--
*/
int TPCCDisconnect( pCallersContext pCC )
{
return ERR_DB_SUCCESS;
}
/* stg - added for TuxShutdown function for Tuxedo */
/*
* FUNCTION int TuxShutdown
*/
int TuxShutdown()
{
return ERR_DB_SUCCESS;
}
/*
**++
** FUNCTION NAME: TPCCShutdown
**--
*/
int TPCCShutdown( void )
{
int retcode;
/* shut down the servers listed in the TUXCONFIG file (ubb* file)
*/
retcode = system("tmshutdown -y");
if (retcode != 0)
{
TPCCErr("Error shutting the tuxedo servers down.");
return retcode;
}
return(TuxShutdown());
}
/* stg - don't need the following for Tuxedo - I think! */
#if 0
void __cdecl force_connect( void *arglist )
{
LoginData login;
int txnType;
login.w_id = 0;
login.ld_id = 0;
login.pCC = 0;
login.szApplication[0] = '\0';
strcpy( login.szServer, gszServer );
strcpy( login.szDatabase, gszDatabase );
strcpy( login.szUser, gszUser );
strcpy( login.szPassword, gszPassword );
txnType = (int) arglist;
switch ( txnType )
{
case TYPE_DY:
dy_transaction_init( STDL_SYNCHRONOUS, &login,(struct io_login_wksp *)&login );
break;
case TYPE_NO:
no_transaction_init( STDL_SYNCHRONOUS, &login,(struct io_login_wksp *)&login );
break;
case TYPE_OS:
os_transaction_init( STDL_SYNCHRONOUS, &login,(struct io_login_wksp *)&login );
break;
case TYPE_PT:
pt_transaction_init( STDL_SYNCHRONOUS, &login,(struct io_login_wksp *)&login );
break;
case TYPE_SL:
sl_transaction_init( STDL_SYNCHRONOUS, &login,(struct io_login_wksp *)&login );
break;
case TYPE_GC:
gc_transaction_init( STDL_SYNCHRONOUS, &login,(struct io_login_wksp *)&login );
break;
}
if ( login.status != ERR_DB_SUCCESS)
{
/** Only store the first failure **/
if ( ERR_DB_SUCCESS == gInitRetStatus )
gInitRetStatus = ERR_FORCE_CONNECT_THREAD_FAILED;
TPCCErr( "Connect Transaction returned %8X\r\n", login.status);
}
if ( InterlockedDecrement( &gForceAllThreadsCtr ) == 0 )
SetEvent( gForceAllThreadsEvent );
return;
}
#endif /*stg - end #if 0 section */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -