Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4UIGainServer Class Reference

#include <G4UIGainServer.hh>

Inheritance diagram for G4UIGainServer:
Collaboration diagram for G4UIGainServer:

Public Member Functions

G4UIsessionSessionStart ()
 
virtual void PauseSessionStart (const G4String &msg)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
 G4UIGainServer ()
 
 ~G4UIGainServer ()
 
void SessionTerminate ()
 
void Prompt (G4String)
 
G4String GetCommand ()
 
- Public Member Functions inherited from G4VBasicShell
 G4VBasicShell ()
 
virtual ~G4VBasicShell ()
 
- Public Member Functions inherited from G4UIsession
 G4UIsession ()
 
 G4UIsession (G4int iBatch)
 
virtual ~G4UIsession ()
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()
 
virtual ~G4coutDestination ()
 

Additional Inherited Members

- Static Public Member Functions inherited from G4UIsession
static G4int InSession ()
 
- Protected Member Functions inherited from G4VBasicShell
G4String ModifyToFullPathCommand (const char *aCommandLine) const
 
G4String GetCurrentWorkingDirectory () const
 
G4bool ChangeDirectory (const char *newDir)
 
G4UIcommandTreeFindDirectory (const char *dirName) const
 
G4UIcommandFindCommand (const char *commandName) const
 
G4String Complete (const G4String &)
 
G4String FindMatchingPath (G4UIcommandTree *, const G4String &)
 
void ApplyShellCommand (const G4String &, G4bool &, G4bool &)
 
void ShowCurrent (const G4String &) const
 
void ChangeDirectoryCommand (const G4String &)
 
void ListDirectory (const G4String &) const
 
void TerminalHelp (const G4String &)
 
- Protected Attributes inherited from G4UIsession
G4int ifBatch
 
- Static Protected Attributes inherited from G4UIsession
static G4int inSession = 0
 
- Static Protected Attributes inherited from G4coutDestination
static G4coutDestinationmasterG4coutDestination = 0
 

Detailed Description

Definition at line 64 of file G4UIGainServer.hh.

Constructor & Destructor Documentation

G4UIGainServer::G4UIGainServer ( )

Definition at line 43 of file G4UIGainServer.cc.

45 {
46  TVersion ="T1.0a"; JVersion="J1.0a";
47  prefix = "/";
48 
49  port = DEFAULT_PORT;
50  while(SetUPServer() == false){
51  G4cout<<"can't get the port no. "<<port<<" Now, try to get the next port "<<port+1<<G4endl;
52  port++;
53  }
54 
55 
57  UI-> SetSession(this);
58  UI-> SetCoutDestination(this);
59 
61  promptCharacter = statM->GetStateString(statM->GetCurrentState());
62  uiMode = terminal_mode;
63 
64  iExit= FALSE;
65  iCont= FALSE;
66 
67  G4UIcommandTree* tree = UI->GetTree();
68  GetNewTreeStructure(tree,0);
69  GetNewTreeValues(tree,0);
70  previousTreeCommands = newTreeCommands;
71  previousTreeParams = newTreeParams;
72  previousTreePCP = newTreePCP;
73 
74 }
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
#define FALSE
Definition: globals.hh:52
G4ApplicationState GetCurrentState() const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
#define DEFAULT_PORT
#define G4endl
Definition: G4ios.hh:61
G4String GetStateString(G4ApplicationState aState) const

Here is the call graph for this function:

G4UIGainServer::~G4UIGainServer ( )

Definition at line 77 of file G4UIGainServer.cc.

79 {
80 
82  UI-> SetSession(NULL);
83  UI-> SetCoutDestination(NULL);
84  }
85 
87  UI->SetSession(NULL);
88  UI->SetCoutDestination(NULL);
89  }
90 }
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:619

Here is the call graph for this function:

Member Function Documentation

G4String G4UIGainServer::GetCommand ( )

Definition at line 183 of file G4UIGainServer.cc.

