00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _CAVERNDB_C
00018 #define _CAVERNDB_C
00019
00020 #include "CAVERN.hxx"
00021 #include "keytool.hxx"
00022
00023
00024 #define CAVERNDB_SERVER_DEFAULT_DB_NAME "CAVERNdbserver"
00025
00026 #define CAVERNDB_CLIENT_DEFAULT_DB_NAME "CAVERNdbclient"
00027
00033 class CAVERNdb_server_c
00034 {
00035 public:
00036 static const char PUT_MESG;
00037 static const char FETCH_MESG;
00038 static const char COMMIT_MESG;
00039
00041
00042 static const int DEFAULT_TCP_REFLECTOR_PORT;
00043
00045 static const int DEFAULT_UDP_REFLECTOR_PORT ;
00046
00048 static const int DEFAULT_MAX_CLIENTS;
00049
00051 static const int OK;
00052
00054 static const int FAILED;
00055
00057 static const int MEM_ALLOC_ERR;
00058
00060 static const int TOO_MANY_CLIENTS;
00061
00063
00064 ~CAVERNdb_server_c();
00065
00074 int init(char *defaultDBName = CAVERNDB_SERVER_DEFAULT_DB_NAME, int incomingPort = CAVERNdb_server_c::DEFAULT_TCP_REFLECTOR_PORT, int maxClients = CAVERNdb_server_c::DEFAULT_MAX_CLIENTS, int udpReflectorPort = CAVERNdb_server_c::DEFAULT_UDP_REFLECTOR_PORT);
00075
00079 int process();
00080
00081
00082 static void newConnectionHandler(CAVERNnet_tcpReflectorClient_c *newClient, void* userData);
00083
00084
00085 static int newDataHandler(CAVERNnet_tcpReflectorClient_c * client, char** buffer, int *bufferSize, void *userData);
00086
00087
00088 static int udpDataHandler(CAVERNnet_udp_c* udpClient, char** buffer, int* bufferSize,void* userData);
00089
00090
00091
00103 void showStats(char* streamInfo, char* comment);
00104
00121 int logStats(char* streamInfo, char* comment, FILE* filePtr);
00122
00136 int sendStats(char* streamInfo, char* comment);
00137
00151 int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00152
00156 void exitSendStats();
00157
00158 private:
00159 CAVERNnet_tcpReflector_c * server;
00160 CAVERNnet_udpReflector_c* udpreflector;
00161 keyToolManager_c *keyToolManager;
00162
00163
00164 int incomingPort;
00165
00166
00167 void handlePut(char *buf, int size);
00168
00169
00170 void handleFetch(CAVERNnet_tcpReflectorClient_c *client, char *buf, int size);
00171
00172
00173 void handleCommit(CAVERNnet_tcpReflectorClient_c *client, char *buf, int size);
00174
00175
00176 void sendPutMessage(CAVERNnet_tcpReflectorClient_c *client, char* pathname, int pathsize, char* keyname, int keysize);
00177
00178
00179 };
00180
00183 class CAVERNdb_client_c : public CAVERNmisc_subject_c
00184 {
00185 public:
00186
00188
00189 static const int FAILED;
00191 static const int OK;
00192
00194 static const int MEM_ALLOC_ERR;
00195
00197 static const int CONNECTION_TERMINATED;
00198
00200 static const int IGNORED;
00201
00203 static const int UNRELIABLE_CONNECTION ;
00204
00206 static const int RELIABLE_CONNECTION ;
00207
00209 static const int MAX_UDP_PACKET_SIZE ;
00210
00212
00213 CAVERNdb_client_c();
00214 ~CAVERNdb_client_c();
00215
00226 int init(char *serverIP, int serverPort= CAVERNdb_server_c::DEFAULT_TCP_REFLECTOR_PORT, char* defaultDBName = CAVERNDB_CLIENT_DEFAULT_DB_NAME, int udp_reflector_port = CAVERNdb_server_c::DEFAULT_UDP_REFLECTOR_PORT);
00227
00233 int fetch(char *pathname, char *keyname);
00239 void trigger(void (*callback) (char* pathname, char* keyname, void *userData), void* userData);
00240
00250 int put(char* pathname, char* keyname, char* data, int datasize, int typeOfConnection = CAVERNdb_client_c::RELIABLE_CONNECTION);
00251
00259 char* get(char* pathname, char* keyname, int* datasize);
00260
00264 int process();
00265
00276 int reconnect(char* servername = NULL, int port = 0);
00277
00283 int commit(char* pathname, char* keyname);
00284
00290 int remoteCommit(char* pathname, char* keyname);
00291
00295 char* getNotifyPathname() {return notifyPathname;}
00296
00300 char* getNotifyKeyname() {return notifyKeyname;}
00301
00302
00303
00304
00317 void showStats(char* streamInfo, char* comment);
00318
00335 int logStats(char* streamInfo, char* comment, FILE* filePtr);
00336
00351 int sendStats(char* streamInfo, char* comment);
00352
00366 int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00367
00371 void exitSendStats();
00372
00373 private:
00374 char *notifyPathname;
00375 char *notifyKeyname;
00376
00377 keyToolManager_c *keyToolManager;
00378 CAVERNnet_tcpReflectorClient_c *client;
00379 CAVERNnet_udp_c* udpClient;
00380 void *callbackUserData;
00381 void (*triggerCallback) (char* pathname, char* keyname, void* userData);
00382 char itsServerName[256];
00383 int itsServerPort;
00384 int udpReflectorPort;
00385
00393 CAVERNts_mutex_c *clientmutex, *callbackmutex;
00394
00395
00396 void handleMessage(char* data, int dataSize);
00397
00398
00399 void handleIncomingPut(char* data, int datasize);
00400 };
00401
00402
00403 #endif
00404
00405
00406