Geant4 10.7.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//
28// Satoshi TANAKA, Wed Jul 3 14:13:52 JST 1996
29////////////////////////////////
30///// G4FRClientServer.h /////
31////////////////////////////////
32
33//=================//
34#if defined (G4VIS_BUILD_DAWN_DRIVER) || defined (G4VIS_USE_DAWN)
35//=================//
36
37
38#if !defined G4FR_CLIENT_SERVER_H
39#define G4FR_CLIENT_SERVER_H
40
41#include<sys/types.h>
42#include<sys/socket.h>
43#include<netinet/in.h>
44#include<arpa/inet.h>
45#include<netdb.h>
46#include<sys/un.h>
47#include<unistd.h>
48#include<stdio.h>
49#include<stdlib.h>
50#include<string.h>
51#include"G4ios.hh"
52
53
54//----- constants
55const char FR_ENV_SERVER_HOST_NAME[] = "G4DAWN_HOST_NAME" ;
56const char FR_ENV_NAMED_PIPE_CONNECTION[] = "G4DAWN_NAMED_PIPE" ;
57
58 //-----------------------------------//
59 //----- class G4FRClientServer -----//
60 //-----------------------------------//
61
62class G4FRClientServer {
63 public:
64 enum { SEND_BUFMAX = 1024 , RECV_BUFMAX = 1024 };
65 enum { SUN_PATH_MAX = 16 };
66
67 protected:
68 const char TERMINATOR ;
69 const char END_OF_LINE;
70 char SUN_PATH[ SUN_PATH_MAX ];
71 int PORT_NUMBER ;
72 int fSocketFd ;
73
74 char fReceivedMessage [ RECV_BUFMAX ];
75 char fSendingMessage [ SEND_BUFMAX ];
76
77 protected:
78
79 void Err( const char* message ) { perror(message) ;}
80 void SetSendingMessage( const char* message )
81 { strcpy( fSendingMessage, message );}
82 void Send() ; // send command in fSendingMessage
83
84 public:
85 //----- Server
86 int AcceptUnix(){ return 0;} // made unfunctioned
87 int AcceptINET(){ return 0 ;} // made unfunctioned
88
89 //----- Client
90 int ConnectUnix();
91 int ConnectINET();
92
93 //----- Common to server and client
94
95 //---------- (1)
96 G4FRClientServer ( char terminator = '.' ,
97 char end_line = '\n' ) ;
98 virtual ~G4FRClientServer () {;}
99 void SetSunPath( const char* sun_path )
100 { strcpy ( SUN_PATH, sun_path ); }
101 void SetPortNumber( int port_num )
102 { PORT_NUMBER = port_num ; }
103 void IncrementPortNumber( int incr = 1 )
104 { PORT_NUMBER += incr ; }
105 const char* GetSendingMessage() const
106 { return fSendingMessage ;}
107 int GetSendingMessageLength() const
108 { return strlen(fSendingMessage) ;}
109 void SetReceivedMessage( const char* message )
110 { strcpy( fReceivedMessage, message );}
111 const char* GetReceivedMessage() const
112 { return fReceivedMessage ;}
113 int GetReceivedMessageLength() const
114 { return strlen(fReceivedMessage) ;}
115 int GetSofd() const { return fSocketFd ; }
116 int GetPortNumber () const { return PORT_NUMBER ; }
117 void ClearReceivedMessage ()
118 { memset(fReceivedMessage, '\0', RECV_BUFMAX) ; }
119
120 int IsTerminator(char ch ) { return ( ch == TERMINATOR ); }
121 char GetTerminator() const { return TERMINATOR ; }
122 int IsEndOfLine (char ch ) { return ( ch == END_OF_LINE ); }
123 char GetEndOfLine() const { return END_OF_LINE ; }
124 void DisConnect();
125 void Clear();
126 void WaitSendBack( const char* command_string ) ;
127
128 //---------- (2) send and receive
129 virtual void Send ( const char* message ) ;
130 virtual void SendLine ( const char* message ) ;
131 // Add END_OF_LINE if the message does not
132 // Terminate with it. And then send the message.
133 virtual void Receive() ;
134 virtual void ReceiveLine() ;
135
136}; // G4FRClientServer
137
138
139#endif
140#endif //G4VIS_BUILD_DAWN_DRIVER
141
void Clear(Node *)