Main Page   Class Hierarchy   Compound List   File List   Compound Members  

CAVERNnet_tcpReflector_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 #include "CAVERNnet_tcp_c.hxx"
00018 
00019 #ifndef _CAVERNPLUS_TCP_REFLECTOR
00020 #define _CAVERNPLUS_TCP_REFLECTOR
00021 
00022 #define TCP_REFLECTOR_DEFAULT_PORT      7000
00023 #define PERFDAEMON_ALIVE 1
00024 #define PERFDAEMON_NOT_ALIVE 0
00025 
00026 class CAVERNnet_tcpReflectorClient_c;
00027 
00044 class CAVERNnet_tcpReflector_c
00045 {
00046 public:
00047         CAVERNnet_tcpReflector_c();
00048         ~CAVERNnet_tcpReflector_c();
00049 
00051 
00052         static const int OK/* = 0*/;
00053 
00055         static const int FAILED/* = 1*/;
00056 
00058         static const int MEM_ALLOC_ERR/* = 2*/;
00059 
00061         static const int NEW_CONNECTION_ESTABLISHED/* = 4*/;
00062 
00064         static const int TOO_MANY_CLIENTS/* = 5*/;
00065 
00067         static const int NO_NEW_CONNECTION/* = 6*/;
00068 
00070         static const int NON_BLOCKING_HAS_NO_DATA/* = 7*/;
00071 
00073         static const int SKIP_DISTRIBUTION/* = 8*/;
00074 
00075         static const int DEFAULT_PORT/* = 7000*/;
00077 
00085         int init(int incomingPort=TCP_REFLECTOR_DEFAULT_PORT, int maxClients = 64, 
00086                      char* forwardAddr = NULL, unsigned short forwardPort = 0);
00087 
00092         int process();
00093 
00101         int checkForNewClients();
00102 
00106         int setForcedDestination(char *ipAddr, unsigned short port);
00107 
00110         void sendToAll(char* buffer, int dataSize);
00111 
00128         void intercept(int (*callback) (CAVERNnet_tcpReflectorClient_c *client, char** buffer, int *bufferSize,  void *userData), void* userData);
00129 
00136         void interceptNewConnection(void (*callback) (CAVERNnet_tcpReflectorClient_c *newClient, void* userData), void *userData);
00137 
00138     //Functions added for performance monitoring interface    
00139 
00151     void showStats(char* streamInfo, char* comment);
00152     
00169     int logStats(char* streamInfo, char* comment, FILE* filePtr);
00170 
00187     int sendStats(char* streamInfo, char* comment);
00188 
00202     int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00203     
00207     void exitSendStats();
00208 
00209 private:
00210         CAVERNnet_tcpReflectorClient_c **clients;
00211         CAVERNnet_tcpServer_c *server;
00212         unsigned short incomingPort;
00213     char* perfDaemonIP;   //IP of the perfDaemon - used for initsendstats
00214     int perfDaemonPort;   //PerfDaemon Port
00215     int perfDaemonStatus; //Status that indicates if the perfDaemon is running
00216         int (*interceptCallback) (CAVERNnet_tcpReflectorClient_c *newClient, char** buffer, int* bufsize, void *userData);
00217         void *interceptUserData;
00218 
00219         void (*interceptNewConnectionCallback) (CAVERNnet_tcpReflectorClient_c *newClient, void *userData);
00220         void *interceptNewConnectionUserData;
00221 
00222 
00223         // Distribute the data to all connected clients except the one indicated in
00224         // clientToIgnore. Specify -1 if want to send to all.
00225         int distributeDataExceptTo(int clientToIgnore, char* buf, int incomingSize);
00226 
00227         // Remove a client from the client array.
00228         void removeClient(int clientNum);
00229 
00230         // Close all client sockets and remove them. Used by destructor.
00231         // Also closes down and deallocates the server.
00232         void closeDownSockets();
00233 
00234         // Add a client to the client pool
00235         int addNewClient(CAVERNnet_tcpReflectorClient_c* newClient);
00236 
00237         int maxNumClients;
00238 };
00239 
00246 class CAVERNnet_tcpReflectorClient_c 
00247 {
00248 private:
00249         CAVERNnet_tcpClient_c *client;
00250         int timeOut;
00251         int connectionAlive;
00252 
00253 public:
00254 
00256 
00257         static const int OK/* = 1*/;
00258 
00260         static const int FAILED/* = 2*/;
00261 
00263         static const int MEM_ALLOC_ERR/* = 3*/;
00264 
00266         static const int NON_BLOCKING_HAS_NO_DATA/* = 7*/;
00267 
00269         static const int CONNECTION_TERMINATED/* = 8*/;
00270 
00272         static const int NOT_READY/* = 9*/;
00273 
00275         static const int READY_TO_READ/* = 10*/;
00276 
00278         static const int READY_TO_WRITE/* = 11*/;
00279 
00281         static const int READY_TO_READ_AND_WRITE/* = 12*/;
00282 
00283         static const int BLOCKING/* = CAVERNnet_tcpClient_c::BLOCKING*/;
00284         static const int NON_BLOCKING/* = CAVERNnet_tcpClient_c::NON_BLOCKING*/;
00285 
00286         static const int NO_TIME_OUT/* = CAVERNnet_tcpClient_c::NO_TIME_OUT*/;
00287 
00289 
00290         CAVERNnet_tcpReflectorClient_c();
00291 
00293         CAVERNnet_tcpReflectorClient_c(CAVERNnet_tcpClient_c *);
00294 
00295         ~CAVERNnet_tcpReflectorClient_c();
00296 
00305         int read(char** ret, int* nbytes, int blockingType);
00306 
00312         int write(char *outgoingData, int* nbytes);
00313 
00318         int isReadyToRead();
00319 
00324         int isReadyToWrite();
00325 
00332         int isReady();
00333 
00335 
00336 
00340         unsigned int getRemoteIP();
00341 
00346         void getRemoteIP(char* name);
00347 
00349         unsigned int getSelfIP();
00350 
00352         void getSelfIP(char *name);
00353 
00355         int  getSelfPort();
00356 
00358         int  getRemotePort();
00360 
00362         void showStatus(int status, int nbytes);
00363 
00365         void close();
00366 
00372         int connectToServer(char *ip, int port=CAVERNnet_tcpReflector_c::DEFAULT_PORT);
00373 
00382         void setTimeOut(int timeout=CAVERNnet_tcpReflectorClient_c::NO_TIME_OUT);
00383 
00384     //Functions added for performance monitoring interface
00385   
00398     void showStats(char* streamInfo, char* comment);
00399     
00416     int logStats(char* streamInfo, char* comment, FILE* filePtr);
00417 
00434     int sendStats(char* streamInfo, char* comment);
00435 
00449     int initSendStats(char* monitorClientIP, int port = PERF_DAEMON_DEFAULT_PORT);
00450     
00455     void exitSendStats();
00456 };
00457 
00458 #endif

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