185 {
186  G4String newCommand;
187  G4String nullString;
188 
189  while( 1 )
190  {
191  G4UIcommandTree* tree = UI->GetTree();
192  if ( uiMode != terminal_mode ){
193  G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl;
194  }
195  if ( uiMode != java_mode ){
196  G4cout << promptCharacter << "> " << G4endl;
197  }else{
198  G4cout << "@@Ready" << G4endl;
199  }
200 
201 
204  read(socketD[1],buf,1024);
205  newCommand=buf;
206  //DEBUG cout<<"->"<<newCommand<<"<-"<<newCommand.length()<<G4endl;
207  //newCommand.readLine( G4cin, FALSE );
210 
211 
212 
213  if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
214 
215  newCommand = newCommand.strip(G4String::leading);
216  if( newCommand.length() < 1) { break; }
217 
218  while( newCommand(newCommand.length()-1) == '_' )
219  {
220  G4String newLine;
221  newCommand.remove(newCommand.length()-1);
222  newLine.readLine( G4cin );
223  if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
224  newCommand.append(newLine);
225  }
226 
227  G4String nC = newCommand.strip(G4String::leading);
228  if( nC.length() < 1) { break; }
229 
230  // -------------------- nC.toUpper();
231  if( nC == "@@GainmodeJAVA" ) {
232  uiMode = java_mode;
233  G4cout << G4endl << "@@Version " << JVersion << G4endl;
234  SendCommandProperties(tree);
235  NotifyStateChange();
236  }
237  else if( nC == "@@GainmodeTcl" ) {
238  uiMode = tcl_mode;
239  G4cout << G4endl << "@@Version " << TVersion << G4endl;
240  SendCommandProperties(tree);
241  NotifyStateChange();
242  }
243  else if( nC(0) == '#' )
244  { G4cout << nC << G4endl; }
245 
246  else if( nC == "ls" || nC(0,3) == "ls " )
247  { ListDirectory( nC ); }
248  else if( nC == "pwd" )
249  { G4cout << "Current Working Directory : " << prefix << G4endl; }
250  else if( nC(0,2) == "cd" || nC(0,3) == "cd " )
251  { ChangeDirectory( nC ); }
252  else if( nC == "help" || nC(0,5) == "help ")
253  { TerminalHelp( nC ); }
254  else if( nC(0) == '?' )
255  { ShowCurrent( nC ); }
256  else if( nC(0,4) == "hist" || nC == "history")
257  {
258  G4int nh = UI->GetNumberOfHistory();
259  for(int i=0;i<nh;i++)
260  { G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl; }
261  }
262  else if( nC(0) == '!' )
263  {
264  G4String ss = nC(1,nC.length()-1);
265  G4int vl;
266  const char* tt = ss;
267  std::istringstream is((char*)tt);
268  is >> vl;
269  G4int nh = UI->GetNumberOfHistory();
270  if(vl>=0 && vl<nh)
271  {
272  newCommand = UI->GetPreviousCommand(vl);
273  G4cout << newCommand << G4endl;
274  break;
275  }
276  else
277  { G4cerr << "history " << vl << " is not found." << G4endl; }
278  }
279  else if( nC(0,4) == "exit" )
280  {
281  if( iCont )
282  {
283  if ( uiMode == terminal_mode){
284  G4cerr << "You are now processing RUN." << G4endl;
285  G4cerr << "Please abrot it using \"/run/abort\" command first" << G4endl;
286  G4cerr << " and use \"continue\" command until the application" << G4endl;
287  G4cerr << " becomes to Idle." << G4endl;
288  }else{
289  G4cout << "@@ErrResult \"You are now processing RUN.\"" << G4endl;
290  }
291  }
292  else
293  {
294  close(socketD[1]);
295  close(socketD[2]);
296  iExit = false;
297  newCommand = nullString;
298  break;
299  }
300  }
301  else if( nC == "cont" || nC == "continue" )
302  {
303  iCont = false;
304  newCommand = nullString;
305  break;
306  }
307  else
308  { break; }
309  }
310  return GetFullPath(newCommand);
311 }
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:229
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:231
G4String & remove(str_size)
G4String strip(G4int strip_Type=trailing, char c=' ')
std::istream & readLine(std::istream &, G4bool skipWhite=true)
int G4int
Definition: G4Types.hh:78
#define G4cin
Definition: G4ios.hh:60
G4GLOB_DLL std::ostream G4cout
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
G4String & append(const G4String &)
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

Here is the caller graph for this function:

void G4UIGainServer::PauseSessionStart ( const G4String msg)
virtual

Implements G4VBasicShell.

Definition at line 113 of file G4UIGainServer.cc.

115 {
116  promptCharacter = msg;
117  G4cout<<"@@PROMPT \""<<promptCharacter<<"\""<<G4endl;
118 
119  iCont= TRUE;
120 
121  G4String newCommand= GetCommand();
122  while(iCont){
123  ExecuteCommand(newCommand);
124  newCommand= GetCommand();
125  strcpy(buf,"nowIdle");
126  write(socketD[1],buf,strlen(buf));
127  }
128 }
G4GLOB_DLL std::ostream G4cout
#define TRUE
Definition: globals.hh:55
G4String GetCommand()
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

void G4UIGainServer::Prompt ( G4String  )
G4int G4UIGainServer::ReceiveG4cerr ( const G4String cerrString)
virtual

Reimplemented from G4UIsession.

Definition at line 327 of file G4UIGainServer.cc.

329 {
330  if(socketD[2]>0){
331  write(socketD[2],cerrString,cerrString.length());
332  }
333  return 0;
334 
335  //std::cerr << cerrString << std::flush;
336  //return 0;
337 }
G4int G4UIGainServer::ReceiveG4cout ( const G4String coutString)
virtual

Reimplemented from G4UIsession.

Definition at line 314 of file G4UIGainServer.cc.

316 {
317  if(socketD[1]>0){
318  write(socketD[1],coutString,coutString.length());
319  }
320  return 0;
321 
322  //std::cout << coutString << std::flush;
323  //return 0;
324 }
G4UIsession * G4UIGainServer::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 94 of file G4UIGainServer.cc.

96 {
97  G4String newCommand;
98 
100  promptCharacter = statM->GetStateString(statM->GetCurrentState());
101 
102  iExit= TRUE;
103 
104  WaitingConnection();
105  while(iExit){
106  newCommand= GetCommand();
107  ExecuteCommand(newCommand);
108  }
109  return NULL;
110 }
static G4StateManager * GetStateManager()
#define TRUE
Definition: globals.hh:55
G4ApplicationState GetCurrentState() const
G4String GetCommand()
G4String GetStateString(G4ApplicationState aState) const

Here is the call graph for this function:

void G4UIGainServer::SessionTerminate ( )

Definition at line 451 of file G4UIGainServer.cc.

451  {
453  G4cout<<"***** Terminal session end *****"<<G4endl;
454 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61

The documentation for this class was generated from the following files: