Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNdb_client_c Class Reference

#include <CAVERNdb_c.hxx>

Inheritance diagram for CAVERNdb_client_c::

CAVERNmisc_subject_c List of all members.

Public Methods

 CAVERNdb_client_c ()
 ~CAVERNdb_client_c ()
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)
int fetch (char *pathname, char *keyname)
void trigger (void(*callback)(char *pathname, char *keyname, void *userData), void *userData)
int put (char *pathname, char *keyname, char *data, int datasize, int typeOfConnection=CAVERNdb_client_c::RELIABLE_CONNECTION)
char* get (char *pathname, char *keyname, int *datasize)
int process ()
int reconnect (char *servername=NULL, int port=0)
int commit (char *pathname, char *keyname)
int remoteCommit (char *pathname, char *keyname)
char* getNotifyPathname ()
char* getNotifyKeyname ()
void showStats (char *streamInfo, char *comment)
int logStats (char *streamInfo, char *comment, FILE *filePtr)
int sendStats (char *streamInfo, char *comment)
int initSendStats (char *monitorClientIP, int port=PERF_DAEMON_DEFAULT_PORT)
void exitSendStats ()

Static Public Attributes

const int FAILED
 Status failed.

const int OK
 Status ok.

const int MEM_ALLOC_ERR
 Memory allocation error.

const int CONNECTION_TERMINATED
 Connection terminated.

const int IGNORED
 Action ignored. See reconnect().

const int UNRELIABLE_CONNECTION
 Use unreliable UDP for data transmission (make sure the datasize is less than 1K).

const int RELIABLE_CONNECTION
 Use reliable TCP for data transmission.

const int MAX_UDP_PACKET_SIZE
 Maximum udp packet size allowed (1 KB).


Private Methods

void handleMessage (char *data, int dataSize)
void handleIncomingPut (char *data, int datasize)

Private Attributes

char* notifyPathname
char* notifyKeyname
keyToolManager_c* keyToolManager
CAVERNnet_tcpReflectorClient_cclient
CAVERNnet_udp_cudpClient
void* callbackUserData
void (* triggerCallback )(char *pathname, char *keyname, void *userData)
char itsServerName [256]
int itsServerPort
int udpReflectorPort
CAVERNts_mutex_cclientmutex
CAVERNts_mutex_ccallbackmutex

Detailed Description

CAVERN database client. This client will connect to database servers written with CAVERNdb_server_c. Currently only a few basic commands have been implemented. More will be added with time.


Member Function Documentation

int CAVERNdb_client_c::commit ( char * pathname,
char * keyname )
 

Commit data in local database.

Parameters:
pathname   pathname
keyname   keyname
Returns:
OK or MEM_ALLOC_ERR

void CAVERNdb_client_c::exitSendStats ( )
 

Properly delete the perfDaemonClient after sendStats is done

int CAVERNdb_client_c::fetch ( char * pathname,
char * keyname )
 

Fetch data from server. This is a non-blocking call so once the fetch command has been issued it will return. It is then up to the server to respond eventually.

Parameters:
pathname   Path name
keyname   Key name
Returns:
FAILED, OK

char * CAVERNdb_client_c::get ( char * pathname,
char * keyname,
int * datasize )
 

Get data in a key.

Parameters:
pathname   Path name
keyname   Key name
datasize   returns size of data
Returns:
memory buffer containing data. Remember to delete the buffer when you are done using it.

char * CAVERNdb_client_c::getNotifyKeyname ( ) [inline]
 

Get the keyname of the key that has triggered a notify event. This is mainly used by observers that have attached to this object.

char * CAVERNdb_client_c::getNotifyPathname ( ) [inline]
 

Get the pathname of the key that has triggered a notify event. This is mainly used by observers that have attached to this object.

int CAVERNdb_client_c::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 )
 

Initialize client by connecting to remote server. If you specify serverIP as NULL then you are making no network connections. Ie you are using the client database in local single user mode.

Parameters:
serverIP   IP address of CAVERNdb_server_c.
serverPort   Listening port of db_server's tcp reflector.Default is 9500.
defaultDBName   Database directory name. Default is CAVERNdbclient.
udp_reflector_port   Listening port of db_server's udp reflector. Default is 9550.

Returns:
OK, FAILED, MEM_ALLOC_ERR

int CAVERNdb_client_c::initSendStats ( char * monitorClientIP,
int port = PERF_DAEMON_DEFAULT_PORT )
 

Initialize sendStats - provide the IP of the perfDaemon and an optional port number to connect to. This should be done initially before using the sendStats API.

