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$
00028 //
00029 
00030 
00031 #ifndef G4UIGainServer_h
00032 #define G4UIGainServer_h 1
00033 
00034 #ifndef WIN32
00035 
00036 #include <stdio.h>
00037 #include <sys/types.h>
00038 #include <sys/socket.h>
00039 //#include <sys/un.h>
00040 #include <netinet/in.h>
00041 #include <unistd.h>
00042 
00043 #include <iostream>
00044 #include <fstream>
00045 #include "globals.hh"
00046 #include "G4UImanager.hh"
00047 #include "G4VBasicShell.hh"
00048 
00049 #define SOCK_NAME "/tmp/socket"
00050 #define DEFAULT_PORT 40000; 
00051 
00052 enum UImode { terminal_mode , java_mode, tcl_mode };
00053 enum ChangeOfTree  { notChanged=0, added, deleted, addedAndDeleted };
00054 
00055 // class description:
00056 //
00057 // This class is similar to G4UIGAG.
00058 // While G4UIGAG provides direct connection to GAG via pipe,
00059 // G4UIGainServer provides socket connection to remote Gain client.
00060 // Gain = Geant4 adaptive interface for network
00061 // Its usage is same as G4UIGAG, except that Geant4 application waits
00062 // a connection from a Gain client.
00063 
00064 class G4UIGainServer : public  G4VBasicShell {
00065 private:
00066   G4String prefix;
00067   G4String promptCharacter;
00068   G4UImanager* UI;
00069   UImode uiMode;
00070   G4String JVersion;
00071   G4String TVersion;
00072 
00073   // shell
00074   //  G4VUIshell* shell;
00075 
00076   // program states
00077   G4bool iExit;
00078   G4bool iCont;
00079 
00080   // need for socket
00081   int socketD[3];
00082   int port;
00083   struct sockaddr_in saddr;
00084   struct sockaddr_in caddr;
00085   int len;
00086   int ret;
00087   char buf[1024];
00088 
00089   // --- the following are used by Notify*Update() and *Updated()
00090   void GetNewTreeStructure( G4UIcommandTree*,int recursiveLevel);
00091   void GetNewTreeValues( G4UIcommandTree*,int recursiveLevel);
00092   
00093   std::vector<G4String> previousTreeCommands;
00094   std::vector<G4String> newTreeCommands;
00095   std::vector<G4String> previousTreeParams;
00096   std::vector<G4String> newTreeParams;
00097   std::vector<G4UIcommand*> previousTreePCP;
00098   std::vector<G4UIcommand*> newTreePCP;
00099 
00100 public:
00101   // These methods are implementation of corresponding virtual methods
00102   // of G4UIsession class.
00103 
00104   // A GainServer session  "gainSession" is instantiated.
00105   // G4cout stream is redirected by default to the constructed instance.
00106   // Usage:  G4UIsession * gainSession = new G4UIGainServer();
00107   // "gainSession" is started.
00108   // Usage: gainSession->SessionStart();
00109   // "gainSession"  is deleted.
00110   // Usage: delete gainSession;
00111   //
00112 
00113   G4UIsession* SessionStart();  
00114   virtual void PauseSessionStart(const G4String& msg);
00115   virtual G4int ReceiveG4cout(const G4String& coutString);
00116   virtual G4int ReceiveG4cerr(const G4String& cerrString);
00117 
00118 public:
00119   //  G4UIGainServer(G4VUIshell* aShell=0);
00120    G4UIGainServer();
00121   //G4UIGainServer(void){}
00122     ~G4UIGainServer();
00123   //~G4UIGainServer(void){}
00124 
00125   //  void SetPrompt(const G4String& prompt);
00126   void SessionTerminate();
00127   void Prompt(G4String);
00128   G4String GetCommand();
00129 
00130 private:
00131   virtual void ExecuteCommand(const G4String& aCommand);
00132   virtual G4bool GetHelpChoice(G4int& aInt);
00133   virtual void ExitHelp() const;
00134   bool SetUPServer();
00135   void WaitingConnection();
00136   void CloseConnection();
00137 
00138   void ChangeDirectory(G4String);
00139   void ListDirectory(G4String);
00140   void TerminalHelp(G4String);
00141   G4String ModifyPrefix(G4String);
00142   G4UIcommandTree * FindDirPath(G4String);
00143   void ShowCurrent(G4String);
00144   G4String GetFullPath(G4String);
00145 
00146   void SendCommandProperties(G4UIcommandTree *);
00147   void SendParameterProperties(G4UIcommandTree *);
00148   void SendAParamProperty(G4UIcommand *);
00149   void SendATclParamProperty(G4UIcommand *);
00150   void CodeGenJavaTree(G4UIcommandTree *,int recursiveLevel); 
00151   void CodeGenJavaParams(G4UIcommandTree *,int recursiveLevel); 
00152   void CodeGenTclTree(G4UIcommandTree *, int recursiveLevel); 
00153   void CodeGenTclParams(G4UIcommandTree *, int recursiveLevel); 
00154   void SendDisableList(G4UIcommandTree *, int recursiveLevel);
00155 
00156   void NotifyStateChange(void);
00157   void NotifyCommandUpdate(void);
00158   void NotifyParameterUpdate(G4UIcommand *);
00159 
00160   int CommandUpdated(void);
00161   void UpdateState(void);
00162   void UpdateParamVal(void);  // if param is updated,
00163                              // call NotifyParameterUpdate()
00164 
00165   
00166 };
00167 
00168 #endif
00169 
00170 #endif
00171 
00172 

Generated on Mon May 27 17:50:06 2013 for Geant4 by  doxygen 1.4.7