#include <G4UIGainServer.hh>
Inheritance diagram for G4UIGainServer:
Public Member Functions | |
G4UIsession * | SessionStart () |
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 () |
Definition at line 64 of file G4UIGainServer.hh.
G4UIGainServer::G4UIGainServer | ( | ) |
Definition at line 43 of file G4UIGainServer.cc.
References DEFAULT_PORT, FALSE, G4cout, G4endl, G4StateManager::GetCurrentState(), G4StateManager::GetStateManager(), G4StateManager::GetStateString(), G4UImanager::GetTree(), G4UImanager::GetUIpointer(), and terminal_mode.
00045 { 00046 TVersion ="T1.0a"; JVersion="J1.0a"; 00047 prefix = "/"; 00048 00049 port = DEFAULT_PORT; 00050 while(SetUPServer() == false){ 00051 G4cout<<"can't get the port no. "<<port<<" Now, try to get the next port "<<port+1<<G4endl; 00052 port++; 00053 } 00054 00055 00056 UI= G4UImanager::GetUIpointer(); 00057 UI-> SetSession(this); 00058 UI-> SetCoutDestination(this); 00059 00060 G4StateManager* statM = G4StateManager::GetStateManager(); 00061 promptCharacter = statM->GetStateString(statM->GetCurrentState()); 00062 uiMode = terminal_mode; 00063 00064 iExit= FALSE; 00065 iCont= FALSE; 00066 00067 G4UIcommandTree* tree = UI->GetTree(); 00068 GetNewTreeStructure(tree,0); 00069 GetNewTreeValues(tree,0); 00070 previousTreeCommands = newTreeCommands; 00071 previousTreeParams = newTreeParams; 00072 previousTreePCP = newTreePCP; 00073 00074 }
G4UIGainServer::~G4UIGainServer | ( | ) |
Definition at line 77 of file G4UIGainServer.cc.
References G4UImanager::GetUIpointer(), G4UImanager::SetCoutDestination(), and G4UImanager::SetSession().
00079 { 00080 00081 if(G4UImanager::GetUIpointer()) { 00082 UI-> SetSession(NULL); 00083 UI-> SetCoutDestination(NULL); 00084 } 00085 00086 if(G4UImanager::GetUIpointer()!=0){ 00087 UI->SetSession(NULL); 00088 UI->SetCoutDestination(NULL); 00089 } 00090 }
G4String G4UIGainServer::GetCommand | ( | ) |
Definition at line 183 of file G4UIGainServer.cc.
References G4String::append(), G4cerr, G4cin, G4cout, G4endl, G4UImanager::GetNumberOfHistory(), G4UImanager::GetPreviousCommand(), G4UImanager::GetTree(), java_mode, G4String::leading, G4String::readLine(), G4String::remove(), G4String::strip(), tcl_mode, and terminal_mode.
Referenced by PauseSessionStart(), and SessionStart().
00185 { 00186 G4String newCommand; 00187 G4String nullString; 00188 00189 while( 1 ) 00190 { 00191 G4UIcommandTree* tree = UI->GetTree(); 00192 if ( uiMode != terminal_mode ){ 00193 G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl; 00194 } 00195 if ( uiMode != java_mode ){ 00196 G4cout << promptCharacter << "> " << G4endl; 00197 }else{ 00198 G4cout << "@@Ready" << G4endl; 00199 } 00200 00201 00204 read(socketD[1],buf,1024); 00205 newCommand=buf; 00206 //DEBUG cout<<"->"<<newCommand<<"<-"<<newCommand.length()<<G4endl; 00207 //newCommand.readLine( G4cin, FALSE ); 00210 00211 00212 00213 if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;} 00214 00215 newCommand = newCommand.strip(G4String::leading); 00216 if( newCommand.length() < 1) { break; } 00217 00218 while( newCommand(newCommand.length()-1) == '_' ) 00219 { 00220 G4String newLine; 00221 newCommand.remove(newCommand.length()-1); 00222 newLine.readLine( G4cin ); 00223 if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;} 00224 newCommand.append(newLine); 00225 } 00226 00227 G4String nC = newCommand.strip(G4String::leading); 00228 if( nC.length() < 1) { break; } 00229 00230 // -------------------- nC.toUpper(); 00231 if( nC == "@@GainmodeJAVA" ) { 00232 uiMode = java_mode; 00233 G4cout << G4endl << "@@Version " << JVersion << G4endl; 00234 SendCommandProperties(tree); 00235 NotifyStateChange(); 00236 } 00237 else if( nC == "@@GainmodeTcl" ) { 00238 uiMode = tcl_mode; 00239 G4cout << G4endl << "@@Version " << TVersion << G4endl; 00240 SendCommandProperties(tree); 00241 NotifyStateChange(); 00242 } 00243 else if( nC(0) == '#' ) 00244 { G4cout << nC << G4endl; } 00245 00246 else if( nC == "ls" || nC(0,3) == "ls " ) 00247 { ListDirectory( nC ); } 00248 else if( nC == "pwd" ) 00249 { G4cout << "Current Working Directory : " << prefix << G4endl; } 00250 else if( nC(0,2) == "cd" || nC(0,3) == "cd " ) 00251 { ChangeDirectory( nC ); } 00252 else if( nC == "help" || nC(0,5) == "help ") 00253 { TerminalHelp( nC ); } 00254 else if( nC(0) == '?' ) 00255 { ShowCurrent( nC ); } 00256 else if( nC(0,4) == "hist" || nC == "history") 00257 { 00258 G4int nh = UI->GetNumberOfHistory(); 00259 for(int i=0;i<nh;i++) 00260 { G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl; } 00261 } 00262 else if( nC(0) == '!' ) 00263 { 00264 G4String ss = nC(1,nC.length()-1); 00265 G4int vl; 00266 const char* tt = ss; 00267 std::istringstream is((char*)tt); 00268 is >> vl; 00269 G4int nh = UI->GetNumberOfHistory(); 00270 if(vl>=0 && vl<nh) 00271 { 00272 newCommand = UI->GetPreviousCommand(vl); 00273 G4cout << newCommand << G4endl; 00274 break; 00275 } 00276 else 00277 { G4cerr << "history " << vl << " is not found." << G4endl; } 00278 } 00279 else if( nC(0,4) == "exit" ) 00280 { 00281 if( iCont ) 00282 { 00283 if ( uiMode == terminal_mode){ 00284 G4cerr << "You are now processing RUN." << G4endl; 00285 G4cerr << "Please abrot it using \"/run/abort\" command first" << G4endl; 00286 G4cerr << " and use \"continue\" command until the application" << G4endl; 00287 G4cerr << " becomes to Idle." << G4endl; 00288 }else{ 00289 G4cout << "@@ErrResult \"You are now processing RUN.\"" << G4endl; 00290 } 00291 } 00292 else 00293 { 00294 close(socketD[1]); 00295 close(socketD[2]); 00296 iExit = false; 00297 newCommand = nullString; 00298 break; 00299 } 00300 } 00301 else if( nC == "cont" || nC == "continue" ) 00302 { 00303 iCont = false; 00304 newCommand = nullString; 00305 break; 00306 } 00307 else 00308 { break; } 00309 } 00310 return GetFullPath(newCommand); 00311 }
void G4UIGainServer::PauseSessionStart | ( | const G4String & | msg | ) | [virtual] |
Implements G4VBasicShell.
Definition at line 113 of file G4UIGainServer.cc.
References G4cout, G4endl, GetCommand(), and TRUE.
00115 { 00116 promptCharacter = msg; 00117 G4cout<<"@@PROMPT \""<<promptCharacter<<"\""<<G4endl; 00118 00119 iCont= TRUE; 00120 00121 G4String newCommand= GetCommand(); 00122 while(iCont){ 00123 ExecuteCommand(newCommand); 00124 newCommand= GetCommand(); 00125 strcpy(buf,"nowIdle"); 00126 write(socketD[1],buf,strlen(buf)); 00127 } 00128 }
void G4UIGainServer::Prompt | ( | G4String | ) |
Reimplemented from G4UIsession.
Definition at line 327 of file G4UIGainServer.cc.
00329 { 00330 if(socketD[2]>0){ 00331 write(socketD[2],cerrString,cerrString.length()); 00332 } 00333 return 0; 00334 00335 //std::cerr << cerrString << std::flush; 00336 //return 0; 00337 }
Reimplemented from G4UIsession.
Definition at line 314 of file G4UIGainServer.cc.
00316 { 00317 if(socketD[1]>0){ 00318 write(socketD[1],coutString,coutString.length()); 00319 } 00320 return 0; 00321 00322 //std::cout << coutString << std::flush; 00323 //return 0; 00324 }
G4UIsession * G4UIGainServer::SessionStart | ( | ) | [virtual] |
Implements G4VBasicShell.
Definition at line 94 of file G4UIGainServer.cc.
References GetCommand(), G4StateManager::GetCurrentState(), G4StateManager::GetStateManager(), G4StateManager::GetStateString(), and TRUE.
00096 { 00097 G4String newCommand; 00098 00099 G4StateManager* statM = G4StateManager::GetStateManager(); 00100 promptCharacter = statM->GetStateString(statM->GetCurrentState()); 00101 00102 iExit= TRUE; 00103 00104 WaitingConnection(); 00105 while(iExit){ 00106 newCommand= GetCommand(); 00107 ExecuteCommand(newCommand); 00108 } 00109 return NULL; 00110 }
void G4UIGainServer::SessionTerminate | ( | ) |