Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4FRClient.cc
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: G4FRClient.cc 66373 2012-12-18 09:41:34Z gcosmo $
28 //
29 // G4FRClient.cc
30 // Yasuhide Sawada & Satoshi Tanaka
31 
32 
33 //=================//
34 #ifndef WIN32
35 //=================//
36 
37 
38 //=================//
39 #ifdef G4VIS_BUILD_VRML_DRIVER
40 //=================//
41 
42 
43 #include <stdio.h>
44 #include "G4FRClient.hh"
45 #include "FRClient.h"
46 
47 G4FRClient::G4FRClient()
48 {
49  fFRClient = NULL;
50  fPort = -1;
51  connected = false;
52 }
53 
54 G4FRClient::~G4FRClient()
55 {
56  if (connected)
57  this->close();
58 }
59 
60 G4bool G4FRClient::connect(const char *hostname, G4int port)
61 {
62  if (connected)
63  return false;
64 
65  delete fFRClient;
66  fFRClient = new FRClient();
67 
68  fPort = port;
69  connected = (fFRClient->connect(hostname, port) < 0) ? false : true ;
70 
71  return connected;
72 }
73 
74 void G4FRClient::close()
75 {
76  delete fFRClient;
77  fFRClient = NULL;
78  connected = false;
79 }
80 
81 G4int G4FRClient::getPort() const
82 {
83  return fPort;
84 }
85 
86 G4FRClient& G4FRClient::operator << (G4int val)
87 {
88  char buf[64];
89  sprintf(buf, "%d", val);
90  fFRClient->send(buf);
91  return *this;
92 }
93 
94 G4FRClient& G4FRClient::operator << (G4double val)
95 {
96  char buf[64];
97  sprintf(buf, "%g", val);
98  fFRClient->send(buf);
99  return *this;
100 }
101 
102 G4FRClient& G4FRClient::operator << (const char *pval)
103 {
104  fFRClient->send(pval);
105  return *this;
106 }
107 
108 G4FRClient& G4FRClient::operator << (G4FRClient& (*func)(G4FRClient&))
109 {
110  return func(*this);
111 }
112 
113 ////////////////////////////////////////
114 ////manipulator
115 //G4FRClient& endl(G4FRClient& c)
116 //{
117 // return c << "\n";
118 //}
119 ///////////////////////////////////////
120 
121 #endif //G4VIS_BUILD_VRML_DRIVER
122 
123 #endif //WIN32
124 
int G4int
Definition: G4Types.hh:78
bool G4bool
Definition: G4Types.hh:79
std::ostream & operator<<(std::ostream &ostr, const G4String &astr)
Definition: pyG4String.cc:40
double G4double
Definition: G4Types.hh:76