Table of Contents
This chapter describes the APIs used in client program development.
The following is a list of APIs available for client program development. For more information about the functions, refer to "Tmax Reference Guide".
Connection and Disconnection
Synchronous Communication
API | Description |
---|---|
tpcall | Sends a service request through synchronous communication and waits for the response. |
Asynchronous Communication
Interactive Communication
Unrequests Message Processing
API | Description |
---|---|
tpsetunsol | Used by the client to set the routine that processes unsolicited messages. |
tpgetunsol | Processes unsolicited messages. |
Timeout Change
API | Description |
---|---|
tpset_timeout | Used by the client and server to set the blocking timeout. |
tpsetsvctimeout | Called within a service to set the service timeout. |
Bufffer Management
API | Description |
---|---|
tpalloc | Used by the client and server to allocate a buffer. |
tprealloc | Used by the client and server to reallocate a buffer. |
tpfree | Used by the client and server to release the memory allocated to the buffer. |
tptypes | Used by the client and server to provide information about the buffer type and sub-type. |
Transaction Management
API | Description |
---|---|
tx_begin | Used by the client and server to start a global transaction. |
tx_commit | Used by the client and server to commit a transaction. |
tx_rollback | Used by the client and server to roll back a transaction |
tx_set_transaction_timeout | Used by the client and server to set the transaction_timeout property with a timeout value. |
tx_set_transaction_control | Used by the client and server to set the transaction_control property with a control value. |
tx_set_commit_return | Used by the client and server to set the commit_return property. |
tx_info | Used by the client and server to return the global transaction information. |
RQ System
API | Description |
---|---|
tpenq | Used by the client and server to store data in RQ. |
tpdeq | Used by the client and server to load data from RQ. |
tpqstat | Used by the client and server to request the statistics of the data stored in RQ. |
tpextsvcname | Used by the client and server to extract the service name of data that is read from the RQ using tpdeq. |
APIs using Events
API | Description |
---|---|
tpsubscribe | Used by the client and server to register a request for the message of a specific event. |
tpunsubscribe | Used by the client and server to unregister the request for the message of a specific event. |
tppost | Used by the client and server to generate a specific event and send a message. |
Broadcast/Multicast
API | Description |
---|---|
tpbroadcast | Used by the client and server to send an unsolicited message to other clients. |
Windows Environment Programming
tmaxmt.dll
API | Description |
---|---|
WinTmaxAcall | Connects to Tmax to request a service, replies to the Windows procedure with the result, and then closes the connection. |
WinTmaxAcall2 | Connects to Tmax to request a service and receives the reply with a callback function. |
WinTmax.dll
API | Description |
---|---|
WinTmaxStart | Creates a thread to process a message and initializes the used memory. |
WinTmaxEnd | Closes the thread that processed a message and releases the used memory. |
WinTmaxSetContext | Sets the Windows and message number to send data received by Tmax. |
WinTmaxSend | Allows a client to call a service and process other jobs immediately. |
The following describes functions that are used to connect to Tmax and disconnect from Tmax.
The tpstart function connects a client to a Tmax system. Before using ATMI functions to process service requests or transactions, a client must use a tpstart() to connect to a Tmax system.
Before a tpstart() is called, if another ATMI function (tpalloc() or tpcall(), etc) is called, a tpstart(NULL) will be called internally. To not use this operation, the TMAX_ACTIVATE_AUTO_TPSTART environment variable can be set to N. In such case if another ATMI function is called, a TPEPROTO error will occur without calling a tpstart(NULL) internally. If a tpstart() is returned successfully, a client can send an initial service request or can define a transaction. After connecting to a Tmax system successfully, if a tpstart() is called again, a TPEPROTO error will occur. To connect to a Tmax system using a tpstart(), the IP and port number of the server in which the Tmax system is installed are required.
The following describes environment variables required to find server information.:
Variable Name | Description |
---|---|
TMAX_HOST_ADDR | The IP address of a node to which a client is to be connected. This variable is used for a client to be internally connected to a server system when a tpstart() is called. |
TMAX_HOST_PORT | The port number of a node to which a client is to be connected. This variable is used together with a TMAX_HOST_ADDR for a client to be internally connected to a server system when a tpstart() is called. The value of this variable must be defined in a TPORTNO in a Tmax configuration file. When both a client and a server reside in a node, a more effective way to process a client request is to use a domain socket rather than a TCP/IP socket. In this case, a PATHDIR can be specified instead of using a value defined in a TPORTNO. See the TPORNO item in the DOMAIN and NODE sections of a Tmax configuration file. |
TMAX_BACKUP_ADDR | Specifies another Tmax systems node in preparation against a fault in the node that contains the address of a TMAX_HOST_ADDR. A client first attempts a connection to the node with the address of the TMAX_HOST_ADDR. If the connection to the node fails, the client will attempt to connect to the node with the address found in a TMAX_BACKUP_ADDR. |
TMAX_BACKUP_PORT | The Tmax system port number of a node with a TMAX_BACKUP_ADDR address. |
TMAX_CONNECT_TIMEOUT | Specifies a timeout value for connecting to a Tmax system in micro-seconds. (e.g.:3.5) |
Prototype
#include <atmi.h> int tpstart (TPSTART_T *tpinfo )
Parameter
A tpinfo is a pointer for a TPSTART_T structure. This structure uses a TPSTART buffer type, and this buffer must be allocated by a tpalloc() before a tpstart() is called. It is desirable that an allocated buffer is freed with a tpfree() after a tpstart() function is called. A client transfers necessary information with a structure type tpinfo, at the time of connecting systems. A tpinfo parameter contains client information, a notification message handling state, and security information.
A tpinfo can be set to NULL. In this case, the string length for a cltid, dompwd, usrname, and usrpwd will be given as 0. In this situation Tmax security features will not be used and flags will not be chosen.
The following shows a TPSTART_T structure.
struct TPSTART_T{ char cltid[MAXTIDENT+2]; /* Client name (tpbroadcast())*/ char dompwd[MAX_PASSWD_LENGTH+2]; /*Password for system access security*/ char usrname[MAXTIDENT+2]; /*Account for user authentication security*/ char usrpwd[MAX_PASSWD_LENGTH+2]; /*Password for user authentication security*/ int flags; /*Unrequested message type and system access method*/ } ;
Member | Description |
---|---|
cltid | A string ending with a NULL value that has up to a 30-character length. A cltid is a name defined by an application program and is used to specify a client to which a tpbroadcast() will send unrequested messages. |
dompwd | Controls system access in the security steps provided by Tmax. It registers a password for an account set to an OWNER item of the DOMAIN section of a Tmax configuration file. |
usrname | Used for user authentication in the security steps provided by Tmax. A usrname must be an account registered in the passwd file of a Tmax system. |
usrpwd | The password for an account. When user authentication security is established, a client can be connected to Tmax systems and use the services provided by the system, by registering a usrname and a usrpwd. See the SECURITY item of a DOMAIN section in a tmax configuration file for the details of security settings. |
flags | Used to enable a specific function of a client when connecting to a Tmax system. Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPUNSOL_POLL | Receives unrequested messages. |
TPUNSOL_HND | Sets a function that receives unrequested messages. For more information, refer to "9.6.1. tpsetunsol". |
TPUNSOL_IGN | Ignores unrequested messages. If not set, a TPUNSOL_IGN is set by default. |
TPMULTICONTEXTS | Must be set when multithread or multicontext functions are used. |
TPTCPNODELAY | Prevents a Tmax system from using the Nagle algorithm for connecting to a system. |
Return Value
Value | Description |
---|---|
0 or 1 | A function call was successful and 0 to a primary host is returned as well as a 1 to a backup host. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpstart() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a tpinfo is NULL or not a pointer for a TPSTART_T. |
[TPEITYPE] | A tpinfo is not a pointer for a TPSTART_T structure. |
[TPEPROTO] | A tpstart() was called from an invalid state. For example, a tpstart() was called in a server program, or it was called after a connection was already established. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Environment variables may be invalid. For example, a connection failed because a TMAX_HOST_ADDR or TMAX_HOST_PORT was invalid. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; TPSTART_T *tpinfo; tpinfo = (TPSTART_T *)tpalloc(“TPSTART”, NULL, sizeof(TPSTART_T)); if (tpinfo==NULL) { error processing } strcpy(tpinfo->cltname, “cli1”); strcpy(tpinfo->usrname, “navis”); strcpy(tpinfo->dompwd, “tmax”); tpinfo->flags = TPUNSOL_HND; ret=tpstart(tpinfo); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; ret=tpcall(“SERVICE”, buf, 20, &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process.... tpfree((char *) buf); tpend(); }
Related Funciton
tpend()
The tpend function disconnects a client from a Tmax system. If a client is in a transaction mode, a transaction will be rolled back automatically. If a tpend() is returned successfully, a caller will not communicate with any other programs and will not participate in any transactions. Maintained interactive connections will be terminated immediately.
If a tpend() is called more than once (if called again after already being disconnected from a Tmax system), a -1 value will be returned without affecting a system.
Prototype
# include <atmi.h> int tpend (void)
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpend() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpend() was called from an invalid state. For example, a caller is a server or a tpend() was called after being disconnected. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *sndbuf, *rcvbuf; long rcvlen, sndlen; int ret; ret=tpstart((TPSTART_T *)NULL) if (ret==-1) {error processing } buf = (char *)tpalloc(“STRING”, NULL, 0) if (buf=NULL) { error processing } data process … ret=tpcall(“SERVICE”, buf, 0, &buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process … printf(“ data: %s\n”, buf); tpfree((char *)buf); tpend(); }
Related Function
tpstart()
The following describes functions that are used for synchronous communication.
The tpcall function sends a service request to a svc service named through synchronous communication and receives a response. It works similar to calling a tpgetrply() successively after calling a tpacall().
Prototype
# include <atmi.h> int tpcall (char *svc, char *idata, long ilen, char **odata, long *olen, long flags)
Parameter
Parameter | Description |
---|---|
svc | A service to call. Must be provided by a Tmax application server program. |
idata | A pointer to service request data. Must be a buffer that is allocated by a tpalloc(). The type and subtype of an idata must be supported by a svc. |
ilen | Data length.
If an idata is NULL, it will be ignored. |
*odata | Response data buffer pointer with length of a *olen. Must be allocated by a tpalloc(). If the same buffer is used for both sent and received data, a *odata must be set to an idata address. To detect change in a response buffer size, compare the response buffer size allocated to a *odata before a tpcall() is complete and the size of a returned *olen. If a *olen size is larger, an allocated response buffer size will be increased. Otherwise, it will remain the same. If a tpcall() is called when an idata and a *odata are using the same buffer, the address indicated by the idata will no longer be valid if the *odata is changed. The *odata may be changed if received data is too big or for other reasons. If a *olen is returned as a 0, no data will be received and a *odata and a buffer pointed to by the *odata will not be changed. If *odata or *olen are NULL, an error will occur. |
*olen | Reply data length in a *odata. |
flags | A communication mode option. |
The following are available flags:
Flag | Description |
---|---|
TPNOTRAN | If a service does not support transactions in a transaction mode, a TPNOTRAN flag must be set in order to call a tpcall() in a transaction mode. If a caller requests a svc service by setting a flag in a transaction mode, the svc service will be excluded from a transaction mode and then executed. When a process that uses a tx_begin() to start a transaction calls a tpcall() in a transaction mode, it will be affected by a transaction timeout (TXTIME) even if a TPNOTRAN was set. For example, a tpacall with a TPNOTRAN set will fail after a transaction times out without calling a service. If a service called with a TPNOTRAN set fails, a caller's current transaction will not be affected. |
TPNOCHANGE | If a TPNOBLOCK flag is set and a blocking condition (e.g., the internal buffer is full with messages to send) occurs, a request will fail. A TPNOCHANGE is applied only to a Tx in a tpcall(). If a tpacall() is called without setting a TPNOBLOCK flag and a blocking condition occurs, a caller must wait until it is unblocked or timeout (transaction or blocking timeout) occurs. |
TPNOTIME | A caller must wait indefinitely until a response is received and blocking timeout will be ignored. Timeout will occur even if a tpcall() is called during a transaction timeout. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. . |
-1 | A function call failed, and a tperrno is set to an error code. |
Error
If a tpcall() fails, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | Invalid parameter or flag. For example, svc is NULL or idata points to a buffer that was not allocated by a tpalloc(). |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support the idata type or subtype. |
[TPEOTYPE] | A function caller does not know the type or subtype of a response buffer, or flags were set to a TPNOCHANGE but the type or the subtype of the buffer pointed to by a *odata does not match that of the response buffer. In this case, the data in a *odata and a *olen are not changed. If a caller requests a service in a transaction mode, the transaction will be rolled back because the reply will be ignored. |
[TPETRAN] | A xa_start failed due to an error in a database while invoking a transaction service. |
[TPETIME] | A transaction timeout occurred when a caller was in a transaction mode, and the transaction was rolled back. If a caller is not in a transaction mode, a block timeout will occur if both a TPNOTIME and a TPNOBLOCK are not set. In such cases, the data in a *data and a *len are not changed. If a transaction timeout occurs, any new service requests and processes waiting for a response will fail due to a [TPETIME] error until the transaction is rolled back. |
[TPESVCFAIL] | A service routine sent a reply by calling a tpreturn() with a TPFAIL because an error occurred in an application program. Service reply data can be accessed through a *odata. When a transaction timeout occurs, other communication may be attempted before a transaction is rolled back. For such attempts to be successful, a TPNOTRAN must be set. All operations performed while a caller is in a transaction mode are rolled back when the transaction is complete. |
[TPESVCERR] | An error occurred during the execution of a service routine or a tpreturn() (e.g., a wrong argument was passed). If this error occurs, no reply data will be returned (i.e., neither *odata nor *olen is changed). This error occurs when a buffer that was not allocated by a tpalloc is used, the Tmax header of an allocated buffer is affected by an invalid pointer (due to memcpy, etc.), a call descriptor of a tpacall or a tpconnect is returned, or when a service includes invalid conversational data while in a Recv mode. A client will receive this error when attempting to execute a tpreturn. When a TPEV_DISCOMN event occurs (e.g., after a client forcefully disconnects a conversation, a service program will receive a TPEV_DISCOMN) a client will receive this error through a tpreturn of a service. When a caller is in a transaction mode, other communication may be attempted before a transaction is rolled back and timeout occurs. For such attempts to be successful, a TPNOTRAN must be set. All operations performed while a caller is in a transaction mode are rolled back when a transaction is complete. A SVCTIMEOUT can be specified for each service. If a service execution time exceeds a specified limit, a service will stop executing and will return a TPESVCERR. If a SVCTIMEOUT occurs, a tpsvctimeout() will be called. Operations such as buffer lock releases and logging can be performed during a tpsvctimeout() as needed. |
[TPEBLOCK] | Blocking occurred while a TPNOBLOCK was set. |
[TPGOTSIG] | A signal was received while a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpcall() was called in an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char *sndbuf, *rcvbuf; long sndlen, rcvlen; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } sndbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (sndbuf==NULL) {error processing }; rcvbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (rcvbuf==NULL) {error processing }; data process.... sndbuf=strlen(sndbuf); ret=tpcall(”SERVICE”, sndbuf, sndlen, &rcvbuf, &rcvlen, TPNOCHANGE); if (ret==-1) { error processing } data process.... tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Related Functions
tpalloc(), tpacall(), tpgetrply(), tpreturn()
The following describes functions that are used for asynchronous communication.
The tpacall function sends a service request to a svc service through asynchronous communication and returns a response immediately. A response can be obtained using a tpgetrply() or canceled using a tpcancel().
Prototype
# include <atmi.h> int tpacall (char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
svc | A service to call. Must be provided by a Tmax application server program. |
data | A pointer to a buffer allocated by a tpalloc(). |
len | The length of data to be sent.
If data is NULL, len will be ignored and a service request is received without data. The data type and subtype must be supported by svc. If a service request is sent in transaction mode, a reply must be received. |
flags | Flags are listed in the following table. |
The following are the available flags:
Flag | Description |
---|---|
TPBLOCK | If a tpacall is used without a flag, a normal reply is returned even if a called service does not exist in a svc or an invalid result is returned. An error is returned when a tpgetrply is called. If a TPBLOCK is used to call a tpacall(), the service state can be checked. |
TPNOTRAN | If a service does not support transactions in a transaction mode, a TPNOTRAN flag must be set in order to call a tpacall(). If a caller requests a svc service by setting a flag in a transaction mode, a svc service will be excluded from the transaction mode and executed. When a process that uses a tx_begin() to start a transaction calls a tpacall() in a transaction mode, it is affected by a transaction timeout (TXTIME) even if a TPNOTRAN is set. For example, a tpacall with a set TPNOTRAN will fail after a transaction times out without calling a service. If a service called when a TPNOTRAN is set fails, the current transaction of the caller will not be affected. |
TPNOREPLY | If a tpacall() is used to send a service request, tpacall will be returned immediately without waiting for a response. A client can retrieve results by using a tpgetrply() through the descriptor returned by tpacall(). If a TPNOREPLY is set, a tpacall() will not receive a reply and will return a 0 if a service is called successfully. If a caller is in transaction mode, a TPNOREPLY must be set together with a TPNOTRAN. If a TPNOREPLY is set, a TPBLOCK must also be set in order to check a service state. If a TPBLOCK is not set, an error will not be returned even if a service is NRDY. |
TPNOBLOCK | If there is a blocking condition (e.g., an internal buffer is filled with messages to transmit), this option will cause a request to fail. If a tpacall() is called without setting a TPNOBLOCK flag and a blocking condition occurs, a caller must wait until a timeout (transaction or blocking timeout) occurs. |
TPNOTIME | A caller must wait indefinitely until a response is received. Blocking timeouts are ignored. A timeout will occur even if a tpacall() is called during a transaction timeout. |
TPSIGRSTRT | Allows signal interrupts. If a system function call is interrupted by a signal, it will be re-executed. If a signal interrupt occurs without this flag set, a function will fail and tperrno will be set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call is successful. A returned descriptor is used to get a service reply. |
-1 | A function call failed, and a tperrno is set to an error code. |
Error
If a tpacall() fails, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, when a svc is NULL, data will point to a buffer that was not allocated by a tpalloc(), or a flag will be invalid. |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A data type or subtype is not supported by a svc. For a struct, this error occurs when the struct is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests has been reached. A request cannot be sent. |
[TPETIME] | A transaction timeout occurred when a caller was in a transaction mode, and a transaction was rolled back. If a caller is not in a transaction mode, a block timeout will occur if both a TPNOTIME and a TPNOBLOCK are not set. In such cases, the data in *data and *len are not changed. If a transaction timeout occurs, any new service requests and processes waiting for a response will fail due to a [TPETIME] error until the transaction is rolled back. |
[TPEBLOCK] | Blocking occurred while a TPNOBLOCK is set. |
[TPGOTSIG] | A signal is received while a TPSIGRSTRT is not set. |
[TPEPROTO] | A tpacall() was called in an invalid state. For example, a TPNOREPLY was called in a transaction mode without setting a TPNOTRAN. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len; ret=tpstart((TPSTART_T *)NULL); if (ret<0) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing } data process.... cd = tpacall(“SERVICE”, sndbuf, 20, TPNOTIME); if (cd<0) {error processing } data process… ret=tpgetrply(&cd, (char **)&buf, &len, TPNOTIME); if (ret<0) { error processing } data process.... tpfree((char *)buf); tpend(); }
Related Functions
tpalloc(), tpcall(), tpcancel(), tpgetrply()
The tpgetrply function is used to get a reply for an asynchronous service request made through a tpacall(). This function can be used on both a client and a server.
Prototype
# include <atmi.h> int tpgetrply(int *cd, char **data, long *len, long flags)
Parameter
Parameter | Description |
---|---|
cd | A call descriptor returned by a tpacall(). In general, a tpgetrply waits until a response for a cd is received or until a timeout occurs. In general, a cd will become invalid after a tpgetrply receives a valid response. |
*data | Must be a pointer to a buffer allocated by a tpalloc(). |
len | The length of data received from a tpgetrply(). If necessary, a buffer size can be increased to store a reply. A *data can be changed for various reasons, including if a buffer is too small for received data. Before a tpgetrply is called, if a len is greater than the total size of a buffer, a buffer size will be set to the valu of len. If a returned len value is 0, no response will be received and buffers pointed to by a *data and len will not be changed. An error will occurs if a *data or a len is NULL. |
flags | Flags are listed in the following table. |
The following are the available flags:
Flag | Description |
---|---|
TPGETANY | Ignores an input argument call descriptor (cd) for a response and returns a reply that can be received. In general, a tpgetrply() will wait until a response is received. If a TPGETANY is not set, a *cd becomes null unless there is no specific configuration. If set, a cd can be used for an error response. If an error occurs before a response is returned, a cd will be set to 0. Unless otherwise specified, this does not affect a current transaction for a caller. |
TPNOCHANGE | The buffer type that a *data points to cannot be changed. If the types of a response buffer and a *data buffer do not match, the *data buffer type will be changed to the type of the response buffer. If a TPNOCHANGE flag is set, a buffer type will not be changed. The buffer type and subtype of a response buffer must be the same as those of a *data buffer. |
TPNOBLOCK | Does not wait for a response, but returns a valid response if available. If a TPNOBLOCK flag is not set, and there is no available response, a caller will wait until a response is received or a timeout (transaction or block timeout) occurs. |
TPNOTIME | A caller must wait indefinitely until a response is received. Blocking timeouts are ignored and timeout will occur even if a tpgetrply() is called during a transaction timeout. |
TPSIGRSTRT | Allows signal interrupts. If a system function call is interrupted by a signal, it will be re-executed. If a signal interrupt occurs without this flag set, the function will fail and a tperrno will be set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. When a tpgetrply() returns successfully or a tperrno is [TPESVCFAIL], the global variable tpurcode returned by a tpreturn() will be set to a value defined in the application. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
If a tpgetrply() fails, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a cd, data, *data, or a len is NULL or a flags is invalid. If a cd is not NULL, it is valid even if an error occurs, and a function will continue to wait for a response. |
[TPEBADDESC] | An invalid cd. |
[TPEOTYPE] | A caller does not know the type or subtype of a response buffer. In this case, flags are set to TPNOCHANGE but the type or subtype of *data does not match that of the response buffer, so the data in *data and *len are not changed. If the caller received a response in a transaction mode, the transaction will be rolled back because the response will be ignored. |
[TPETIME] | A transaction timeout occurred when a caller is in a transaction mode, and the transaction is rolled back. If a caller is not in a transaction mode, a block timeout will occur if both a TPNOTIME and a TPNOBLOCK are not set. In such cases, the data in a *data and a *len are not changed. If a transaction timeout occurs, any new service requests and processes waiting for a response will fail due to a [TPETIME] error until the transaction is rolled back. |
[TPESVCFAIL] | A service routine sent a reply by calling a tpreturn() with a TPFAIL because an error occurred in an application program. Service reply data can be accessed through a *data. If a caller is in a transaction mode, the transaction will be rolled back. When a transaction timeout occurs, other communication may be attempted before a transaction is rolled back. For such attempts to be successful, a TPNOTRAN must be set. All operations performed while a caller is in a transaction mode are rolled back when the transaction is complete. |
[TPEBLOCK] | Blocking occurred while a TPNOBLOCK was set. A cd is valid. |
[TPGOTSIG] | A signal was received while a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpcall() was called in an invalid state. |
[TPETRAN] | A xa_start failed due to an error in the database while invoking a transaction service. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; long len; char *buf; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process … cd = tpacall(“SERVICE”, buf, 0, TPNOFLAGS); if (cd==-1) { error procesing } data process.... ret=tpgetrply(&cd, &buf, &len, TPNOTIME); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpacall(), tpalloc(), tpreturn()
The tpcancel function cancels a server or client response. It cancels a cd, the caller description returned by a tpacall().
Prototype
# include <atmi.h> int tpcancel (int cd)
Parameter
Parameter | Description |
---|---|
cd | A target to be canceled, which is set by a caller descriptor returned by a tpacall(). Services related to global transactions cannot be canceled. If a service response is canceled, a cd is nullified and all responses received through the cd are ignored. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpcancel() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid cd. |
[TPETRAN] | A cd is related to a caller's global transaction. It is still valid and the caller's current transaction is not affected. |
[TPEPROTO] | A tpcanceled() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *test[2]; int ret, i, cd[2]; long len; if (argc != 4) { error processing } ret=tpstart((TPSTART_T *)NULL; if (ret==-1) { error processing } for (i=0; i<3; i++) { test[i] = tpalloc(“STRING”,NULL,0); if (test[I])==NULL} { error processing } strcpy(test[i],argv[i+1]); cd[i]=tpacall(“SERVICE”, test[i], 0, TPNOTIME); ) ret=tpcancel(cd[1]); /* Cancels the second response. */ if (ret==-1) { error processing } for (i=0; i<3; i++) { ret=tpgetrply(&cd[i], (char **)&test[i], &len, TPNOTIME) if (ret==-1) printf(“Can’t rcv data from service of %d\n”,cd[i]); else prtinf(“%dth rcv data : %s\n”, I+1, test[I]); tpfree(test[I]); } tpend(); }
Related Function
tpacall()
The following describes functions that are used for interactive communication.
The tpconnect function allows a program to communicate with an interactive service svc. Communication is half-duplex, which only allows receiving or sending but not both at the same time. During a connection configuration process, a function caller can deliver data to a service routine. Interactive services receives data and len using a TPVCINFO structure, so calling a tprecv() is unnecessary to receive data delivered by a tpconnect(). This function can be used on both a client and a server.
Prototype
# include <atmi.h> int tpconnect (char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
svc | The service name of an interactive service. |
data | A buffer must be allocated by a tpalloc() for a caller to deliver data. |
len | The length of data to be sent.
If data is NULL, a len will be ignored and a service request will be received without data. The data type and subtype must be supported by a svc. |
flags | An option to call a function. Determines a call mode. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOTRAN | If a tpconnect() caller requests a svc service by setting a TPNOTRAN flag in a transaction mode, the svc service will be excluded from a transaction mode and then executed. If a svc does not support transactions in a transaction mode and a tpconnect() is called in a transaction mode, a flag must be set to TPNOTRAN. If a tpconnect() is called in a transaction mode, it is affected by a transaction timeout even if TPNOTRAN is set. If a service with a TPNOTRAN flag set fails, a caller's transaction will not be affected. |
TPSENDONLY | After a connection is made, a caller can initially only send data and only requested services can be performed, so at first, a caller only has communication control. Either a TPSENDONLY or TPRECVONLY must be set. |
TPRECVONLY | After a connection is made, a caller can initially only receive data and a requested service will send data, so at first, a requested service only has communication control. Either a TPSENDONLY or TPRECVONLY must be set. |
TPNOTIME | A function caller must wait indefinitely until a response is received. Blocking timeouts are ignored. If a tpacall() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, the function will fail and a tperrno will be set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call was successful and a descriptor used for a following connection is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
If a function call fails, a caller's transaction will not be affected unless there is a specific direction. When a tpconnect() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | Cannot request a service because a service corresponding to a svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. |
[TPELIMIT] | A maximum number of connections has been reached. Cannot request a service. |
[TPETRAN] | A xa_start failed because a problem occurred in a database when a transaction service was requested. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, the transaction will be rolled back. If the function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, *data content and *len are not changed. If a transaction timeout occurs, new service requests and processes waiting for a response fail with the [TPETIME] error until the transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal was received when a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpconnect() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *buf; int ret, cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”,NULL,0); if (buf=NULL) { error procesing } data process .... cd = tpconnect(“SERVICE”,sndbuf,0,TPRECVONLY); if (cd==-1) { error processing } data process.... ret=tprecv(cd, &buf, &len, TPNOFLAGS, revent); if (ret==-1) { error processing } tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpdiscon(), tprecv(), tpsend()
Available in a server and a client. The tpsend function sends data to a partner program in an interactive communication. A caller must have communication control.
Prototype
# include <atmi.h> int tpsend (int cd, char *data, long len, long flags, long *revent)
Parameter
Parameter | Description |
---|---|
cd | Sets a connection to receive data. It is a descriptor returned by a tpconnect() or a TPSVCINFO parameter. |
data | A buffer allocated by a tpalloc(). If no application data is received (for example, only a communication control was passed without any data), data can be NULL. The data type and subtype must be recognizable by a connected partner. |
len | A buffer length to receive. If data points to a buffer that does not need to be specified, a len will be ignored and 0 will be used. If data points to a buffer which must be specified, a len cannot be 0. |
flags | Flag values are listed in the table below. |
revent | If an event exists for a descriptor cd, a tpsend() will fail and data will not be received. The event type will be returned as a revent. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOBLOCK | If a blocking situation occurs, for example if an internal buffer is filled with messages to be sent, data and events will not be sent. If a tpsend() is called without setting a TPNOBLOCK flag or if a blocking state occurs, a caller will wait until either a transaction or a block timeout occurs or a state is resolved. |
TPNOTIME | A function caller waits for a response and infinitely ignores a block timeout. If a tpsend() is used within a transaction timeout, the transaction time will still apply. |
TPRECVONLY | A caller sends a communication control to a partner after receiving data. A caller cannot call a tpsend() until it receives a communication control again. A communication partner will receive a TPEV_SENDONLY event, which means a communication control will be received when receiving data using a tprecv(). A receiver cannot call a tprecv() until receiving a communication control from a partner. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to TPGOTSIG. |
The events that can be delivered to revent are as follows:
Event Type | Description |
---|---|
TPEV_DISCONIMM | A communication starter used a tpdiscon() to forcefully terminate a connection. This event is received by a communication subordinate and is returned when a connection is terminated due to a communication error such as server, node, or network error. |
TREV_SVCERR | This event is received by a communication starter and notifies that a communication subordinator performed a tpreturn() without a communication control being in a TPEV_SVCFAIL state. |
TREV_SVCFAIL | This event is received by a communication starter and notifies that a communication subordinator performed a tpreturn() without a communication control, and that a tpreturn() was called as a TPFAIL without data and that it was performed as a TPFAIL rval and had data with a NULL value. |
Return Value
If a revent is a TREV_SVCFAIL, a tpurcode global variable is set to a rcode value, which is delivered when calling a tpreturn().
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsend() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPEBADDESC] | An invalid cd. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEEVENT] | An event occurred. If an error occurs, data will not be sent and an event type will be returned as a revent. |
[TPEBLOCK] | A blocking state occured when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT was not set. |
[TPEPROTO] | A tpsend() was called from an invalid state. For example, a tpsend() was called in a receiver mode. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” main(int argc, char* argv[]) { int ret, cd; struct dat *buf; long revent, len; if (argc!=3) {error processing } ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct dat *)tpalloc(“STRUCT”, “dat”, 0); if (buf==NULL) { error processing } strcpy(buf->sdata, argv[1]); data process…. cd=tpconnect(“SERVICE”, buf, 0, TPSENDONLY); if (cd==-1) { error processing } strcpy(buf->sdata, argv[2]); data process…. ret=tpsend(cd, buf, 0,TPRECVONLY,&revent); if (ret==-1) { error processing } ret=tprecv(&cd,(char**)&buf,&len,TPNOTIME,&revent); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpconnect(), tpdiscon(), tprecv(), tpreturn()
Available in a server and a client. The tprecv function receives messages in an interactive communication. This is used to receive data sent from a partner in an interactive communication. A tprecv() can be used only by a program (on a server or a client) which does not have communication control.
Prototype
# include <atmi.h> int tprecv (int cd, char **data, long *len, long flags, long *revent)
Parameter
Parameter | Description |
---|---|
cd | Sets a connection to receive data. It is a descriptor returned by a tpconnect() or a TPSVCINFO parameter. |
data | Pointer to a buffer allocated by a tpalloc(). If a function successfully returns, a *data will point to received data. |
len | The length of data to be sent. If the value of a len is bigger than the total size of a buffer before calling it, the size of the buffer will be set to the value of len. If the value of a len is 0, no data will be received and neither *data nor a buffer, which a *data points to, will be changed. |
flags | Flag values are listed in the table below. |
revent | The event types returned to a revent are explained in the following table. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOCHANGE | If a received response buffer and a buffer type that a *data points to are not the same, the buffer type of a *data will be changed to a received response buffer type in a scope that a receiver can recognize. If a TPNOCHANGE flag is set, the buffer type that a *data points to will not be changed. A received response buffer type and subtype must be the same with those of the buffer that a *data points to. |
TPNOBLOCK | Does not wait for data. If there is receivable data the data will be returned. If a TPNOBLOCK flag is not set, and there is no receivable data, a caller will wait for data to arrived. |
TPNOTIME | A function caller waits infinitely until a response is received, and ignores block timeouts. If a tprecv() is used within a transaction timeout, a transaction time will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to TPGOTSIG. |
The following describes event types that are returned to a revent:
Event Type | Description |
---|---|
TPEV_DISCONIMM | A communication starter used a tpdiscon() to forcefully terminate a connection. This event is received by a communication subordinate. This event is also returned when a connection is terminated due to a communication error such as a server, node, or network error. Any data being sent may be lost. If two programs participate in the same transaction, the transaction will be rolled back. a cd used by an interactive communication will not be valid. |
TPEV_SENDONLY | A connected partner program gave up on a communication control. A TPEV_SENDONLY event receiver can send data but cannot receive any data until a receiver returns a control. |
TPEV_SVCERR | This event notifies a communication starter of an error that occurred while a communication subordinator executes a tpreturn(). The error can occur if an invalid parameter is passed to a tpreturn(), or a tpreturn() is called while a service maintains a connection to another subordinator. In these cases, a return code or a part of data cannot be used. An interactive connection will be terminated a cd will not be valid. If this event occurs during a receiver's transaction, the transaction will be rolled back. |
TPEV_SVCFAIL | This event notifies a communication starter of information that a service of a communication subordinator was terminated due to a failure. A tpreturn() was called using a TPFAIL as an argument. If a communication subordinator service has a communication control when calling a tpreturn(), a service cannot send data to a connected partner. A server process terminates an interactive connection when a service is terminated. Therefore, a cd will not be valid anymore. If this event occurs to a receiver transaction process, the transaction will be rolled back. |
TPEV_SVCSUCC | This event, which a communication starter receives, notifies that a communication subordinator service was terminated successfully. This event notifies a communication starter that a service of a communication subordinator was terminated successfully. A tpreturn() was called using a TPSUCCESS as an argument. |
Return Value
If the value of a revent is TREV_SVCSUCC or TREV_SVCFAIL, a tpurcode global variable that is delivered by a tpreturn() will be defined by an application. Otherwise, a -1 will be returned and a tperrno will be set to the value corresponding to a state. If an event has no error, a tprecv() will return a -1 and a tperrno will be set to [TPEEVENT].
Error
When a tprecv() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid cd. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPEEVENT] | An event occurred. Use a revent to find the event type. |
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, a *data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPEOS] | An operating system error occurred. |
[TPEOTYPE] | The type or subtype of an entered buffer is unknown to a caller, or a TPNOCHANGE flag was set but the type or subtype of a buffer pointed to by a *data did not match the type or subtype of an entered buffer. In this case, both the contents of a *data and a *len are not changed. If interactive communication is a part of a transaction, the transaction will be rolled back because a reply will be ignored. If an error occurred, the event for a cd will be ignored and an interactive communication state cannot be guaranteed. Therefore a caller must terminate an interactive communication. |
[TPEPROTO] | A tprecv() was called from an invalid state. For example, a tprecv() was called in a sender mode. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK are set. In these cases, a *data content and a *len are not changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPGOTSIG] | A signal was received when a TPSIGRSTRT was not set. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” main(int argc,char* argv[]) { int ret, cd; struct dat *buf; long revent, len; if (argc!=3) {error processing } ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct dat *)tpalloc(“STRUCT”, “dat”, 0); if (buf==NULL) { error processing } strcpy(buf->sdata, argv[1]); data process…. cd=tpconnect(“SERVICE”, buf, 0, TPSENDONLY); if (cd==-1) { error processing } strcpy(buf->sdata, argv[2]); data process…. ret=tpsend(cd, buf, 0,TPRECVONLY,&revent); if (ret==-1) { error processing } ret=tprecv(cd,(char**)&buf,&len,TPNOTIME,&revent); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpconnect(), tpdiscon(), tpsend()
The tpdiscon function terminates an interactive communications connection. If a service is connected by a tpconnect(), in extremely rare cases the connection will immediately terminate and a TPEV_DISCONIMM event will occur for the connection partner. This function can be used on both a client and a server.
A tpdiscon() can be called only by the side that started an interactive communication. The service that provides a descriptor cannot call a tpdiscon(). A program that communicates with an interactive service can terminate communication. To ensure correct results, a tpreturn() should be called to terminate the connection.
A tpdiscon() terminates a connection forcibly, which may result in data that did reach a target to become lost. It can be called while a connected program participates in a caller's transaction. In this case a transaction is canceled and data may be lost. A function caller does not need to have communication control.
Prototype
# include <atmi.h> int tpdiscon (int cd)
Parameter
Parameter | Description |
---|---|
cd | A descriptor returned by a tpconnect(). |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpdiscon() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | An invalid cd, or a cd is already in use by an interactive service. |
[TPETIME] | A timeout occurred due to an invalid cd. |
[TPEPROTO] | A tpdiscon() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <stdlib.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret, cd; char *buf long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... cd=tpconnect(“SERVICE”,buf,0,TPRECVONLY); if (cd==-1) { error processing } data process.... ret=tprecv(cd, (char **)&buf, &len, TPNOFLAGS, &revent); if (ret==-1 && revent != TPEV_SENDONLY && revent != TPEV_SVCSUCC) { error processing } printf(“received data = %s\n”, buf); if (atoi(buf)>90) { ret=tpdiscon(cd); if (ret==-1) {error processing } tpfree(buf); tpend(); exit(1); } data process.... tpfree(buf); tpend(); }
Related Functions
tpconnect(), tprecv(), tpreturn(), tpsend()
These functions are used to send messages unilaterally or to process messages received unilaterally. Not all clients can always receive unsolicited messages (tpbroadcast()) sent by a server. To receive an unsolicited message, the client must be connected to Tmax. When connecting to Tmax, the client must notify the server that it can receive unsolicited messages.
For Tmax to handle data that is sent from a server unilaterally, the flags field of the TPSTART_T structure, which is used when calling tpstart(), must be set to TPUNSOL_POLL or TPUNSOL_HND.
The tpsetunsol function is available in a client. It sets a routine that processes unrequested and received messages. How a system receives unrequested messages is determined by each application and can be changed by each client.
Any unrequested messages received by Tmax libraries before a tpsetunsol() is called will be ignored. A tpsetunsol() that is called by a NULL function pointer is also ignored. The function pointer delivered by a call must be suitable for a parameter definition.
Prototype
# include <atmi.h> Unsolfunc *tpsetunsol (void ( *disp ) ( char *data, long len, long flags ) )
Parameter
Parameter | Description |
---|---|
data | Points to a received type buffer. If there is no data, a DATA can be NULL. If a buffer type or subtype of a DATA are unknown by a client, data cannot be recognized. An application cannot delete a DATA, instead a system deletes it and nullify a data area to return. |
len | Data length |
flags | Not currently supported. |
Return Value
Value | Description |
---|---|
Pointer / NULL | A function call was a success.
|
TPUNSOLERR | A function call failed. An error code will be set in tperrno. |
Error
When a tpsetunsol() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpsetunsol() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” void get_unsol(char *data, long len, long flags) { printf(“get unsolicited data = %s\n”, data); data process.... } void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } ret=tpsetupsol_flag(TPUNSOL_HND); if (ret==-1) { error processing } ret=tpsetunsol(get_unsol); if (ret==TPUNSOLERR) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process... ret=tpcall(“SERVICE”, buf, 20, (char **)&buf, &len, TPNOFLAGS); if (ret==-1) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tpstart(), tpend(), tpgetunsol()
The tpgetunsol function processes a message that was received unilaterally without a client request. The message is sent through a tpbroadcast(), tpsendtoci(), tppost() from a sender.
All messages received before calling a tpgetunsol() will be ignored. To receive unrequested messages through a tpgetunsol(), a TPUNSOL_POLL or a TPUNSOL_HND must be set when connecting to a Tmax system through a tpstart(). If a tpgetunsol() is called from a program, a client will receive an unrequested message from a server because a flag has been changed to TPUNSOL_POLL internally even though the flag of a tpstart() was initially set to TPUNSOL_IGN.
Prototype
#include <tmaxapi.h> int tpgetunsol (int type, char **data, long *len, long flags)
Parameter
Parameter | Description |
---|---|
type | A message type delivered from a server. The types are UNSOL_TPPOST, UNSOL_TPBROADCAST, and UNSOL_TPSENDTOCLI. |
data | A pointer to a delivered message. If this is a buffer type or subtype that is not known by a client, "data" cannot be used. |
len | The total length of a message. |
flags | Determines whether to block a message. Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | A caller waits for a reply in a blocking state. |
NOCHANGE | In general, if a received response buffer and the buffer type pointed to by a *data do not match, the *data buffer type will be changed to a received response buffer in a scope that a receiver can recognize. If this is set, the buffer type pointed to by a *data cannot be changed. A received response buffer type and subtype must match those of a buffer pointed to by a *data. |
TPNOTIME | A function caller must wait indefinitely until a response is received. Blocking a timeout will be ignored. If a tpgetrply() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and tperrno will be set to TPGOTSIG. |
TPGETANY | Ignores a cd as an input value and returns any receivable responses. A cd will become a caller descriptor for a returned response. If there is no response, a tpgetrply() will wait until a response is received. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetunsol() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A tpgetunsol() was called from an invalid state. A tpstart() will not be executed, and a TMAX_ACTIVATE_AUTO_TPSTART will be set to N. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <string.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... while(1) { ret=tp_sleep(2); if (ret==-1) { error processing } if (ret==0) printf(“nothing happened\n”); else { ret=tpgetunsol(UNSOL_TPSENDTOCLI, (char **)&buf, &len, TPNOCHANGE); if (ret==-1) { error processing } printf(“received data : %s\n”, buf); } data process.... if (strncmp(buf, “end”, 3)==0) break; } data process.... tpfree(buf); tpend(); }
Related Functions
tpbroadcast(), tpsetunsol(), tpstart(), tpend()
The following describes functions that are used to change timeout.
Available in a server and a client. The tpset_timeout function sets a block timeout, a service limited time set in a server. If a timeout is set using a tpset_timeout(), the response for a service request will wait during the specified amount of time. If a response is not received during the specified amount of time, a timeout error will occur and the service request will be returned as a failure without waiting for a response.
A tpset_timeout() applies to service requests that were received after this function was called. The function is valid until a tpset_timeout() is called again, or a client or server process is terminated. If a tpset_timeout() is not used, a BLOCKTIME set in a Tmax configuration file will be used as a block timeout.
Prototype
#include <tmaxapi.h> int tpset_timeout (int sec)
Parameter
Parameter | Description |
---|---|
sec | Sets a block time in seconds. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpset_timeout() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *sndbuf, *rcvbuf; long sndlen, rcvlen; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } sndbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (sndbuf==NULL) {error processing }; rcvbuf = (char *)tpalloc(“CARRAY”, NULL, 20); if (rcvbuf==NULL) {error processing }; data process.... sndbuf=strlen(sndbuf); ret=tpset_timeout(4); if (ret==-1) { error processing } ret=tpcall(“SERVICE”, sndbuf, sndlen, &rcvbuf, &rcvlen, TPNOCHANGE); if (ret==-1) { error processing } data process.... tpfree((char *)sndbuf); tpfree((char *)rcvbuf); tpend(); }
Available in a server. The tpsetsvctimeout function sets a service timeout in a server. If a service time is set using a tpsetsvctimeout(), a service request will wait for a response during the time set by this function. If a response was not received during the set time, a timeout error will occur and a service request will be returned as a service failure without waiting for a response.
Prototype
#include <tmaxapi.h> int tpsetsvctimeout (int sec, long flags)
Parameter
Parameter | Description |
---|---|
sec | Sets a service timeout in seconds. |
flags | Not currently supported. |
Return Value
Value | Description |
---|---|
0 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsetsvctimeout() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <stdlib.h> #include <usrinc/tmaxapi.h> #include <usrinc/tdlcall.h> TOUPPER(TPSVCINFO *msg) { int i; if ( tpsetsvctimeout(10, 0) < 0 ) ; //error handle code printf("TOUPPER service is started!\n"); sleep(15); printf("INPUT : data=%s\n", msg->data); for (i = 0; i < msg->len; i++) msg->data[i] = toupper(msg->data[i]); printf("OUTPUT: data=%s\n", msg->data); tpreturn(TPSUCCESS,0,(char *)msg->data, 0,0); }
Bcause memory allocation methods and data types differ according to hardware and operating system, received data may have different data values. Therefore, in a general client/server environment, heterogeneous systems communicate through conversion, which creates network overhead.
The following describes APIs that are used for buffer management.
A server or client allocates the buffer type to be used. A buffer cannot be set by malloc(), realloc(), or free() of C library. For example, the buffer allocated with tpalloc() cannot be deleted through free().The tpalloc function allocates a typed buffer in servers and clients. It cannot be used along with malloc(), realloc(), or free() of C library. For example, a buffer allocated by tpalloc() cannot be released by free().In this case, tpfree() must be used.
The tpalloc function allocates a buffer of the type specified by "type", and it returns the pointer to the buffer. The buffer subtype and size can also be specified for some types. Some types of buffers require initialization, so tpalloc() initializes and returns pointers to these buffers. The buffer returned to the caller can be used immediately. If tpalloc() fails to initialize the buffer to 0, the allocated buffer becomes free.
Prototype
# include <atmi.h> char * tpalloc (char *type, char *subtype, long size)
Parameter
Parameter | Description |
---|---|
type | Buffer type. Input options:
|
subtype | For STRUCT, X_C_TYPE, and X_COMMON type buffers, a subtype must be set. Only the first 8 bytes of type and the first 16 bytes of subtype are used. Any remaining data is truncated. If the specified buffer type does not use a subtype, the subtype is ignored and NULL is used. The default allocated buffer size is greater than 1024 bytes. |
size | If type is CARRY or X_OCTET, size must be specified. size is not required for other buffer types. If size is 0, the default size of each buffer is used. The default size of STRING, STRUCT, X_C_TYPE, X_COMMON is 1024 bytes. The default size of CARRY is 0, but the size must be greater than 0 when allocating a buffer. |
Return Value
Value | Description |
---|---|
Buffer Pointer | A function call was successful and a proper buffer pointer is returned. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tpalloc() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a type is NULL. |
[TPENOENT] | Unknown type or subtype. For example, in a STRUCT buffer type the subtype (tag name of the structure) does not exist in SDLFILE. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
[TPEOTYPE] | Buffer type is STRUCT but the server is compiled without a structure file. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” void main(int argc, char *argv[]) { int ret; struct data *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret<0) { error processing } buf=(struct data *)tpalloc(“STRUCT”, “data”,0); data process.... ret=tpcall(“SERVICE”, (char *)sndbuf, 0, (char **)&rcvbuf, &len, TPNOFLAGS); if (ret<0) {error processing } data process.... tpfree((char *)buf); tpend(); }
Related Functions
tpfree(), tprealloc(), tptypes()
The tprealloc function reallocates a buffer pointed to by a ptr in bytes, and returns a pointer for a new buffer (when a buffer is changed).
Like a tpalloc(), a buffer size must be larger than the default size (1024 bytes). A buffer type is kept the same even after it is reallocated. When a function successfully returns a pointer, the returned pointer is used to refer to a reallocated buffer. At this time, a ptr cannot be used any more. If a reallocated buffer size is smaller than a previous buffer size, the original ptr content can not be ensured.
Some buffer types need to be initialized to be used. A tprealloc() re-initializes a re-allocated buffer and then returns it. Therefore, a buffer returned to a caller can be used immediately. If it fails to reinitialize a buffer, a tprealloc() will returns a NULL and data in a buffer pointed by a ptr will not be valid.
Prototype
# include <atmi.h> char * tprealloc (char *ptr, long size)
Parameter
Parameter | Description |
---|---|
ptr | A pointer to a buffer to be allocated. |
size | The size of a buffer to be allocated. |
Return Values
Value | Description |
---|---|
Buffer Pointer | A function call was successful and a proper buffer pointer is returned. |
NULL | A function call failed. A tperrno is set to an error code. |
Error
When a tprealloc() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a buffer pointed by a ptr is not the one allocated by a tpalloc(). |
[TPEPROTO] | A tprealloc() was called from an invalid state. |
[TPENOENT] | A buffer pointed to by a ptr was not allocated by a tpalloc(). |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { char *buf; buf=tpalloc(“STRING”,NULL,10); if (buf==NULL) { error processing } buf=tprealloc(buf,20); /* ok */ if (buf==NULL) { error processing } buf=”test”; buf=tprealloc(buf,30); /*error : TPEINVAL */ if (buf==NULL) { error processing } }
Related Functions
tpalloc(), tpfree(), tptypes()
This function cannot be used together with a malloc(), realloc(), or free() from a C library. For example, it is impossible to free a buffer allocated by a tprealloc() using a free().
The tpfree function releases memory that is allocated to a typed buffer by a tpalloc() or a tprealloc(). This function can be used on both a client and a server.
Prototype
# include <atmi.h> void tpfree(char *ptr)
Parameter
Parameter | Description |
---|---|
ptr | A pointer to a buffer allocated by a tpalloc() or a tprealloc(). If a ptr is NULL, nothing will happen. If a ptr points to a non-typed buffer or a buffer already released by a tpfree(), nothing will happen. If a ptr points to a buffer sent to a service routine, a tpfree() will not free the buffer but instead will return it as it is. To free some buffer types, related data or status information must first be removed. A tpfree() removes related information before freeing these types of buffers. Once a tpfree() returns, a ptr cannot be transferred to a XATMI routine as a parameter, and it cannot be used in any other way. |
Return Value
A tpfree() function does not return any value to a function caller.
Example
#include <usrinc/atmi.h> #include <stdio.h> #include “../sdl/demo.s” void main(int argc, char *argv[]) { int ret; struct data *buf; char *message, *message2; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct data *)tpalloc(“STRUCT”, “data”,0); if (buf==NULL) { error processing } message=tpalloc(“STRING”, NULL, 0); if (message==NULL) { error processing } message2=tpalloc(“CARRAY”, NULL, 20); if (message==NULL) { error processing } data process.... tpfree((char *)buf); tpfree(message); tpfree((char *)message2); tpend(); }
Related Functions
tpalloc(), tprealloc()
A tpfree() cannot be set with a malloc(), a realloc(), or a free() from a C library. A buffer allocated by a tpalloc() cannot be freed using a free().
The tptypes function provides information about the type and subtype of a buffer. This function is available both in a server and a client. A tptypes() function receives a pointer for a data buffer, and returns the type and subtype of the buffer.
Prototype
#include <atmi.h> long tptypes (char *ptr, char *type, char *subtype)
Parameter
Parameter | Description |
---|---|
ptr | Must indicate a buffer allocated by a tpalloc(). |
type, subtype | Types and subtypes will have type and subtype names of each buffer respectively for the string they indicate if they are not NULL. If names have a maximum length (8 characters for a type, and 16 characters for a subtype), a string could not end with a NULL. If there is no subtype, the arrangement indicated by a subtype will contain a NULL string ('''''). Only the first 8 bytes of a type and 16 bytes of a subtype have valid values. |
Return Value
Value | Description |
---|---|
Buffer Size | A function call was successful and a proper buffer pointer is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tptypes() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a buffer pointed to by a ptr is not allocated by a tpalloc(). |
[TPEPROTO] | A tptypes() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include “../sdl/demo.s” main(int argc, char *argv[]) { int ret; struct sel_o *rcvbuf; char type[9], subtype[17]; long size; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf=(struct sel_o*)tpalloc(“STRUCT”,”sel_o”,0); if (buf==NULL) {error processing }; size =tptypes((char*)buf, type,subtype); if (size==-1) {error processing }; printf (“buf : size %d, type %s, subtype %s\n\n”, size, type, subtype); /*rcvbuf : size 1024, type STRUCT, subtype sel_o */ data process... tpfree((char *)buf); tpend(); }
Related Functions
tpalloc(), tpfree(), tprealloc()
The following describes functions that are used for transaction management.
The tx_begin function begins a global transaction, for which a function caller becomes a transaction mode. This function is available for both servers and clients. To start a transaction, a calling process must be first connected to a resource manager with a tx_open(), then, it will return a [TX_PROTOCOL_ERROR]. A tx_begin() function will fail if a caller is already in a transaction mode or a tx_open() is not called first.
Once a transaction begins, a calling process must call a tx_commit() or a tx_rollback() in order to complete a current transaction. There are also chaining transactions that do not need to call a tx_begin() directly in order to begin. For further information, see "9.9.2. tx_commit" and "9.9.4. tx_rollback".
Prototype
#include <tx.h> int tx_begin (void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. |
Error
When a tx_begin() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_OUTSIDE] | A transaction manager cannot start a global transaction because a current calling process is participating in external global transactions. The global transaction can be started after all outside jobs are complete. This error does not affect the participating transactions. |
[TX_PROTOCOL_ERROR] | A tx_begin() was called from an invalid state. For example, a caller is already in a transaction mode. This error does not affect current transactions. |
[TX_ERROR] | A transaction manager or a resource manager momentarily encountered an error while starting a transaction. When this error is returned, a caller is not in a transaction mode. Exact causes of the error depend on product characteristics. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. The manager can no longer execute jobs for an application program. When this error is returned, a caller is not in a transaction mode. Exact causes of the error differ depending on product characteristics. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.… ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } cd = tpconnect(“SERVICE”, buf, 20, TPRECVONLY); if (cd==-1) { error processing } ret = tprecv(cd, (char **)&buf, &len,TPNOFLAGS, &revent)}; if (ret < 0 && revent != TPEV_SVCSUCC) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_commit(), tx_open(), tx_rollback(), tx_set_transaction_timeout()
The tx_commit function commits a global transaction. This function is available for both servers and clients.
When a transaction_control property value is TX_UNCHAINED, a caller will not be in a transaction mode anymore when a tx_commit() returns. However, if the value is TX_CHAINED, the caller will remain in the transaction mode for a new transaction when the tx_commit() returns. For detailed information, see "9.9.6. tx_set_transaction_control".
Prototype
# include <tx.h> int tx_commit(void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_commit() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_NO_BEGIN] | Occurs only when a transaction_control property is a TX_CHAINED. A transaction was successfully committed, but new transactions cannot be started, and a caller will no longer be in a transaction mode. |
[TX_ROLLBACK] | A transaction is rolled back. If a transaction_control property is TX_CHAINED, a new transaction will begin. |
[TX_ROLLBACK_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. A transaction is rolled back, but new transactions cannot be started, and a caller is no longer in a transaction mode. |
[TX_HAZARD] | Portions of a transaction may be committed while others may be rolled back due to an error. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_HAZARD_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. Portions of a transaction are committed while others are rolled back. A new transaction cannot be started and a caller will no longer be in a transaction mode. |
[TX_PROTOCOL_ERROR] | A tx_commit() was called from an invalid state. For example, a caller was not in a transaction mode. a caller's status is not affected by the transaction. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. The caller's status related to the transaction is unknown. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.… ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } cd = tpconnect(“SERVICE”, buf, 20, TPRECVONLY); if (cd==-1) { error processing } ret = tprecv(cd, (char **)&buf, &len,TPNOFLAGS, &revent)}; if (ret < 0 && revent != TPEV_SVCSUCC) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_set_commit_return(), tx_set_transaction_control(), tx_set_transaction_timeout()
The tx_info function returns global transaction information. This function is available for both servers and clients. It notifies global transaction information through a structure indicated by info. It also returns a value informing whether a caller is in a transaction mode or not.
Prototype
#include <tx.h> int tx_info (TXINFO *info)
Parameter
If info is not NULL, a TXINFO structure indicated by an info will be global transaction information.
A TXINFO structure is composed as follows.
struct TXINFO { XID xid; COMMIT_RETURN when_return; TRANSACTION_CONTROL transaction_control; TRANSACTION_TIMEOUT transaction_timeout; TRANSACTION_STATE transaction_state; };
If a tx_info() is called in a transaction mode, a xid will be the current transaction branch ID, and a transaction_state will be the current transaction state. If a caller is not in a transaction mode, a xid will be a NULL XID (See <tx.h> for further information).
In addition, regardless of whether a caller is in transaction mode or not, when_return, transaction_control, and transaction_timeout will contain the current settings of a commit_return, transaction_control property, and a transaction timeout value in seconds.
A returned transaction timeout value is used when a next transaction begins. It may not be a timeout value for a caller's current global transaction, because the caller might have changed the transaction timeout by calling a tx_set_transaction_timeout() after a current transaction began. If info is NULL, a TXINFO structure will not be returned.
Continuous tx_info() calling within the same global transaction ensures provision of a XID of the same gtrid (global transaction identifier). However, it does not ensure a same bqual (local transaction identifier). Thus, XIDs may not be the same.
Return Value
Value | Description |
---|---|
1 | A caller is in a transaction mode and a function call was successful. |
0 | A caller is not in a transaction mode and a function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_info() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_PROTOCOL_ERROR] | A tx_info() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager encountered a critical error. The manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. |
Example
#include <stdio.h> #include <string.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { int ret; long len; char *buf; TXINFO info; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.... ret=tx_begin(); if (ret<0) { error processing } ret=tpcall(“SERVICE”, buf, 20, (char **)&buf, &len, TPNOFLAGS); if (ret==-1) { error processing } if (tx_info(&info)==1) printf(“In transaction \n”); else printf(“Not in transaction \n”); if (strncmp(buf, “err”, 3)==0) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_open(), tx_set_commit_return(), tx_set_transaction_control(), tx_set_transaction_timeout()
The tx_rollback function is used to roll back a global transaction. This function is available for both servers and clients.
If a transaction_control property is TX_UNCHAINED, a caller will not be in a transaction mode any more when a tx_rollback() returns. If a transaction_control property is TX_CHAINED, however, a caller will remain in a transaction mode for a new transaction when a tx_rollback() returns. For detailed information about a transaction_control property, see "9.9.6. tx_set_transaction_control".
Prototype
#include <tx.h> int tx_rollback(void)
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_rollback() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TX_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. New transactions cannot be started, and a caller is no longer in a transaction mode. |
[TX_MIXED] | Portions of a transaction may be committed while others may be rolled back due to an error. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_MIXED_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. Portions of a transaction are committed while others are rolled back. A new transaction cannot be started and a caller will no longer be in a transaction mode. |
[TX_HAZARD] | Portions of a transaction may be committed while others may be rolled back due to an error. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_HAZARD_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. Portions of a transaction are committed while others are rolled back. A new transaction cannot be started and a caller will no longer be in a transaction mode. |
[TX_COMMITTED] | A transaction was committed independently. If a transaction_control property is TX_CHAINED, a new transaction will be started. |
[TX_COMMITTED_NO_BEGIN] | Occurs only when a transaction_control property is TX_CHAINED. A transaction was successfully committed, but new transactions cannot be started, and a caller will no longer be in a transaction mode. |
[TX_PROTOCOL_ERROR] | A tx_rollback() was called from an invalid state. For example, a caller was not in a transaction mode. A caller's status is not affected by a transaction. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of an error differ depending on product characteristics. A caller's status related to a transaction is unknown. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { char *buf; int ret,cd; long len, revent; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; data process.… ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } cd = tpconnect(“SERVICE”, buf, 20, TPRECVONLY); if (cd==-1) { error processing } ret = tprecv(cd, (char **)&buf, &len,TPNOFLAGS, &revent)}; if (ret < 0 && revent != TPEV_SVCSUCC) tx_rollback(); else tx_commit(); data process.... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_set_transaction_control(), tx_set_transaction_timeout()
The tx_set_transaction_timeout function sets a transaction_timeout property for a timeout value. This function is available for both servers and clients. This value indicates the time in which a transaction must be completed before a transaction timeout occurs. In other words, it is the interval between a tx_begin() and a tx_commit(), or a tx_begin() and a tx_rollback().
A tx_set_transaction_timeout() function can be called regardless of whether a function caller is in a transaction mode or not. If a tx_set_transaction_timeout() is called in a transaction mode, a new timeout value will be applied from a following transaction.
Prototype
# include <tx.h> int tx_set_transaction_timeout (TRANSACTION_TIMEOUT timeout)
Parameter
Parameter | Description |
---|---|
timeout | Specifies a time allowed until a transaction timeout occurs, in seconds. It can be set up to a maximum value of a long type defined for each system. Default setting of a transaction_timeout is 0, which means there is no timeout limit. |
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tx_set_transaction_timeout() fails to execute, tperrno will be set to one of the following values and a transaction_timeout value will be unchanged.
Error Code | Description |
---|---|
[TX_EINVAL] | An invalid timeout value. |
[TX_PROTOCOL_ERROR] | A tx_set_transaction_timeout() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager encountered a critical error. A manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. |
Example
#include <usrinc/atmi.h> #include <usrinc/tx.h> void main(int argc, char *argv[]) { int ret; long len; char *buf; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) {error processing }; ret=tx_set_transaction_timeout( 5 ); if (ret<0) { error processing } ret=tx_begin(); if (ret<0) { error processing } ret = tpcall(“SERVICE”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process …. ret = tx_commit(); if (ret < 0) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_commit(), tx_open(), tx_rollback(), tx_info()
The tx_set_transaction_control function sets a transaction_control property with a control value. This function is available for both servers and clients.
This property determines whether to or not start a new transaction before a tx_commit() and a tx_rollback() returns to a caller. a tx_set_transaction_control() function can be called regardless of whether an application program is in a transaction mode or not. This setting is valid until it is changed as a tx_set_transaction_control() is called again.
Prototype
# include <tx.h> int tx_set_transaction_control(TRANSACTION_CONTROL control)
Parameter
Values available for control are as follows:
Configuration Value | Description |
---|---|
TX_UNCHAINED | The initial value of transaction_control property. Does not start a new transaction until a tx_commit() or a tx_rollback() is returned to a caller. In this case, a caller must execute a tx_begin() in order to begin a new transaction. |
TX_CHAINED | Allows a new transaction to start before a tx_commit() or a tx_rollback() is returned to a caller. |
Return Value
Value | Description |
---|---|
TX_OK | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When tx_set_transaction_control() fails to execute, tperrno will be set to one of the following values and a previous transaction_control property will be unchanged.
Error Code | Description |
---|---|
[TX_EINVAL] | A control parameter is neither TX_UNCHAINED nor TX_CHAINED. |
[TX_PROTOCOL_ERROR] | A tx_set_transaction_control() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager encountered a critical error. The manager can no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. |
Example
#include <usrinc/atmi.h> #include <usrinc/tx.h> int main(int argc, char *argv[]) { int ret; long len; char *buf; ret = tpstart((TPSTART_T *)NULL); if (ret == -1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; ret = tx_set_transaction_timeout(5); if (ret < 0){ error processing } ret = tx_set_transaciont_control(TX_UNCHAINED); if (ret < 0){ error processing } ret = tx_begin(); if (ret < 0) { error processing } data process.... ret = tpcall(“SERVICE1”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process... ret = tpcall(“SERVICE2”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process …. ret = tx_commit(); if (ret < 0) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tx_begin(), tx_commit(), tx_open(), tx_rollback(), tx_info()
The tx_set_commit_return function sets a commit_return property with a when_return value. This function is available for both servers and clients.
This property determines the method how a tx_commit() function returns a control to a caller. A tx_set_commit_return() can be called regardless of whether a function caller is in a transaction mode. This setting is valid until it is changed as a tx_set_commit_return() is called again. Initial setting of a commit_return property depends on the situation when the function is executed.
Prototype
#include <tx.h> int tx_set_commit_return (COMMIT_RETURN when_return)
Parameter
Values available for when_return are as follows:
Configuration Value | Description |
---|---|
TX_COMMIT_DECISION _LOGGED | This flag causes a tx_commit() to return before the second phase of a Two-Phase Commit (2PC) protocol is completed after it was logged in a first phase. This allows a tx_commit() to respond to a caller more quickly. However, there is a danger that a transaction may have a heuristic result. In this case, a caller cannot understand the situation generated by the code returned from a tx_commit(). In normal cases, a transaction participant scheduled to commit a transaction in a first phase can normally commit a transaction in a second phase. In abnormal cases such as a network failure or a node fail lasting too long, it may be impossible to complete a second phase and a heuristic result may be resulted. A transaction manager can select this property not to be supported, using a parameter. At this time, a tx_commit() returns [TX_NOT_SUPPORTED], indicating that this property is not supported. |
TX_COMMIT_COMPLETED | This flag causes a tx_commit() to return after a 2PC protocol is completed. This setting shows a function caller return code indicating that a transaction produced a heuristic result or a probability. A transaction manager can select this property not to be supported, using a parameter. At this time a tx_commit() returns a [TX_NOT_SUPPORTED], indicating that this property is not supported. |
Return Value
When successfully completed, a tx_set_commit_return() returns a [TX_OK] of a value other than a negative value.
If a when_return is set to a TX_COMMIT_COMPLETED or a TX_COMMIT_DECISION_LOGGED, a function will return a [TX_NOT_SUPPORTED] instead of a negative value and a previously used commit_return property will still be valid. A transaction manager must set a when_return to either a TX_COMMIT_COMPLETED or a TX_COMMIT_DECISION_ LOGGED.
Error
When a tmax_chk_conn() fails to execute, a tperrno will be set to one of the following values, and a commit_return property will be unchanged.
Error Code | Description |
---|---|
[TX_EINVAL] | A when_return is not set to TX_COMMIT_COMPLETED or TX_COMMIT_DECISION_LOGGED. |
[TX_PROTOCOL_ERROR] | A tx_set_commit_return() was called from an invalid state. For example, a tx_open() was not yet called. |
[TX_FAIL] | A transaction manager or a resource manager encountered a critical error. The managers could no longer execute jobs for an application program. Exact causes of the error differ depending on product characteristics. A caller's status, related to the transaction, is unknown. |
Example
#include <usrinc/tx.h> int main(int argc, char *argv[]) { int ret; long len; char *buf; ret = tpstart((TPSTART_T *)NULL); if (ret == -1) { error processing } buf = (char *)tpalloc(“CARRAY”, NULL, 20); if (buf==NULL) {error processing }; ret = tx_set_transaction_timeout(5); if (ret < 0){ error processing } ret = tx_set_commit_return(TX_COMMIT_COMPLETED); if (ret < 0){ error processing } ret = tx_begin(); if (ret < 0){ error processing } data process.... ret = tpcall(“SERVICE1”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process... ret = tpcall(“SERVICE2”, (char *)buf, strlen(buf), (char **)&buf, &len, TPNOFLAGS); if (ret == -1) { tx_rollback(); error processing } data process …. ret = tx_commit(); if (ret < 0) { error processing } data process... tpfree((char *)buf); tpend(); }
Related Functions
tx_commit(), tx_open(), tx_info()
This section describes functions that are used by RQ. The Tmax system provides the RQ system for reliable queues. ENQSVR works as a queue management process to enqueue/dequeue data to/from RQ. This function cannot be used in Windows NT or 2000.
Even when services cannot be provided due to a system failiure or error, data stored in the queue can guarantee its integrity. If multiple servers are established in a WAN environment or the load is large, RQ can be used to process applications with guaranted data integrity.
The Tmax system ensures the integrity of data stored in a RQ even when a system fault or error causes an out of service status. A tpenq() saves data to a RQ. If a system crashes, it will continue processing data once the system recovers.
If a service is requested through a tpcall() or a tpacall(), requests will be queued if there are other requests waiting to be processed. If a system error or failure causes a system shutdown, queued data will be lost. To prevent data loss and to improve data consistency, a tpenq() saves data in a RQ for each service request.
Although a tpenq() is executed in a transaction mode, it is excluded from transaction modes. If an error occurs while this function is being executed in a transaction mode, a transaction will not be affected.
Prototype
# include <tmaxapi.h> int tpenq (char *qname, char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
svc | Stores data to a RQ and immediately requests a service unless a svc name is NULL. If the svc name is NULL, data is stored in the RQ but a service will not be performed. In this case, a function caller must request the service again using a tpdeq(). If a system fault occurs when there is no service named svc or a service result has not been received after a service was performed, the data will be stored internally in a Fail Queue. This data must be re-requested using a tpdeq() or processed as an error. |
data | This is a pointer to a buffer allocated by a tpalloc() unless the value is NULL,. The type and subtype of data must be supported by a svc. |
len | The length of data to be sent.
If data is NULL, len is ignored and a service request will be received without data. The data type and subtype must be supported by a svc. If a service request is sent in a transaction mode, a response must be received. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPRQS | When a svc is not NULL, a function caller will request a svc service and store service results in a RQ. To receive service results,a tpdeq() must be called. If a svc is NULL, data will be stored in a RQ but a service will not be performed. |
TPNOREPLY | When a svc is not NULL, a function caller will request a svc service and will not store results in a RQ. If a svc is NULL, data will be stored in a RQ but a service will not be not performed. |
TPFUNC | Manages RQ data by service. If a TPFUNC is not set, data stored by a tpenq() will be de-queued when it is initially stored. If data must be de-queued before it is stored, a TPFUNC must be set when calling a tpenq(). |
0(zero) | Stores service results to a client buffer of a Tmax system that is connected to a function caller. Service is requested through a RQ, but the results are saved to a client’s buffer similarly to a tpcall() function. Once this flag is set, a 0 (zero) must also be set when calling a tpdeq() in order to receive service results. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpenq() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | A qname does not exist. |
[TPEQFULL] | A maximum queue length reached due to continuous service results. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A tpenq() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) { error processing } data process.... ret=tpdeq(“RQ”, “SERVICE”, (char **)&buf, (long *)&len, TPRQS); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpdeq(), tpqstat()
The tpdeq function loads data from a RQ. It receives the result of a service request or sets a service name to NULL and then reads stored data by using a tpenq() function. However, if a TPNOREPLY is set when a tpenq() is called, a service cannot receive any results, so even if an error occurs while executing a tpdeq() in a transaction mode, a transaction will not be affected.
Prototype
# include <tmaxapi.h> int tpdeq (char *qname, char *svc, char **data, long *len, long flags)
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
svc | A svc must be set to a service name when a tpenq() is called. In other words, if a tpenq() is called with a service name, a service will automatically be requested and the results will be stored in a RQ. In order to receive service results, the same service name must be specified. If the service name is NULL when a tpenq() is called, the same service name must be entered for a tpdeq_ctl(). If the service name is NULL, all data accumulated in a queue can be loaded individually regardless of the service name. To call a tpdeq() for data saved in a fail queue due to an error or a system failure, a svc must be set to _rq_sub_queue_name[TMAX_FAIL_QUEUE]. |
*data | A pointer to a buffer allocated by a tpalloc(). When a function is successfully returned, received data will be stored in a *data. |
len | Size of the data received by a tpdeq(). A tpdeq() can increase a buffer size if a reply is larger than the buffer. Returned results are stored in a *data, and a len will be the size of received data. A *data can be modified if the size of received data is too large. If a len is larger than the total size of a previously called buffer, a larger buffer size will be allocated. If a len returns a 0, no data will be received and nothing will be changed in the buffer indicated by a *data and a len. If a *data or a len is NULL, an error will occur. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPRQS | Loads service results from a reply queue (RQ). |
TPFUNC | Manages RQ data by service. If a TPFUNC is not set, data stored by a tpenq() will be dequeued when it is initially stored. If data must be dequeued before it is stored, a TPFUNC must be set when calling a tpenq(). |
TPBLOCK | Waits until a message is returned during a block timeout. |
TPNOTIME | If a TPNOTIME and a TPBLOCK are both set, a function will wait until a reply is returned regardless of a block timeout. |
0(zero) | Loads data from the buffer of a client that a function caller is connected to. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpdeq() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT was not set. |
[TPEMATCH] | When a service name is wrong or there is no data to be dequeued, no data will be found for a given key. |
[TPENOENT] | An invalid qname. |
[TPEPROTO] | A tpdeq() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) { error processing } data process.... ret=tpdeq(“RQ”, “SERVICE”, (char **)&buf, (long *)&len, TPRQS); if (ret==-1) { error processing } data process.... tpfree(buf); tpend(); }
Related Functions
tpenq(), tpqstat()
The tpqstat function is used to get the data statistics accumulated in a current RQ. This function is available both in a server and a client. A RQ internally consists of three queues: a _fail queue, a _request queue, and a _ reply queue. A tpqstat( ) can get the data statistics stored in each of these queues, by using a flag value.
Prototype
# include <tmaxapi.h> int tpqstat (char *qname, long flags)
Parameter
Parameter | Description |
---|---|
qname | A RQ that saves data. A name must be specified and registered in a configuration file. |
flags | A target data type. Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
0(TMAX_ANY_QUEUE) | Retrieves the statistics about all data stored in a _fail queue, _request queue, and _reply queue. |
1(TMAX_FAIL_QUEUE) | Retrieves the data statistics stored in a _fail queue. |
2(TMAX_REQ_QUEUE) | Retrieves the data statistics stored in a _request queue. |
3(TMAX_RPLY_QUEUE) | Retrieves the data statistics stored in a _reply queue. |
Return Values
Value | Description |
---|---|
-1 | A function call was successful. A tperrno is set to an error code. |
Error
When a tpqstat() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, when a qname is NULL, there will be no queue with a corresponding name, or a flag will be invalid. |
[TPEPROTO] | A tpqstat() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret, i; char *buf; if (argc!=2) { error processing } ret=tpstart((TPSTART_T *)NULL); if (ret==-1) {error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } strcpy(buf, argv[1]); data process… ret=tpenq(“RQ”, NULL, (char *)buf, strlen(buf), TPRQS); if (ret==-1) {error processing } printf(“qstat :”); for (i=0;i<4;i++) { ret=tpqstat(“rq”, i); if (ret==-1) {error processing } printf(“ %d”,ret); /* qstat : 1 0 0 1 */ } printf(“\n”); data process… ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) {error processing } printf(”qstat :”); for (i=0;i<4;i++) { ret=tpqstat(“rq”, i); if (ret==-1) {error processing } printf(” %d”,ret); /* qstat : 2 0 0 2 */ } printf(“\n”); tpfree((char *)buf); tpend(); }
Related Functions
tpenq(), tpdeq()
The tpextsvcname function extracts a service name from the data read from a RQ by using a tpdeq(). This function is generally used to read data stored in a Fail Queue and can be used on both a client and a server.
Prototype
# include <tmaxapi.h> int tpextsvcname (char *data, char *svc)
Parameter
Parameter | Description |
---|---|
data | A pointer allocated by a tpalloc() that stores read data from a RQ through a tpdeq(). |
svc | A pointer that receives the service name of data. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpextsvcname() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/tmaxapi.h> void main(int argc, char *argv[]) { int ret; char *buf, *svc_name; long len; ret=tpstart((TPSTART_T *)NULL); if (ret==-1) { error processing } buf = (char *)tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process.... ret=tpenq(“RQ”, “SERVICE”, (char *)buf, strlen(buf), TPRQS); if (ret==-1) { error processing } data process.... ret=tpdeq(“RQ”, “SERVICE”, (char **)&buf, (long *)&len, TPRQS); if (ret==-1) { error processing } ret=tpextsvcname(buf, svc_name); if (ret==-1) { error processing } printf(“svc name : %s ,”,svc_name); data process.... tpfree(buf); tpend(); }
Related Functions
tpenq(), tpdeq()
Tmax can send messages to service routines and multiple clients. Developers can specify any client and service routine to register, cancel, or generate an event. Client and service routines can register in each event redundantly or register in multiple events simultaneously.
Note that an event data transfer and the results generated by that event do not fall in the scope of the transaction.
The tpsubscribe function subscribes to an event or set of events named by an eventname. It is used to request a notification for an event when an event is posted. This function is available for both servers and clients.
Prototype
# include <tmaxapi.h> long tpsubscribe(char *eventname, char *filter, TPEVCTL *ctl, long flags)
Parameter
Parameter | Description |
---|---|
eventname | A string ending with NULL that has up to a 15-character length. A wildcard character or partial-matching is not supported. Only a name that matches an entire string can be registered. |
filter | Reserved for future-use. NULL must be set in this parameter. |
ctl | A structure that receives a message when an event occurs. It works differently depending on the subject of a tpsubscribe(). If a client used a tpsubscribe(), a ctl must always be NULL and a message will be delivered to a client as an unsolicited data type. Afterwards, the client will handle the received data using a tpsubscribe() or a tpgetunsol(). |
flags | Currently, only a TPNOTIME can be used. |
If a tpsubscribe() is executed by a server, a ctl must not be NULL and it should be configured as shown below:
struct tpevctl { long ctl_flags; long post_flags; char svc[XATMI_SERVICE_NAME_LENGTH]; char qname[RQ_NAME_LENGTH]; }; typedef struct tpevctl TPEVCTL;
Member | Description |
---|---|
ctl_flags | Not currently supported. Set to 0. |
post_flags | Not currently supported. Set to 0. |
qname | When using a qname, a message will be queued in a RQ via a tpenq (qname, NULL, data, len, TPNOFLAGS). |
svc | When using a svc, a message will be sent to a server in a similar manner to a tpacall (svc, data, len, TPNOREPLY) and a response from the server will be ignored. Only one qname or svc can be used at a time. |
Return Value
Value | Description |
---|---|
descriptor | A function call was successful and a descriptor to be used for a tpunsubscribe() is returned. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsubscribe() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. For a client program, a network error is the most common error. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
[TPEINVAL] | An invalid parameter. |
[TPENOENT] | A RQ or a server corresponding to a specified qname or svc of a TPEVCTL structure does not exist. |
[TPEPROTO] | A ctl is not NULL in a client and a server. |
[TPETIME] | A timeout occurred. |
Related Functions
tpsetunsol(), tpsetunsol_flag(), tpgetunsol(), tpacall(), tpenq()
The tpunsubscribe function removes an event subscription or a set of event subscriptions registered by a tpsubscribe() from a Tmax system's list of subscriptions. If all subscriptions are removed, a Tmax system will delete the table containing the events.
Prototype
# include <tmaxapi.h> int tpunsubscribe(long sd, long flags)
Parameter
Parameter | Description |
---|---|
sd | A return value received when registering for a subscription with a tpsubscribe(). |
flags | Currently, only a TPNOTIME can be used. |
Return Value
Value | Description |
---|---|
Positive Value | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tpunsubscribe() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. For a client program, a network error is the most common error. |
[TPEOS] | An operating system error occurred. Memory cannot be allocated. |
[TPEINVAL] | An invalid parameter. |
[TPETIME] | A timeout occurred. |
Related Functions
tpsetunsol(), tpsetunsol_flag(), tpgetunsol(), tpacall(), tpenq()
The tppost function generates a specific event from a server or client and delivers a message. A tppost() notifies the occurence of an event to all clients and server processes that registered for the event by using the eventname in a tpsubscribe(). If required, a message can be delivered.
Prototype
# include <tmaxapi.h> int tppost(char *eventname, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
eventname | A string that ends with a NULL, and has up to a 15-character length. Wildcard or partial-matching is not supported. |
data | A pointer to a buffer for messages to be sent. Must be a buffer allocated by a tpalloc(). |
len | The length of a buffer to be sent. If data indicates a buffer that does not require a data length to be provided, a len will be ignored (0 is used by default). If data indicates a buffer that requires a data length, a len must not be 0. If data is NULL, a len will be ignored. |
flags | Currently, only a TPNOTIME can be used. |
Return Values
Value | Description |
---|---|
Positive Value | A function call was successful. |
Negative Value | A function call failed. A tperrno is set to an error code. |
Error
When a tppost() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. Detailed error information will be recorded in a system log file. For a client program, a network error is the most common error. |
[TPEOS] | An operating system error occurred. |
[TPEINVAL] | An invalid parameter. |
[TPENOENT] | When using a tpsubscribe(), this error indicates that a RQ, a server corresponding to a qname, or a svc of a TPEVCTL structure does not exist. |
[TPEPROTO] | When a tpsubscribe() is executed in a client, a ctl is not NULL. When a tpsubscribe() is executed in a server, a ctl is NULL. |
[TPETIME] | A timeout occurred. |
Related Functions
tpsetunsol(), tpsetunsol_flag(), tpgetunsol(), tpacall(), tpenq()
Tmax can send data to clients in various ways. When sending data to multiple clients for management or development, Tmax can manage all client IDs and send messages to each client. This method, however, is not efficient when there are many concurrent users in the system.
If clients can be divided into several groups, an API can be used to send messages to all related clients. Tmax implements broadcast and multicast by utilizing client access information or events. Both the broadcast and multicast APIs can broadcast and multicast, but they are named so to distinguish them.
The tpbroadcast function broadcasts notifications to clients registered in the Tmax system. To receive a notification, a client must be connected to the Tmax system using tpstart(), the client name and flags must be defined correctly, and flag values of the TPSTART_T structure used for tpstart() must be set to TPUNSOL_POLL or TPUNSOL_HND. This function can be used on both the client and the server.
Prototype
# include <atmi.h> int tpbroadcast (char *nodename, char *usrname, char *cltname, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
nodename, usrname, cltname | Logical names used to select target clients. The name length must be 15 characters or less. Wildcards (?, *, etc.) can be used to specify names. NULL can also be used as a wildcard corresponding to all clients. A string argument with a length of 0 corresponds only to a client name with a string length of 0. cltname is the client name used, which is registered when the client first accesses the Tmax system, when using the tpstart() function. |
data | A buffer must be allocated through tpalloc() in advance. |
len | Length of data to receive. For STRING, STRUCT, X_COMMON, and X_C_TYPE buffers, which require no length specification, len is ignored and 0 is used by default. len is also ignored if data is NULL. |
flags | Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPNOBLOCK | If a blocking condition (e.g., the internal buffer is filled with messages to be transmitted) is encountered, the request is not sent. |
TPNOTIME | Function caller must wait indefinitely until a response is received. Blocking timeout is ignored. If tpbroadcast() is called during a transaction timeout, transaction timeout applies. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function is executed again. If the signal interrupt occurs without this flag, the function fails and tperrno is set to TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpbroadcast() fails to execute and no messages can be transmitted to a client, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, an identifier is too long or a flag is invalid. If a nodename is incorrect, a tpbroadcast() will fail and return a TPEINVAL. However, if a usrname or cltname is invalid, a message will not be transmitted, but a function will be considered to have executed successfully. |
[TPETIME] | Blocking timeout occurred while TPNOBLOCK or TPNOTIME is not set. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A tpbroadcast() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example
#include <stdio.h> #include <usrinc/atmi.h> void main(int argc, char *argv[]) { int ret; char *buf; TPSTART_T *tpinfo; tpinfo = (TPSTART_T *)tpalloc(“TPSTART”, NULL, sizeof(TPSTART_T)); if (tpinfo==NULL) { error processing } strcpy(tpinfo->cltname, “cli1”); strcpy(tpinfo->usrname, “navis”); ret=tpstart(tpinfo); if (ret==-1) { error processing } buf=tpalloc(“STRING”, NULL, 0); if (buf==NULL) { error processing } data process… tpbroadcast(“tmax”, NULL, NULL, buf, 0, TPNOFLAGS); data process.... tpfree(buf); tpend(); }
Related Functions
tpalloc(), tpend(), tpstart()
To develop services for general users, the client program is generally developed in Windows. For development in Windows, Tmax provides interfaces for various development tools. Tmax also provides various types of libraries for developer convenience. According to the library, APIs can be added or replaced.
Tmax supports the following development tools: PowerBuilder, Delphi, VC++, BC++, VB, VB .Net, C#, and Net. For more information about each development tool, refer to " Tmax Programming Guide"(4GL).
The following describes the supported libraries.
Library | Description |
---|---|
tmax.lib (dll) | Used for VC++, Delphi, and C#. (cdecl) |
tmax4gl. lib (dll) | Used for BC++, PowerBuilder, VB, and VB.Net. (stdcall) |
tmaxmt. lib (dll) | Supports multi-thread type. (cdecl) |
Wintmax. lib (dll) | Supports multi-windows. (cdecl) |
tmaxce.lib (dll) | Supports Windows ce. (cdecl) |
tmaxmt.dll
APIs were added to process message-driven type service requests, which are used in the Windows programming environment. The two APIs only differ in whether the message is returned to Windows or to the specified Callback function. Whenever an API is run, a thread is created to process the message. tmaxpi.h is used as the header file.
WinTmaxAcall()
WinTmaxAcall2()
WinTmax.dll
APIs were added to process message-driven type service requests, which are used in the Windows programming environment. Messages are processed by independent threads, so WinTmaxStart() or WinTmaxEnd() is used instead of tpstart() or tpend().
WinTmaxStart()
WinTmaxEnd()
WinTmaxSetContext ()
WinTmaxSend ()
WinTmax.dll works similarly to tmaxmt.dll but it does not connect to/disconnect from the Tmax system automatically. Also, a thread processes all messages instead of creating a thread for each API. If Windows is not set separately to process error messages and unrequested messages, the messages are ignored.
For debugging and management, logs can be left in the file specified in the MAX_DEBUG environment variable. WinTmax.h is used as the header file.
The WinTmaxAcall function, available in a client in a Windows system environment, performs the same functions as a tpacall() in a multi threaded environment. It creates a new thread and invokes a tpstart() → tpacall() → tpgetrply() in the thread. After calling a tpgetrply(), it invokes a SendMessage(wHandle, msgType, (UINT) &MSG, tperrno).
Prototype
# include <tmaxapi.h> int WinTmaxAcall(TPSTART_T *sinfo, HANDLE wHandle, unsigned int msgtype, char *svc, char *sndbuf, int len, int flags)
Parameter
Parameter | Description |
---|---|
sinfo | The structure that is used when sending client information to a Tmax system. Identical to the parameter of a tpstart(). |
wHandle | A Windows Handler used to receive a messages. |
msgtype | An arrival message. Generally, a WM_USER is freely defined by a developer. Specify a service name registered in a svc Tmax configuration file. |
svc | A service to send a request. |
sndbuf | Data to be sent when calling a service. If not null, it must use a buffer allocated using a tpalloc(). |
len | The length of data to be sent. It must be specified for CARRAY, X_OCTET, and Structure array types. |
flags | Identical to the flags of a tpacall(). |
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | If a tpacall was used without flags, a normal result will be returned even if a called service does not exist in a svc or an invalid result is returned. If a tpacall() is called using a TPBLOCK, a service state can be checked if it is normal or not. |
TPNOTRAN | If a service does not support transactions in a transaction mode, flags must be set to a TPNOTRAN for a tpacall() to be called in the transaction mode. If a tpacall() caller requests a svc service by setting a TPNOTRAN in a transaction mode, a svc service will be executed by being excluded from the transaction mode. When calling a tpacall() within a transaction mode, a call will still affected by a transaction timeout even if a tpacall() is set to TPNOTRAN. In other words, calling a tpacall that is set as a TPNOTRAN after a transaction timeout will fail except when calling a tpacall that has been set as a TPNOTRAN|TPNOREPLY. If a service with a flag set to a TPNOTRAN fails, this does not affect a caller's transaction. |
TPNOREPLY | If a tpacall() is used to send a service request, a tpacall will return immediately without waiting for a response. A client can retrieve results by using a tpgetrply() with a descriptor returned by a tpacall(). If a TPNOREPLY is set, a response for a service request will not be received. If set to a TPNOREPLY, a tpacall() will return a 0 if a service is called normally. If a function caller is in a transaction mode, a TPNOREPLY must be set along with a TPNOTRAN. In case of a TPNOREPLY, to check if a service state is normal or not, a TPBLOCK also must be set. If a TPBLOCK is not set, an error will not be returned even a service is NRDY. |
TPNOBLOCK | Upon encountering a blocking condition with this flag, for example, an internal buffer is filled with messages to be transmitted, a service request will fail. When calling a tpacall() function without setting a TPNOBLOCK flag, if a blocking condition is encountered, a function caller must wait until blocking is released or a timeout (transaction timeout or blocking timeout) occurs. |
TPNOTIME | A function caller must wait indefinitely until a response is received and blocking timeouts are ignored. If a tpacall() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call was successful. A returned descriptor is used to receive a response for a sent service request. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxAcall() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. For a structure, this error occurs when the structure is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests was reached. Service requests from a caller cannot be sent. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A WinTmaxAcall() was called from an invalid state. For example, a TPNOREPLY was called in a transaction mode, but a TPNOTRAN was not set. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPEOS] | An operating system error occurred. |
Example
... #include <usrinc/tmaxapi.h> #define WM_WINTMAX_RECV WM_USER + 1 ... BEGIN_MESSAGE_MAP(CWinTmaxAcall2TestDlg, CDialog) ... ON_MESSAGE(WM_WINTMAX_RECV, OnWinTmaxAcall) ... END_MESSAGE_MAP() BOOL CWinTmaxAcall2TestDlg::OnInitDialog() { CDialog::OnInitDialog(); ... ret = tmaxreadenv(“tmax.env”, “TMAX”); if (ret == -1){ AfxMessageBox(“tmaxreadenv fail...”); return FALSE; } return TRUE; // return TRUE unless you set the focus to a control } void CWinTmaxAcall2TestDlg::OnOK() { ... GetDlgItemText(IDC_EDIT1, m_Input); lstrcpy((LPTSTR)buf, (LPCTSTR)m_Input.operator const char *()); ... buf = tpalloc(“STRING”, NULL, 0); if (buf == NULL){ AfxMessageBox(“buf alloc fail...”); return FALSE; } ret = WinTmaxAcall((TPSTART_T *)NULL, m_hWnd, WM_WINTMAX_RECV, “TOUPPER”, buf, 0, TPNOFLAGS); if (ret == -1){ error processing } } LRESULT CWinTmaxAcall2TestDlg::OnWinTmaxAcall(WPARAM wp, LPARAM lp) { char msg[100]; memset(msg, 0x00, 100); TPSVCINFO *get = (TPSVCINFO *)wp; if (lp < 0){ error processing } ... SetDlgItemText(IDC_EDIT2, get->data); return 0; }
Related Functions
tpacall(), WinTmaxAcall2()
The WinTmaxAcall2 function, available in a client in a Windows system environment, performs the same function as a tpacall() in a multi thread environment. It issues a new thread and invokes a tpstart() → tpacall() → tpgetrply() in the thread. After calling a tpgetrply(), it delivers received data to a specified Callback function.
Prototype
# include <tmaxapi.h> int WinTmaxAcall2(TPSTART_T *sinfo, WinTmaxCallback fn, char *svc, char *sndbuf, int len, int flags)
Parameter
Parameter | Description |
---|---|
sinfo | The structure used when sending information about a client to a Tmax system. Identical to the parameters of a tpstart(). |
fn | Sets a Callback function to receive a response for a service request. |
svc | Sets a service name registered in a Tmax environment configuration file. |
sndbuf | Data to be sent when calling a service. If not null, it must use a buffer allocated through a tpalloc(). |
len | The length of data to be sent. It must be specified for CARRAY, X_OCTET, and Structure array types. |
flags | Identical to the flags of a tpacall(). Flag values are listed in the table below. |
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | If tpacall was used without flags, a normal result is returned even if a called service does not exist in a svc or an invalid result is returned. If a tpacall() is called using a TPBLOCK, a service state can be checked if it is normal or not. |
TPNOTRAN | If a service does not support transactions in a transaction mode, flags must be set to a TPNOTRAN for a tpacall() to be called in the transaction mode. If a tpacall() caller requests a svc service by setting a TPNOTRAN in a transaction mode, a svc service will be executed by being excluded from the transaction mode. When calling a tpacall() within a transaction mode, a call will still affected by a transaction timeout even if a tpacall() is set to TPNOTRAN. If a service with a flag set to a TPNOTRAN fails, this does not affect a caller's transaction. |
TPNOREPLY | If a tpacall() is used to send a service request, a tpacall will return immediately without waiting for a response. A client can retrieve results by using a tpgetrply() with a descriptor returned by a tpacall(). If a TPNOREPLY is set, a response for a service request will not be received. If set to a TPNOREPLY, a tpacall() will return a 0 if a service is called normally. If a function caller is in a transaction mode, a TPNOREPLY must be set along with a TPNOTRAN. In case of a TPNOREPLY, to check if a service state is normal or not, a TPBLOCK also must be set. If a TPBLOCK is not set, an error will not be returned even a service is NRDY. |
TPNOBLOCK | Upon encountering a blocking condition with this flag, for example, an internal buffer is filled with messages to be transmitted, a service request will fail. When calling a tpacall() function without setting a TPNOBLOCK flag, if a blocking condition is encountered, a function caller must wait until blocking is released or a timeout (transaction timeout or blocking timeout) occurs. |
TPNOTIME | A function caller must wait indefinitely until a response is received and blocking timeouts are ignored. If a tpacall() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxAcall2() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a svc is NULL, data points to a buffer that was not allocated by a tpalloc(), or a flag is invalid. |
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. For a structure, this error occurs when the structure is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests was reached. Service requests from a caller cannot be sent. |
[TPETRAN] | A svc does not support transactions, and a TPNOTRAN was not set. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A WinTmaxAcall2() was called from an invalid state. For example, a TPNOREPLY was called in a transaction mode, but a TPNOTRAN was not set. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPEOS] | An operating system error occurred. |
Example
#include <usrinc/tmaxapi.h> #define WM_WINTMAX_RECV WM_USER + 1 int mycallfn(unsigned int, long); ... BEGIN_MESSAGE_MAP(CWinTmaxAcall2TestDlg, CDialog) ... END_MESSAGE_MAP() BOOL CWinTmaxAcall2TestDlg::OnInitDialog() { CDialog::OnInitDialog(); ... ret = tmaxreadenv(“tmax.env”, “TMAX”); if (ret == -1){ AfxMessageBox(“tmaxreadenv fail...”); return FALSE; } return TRUE; // return TRUE unless you set the focus to a control } void CWinTmaxAcall2TestDlg::OnOK() { ... GetDlgItemText(IDC_EDIT1, m_Input); lstrcpy((LPTSTR)buf, (LPCTSTR)m_Input.operator const char *()); ... buf = tpalloc(“STRING”, NULL, 0); if (buf == NULL){ AfxMessageBox(“buf alloc fail...”); return FALSE; } ret = WinTmaxAcall2((TPSTART_T *)NULL, (WinTmaxCallback)mycallfn, “TOUPPER”, (char *)buf, 0, TPNOFLAGS); if (ret == -1){ error processing } } int mycallfn(unsigned int msg, long retval) { TPSVCINFO *svcinfo; char infomsg[30]; memset(infomsg, 0x00, sizeof(infomsg)); svcinfo = (TPSVCINFO *)msg; strncpy(infomsg, svcinfo->data, svcinfo->len); if (retval != 0){ strcpy(infomsg,tpstrerror(retval)); AfxMessageBox(infomsg); return -1; } else { strncpy(infomsg, svcinfo->data, sizeof(infomsg) - 1); AfxMessageBox(infomsg); return 1; } }
Related Functions
tpacall(),WinTmaxAcall()
The WinTmaxStart function, available in a client in a Windows system environment, is used to connect to a Tmax system in a multi-Windows environment. This function is identical to a tpstart(). When using multiple threads, connections should be respectively established per thread through a WinTmaxStart().
Prototype
# include <WinTmax.h> int WinTmaxStart(TPSTART_T *tpinfo)
Parameter
Refer to "9.2.1. tpstart" for more information about a TPSTART_T.
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxStart() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a tpinfo is NULL or not a pointer for a TPSTART_T. |
[TPEITYPE] | A tpinfo is not a pointer for a TPSTART_T structure. |
[TPEPROTO] | A WinTmaxStart() was called in an inappropriate condition. For example, a WinTmaxStart() was called in a server program, or it was called after a connection was already established. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. Environment variables may be invalid. For example, a connection failed because a TMAX_BACKUP_ADDR or TMAX_BACKUP_PORT was invalid. |
Related Functions
tpstart(), WinTmaxEnd(), WinTmaxSend(), WinTmaxSetContext()
The WinTmaxEnd function, available in a client in a Windows system environment, closes a connection to a Tmax system. It functions identically to a tpend(). In a Multi threaded environment, a client is connected to each thread via a WinTmaxStart(), so a WinTmaxEnd() must be used for each thread to close the connection.
Prototype
# include <WinTmax.h> int WinTmaxEnd(void)
Return Value
Value | Description |
---|---|
1 | A function call was successful. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxEnd() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPETIME] | Cannot access a critical section due to an internal system error. Check the system status. |
[TPEPROTO] | A WinTmaxEnd() was called from an invalid state. For example, a WinTmaxEnd() was called after a connection was already closed. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Related Functions
tpend(), WinTmaxStart()
The WinTmaxSetContext function, available in a client in a Windows system environment, controls window handles and message types.
This function, used in a Windows environment, manages specified Windows handles and message types by storing them in a vacant slot of a library. Using this information, when a working thread receives a reply, it will send data to the specified Windows in the specified type. The following is the data transmission format:
SendMessage(winhandle, msgType, (UINT) &msg, callRet)
In a Windows environment, a WARM corresponds to a msg and a LARA corresponds to a callRet. A msg is a TPSVCINFO structure and a callRet indicates a result of the process. If a proper message is received, a callRet is 0, and if an improper message is received, a callRet is -1.
For example, if a service is processed as atpreturn (TPSUCCESS, …), or a service fails with a tpreturn (TPFAIL, …), or an unrequested message is received, a callRet becomes 0, since it will be considered as a proper message was received. However, if a synchronous or conversational message is delivered, a callRet will be -1 because those message types cannot be used in a multi Window environment. If a callRet value is -1, a tperrno value can be checked to know the error cause.
Prototype
# include <WinTmax.h> int WinTmaxSetContext(void *winhandle, unsigned int msgType, int slot)
Parameter
Parameter | Description |
---|---|
winhandle | A windows handle to process received data. |
msgType | A message type. |
slot | Indicates a slot used to allocate a specified Windows handle and message type. The maximum available number of slots is 256, and 0 and 1 are internally specified within a system for a default display and error respectively. Thus, if an error occurs while receiving data or a Windows for display is not specified, a default Windows is used. The default slots can be redefined by a user. In case of an unrequested message, a user defined Windows will not exists, so messages are delivered to the number 0 default display Windows. |
The values available for the slot are as follows.
Configuration Value | Description |
---|---|
–1 | Allocates a specified Windows handle and message type by automatically searching for vacant slots within a system. |
0 or a value greater than 0 | Allocates a specified Windows and message type to a slot specified with a given index. |
Return Value
Value | Description |
---|---|
index | A function call was successful and an index for a slot was returned. As well, an index is used as a first parameter of a WinTmaxSend(). |
-1 | A function call failed. A tperrno is set to an error code. |
Error When a WinTmaxSetContext() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPESYSTEM] | A Tmax system error occurred. |
[TPEOS] | An operating system error occurred. |
Example
... int CTMaxGwView::Connect() { CString szTemp, Fname; WinTmaxEnd(); int Ret = tmaxreadenv(TMAXINI, “TMAX117”); if(Ret<0) { szTemp.Format(“tmaxreadenv error”); LogDisplay2(2, (char *)(const char *)szTemp, szTemp.GetLength()); return FALSE; } if (WinTmaxStart((TPSTART_T *)NULL) == -1) { szTemp.Format(“WinTmaxStart 에러 = [%s]”, tpstrerror(tperrno)); LogDisplay2(2, (char *)(const char *)szTemp, szTemp.GetLength()); return FALSE; } WinTmaxSetContext(m_hWnd, WM_TMAX_RECV_RDP, 0); WinTmaxSetContext(m_hWnd, WM_TMAX_RECV_ERR, 1); WinTmaxSetContext(m_hWnd, WM_TMAX_RECV, 2); return TRUE; }
Related Functions
WinTmaxStart(),WinTmaxEnd(), WinTmaxSend()
The WinTmaxSend function, available in a client in a Window system environment, sends data. This function requests a service in a multi-windows environment.
Prototype
# include <WinTmax.h> int WinTmaxSend(int recvContext, char *svc, char *data, long len, long flags)
Parameter
Parameter | Description |
---|---|
recvContext | Sets a Windows for receiving a response from a Tmax system. It is the return value of a WinTmaxSetContext(). |
svc | A service name. |
data | A buffer allocated through a tpalloc(). The data used to request a service is stored. |
len | Data length. The length must be correctly defined when using a CARRAY or a multiple Structure buffer. |
flags | Flag values are listed in the table below. |
A WinTmaxSend() works similarly to a tpacall() function. It requests a service and is returned immediately without waiting for a response. A response is processed by the thread that was created when calling a WinTmaxStart(), and the response result will be sent to a Windows set by a WinTmaxSetContext(), so a separate API is not provided to receive the response.
The following example finds a vacant slot to store (hwd, 0x300) and returns an index. The return value a rc of a WinTmaxSetContext() is used as a recvContext parameter of a WinTmaxSend(). If a response is received after calling a WinTmaxSend(rc, svc, data, len, 0), a 0 x 300 message and a response result will be sent to a hwd windows.
rc = WinTmaxSetContext(hwd, 0x300, -1); int nSendResult = WindTmaxSend(rc, (LPSTR)(LPCSTR)strService, (Char*)tpbuf, nLen, TPNOFLAGS); /* The internal thread processes the response message and sends the result to the Windows SendMessage(hwd, 0x300, (UINT) &msg, callRet); */
A Windows that receives a message will receive a response data through a WPARAM and a response result through a LPARAM. If a callRet is 0, it means the response will be normal, and -1 means an error occurred. The cause of an error can be known through a tperrno value.
A WinTmaxSend() does not support transactions due to its structure and is not affected by a BLOCKTIME in a Tmax configuration file or a tpsettimeout(). However, when calling a WinTmaxSend(), if a TPBLOCK flag is given, a BLOCKTIME will be applied according to a corresponding flag.
The following are possible flag values:
Flag | Description |
---|---|
TPBLOCK | If a WinTmaxSend() function is used without this flag, a normal result will be returned even if a called service did not exist in a svc or an invalid result was returned. Errors can be checked at the time of receiving a result. Using this flag, it is possible to check whether a service status is normal or not normal at the time of calling a function. In other words, a WinTmaxSend() checks if a request service can be processed normally within a BLOCKTIME and returns the result. If a service cannot be processed, an error will be stored in a tperrno and a -1 will be returned. If it is impossible to check if a requested service can be processed within a BLOCKTIME, a TPETIME error will be returned. In this case, a client cannot know whether a requested service is processed or not, so an error routine must be written carefully. If a request should be sent again, an error routine must be to check if a previous request was processed. |
TPNOREPLY | Immediately returns a service request sent with a WinTmaxSend() function without waiting for a response. A worker thread receives the result and sends it to the a specified Windows. However, a TPNOREPLY flag will be set to not receive a response for the service. |
TPNOTRAN | If a WinTmaxSend() function caller requests a svc service by setting this flag in a transaction mode, the svc service will be executed while being excluded from the transaction mode. If a svc does not support transactions in a transaction mode, a flag must be set to a TPNOTRAN when a WinTmaxSend() function is called in the transaction mode. If called in the transaction mode, the WinTmaxSend() function will still be affected by a transaction timeout even though a service flag was set to TPNOTRAN. If the service called with a TPNOTRAN fails, it will not affect a caller's transaction. |
TPNOBLOCK | Upon encountering a blocking condition with this flag set (e.g., an internal buffer is filled with messages to be transmitted), a service request will fail. When calling a WinTmaxSend() function without setting a TPNOBLOCK flag and encountering a blocking condition, a function caller will wait until blocking is released or a timeout (transaction timeout or blocking timeout) occurs. |
TPNOTIME | A function caller must wait indefinitely until a response is received and blocking timeouts are ignored. If a WinTmaxSend() is called during a transaction timeout, a transaction timeout will be applied. |
TPSIGRSTRT | Allows signal interrupts. If a system function is interrupted by a signal, the system function will be executed again. If a signal interrupt occurs without this flag, a function will fail and a tperrno will be set to a TPGOTSIG. |
Return Value
Value | Description |
---|---|
Descriptor | A function call was successful and a descriptor is returned. Currently this descriptor is not used. |
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a WinTmaxSend() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPENOENT] | A specified svc does not exist. |
[TPEITYPE] | A svc does not support a data type or subtype. For a structure, this error occurs when the structure is not declared in a SDLFILE file. |
[TPELIMIT] | A maximum number of unprocessed asynchronous service requests was reached. Service requests from a caller cannot be sent. |
[TPETIME] | A timeout occurred. If a transaction timeout occurs when a function caller is in a transaction mode, a transaction will be rolled back. If a function caller is not in a transaction mode, a block timeout will occur if neither a TPNOTIME nor a TPNOBLOCK is set. In these cases, a *data content and a *len will not be changed. If a transaction timeout occurs, new service requests and processes waiting for a response will fail with a [TPETIME] error until a transaction is rolled back. |
[TPEBLOCK] | A blocking state occurred when a TPNOBLOCK was set. |
[TPGOTSIG] | A signal that is received when a TPSIGRSTRT is not set. |
[TPEPROTO] | A WinTmaxSend() was called from an invalid state. For example, a TPNOREPLY was called in a transaction mode, but a TPNOTRAN was not set. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPECLOSE] | Disconnected from a Tmax system due to various reasons (e.g., network issues). |
[TPEOS] | An operating system error occurred. |
If a LPARAM of a message sent to Windows is -1, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEBADDESC] | Occurs when a valid descriptor cannot be found when a response message is received. |
[TPEOTYPE] | Occurs when the buffer types of client and server programs do not match when a response message is received. |
[TPEPROTO] | A WinTmaxStart() or a WinTmaxEnd() was called from an invalid state. |
[TPESYSTEM] | A Tmax system error occurred. |
[TPECLOSE] | Disconnected from a Tmax system due to various reasons (e.g., network issues). |
[TPEOS] | An operating system error occurred. |
Example
... int CTMaxGwView::SendData2(char *data, long nLen) { CString szTemp; m_send_length.Format(“%d”,nLen); UpdateData(FALSE); char *tpbuf = tpalloc(“STRING”, NULL, nLen); if (tpbuf == NULL) { szTemp.Format(“tpalloc Error [%s]”, tpstrerror(tperrno)); LogDisplay2(2, (char *)(const char *)szTemp, szTemp.GetLength()); return -1; } memcpy(tpbuf, data, nLen); CString strService; strService.Format(“TOUPPER_STRING”); int nSendResult=WinTmaxSend(2,(LPSTR)(LPCSTR)strService, (char*)tpbuf, nLen, 0); tpfree(tpbuf); … }
Related Functions
WinTmaxStart(),WinTmaxEnd()
Describes functions that are related to multithread/multicontext. Multithread and multicontext server libraries are different from client libraries in the multicontext type.
The tpgetctxt function returns a context ID, which is set in a thread that calls a function, as its first parameter.
In a MultiThread/MultiContext server, a tpgetctxt returns a value of 1 or greater when the context set in a thread is valid. A tpgetctxt returns a TPNULLCONTEXT(-2) when a context is invalid or not set. A context is valid only while a service thread is processing a service request. If a tpreturn() is called after completing a service request, a context will no longer be valid and a user created thread can no longer use the context.
A tpgetctxt() is used differently in client and server programs. The following information describes the function by separating examples by server and client.
A MultiThread/MultiContext server does not support a Singlecontext.
Prototype
#include <usrinc/atmi.h> int tpgetctxt(int *ctxtid, long flags)
Parameter
Parameter | Description |
---|---|
ctxtid | Retrieves a current context at the time a function is called.
|
flags | Not currently supported. Set to TPNOFLAGS. |
Return Values
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpgetctxt() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEINVAL] | An invalid parameter. For example, a first parameter is a pointer or a second parameter is not set to 0. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example - Client Program
int newContext() { int i; int id; i = tpstart(tpinfo); if (i < 0) { printf(“\t[newContext]tpstart fail[%d][%s]\n",tperrno,tpstrerror(tperrno)); tpfree((char *)tpinfo); return -1; } i = tpgetctxt(&id,TPNOFLAGS); if (i < 0) { printf(“\t[newContext]tpgetctxt fail[%d][%s]\n",tperrno,tpstrerror(tperrno)); return -1; } return id; }
Example - Server Program
typedef param { int ctxtid; TPSVCINFO *svcinfo; } param_t; MSERVICE(TPSVCINFO *svcinfo) { pthread_t tid; param_t param; printf("MSERVICE service is started!"); tpgetctxt(¶m.ctxtid, TPNOFLAGS); param.svcinfo = svcinfo; pthread_create(&tid, NULL, THREAD_ROUTINE, ¶m); pthread_join(tid, NULL); printf("MSERVICE service is finished!"); tpreturn(TPSUCCESS, 0, svcinfo->data, 0L, TPNOFLAGS); } void *THREAD_ROUTINE(void *arg) { param_t *param; TPSVCINFO *svcinfo; param = (param_t *)arg; svcinfo = param->svcinfo; if (tpsetctxt(param->ctxtid, TPNOFLAGS) == -1) { printf("tpsetctxt(%d) failed, [tperrno:%d]", param->ctxtid, tperrno); return NULL; } tpcall("MTOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, TPNOFLAGS); if (tpsetctxt(TPNULLCONTEXT, TPNOFLAGS) == -1) { printf("tpsetctxt(TPNULLCONTEXT) failed, [tperrno:%d]", tperrno); return NULL; } return NULL; }
Related Function
tpsetctxt()
The tpsetctxt function sets a current context. The way the function is used differs in a client program and a server program as follows:
Client Program
A client can assign a different previously created context to a current client using a function. Most ATMI functions are based on per-context. To know the current context of a client, the return value of a tpgetctxt() can be checked.
A client can use multiple contexts, but only one context is used at a time. For example, if a tpacall() is called in context1, tpgetrply() must be called in context1 even though another context has been used.
Server Program
A service thread processes a service by getting a context, but a user created thread does not have its own context. Most ATMI functions can work after getting a context. Therefore a user created thread must share a context with a service thread if required. A user created thread can share a context with other service threads by using a tpsetctxt().
A user created thread that calls a tpsetctxt() shares context information with a service thread. For example, if a service thread calls a tpacall(), after that it is possible for a user created thread to receive a response for a request through a tpgetrply().
A tpsetctxt() cannot be used in a service thread. A service thread has its own context by default, and cannot replace the context with other one. Therefore, if a service thread calls a tpsetctxt(), an error will be returned with a TPEPROTO error code.
If a user created thread shares a context with a service thread through this function, the user created thread must call a tpsetctxt (TPNULLCONTEXT) before the service thread calls a tpreturn(). In other words, at the time that the service thread calls tpreturn(), the context of the service thread must be changed not to be shared by other user created threads. If this is not kept, tpreturn() will fail and aTPESVCERR error code will be returned to the client. Therefore, the process flow between threads must be controlled through synchronization. The ctxtid parameter of a tpsetctxt() uses the Context-ID which that is retrieved by calling a tpgetctxt() from a service thread.
With consideration of the different ways how a function is written depending on the program, the basic information of a tpsetctxt() is as follows:
Prototype
#include <usrinc/atmi.h> int tpsetctxt(int ctxtid, long flags)
Parameter
Parameter | Description |
---|---|
ctxtid | Sets a current context at the time point of a function call. In a client program, new context IDs created using a tpstart() can be used. In a server program, the Context-ID of a service thread can be used. Other contexts such as a TPNULLCONTEXT can be used but not a TPINVALIDCONTEXT. |
flags | Not currently supported. Set to TPNOFLAGS. |
Return Value
Value | Description |
---|---|
-1 | A function call failed. A tperrno is set to an error code. |
Error
When a tpsetctxt() fails to execute, a tperrno will be set to one of the following values:
Error Code | Description |
---|---|
[TPEPROTO] | A function was called from an invalid state. For example, a service thread called a function or a Context ID was delivered as a parameter that was invalid in a server program. |
[TPEINVAL] | An invalid parameter. A ctxid is set to 0 or TPINVALIDCONTEXT, or flags are set to non-zero. In a client program, a tpsetctxt() is called before the program calls a tpstart(). A buffer flag is not set to TPMULTICONTEXTS when this function is called before the tpstart() is called. This error occurs when a context ID is set to TPINVALIDCONTEXT or 0. |
[TPENOENT] | A ctxtid value is not a configurable context. |
[TPESYSTEM] | A Tmax system error occurred. Detailed error information is recorded in a system log file. |
[TPEOS] | An operating system error occurred. |
Example - Client Program
int altContext(int id) { int i; int ret; ret = tpsetctxt(id, TPNOFLAGS); if (ret < 0) { printf(“\t[altContext]tpsetctxt fail[%d][%s]\n"tperrno, tpstrerror(tperrno)); tpfree((char *)tpinfo); return -1; } return 1; }
Example - Server Program
typedef param { int ctxtid; TPSVCINFO *svcinfo; } param_t; MSERVICE(TPSVCINFO *svcinfo) { pthread_t tid; param_t param; printf("MSERVICE service is started!"); tpgetctxt(¶m.ctxtid, TPNOFLAGS); param.svcinfo = svcinfo; pthread_create(&tid, NULL, THREAD_ROUTINE, ¶m); pthread_join(tid, NULL); printf("MSERVICE service is finished!"); tpreturn(TPSUCCESS, 0, svcinfo->data, 0L, TPNOFLAGS); } void *THREAD_ROUTINE(void *arg) { param_t *param; TPSVCINFO *svcinfo; param = (param_t *)arg; svcinfo = param->svcinfo; if (tpsetctxt(param->ctxtid, TPNOFLAGS) == -1) { printf("tpsetctxt(%d) failed, [tperrno:%d]", param->ctxtid, tperrno); return NULL; } tpcall("MTOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, TPNOFLAGS); if (tpsetctxt(TPNULLCONTEXT, TPNOFLAGS) == -1) { printf("tpsetctxt(TPNULLCONTEXT) failed, [tperrno:%d]", tperrno); return NULL; } return NULL; }
Related Function
tpgetctxt()