Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNdb_c.hxx

00001 /******************************************************************
00002  * CAVERNsoft
00003  * Copyright (C) 1994-2000 Electronic Visualization Laboratory,
00004  * all rights reserved
00005  * By Jason Leigh, Yong-joo Cho, Naveen Krishnaprasad, Chris Scharver,
00006  * Stuart Bailey, Atul Nayak, Shalini Venkataraman 
00007  * University of Illinois at Chicago
00008  * 
00009  * This publication and its text and code may not be copied for commercial 
00010  * use without the express written permission of the University of Illinois
00011  * at Chicago.
00012  * The contributors disclaim any representation of warranty: use this
00013  * code at your own risk.
00014  * Direct questions, comments etc to cavern@evl.uic.edu
00015  ******************************************************************/
00016 
00017 #ifndef _CAVERNDB_C
00018 #define _CAVERNDB_C
00019 
00020 #include "CAVERN.hxx"
00021 #include "keytool.hxx"
00022 
00023 // Default server database directory name.
00024 #define CAVERNDB_SERVER_DEFAULT_DB_NAME "CAVERNdbserver"
00025 // Default client database directory name.
00026 #define CAVERNDB_CLIENT_DEFAULT_DB_NAME "CAVERNdbclient"
00027 
00033 class CAVERNdb_server_c
00034 {
00035 public:
00036         static const char PUT_MESG/* = 'p'*/;
00037         static const char FETCH_MESG/* = 'f'*/;
00038         static const char COMMIT_MESG/* = 'c'*/;
00039 
00041 
00042         static const int DEFAULT_TCP_REFLECTOR_PORT/* = 9500*/;
00043 
00045     static const int DEFAULT_UDP_REFLECTOR_PORT /* = 9550*/;
00046     
00048         static const int DEFAULT_MAX_CLIENTS/* = 64*/;
00049 
00051         static const int OK/* = 1*/;
00052 
00054         static const int FAILED/* = 0*/;
00055 
00057         static const int MEM_ALLOC_ERR/* = 3*/;
00058 
00060         static const int TOO_MANY_CLIENTS/* = 4*/;
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         // Handle any new connections. This does nothing.
00082         static  void newConnectionHandler(CAVERNnet_tcpReflectorClient_c *newClient, void* userData);
00083 
00084         // Handle incoming commands.
00085         static int newDataHandler(CAVERNnet_tcpReflectorClient_c * client, char** buffer, int *bufferSize, void *userData);
00086 
00087     // Handler for incoming commands received by the udp reflector
00088     static int udpDataHandler(CAVERNnet_udp_c* udpClient, char** buffer, int* bufferSize,void* userData);
00089     
00090     //Functions for performance monitoring
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     //TCP Reflector listening port
00164         int incomingPort;
00165 
00166         // Handle PUT commands.
00167         void handlePut(char *buf, int size);
00168 
00169         // Handle FETCH commands.
00170         void handleFetch(CAVERNnet_tcpReflectorClient_c *client, char *buf, int size);
00171 
00172         // Handle COMMIT command.
00173         void handleCommit(CAVERNnet_tcpReflectorClient_c *client, char *buf, int size);
00174 
00175         // Send a put message
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/* = 0*/;
00191         static const int OK/* = 1*/;
00192 
00194         static const int MEM_ALLOC_ERR/* = 2*/;
00195 
00197         static const int CONNECTION_TERMINATED/* = 3*/;
00198 
00200         static const int IGNORED/* = 4*/;
00201 
00203     static  const int UNRELIABLE_CONNECTION /* = 5*/;
00204     
00206     static  const int RELIABLE_CONNECTION /* = 6*/;
00207     
00209     static const int MAX_UDP_PACKET_SIZE /* = 1K*/;
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     //Functions for performance monitoring
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         // Handle incoming messages
00396         void handleMessage(char* data, int dataSize);
00397 
00398         // Handle incoming PUT messags
00399         void handleIncomingPut(char* data, int datasize);
00400 };
00401 
00402 
00403 #endif
00404 
00405 
00406 

Generated at Mon Jul 2 14:24:42 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001