Parameters:
monitorClientIP   IP address of the perfDameon to connect to
port   Port number at which the perfDaemon is running -this is optional. The default port number for perfDaemon is 9500 -so a different port number has to be specified if the perfDaemon is running on a different port.

Returns:
Either CAVERNnet_perfMonitor_c::OK or CAVERNnet_perfMonitor_c::FAILED

int CAVERNdb_client_c::logStats ( char * streamInfo,
char * comment,
FILE * filePtr )
 

This logs performance statistics in a file. The user opens a file and passes the file pointer with this function and results of monitoring are written into the logfile.

Parameters:
streamInfo   A label describing the stream that is being monitored.
comment   A comment on the event that marks the time at which the stream is being monitored
filePtr   File pointer to the file in which the results of monitoring are to be stored

Returns:
Either CAVERNnet_perfMonitor_c::OK or CAVERNnet_perfMonitor_c::FAILED

int CAVERNdb_client_c::process ( )
 

Process the client. Do this as frequently as possible and in a while loop.

Returns:
OK, CONNECTION_TERMINATED

int CAVERNdb_client_c::put ( char * pathname,
char * keyname,
char * data,
int datasize,
int typeOfConnection = CAVERNdb_client_c::RELIABLE_CONNECTION )
 

Put data into a key. The users can also make use of a UDP connection for the data transmission by using CAVERNdb_client_c::UNRELIABLE_CONNECTION (the default is a reliable tcp connection). Please note that the datasize for UDP should be less than 1K. If the datasize is more than 1K, the data is sent via a TCP connection

Parameters:
pathname   Path name
keyname   Key name
data   data to put
datasize   size of data buffer
typeOfConnection   the type of connetion to be used
Returns:
MEM_ALLOC_ERR, OK.

int CAVERNdb_client_c::reconnect ( char * servername = NULL,
int port = 0 )
 

Reconnect to server on broken connection. If the result of process() call is CONNECTION_TERMINATED you can try to reconnect to the server.

Parameters:
servername   set this to NULL to have it reconnect using the last server name.
port   set this to 0 to have it reconnect using the last server port.
Returns:
OK, FAILED, MEM_ALLOC_ERR, IGNORED. IGNORED is returned if you are trying to do a reconnect but originally you were running in non-networked mode (ie you called init() with a NULL serverIP name).

int CAVERNdb_client_c::remoteCommit ( char * pathname,
char * keyname )
 

Commit data in server database.

Parameters:
pathname   pathname
keyname   keyname
Returns:
OK or FAILED.

int CAVERNdb_client_c::sendStats ( char * streamInfo,
char * comment )
 

Sends the performance statistics to a remote perfdaemon -for further analysis of the monitored data - the initSendStats API should be called first, before calling a sendStats (In order to connect to the perfdaemon initially)

Parameters:
streamInfo   A label describing the stream that is being monitored.
comment   A comment on the event that marks the time at which the stream is being monitored

Returns:
Either CAVERNnet_perfMonitor_c::OK or CAVERNnet_perfMonitor_c::FAILED

void CAVERNdb_client_c::showStats ( char * streamInfo,
char * comment )
 

Displays the resultant statistics instantaneously in the netlogger format - this should be typically done after a read/write is done a network.

Also, it should be noted that a showStats call should be made at the end of atleast one send and receive for two-way information (the same applies for logStats and sendStats)

Parameters:
streamInfo   A label describing the stream that is being monitored.
comment   A comment on the event that marks the time at which the stream is being monitored

void CAVERNdb_client_c::trigger ( void(* callback)(char *pathname, char *keyname, void *userData),
void * userData )
 

Set a trigger so that when data arrives it will fire a callback. Callbacks are fired after notification of observers.

Parameters:
callback   callback function pointer. Set this to NULL for no trigger.
userData   user data to pass onto callback when it is fired.


Member Data Documentation

CAVERNts_mutex_c * CAVERNdb_client_c::callbackmutex [private]
 

Clientmutex is used to try and prevent multiple threads from using the socket at the same time or using the keytool database. Callbackmutex is used to make sure multiple callbacks do not fire at the same time since there is no guarantee that the user will write a thread-safe callback function.

CAVERNts_mutex_c * CAVERNdb_client_c::clientmutex [private]
 

Clientmutex is used to try and prevent multiple threads from using the socket at the same time or using the keytool database. Callbackmutex is used to make sure multiple callbacks do not fire at the same time since there is no guarantee that the user will write a thread-safe callback function.


The documentation for this class was generated from the following file:
Generated at Mon Jul 2 14:24:43 2001 for CAVERNsoft by doxygen1.2.8-20010617 written by Dimitri van Heesch, © 1997-2001