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