[834] | 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,v 1.8 2006/06/29 21:25:51 gunter Exp $ |
---|
[850] | 28 | // GEANT4 tag $Name: HEAD $ |
---|
[834] | 29 | // |
---|
| 30 | // G4FRClient.cc |
---|
| 31 | // Yasuhide Sawada & Satoshi Tanaka |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | //=================// |
---|
| 35 | #ifndef WIN32 |
---|
| 36 | //=================// |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | //=================// |
---|
| 40 | #ifdef G4VIS_BUILD_VRML_DRIVER |
---|
| 41 | //=================// |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | #include <stdio.h> |
---|
| 45 | #include "G4FRClient.hh" |
---|
| 46 | #include "FRClient.h" |
---|
| 47 | |
---|
| 48 | G4FRClient::G4FRClient() |
---|
| 49 | { |
---|
| 50 | fFRClient = NULL; |
---|
| 51 | fPort = -1; |
---|
| 52 | connected = false; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | G4FRClient::~G4FRClient() |
---|
| 56 | { |
---|
| 57 | if (connected) |
---|
| 58 | this->close(); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | G4bool G4FRClient::connect(const char *hostname, G4int port) |
---|
| 62 | { |
---|
| 63 | if (connected) |
---|
| 64 | return false; |
---|
| 65 | |
---|
| 66 | delete fFRClient; |
---|
| 67 | fFRClient = new FRClient(); |
---|
| 68 | |
---|
| 69 | fPort = port; |
---|
| 70 | connected = (fFRClient->connect(hostname, port) < 0) ? false : true ; |
---|
| 71 | |
---|
| 72 | return connected; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void G4FRClient::close() |
---|
| 76 | { |
---|
| 77 | delete fFRClient; |
---|
| 78 | fFRClient = NULL; |
---|
| 79 | connected = false; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | G4int G4FRClient::getPort() const |
---|
| 83 | { |
---|
| 84 | return fPort; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | G4FRClient& G4FRClient::operator << (G4int val) |
---|
| 88 | { |
---|
| 89 | char buf[64]; |
---|
| 90 | sprintf(buf, "%d", val); |
---|
| 91 | fFRClient->send(buf); |
---|
| 92 | return *this; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | G4FRClient& G4FRClient::operator << (G4double val) |
---|
| 96 | { |
---|
| 97 | char buf[64]; |
---|
| 98 | sprintf(buf, "%g", val); |
---|
| 99 | fFRClient->send(buf); |
---|
| 100 | return *this; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | G4FRClient& G4FRClient::operator << (const char *pval) |
---|
| 104 | { |
---|
| 105 | fFRClient->send(pval); |
---|
| 106 | return *this; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | G4FRClient& G4FRClient::operator << (G4FRClient& (*func)(G4FRClient&)) |
---|
| 110 | { |
---|
| 111 | return func(*this); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | //////////////////////////////////////// |
---|
| 115 | ////manipulator |
---|
| 116 | //G4FRClient& endl(G4FRClient& c) |
---|
| 117 | //{ |
---|
| 118 | // return c << "\n"; |
---|
| 119 | //} |
---|
| 120 | /////////////////////////////////////// |
---|
| 121 | |
---|
| 122 | #endif //G4VIS_BUILD_VRML_DRIVER |
---|
| 123 | |
---|
| 124 | #endif //WIN32 |
---|
| 125 | |
---|