Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIGainServer Class Reference

#include <G4UIGainServer.hh>

+ Inheritance 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 ()
 
virtual G4UIsessionSessionStart ()=0
 
virtual void PauseSessionStart (const G4String &Prompt)=0
 
- Public Member Functions inherited from G4UIsession
 G4UIsession ()
 
 G4UIsession (G4int iBatch)
 
virtual ~G4UIsession ()
 
virtual G4UIsessionSessionStart ()
 
virtual void PauseSessionStart (const G4String &Prompt)
 
virtual G4int ReceiveG4cout (const G4String &coutString)
 
virtual G4int ReceiveG4cerr (const G4String &cerrString)
 
G4int GetLastReturnCode () const
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()=default
 
virtual ~G4coutDestination ()
 
void AddCoutTransformer (const Transformer &t)
 
void AddCoutTransformer (Transformer &&t)
 
void AddCerrTransformer (const Transformer &t)
 
void AddCerrTransformer (Transformer &&t)
 
virtual void ResetTransformers ()
 
virtual G4int ReceiveG4cout (const G4String &msg)
 
virtual G4int ReceiveG4cerr (const G4String &msg)
 
G4int ReceiveG4cout_ (const G4String &msg)
 
G4int ReceiveG4cerr_ (const G4String &msg)
 

Additional Inherited Members

- Public Types inherited from G4coutDestination
using Transformer = std::function< G4bool(G4String &)>
 
- 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 &)
 
virtual void ExecuteCommand (const G4String &)
 
virtual G4bool GetHelpChoice (G4int &)=0
 
virtual void ExitHelp () const =0
 
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 = 0
 
G4int lastRC = 0
 
- Protected Attributes inherited from G4coutDestination
std::vector< TransformertransformersCout
 
std::vector< TransformertransformersCerr
 
- Static Protected Attributes inherited from G4UIsession
static G4ICOMS_DLL G4int inSession = 0
 
- Static Protected Attributes inherited from G4coutDestination
static G4MTGLOB_DLL G4coutDestinationmasterG4coutDestination = nullptr
 

Detailed Description

Definition at line 63 of file G4UIGainServer.hh.

Constructor & Destructor Documentation

◆ G4UIGainServer()

G4UIGainServer::G4UIGainServer ( )

Definition at line 42 of file G4UIGainServer.cc.

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

◆ ~G4UIGainServer()

G4UIGainServer::~G4UIGainServer ( )

Definition at line 76 of file G4UIGainServer.cc.

78{
79
81 UI-> SetSession(NULL);
82 UI-> SetCoutDestination(NULL);
83 }
84
86 UI->SetSession(NULL);
87 UI->SetCoutDestination(NULL);
88 }
89}
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:699
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:183

Member Function Documentation

◆ GetCommand()

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

Referenced by PauseSessionStart(), and SessionStart().

◆ PauseSessionStart()

void G4UIGainServer::PauseSessionStart ( const G4String msg)
virtual

Implements G4VBasicShell.

Definition at line 112 of file G4UIGainServer.cc.

114{
115 promptCharacter = msg;
116 G4cout<<"@@PROMPT \""<<promptCharacter<<"\""<<G4endl;
117
118 iCont= TRUE;
119
120 G4String newCommand= GetCommand();
121 while(iCont){
122 ExecuteCommand(newCommand);
123 newCommand= GetCommand();
124 strcpy(buf,"nowIdle");
125 ssize_t rc = write(socketD[1],buf,strlen(buf));
126 if (rc < 0) {}
127 }
128}
#define TRUE
Definition: Globals.hh:27
G4String GetCommand()

◆ Prompt()

void G4UIGainServer::Prompt ( G4String  )

◆ ReceiveG4cerr()

G4int G4UIGainServer::ReceiveG4cerr ( const G4String cerrString)
virtual

Reimplemented from G4UIsession.

Definition at line 329 of file G4UIGainServer.cc.

331{
332 if(socketD[2]>0){
333 ssize_t rc = write(socketD[2],cerrString,cerrString.length());
334 if ( rc < 0 ) {}
335 }
336 return 0;
337
338 //std::cerr << cerrString << std::flush;
339 //return 0;
340}

◆ ReceiveG4cout()

G4int G4UIGainServer::ReceiveG4cout ( const G4String coutString)
virtual

Reimplemented from G4UIsession.

Definition at line 315 of file G4UIGainServer.cc.

317{
318 if(socketD[1]>0){
319 ssize_t rc = write(socketD[1],coutString,coutString.length());
320 if ( rc < 0 ){}
321 }
322 return 0;
323
324 //std::cout << coutString << std::flush;
325 //return 0;
326}

◆ SessionStart()

G4UIsession * G4UIGainServer::SessionStart ( )
virtual

Implements G4VBasicShell.

Definition at line 93 of file G4UIGainServer.cc.

95{
96 G4String newCommand;
97
99 promptCharacter = statM->GetStateString(statM->GetCurrentState());
100
101 iExit= TRUE;
102
103 WaitingConnection();
104 while(iExit){
105 newCommand= GetCommand();
106 ExecuteCommand(newCommand);
107 }
108 return NULL;
109}

◆ SessionTerminate()

void G4UIGainServer::SessionTerminate ( )

Definition at line 454 of file G4UIGainServer.cc.

454 {
455////////////////////////////////
456 G4cout<<"***** Terminal session end *****"<<G4endl;
457}

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