00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _MESSAGES_H_
00026 #define _MESSAGES_H_
00027
00028 #include <limits.h>
00029
00030 #ifdef _WIN32
00031 #include "pthread.h"
00032 #else
00033 #include <pthread.h>
00034 #endif //_WIN32
00035
00036 #include "sockets.h"
00037 #include "../stmt/statement.h"
00038
00044 #define MSG_V3_PROTO_ERROR -234422
00045
00046 #define MSG_V3_PROTO_TIMEOUT -234423
00047
00048 #define MSG_V3_PROTO_OK 0
00049 #define MSG_V3_PROTO_SOCKET_ERROR -234424
00050 #define MSG_V3_PROTO_NOMEM -234425
00051 #define MSG_V3_PROTO_WRONG_MAGIC -234426
00052 #define MSG_V3_PROTO_UNKNOWN_PREFIX -234427
00053 #define MSG_V3_PROTO_UNKNOWN_COMMAND -234428
00054 #define MSG_V3_PROTO_NOT_READY -234429
00055 #define MSG_V3_PROTO_WRONG_STATE -234430
00056 #define MSG_V3_PROTO_BAD_VALUE -234431
00057
00058 #define MSG_V3_PROTO_NO_ROOM_FOR_TXN -234432
00059
00061 #define CONN_RECV_TIME_OUT LONG_MAX
00062
00064 #define CONN_SEND_TIME_OUT LONG_MAX
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #define SAFE_STR(s) (s ? s : "")
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #ifdef __cplusplus
00100 extern "C"
00101 {
00102 #endif
00103
00104
00105
00107 typedef enum {
00108 MSG_V3_ALLOC_SELF,
00109 MSG_V3_ALLOC_AUTO
00110
00111 } msgv3_alloc;
00112
00114 typedef enum {
00115 MSG_V3_PREFIX_DEFAULT = 0,
00116 MSG_V3_PREFIX_LEN = 1,
00117 MSG_V3_PREFIX_CONTEXT,
00118 MSG_V3_PREFIX_PREDICATE,
00119 MSG_V3_PREFIX_SUBJECT,
00120 MSG_V3_PREFIX_OBJECT,
00121 MSG_V3_PREFIX_OPERATION,
00122 MSG_V3_PREFIX_PREV,
00123 MSG_V3_PREFIX_NUM,
00124 MSG_V3_PREFIX_ERRSTR,
00125 MSG_V3_PREFIX_START,
00126 MSG_V3_PREFIX_END,
00127 MSG_V3_PREFIX_TXN,
00128 MSG_V3_PREFIX_LOGIN,
00129 MSG_V3_PREFIX_FINAL,
00130 MSG_V3_PREFIX_CMD,
00131 MSG_V3_PREFIX_MAGIC,
00132 MSG_V3_PREFIXES_COUNT
00133
00134 } msgv3_prefix;
00135
00136 #define MSG_V3_PREFIX_DEFAULT_BIT (0x01 << MSG_V3_PREFIX_DEFAULT)
00137 #define MSG_V3_PREFIX_LEN_BIT (0x01 << MSG_V3_PREFIX_LEN)
00138 #define MSG_V3_PREFIX_CONTEXT_BIT (0x01 << MSG_V3_PREFIX_CONTEXT)
00139 #define MSG_V3_PREFIX_PREDICATE_BIT (0x01 << MSG_V3_PREFIX_PREDICATE)
00140 #define MSG_V3_PREFIX_SUBJECT_BIT (0x01 << MSG_V3_PREFIX_SUBJECT)
00141 #define MSG_V3_PREFIX_OBJECT_BIT (0x01 << MSG_V3_PREFIX_OBJECT)
00142 #define MSG_V3_PREFIX_NUM_BIT (0x01 << MSG_V3_PREFIX_NUM)
00143 #define MSG_V3_PREFIX_ERR_BIT (0x01 << MSG_V3_PREFIX_ERRSTR)
00144 #define MSG_V3_PREFIX_START_BIT (0x01 << MSG_V3_PREFIX_START)
00145 #define MSG_V3_PREFIX_END_BIT (0x01 << MSG_V3_PREFIX_END)
00146 #define MSG_V3_PREFIX_TXN_BIT (0x01 << MSG_V3_PREFIX_TXN)
00147 #define MSG_V3_PREFIX_LOGIN_BIT (0x01 << MSG_V3_PREFIX_LOGIN)
00148 #define MSG_V3_PREFIX_OPERATION_BIT (0x01 << MSG_V3_PREFIX_OPERATION)
00149 #define MSG_V3_PREFIX_PREV_BIT (0x01 << MSG_V3_PREFIX_PREV)
00150 #define MSG_V3_PREFIX_STATEMENT_BITS (MSG_V3_PREFIX_CONTEXT_BIT | MSG_V3_PREFIX_SUBJECT_BIT | MSG_V3_PREFIX_PREDICATE_BIT | MSG_V3_PREFIX_OBJECT_BIT | MSG_V3_PREFIX_OPERATION_BIT | MSG_V3_PREFIX_PREV_BIT | MSG_V3_PREFIX_START_BIT | MSG_V3_PREFIX_END_BIT )
00151 #define MSG_V3_PREFIX_MASK_BITS (MSG_V3_PREFIX_CONTEXT_BIT | MSG_V3_PREFIX_SUBJECT_BIT | MSG_V3_PREFIX_PREDICATE_BIT | MSG_V3_PREFIX_OBJECT_BIT )
00152
00153
00155 typedef enum {
00157 MSG_V3_COMMAND_OK = 0,
00159 MSG_V3_COMMAND_FAIL = 1,
00160 MSG_V3_COMMAND_SET,
00161 MSG_V3_COMMAND_NOP,
00162 MSG_V3_COMMAND_NOTIFY,
00163 MSG_V3_COMMAND_BEGIN,
00164 MSG_V3_COMMAND_COMMIT,
00165 MSG_V3_COMMAND_ROLLBACK,
00166 MSG_V3_COMMAND_LOGIN,
00167 MSG_V3_COMMAND_LOGOUT,
00168 MSG_V3_COMMAND_GET,
00169 MSG_V3_COMMAND_BATCHGET,
00170 MSG_V3_COMMAND_SYNC,
00171 MSG_V3_COMMAND_NEWID,
00172 MSG_V3_COMMAND_EMPTY,
00173 MSG_V3_COMMAND_GETCOUNT,
00174 MSG_V3_COMMANDS_COUNT
00175 } msgv3_command;
00176
00177
00180 typedef struct {
00182 msgv3_alloc alloc_type;
00184 msgv3_prefix prefix;
00186 unsigned int size;
00188 void *value;
00190 long integer;
00191
00192 } VrbProt3Value;
00193
00195 typedef struct {
00196 unsigned int magic;
00197 msgv3_command cmd;
00198 } VrbProt3Msg;
00199
00201 typedef struct {
00203 VrbProt3Value values[MSG_V3_PREFIXES_COUNT];
00205 unsigned int update_bits;
00206
00207 } VrbProt3Pool;
00208
00209
00219 int msgv3_msg_send(hsocket sk, msgv3_command cmd, VrbProt3Pool *pool, unsigned int prefix_mask);
00220
00223 int msgv3_msg_recv(hsocket sk, msgv3_command *cmd, VrbProt3Pool *pool);
00224
00226 void msgv3_value_init(VrbProt3Value *value,
00227 msgv3_alloc alloc,
00228 msgv3_prefix prefix,
00229 unsigned int size, void *buf);
00230
00232 void msgv3_value_free(VrbProt3Value *value);
00233
00235 void msgv3_value_init_string(VrbProt3Value *value, unsigned char prefix, const char *str);
00236
00237
00239 void msgv3_pool_init(VrbProt3Pool *pool);
00240
00242 void msgv3_pool_update(VrbProt3Pool *pool, VrbProt3Value *value);
00243
00244 void msgv3_pool_get_value(VrbProt3Pool *pool, msgv3_prefix prefix, VrbProt3Value *value);
00245
00249 int msgv3_pool_read_value(VrbProt3Pool *pool, msgv3_prefix prefix, unsigned int offset, void *buf, unsigned int size);
00250
00254 void msgv3_pool_clear(VrbProt3Pool *pool);
00255
00259 int msgv3_pool_get_statement(VrbProt3Pool *pool, Statement *stmt);
00260
00261
00264 int msgv3_pool_get_mask(VrbProt3Pool *pool, Statement *mask);
00265
00266
00269 int msgv3_pool_set_statement(VrbProt3Pool *pool, const Statement *stmt);
00270
00273 int msgv3_pool_set_mask(VrbProt3Pool *pool, const Statement *mask);
00274
00277 void msgv3_value_init_integer(VrbProt3Value *value, msgv3_prefix prefix, long integer);
00278
00281 void msgv3_value_init_null(VrbProt3Value *value, msgv3_prefix prefix);
00282
00283
00287 void msgv3_value_ensure_string(VrbProt3Value *value);
00288
00289 #ifdef __cplusplus
00290 }
00291 #endif
00292
00293
00294 #endif
00295