G4FRClientServer.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // Satoshi TANAKA, Wed Jul  3 14:13:52 JST 1996
00033 
00034 //=================//
00035 #if defined (G4VIS_BUILD_DAWN_DRIVER) || defined (G4VIS_USE_DAWN)
00036 //=================//
00037 
00038 
00039 #if !defined G4FR_CLIENT_SERVER_H
00040 #define G4FR_CLIENT_SERVER_H
00041 
00042 #include<sys/types.h>
00043 #include<sys/socket.h>
00044 #include<netinet/in.h>
00045 #include<arpa/inet.h>
00046 #include<netdb.h>
00047 #include<sys/un.h>
00048 #include<unistd.h>
00049 #include<stdio.h>
00050 #include<stdlib.h>
00051 #include<string.h>
00052 #include"G4ios.hh"
00053 
00054 
00055 //----- constants
00056 const  char     FR_ENV_SERVER_HOST_NAME[]       = "G4DAWN_HOST_NAME"  ;
00057 const  char     FR_ENV_NAMED_PIPE_CONNECTION[]  = "G4DAWN_NAMED_PIPE" ;
00058 
00059         //-----------------------------------//
00060         //-----  class G4FRClientServer -----//
00061         //-----------------------------------//
00062 
00063 class G4FRClientServer { 
00064  public:
00065         enum { SEND_BUFMAX = 1024 , RECV_BUFMAX = 1024 };
00066         enum { SUN_PATH_MAX = 16 };
00067 
00068  protected:     
00069         const char              TERMINATOR ;
00070         const char              END_OF_LINE;
00071         char                    SUN_PATH[ SUN_PATH_MAX ];
00072         int                     PORT_NUMBER ;
00073         int                     fSocketFd ;
00074 
00075         char            fReceivedMessage [ RECV_BUFMAX ];
00076         char            fSendingMessage  [ SEND_BUFMAX ];
00077 
00078  protected:
00079 
00080         void            Err( const char* message ) { perror(message) ;}
00081         void            SetSendingMessage( const char* message ) 
00082                                 { strcpy( fSendingMessage, message );}
00083         void            Send() ; // send command in fSendingMessage
00084 
00085  public:        
00086                 //----- Server
00087         int             AcceptUnix(){ return 0;}  // made unfunctioned  
00088         int             AcceptINET(){ return 0 ;}  // made unfunctioned  
00089 
00090                 //----- Client
00091         int             ConnectUnix(); 
00092         int             ConnectINET(); 
00093 
00094                 //----- Common to server and client
00095 
00096                 //---------- (1)
00097         G4FRClientServer (      char terminator = '.'           ,
00098                                 char end_line = '\n'              ) ;  
00099         virtual ~G4FRClientServer () {;}
00100         void            SetSunPath( const char* sun_path ) 
00101                         { strcpy     ( SUN_PATH, sun_path ); }
00102         void            SetPortNumber( int port_num ) 
00103                         { PORT_NUMBER = port_num ; }
00104         void            IncrementPortNumber( int incr = 1 ) 
00105                         { PORT_NUMBER += incr ; }
00106         const char*     GetSendingMessage() const
00107                                 { return  fSendingMessage            ;}
00108         int             GetSendingMessageLength() const
00109                                 { return  strlen(fSendingMessage)    ;}
00110         void            SetReceivedMessage( const char* message ) 
00111                                 { strcpy( fReceivedMessage, message );}
00112         const char*     GetReceivedMessage() const
00113                                 { return fReceivedMessage            ;}
00114         int             GetReceivedMessageLength() const    
00115                                 { return strlen(fReceivedMessage)    ;}
00116         int             GetSofd() const { return fSocketFd ; }
00117         int             GetPortNumber () const { return PORT_NUMBER ; }
00118         void            ClearReceivedMessage () 
00119                         { memset(fReceivedMessage, '\0', RECV_BUFMAX) ; }
00120 
00121         int             IsTerminator(char ch ) { return ( ch == TERMINATOR ); }
00122         char            GetTerminator()  const  { return TERMINATOR ; }
00123         int             IsEndOfLine (char ch ) { return ( ch == END_OF_LINE ); }
00124         char            GetEndOfLine() const { return END_OF_LINE ; }
00125         void            DisConnect();
00126         void            Clear();
00127         void            WaitSendBack( const char* command_string ) ;
00128 
00129                 //---------- (2) send and receive
00130         virtual void    Send     ( const char* message ) ; 
00131         virtual void    SendLine ( const char* message ) ; 
00132                                 // Add END_OF_LINE if the message does not
00133                                 // Terminate with it. And then send the message.
00134         virtual void    Receive() ;
00135         virtual void    ReceiveLine() ;
00136 
00137 }; // G4FRClientServer
00138 
00139 
00140 #endif
00141 #endif //G4VIS_BUILD_DAWN_DRIVER
00142 

Generated on Mon May 27 17:48:17 2013 for Geant4 by  doxygen 1.4.7