Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

messages.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *
00003  * Verball Model Storage Library, Common Information Model Library 
00004  * for integration of Intelligent Services.
00005  * Copyright (C) 2005 Nikita Vinokurov, Orgway LLC.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; 
00010  * version 2.1 of the License.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00020  * Boston, MA  02110-1301  USA
00021  *
00022  * $Id: messages.h,v 1.12 2006/09/18 21:38:30 sbreg Exp $
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     Note, what time-out will set again and again
00068     after every incoming/outgoing TCP packet
00069     while whole message is not be readed/sent.
00070  */
00071 
00072 
00073 
00074 
00075 #define SAFE_STR(s) (s ? s : "")
00076 
00077 /* macro _MS_SERVER defined only in server project. */
00078 //#ifndef _MS_SERVER
00079 //typedef enum _client_connection_states {
00080 //  error = -1,
00081 //  inactive,
00082 //  connected,
00083 //  active,
00084 //  closed
00085 //} client_conn_state;
00086 //
00087 //typedef struct _client_connection {
00088 //  hsocket                 sk;
00089 //  client_conn_state       ccs;
00090 //  int                     final_read; /**< The final message read flag */
00091 //  pthread_mutex_t         session_lock; /**< Session locker */
00092 //  int                     last_error;
00093 //} client_conn;
00094 
00095 // #else // i.e. server project
00096 // #include "../ols/conn_pool.h"
00097 //#endif //_MS_SERVER
00098 
00099 #ifdef __cplusplus
00100 extern "C"
00101 {
00102 #endif/* __cplusplus */
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/* __cplusplus */
00292 
00293 
00294 #endif /* _MESSAGES_H_ */
00295 

Generated on Wed Dec 27 16:52:17 2006 for VRB Online Server by  doxygen 1.4.4