74 lines
2.7 KiB
C
74 lines
2.7 KiB
C
#ifndef ASYNCPROTOCOL
|
|
#define ASYNCPROTOCOL
|
|
|
|
typedef struct __AsyncUnit AsyncUnit, *pAsyncUnit;
|
|
|
|
typedef struct __async_txn AsyncTxn, *pAsyncTxn;
|
|
typedef int (*AsyncTxnHandler) (pAsyncTxn pTxn);
|
|
|
|
typedef struct __async_protocol AsyncProtocol, *pAsyncProtocol;
|
|
|
|
pAsyncProtocol AsyncProtocolCreate(SicsInterp * pSics,
|
|
const char *protocolName,
|
|
ObjectFunc pFunc, KillFunc pKFunc);
|
|
|
|
int AsyncProtocolAction(SConnection * pCon, SicsInterp * pSics,
|
|
void *pData, int argc, char *argv[]);
|
|
|
|
int AsyncProtocolFactory(SConnection * pCon, SicsInterp * pSics,
|
|
void *pData, int argc, char *argv[]);
|
|
|
|
typedef enum {
|
|
ATX_NULL = 0,
|
|
ATX_TIMEOUT = -1,
|
|
ATX_ACTIVE = 1,
|
|
ATX_COMPLETE = 2,
|
|
ATX_DISCO = 3
|
|
} ATX_STATUS;
|
|
|
|
#define AQU_TIMEOUT -1
|
|
#define AQU_DISCONNECT -2
|
|
#define AQU_RECONNECT -3
|
|
#define AQU_RETRY_CMD -4
|
|
#define AQU_POP_CMD -5
|
|
|
|
struct __async_txn {
|
|
int ref_counter; /**< reference counter (reference counted object) */
|
|
pAsyncUnit unit; /**< unit that transaction is associated with */
|
|
int txn_state; /**< protocol handler transaction parse state */
|
|
ATX_STATUS txn_status; /**< status of the transaction OK, Error, ... */
|
|
int txn_timeout; /**< transaction timeout in milliseconds */
|
|
char *out_buf; /**< output buffer for sendCommand */
|
|
int out_len; /**< length of data to be sent */
|
|
int out_idx; /**< index of next character to transmit */
|
|
char *inp_buf; /**< input buffer for transaction response */
|
|
int inp_len; /**< length of input buffer */
|
|
int inp_idx; /**< index of next character (number already received) */
|
|
AsyncTxnHandler handleResponse; /**< Txn response handler of command sender */
|
|
void *proto_private; /**< Protocol Private structure */
|
|
void (*kill_private) (pAsyncTxn pTxn); /**< if it needs killing */
|
|
void *cntx; /**< opaque context used by command sender */
|
|
/* The cntx field may be used by protocol handler from sendCommand
|
|
* as long as it is restored when response is complete
|
|
*/
|
|
};
|
|
|
|
/*
|
|
* The async protocol interface virtual function table
|
|
*/
|
|
struct __async_protocol {
|
|
pObjectDescriptor pDes;
|
|
char *protocolName;
|
|
char *sendTerminator;
|
|
char *replyTerminator[10];
|
|
void *privateData;
|
|
int (*sendCommand) (pAsyncProtocol p, pAsyncTxn txn);
|
|
int (*handleInput) (pAsyncProtocol p, pAsyncTxn txn, int ch);
|
|
int (*handleEvent) (pAsyncProtocol p, pAsyncTxn txn, int event);
|
|
int (*prepareTxn) (pAsyncProtocol p, pAsyncTxn txn, const char *cmd,
|
|
int cmd_len, int rsp_len);
|
|
void (*killPrivate) (pAsyncProtocol p);
|
|
};
|
|
|
|
#endif /* ASYNCPROTOCOL */
|