Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIGainServer.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: G4UIGainServer.hh 66892 2013-01-17 10:57:59Z gunter $
28 //
29 
30 
31 #ifndef G4UIGainServer_h
32 #define G4UIGainServer_h 1
33 
34 #ifndef WIN32
35 
36 #include <stdio.h>
37 #include <sys/types.h>
38 #include <sys/socket.h>
39 //#include <sys/un.h>
40 #include <netinet/in.h>
41 #include <unistd.h>
42 
43 #include <iostream>
44 #include <fstream>
45 #include "globals.hh"
46 #include "G4UImanager.hh"
47 #include "G4VBasicShell.hh"
48 
49 #define SOCK_NAME "/tmp/socket"
50 #define DEFAULT_PORT 40000;
51 
54 
55 // class description:
56 //
57 // This class is similar to G4UIGAG.
58 // While G4UIGAG provides direct connection to GAG via pipe,
59 // G4UIGainServer provides socket connection to remote Gain client.
60 // Gain = Geant4 adaptive interface for network
61 // Its usage is same as G4UIGAG, except that Geant4 application waits
62 // a connection from a Gain client.
63 
64 class G4UIGainServer : public G4VBasicShell {
65 private:
67  G4String promptCharacter;
68  G4UImanager* UI;
69  UImode uiMode;
70  G4String JVersion;
71  G4String TVersion;
72 
73  // shell
74  // G4VUIshell* shell;
75 
76  // program states
77  G4bool iExit;
78  G4bool iCont;
79 
80  // need for socket
81  int socketD[3];
82  int port;
83  struct sockaddr_in saddr;
84  struct sockaddr_in caddr;
85  int len;
86  int ret;
87  char buf[1024];
88 
89  // --- the following are used by Notify*Update() and *Updated()
90  void GetNewTreeStructure( G4UIcommandTree*,int recursiveLevel);
91  void GetNewTreeValues( G4UIcommandTree*,int recursiveLevel);
92 
93  std::vector<G4String> previousTreeCommands;
94  std::vector<G4String> newTreeCommands;
95  std::vector<G4String> previousTreeParams;
96  std::vector<G4String> newTreeParams;
97  std::vector<G4UIcommand*> previousTreePCP;
98  std::vector<G4UIcommand*> newTreePCP;
99 
100 public:
101  // These methods are implementation of corresponding virtual methods
102  // of G4UIsession class.
103 
104  // A GainServer session "gainSession" is instantiated.
105  // G4cout stream is redirected by default to the constructed instance.
106  // Usage: G4UIsession * gainSession = new G4UIGainServer();
107  // "gainSession" is started.
108  // Usage: gainSession->SessionStart();
109  // "gainSession" is deleted.
110  // Usage: delete gainSession;
111  //
112 
114  virtual void PauseSessionStart(const G4String& msg);
115  virtual G4int ReceiveG4cout(const G4String& coutString);
116  virtual G4int ReceiveG4cerr(const G4String& cerrString);
117 
118 public:
119  // G4UIGainServer(G4VUIshell* aShell=0);
120  G4UIGainServer();
121  //G4UIGainServer(void){}
122  ~G4UIGainServer();
123  //~G4UIGainServer(void){}
124 
125  // void SetPrompt(const G4String& prompt);
126  void SessionTerminate();
127  void Prompt(G4String);
129 
130 private:
131  virtual void ExecuteCommand(const G4String& aCommand);
132  virtual G4bool GetHelpChoice(G4int& aInt);
133  virtual void ExitHelp() const;
134  bool SetUPServer();
135  void WaitingConnection();
136  void CloseConnection();
137 
138  void ChangeDirectory(G4String);
139  void ListDirectory(G4String);
140  void TerminalHelp(G4String);
141  G4String ModifyPrefix(G4String);
142  G4UIcommandTree * FindDirPath(G4String);
143  void ShowCurrent(G4String);
144  G4String GetFullPath(G4String);
145 
146  void SendCommandProperties(G4UIcommandTree *);
147  void SendParameterProperties(G4UIcommandTree *);
148  void SendAParamProperty(G4UIcommand *);
149  void SendATclParamProperty(G4UIcommand *);
150  void CodeGenJavaTree(G4UIcommandTree *,int recursiveLevel);
151  void CodeGenJavaParams(G4UIcommandTree *,int recursiveLevel);
152  void CodeGenTclTree(G4UIcommandTree *, int recursiveLevel);
153  void CodeGenTclParams(G4UIcommandTree *, int recursiveLevel);
154  void SendDisableList(G4UIcommandTree *, int recursiveLevel);
155 
156  void NotifyStateChange(void);
157  void NotifyCommandUpdate(void);
158  void NotifyParameterUpdate(G4UIcommand *);
159 
160  int CommandUpdated(void);
161  void UpdateState(void);
162  void UpdateParamVal(void); // if param is updated,
163  // call NotifyParameterUpdate()
164 
165 
166 };
167 
168 #endif
169 
170 #endif
171 
172 
UImode
Definition: G4UIGAG.hh:44
int G4int
Definition: G4Types.hh:78
virtual void PauseSessionStart(const G4String &msg)
virtual G4int ReceiveG4cerr(const G4String &cerrString)
bool G4bool
Definition: G4Types.hh:79
virtual G4int ReceiveG4cout(const G4String &coutString)
G4String GetCommand()
const XML_Char int len
G4UIsession * SessionStart()
void Prompt(G4String)
ChangeOfTree
Definition: G4UIGAG.hh:45