Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4FRClientServer.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id$
28//
29// Satoshi TANAKA, Wed Jul 3 14:13:52 JST 1996
30////////////////////////////////
31///// G4FRClientServer.h /////
32////////////////////////////////
33
34//=================//
35#if defined (G4VIS_BUILD_DAWN_DRIVER) || defined (G4VIS_USE_DAWN)
36//=================//
37
38
39#if !defined G4FR_CLIENT_SERVER_H
40#define G4FR_CLIENT_SERVER_H
41
42#include<sys/types.h>
43#include<sys/socket.h>
44#include<netinet/in.h>
45#include<arpa/inet.h>
46#include<netdb.h>
47#include<sys/un.h>
48#include<unistd.h>
49#include<stdio.h>
50#include<stdlib.h>
51#include<string.h>
52#include"G4ios.hh"
53
54
55//----- constants
56const char FR_ENV_SERVER_HOST_NAME[] = "G4DAWN_HOST_NAME" ;
57const char FR_ENV_NAMED_PIPE_CONNECTION[] = "G4DAWN_NAMED_PIPE" ;
58
59 //-----------------------------------//
60 //----- class G4FRClientServer -----//
61 //-----------------------------------//
62
63class G4FRClientServer {
64 public:
65 enum { SEND_BUFMAX = 1024 , RECV_BUFMAX = 1024 };
66 enum { SUN_PATH_MAX = 16 };
67
68 protected:
69 const char TERMINATOR ;
70 const char END_OF_LINE;
71 char SUN_PATH[ SUN_PATH_MAX ];
72 int PORT_NUMBER ;
73 int fSocketFd ;
74
75 char fReceivedMessage [ RECV_BUFMAX ];
76 char fSendingMessage [ SEND_BUFMAX ];
77
78 protected:
79
80 void Err( const char* message ) { perror(message) ;}
81 void SetSendingMessage( const char* message )
82 { strcpy( fSendingMessage, message );}
83 void Send() ; // send command in fSendingMessage
84
85 public:
86 //----- Server
87 int AcceptUnix(){ return 0;} // made unfunctioned
88 int AcceptINET(){ return 0 ;} // made unfunctioned
89
90 //----- Client
91 int ConnectUnix();
92 int ConnectINET();
93
94 //----- Common to server and client
95
96 //---------- (1)
97 G4FRClientServer ( char terminator = '.' ,
98 char end_line = '\n' ) ;
99 virtual ~G4FRClientServer () {;}
100 void SetSunPath( const char* sun_path )
101 { strcpy ( SUN_PATH, sun_path ); }
102 void SetPortNumber( int port_num )
103 { PORT_NUMBER = port_num ; }
104 void IncrementPortNumber( int incr = 1 )
105 { PORT_NUMBER += incr ; }
106 const char* GetSendingMessage() const
107 { return fSendingMessage ;}
108 int GetSendingMessageLength() const
109 { return strlen(fSendingMessage) ;}
110 void SetReceivedMessage( const char* message )
111 { strcpy( fReceivedMessage, message );}
112 const char* GetReceivedMessage() const
113 { return fReceivedMessage ;}
114 int GetReceivedMessageLength() const
115 { return strlen(fReceivedMessage) ;}
116 int GetSofd() const { return fSocketFd ; }
117 int GetPortNumber () const { return PORT_NUMBER ; }
118 void ClearReceivedMessage ()
119 { memset(fReceivedMessage, '\0', RECV_BUFMAX) ; }
120
121 int IsTerminator(char ch ) { return ( ch == TERMINATOR ); }
122 char GetTerminator() const { return TERMINATOR ; }
123 int IsEndOfLine (char ch ) { return ( ch == END_OF_LINE ); }
124 char GetEndOfLine() const { return END_OF_LINE ; }
125 void DisConnect();
126 void Clear();
127 void WaitSendBack( const char* command_string ) ;
128
129 //---------- (2) send and receive
130 virtual void Send ( const char* message ) ;
131 virtual void SendLine ( const char* message ) ;
132 // Add END_OF_LINE if the message does not
133 // Terminate with it. And then send the message.
134 virtual void Receive() ;
135 virtual void ReceiveLine() ;
136
137}; // G4FRClientServer
138
139
140#endif
141#endif //G4VIS_BUILD_DAWN_DRIVER
142
void Clear(Node *)