Files
sics/asyncprotocol.h
2012-11-28 11:03:51 +11:00

65 lines
2.4 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;
struct __async_txn {
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 *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 */