Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# G4UIGainServer.hh

Go to the documentation of this file.

    00001 //
    00002 // ********************************************************************
    00003 // * License and Disclaimer                                           *
    00004 // *                                                                  *
    00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
    00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
    00007 // * conditions of the Geant4 Software License,  included in the file *
    00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
    00009 // * include a list of copyright holders.                             *
    00010 // *                                                                  *
    00011 // * Neither the authors of this software system, nor their employing *
    00012 // * institutes,nor the agencies providing financial support for this *
    00013 // * work  make  any representation or  warranty, express or implied, *
    00014 // * regarding  this  software system or assume any liability for its *
    00015 // * use.  Please see the license in the file  LICENSE  and URL above *
    00016 // * for the full disclaimer and the limitation of liability.         *
    00017 // *                                                                  *
    00018 // * This  code  implementation is the result of  the  scientific and *
    00019 // * technical work of the GEANT4 collaboration.                      *
    00020 // * By using,  copying,  modifying or  distributing the software (or *
    00021 // * any work based  on the software)  you  agree  to acknowledge its *
    00022 // * use  in  resulting  scientific  publications,  and indicate your *
    00023 // * acceptance of all terms of the Geant4 Software license.          *
    00024 // ********************************************************************
    00025 //
    00026 //
    00027 // $Id: G4UIGainServer.hh,v 1.5 2006/06/29 19:09:21 gunter Exp $
    00028 // $Name: geant4-08-01-patch-01 $
    00029 //
    00030
    00031
    00032 #ifndef G4UIGainServer_h
    00033 #define G4UIGainServer_h 1
    00034
    00035 #ifndef WIN32
    00036
    00037 #include <stdio.h>
    00038 #include <sys/types.h>
    00039 #include <sys/socket.h>
    00040 //#include <sys/un.h>
    00041 #include <netinet/in.h>
    00042 #include <unistd.h>
    00043
    00044 #include <iostream>
    00045 #include <fstream>
    00046 #include "globals.hh"
    00047 #include "G4UImanager.hh"
    00048 #include "G4VBasicShell.hh"
    00049
    00050 #define SOCK_NAME "/tmp/socket"
    00051 #define DEFAULT_PORT 40000;
    00052
    00053 enum UImode { terminal_mode , java_mode, tcl_mode };
    00054 enum ChangeOfTree  { notChanged=0, added, deleted, addedAndDeleted };
    00055
    00056 // class description:
    00057 //
    00058 // This class is similar to G4UIGAG.
    00059 // While G4UIGAG provides direct connection to GAG via pipe,
    00060 // G4UIGainServer provides socket connection to remote Gain client.
    00061 // Gain = Geant4 adaptive interface for network
    00062 // Its usage is same as G4UIGAG, except that Geant4 application waits
    00063 // a connection from a Gain client.
    00064
    00065 class G4UIGainServer : public  G4VBasicShell {
    00066 private:
    00067   G4String prefix;
    00068   G4String promptCharacter;
    00069   G4UImanager* UI;
    00070   UImode uiMode;
    00071   G4String JVersion;
    00072   G4String TVersion;
    00073
    00074   // shell
    00075   //  G4VUIshell* shell;
    00076
    00077   // program states
    00078   G4bool iExit;
    00079   G4bool iCont;
    00080
    00081   // need for socket
    00082   int socketD[3];
    00083   int port;
    00084   struct sockaddr_in saddr;
    00085   struct sockaddr_in caddr;
    00086   int len;
    00087   int ret;
    00088   char buf[1024];
    00089
    00090   // --- the following are used by Notify*Update() and *Updated()
    00091   void GetNewTreeStructure( G4UIcommandTree*,int recursiveLevel);
    00092   void GetNewTreeValues( G4UIcommandTree*,int recursiveLevel);
    00093
    00094   std::vector<G4String> previousTreeCommands;
    00095   std::vector<G4String> newTreeCommands;
    00096   std::vector<G4String> previousTreeParams;
    00097   std::vector<G4String> newTreeParams;
    00098   std::vector<G4UIcommand*> previousTreePCP;
    00099   std::vector<G4UIcommand*> newTreePCP;
    00100
    00101 public:
    00102   // These methods are implementation of corresponding virtual methods
    00103   // of G4UIsession class.
    00104
    00105   // A GainServer session  "gainSession" is instantiated.
    00106   // G4cout stream is redirected by default to the constructed instance.
    00107   // Usage:  G4UIsession * gainSession = new G4UIGainServer();
    00108   // "gainSession" is started.
    00109   // Usage: gainSession->SessionStart();
    00110   // "gainSession"  is deleted.
    00111   // Usage: delete gainSession;
    00112   //
    00113
    00114
    00115    G4UIsession* SessionStart();
    00116    void PauseSessionStart(G4String msg);
    00117    G4int ReceiveG4cout(G4String coutString);
    00118    G4int ReceiveG4cerr(G4String cerrString);
    00119
    00120
    00121
    00122 public:
    00123   //  G4UIGainServer(G4VUIshell* aShell=0);
    00124    G4UIGainServer();
    00125   //G4UIGainServer(void){}
    00126     ~G4UIGainServer();
    00127   //~G4UIGainServer(void){}
    00128
    00129   //  void SetPrompt(const G4String& prompt);
    00130   void SessionTerminate();
    00131   void Prompt(G4String);
    00132   G4String GetCommand();
    00133
    00134 private:
    00135   void ExecuteCommand(G4String aCommand);
    00136   G4bool GetHelpChoice(G4int& aInt);
    00137   void ExitHelp();
    00138   bool SetUPServer();
    00139   void WaitingConnection();
    00140   void CloseConnection();
    00141
    00142   void ChangeDirectory(G4String);
    00143   void ListDirectory(G4String);
    00144   void TerminalHelp(G4String);
    00145   G4String ModifyPrefix(G4String);
    00146   G4UIcommandTree * FindDirPath(G4String);
    00147   void ShowCurrent(G4String);
    00148   G4String GetFullPath(G4String);
    00149
    00150   void SendCommandProperties(G4UIcommandTree *);
    00151   void SendParameterProperties(G4UIcommandTree *);
    00152   void SendAParamProperty(G4UIcommand *);
    00153   void SendATclParamProperty(G4UIcommand *);
    00154   void CodeGenJavaTree(G4UIcommandTree *,int recursiveLevel);
    00155   void CodeGenJavaParams(G4UIcommandTree *,int recursiveLevel);
    00156   void CodeGenTclTree(G4UIcommandTree *, int recursiveLevel);
    00157   void CodeGenTclParams(G4UIcommandTree *, int recursiveLevel);
    00158   void SendDisableList(G4UIcommandTree *, int recursiveLevel);
    00159
    00160   void NotifyStateChange(void);
    00161   void NotifyCommandUpdate(void);
    00162   void NotifyParameterUpdate(G4UIcommand *);
    00163
    00164   int CommandUpdated(void);
    00165   void UpdateState(void);
    00166   void UpdateParamVal(void);  // if param is updated,
    00167                              // call NotifyParameterUpdate()
    00168
    00169
    00170 };
    00171
    00172 #endif
    00173
    00174 #endif
    00175
    00176