43 std::stringstream cout_stream;
44 std::string black_str =
"\033[30m";
45 std::string command_list =
"";
47 void ThrowException(
const std::string&
message)
50 ss <<
"[ERROR] " << message << std::endl;
51 throw std::runtime_error(ss.str());
57 command_list += (ctree-> GetPathName() +
" ");
59 auto n_cmd = ctree-> GetCommandEntry();
60 for (
auto icmd = 1; icmd <= n_cmd; icmd++ ) {
61 auto cmd_path = ctree-> GetCommand(icmd)-> GetCommandPath();
62 command_list += (cmd_path +
" ");
65 auto n_tree = ctree-> GetTreeEntry();
66 for (
auto itr = 1; itr <= n_tree ; itr++ ) {
68 ::GetCommandTree(atree);
83 ::ui_manager-> SetSession(
this);
84 ::ui_manager-> SetCoutDestination(
this);
99 zmq::socket_t socket( context, ZMQ_REP );
102 enum { kBufferSize = 4096 };
105 while ( ! ::qexit ) {
107 std::cout <<
"@@ Waiting..." << std::endl;
111 zmq::message_t request;
112 G4bool qok = socket.recv(&request);
113 if ( qok ==
false ) ::ThrowException(
"G4ZMQSever: socket recv error");
114 auto end_pos = request.size();
115 if ( end_pos >= kBufferSize ) end_pos = kBufferSize - 1;
116 std::memcpy(buffer, request.data(), end_pos);
117 buffer[end_pos] =
'\0';
118 std::string cmd_str =
buffer;
121 std::cout <<
"@@ Recv=" << cmd_str <<
"<<" << std::endl;
125 ::cout_stream.str(
"");
127 if ( cmd_str ==
"@@ping" ) {
130 }
else if ( cmd_str ==
"@@debug") {
134 }
else if ( cmd_str ==
"@@nodebug") {
138 }
else if ( cmd_str ==
"@@get_command_tree" ) {
142 ::GetCommandTree(cwd_tree);
143 G4cout << ::command_list << std::flush;
145 }
else if ( cmd_str ==
"@@get_fullcommand_tree" ) {
146 auto root = ::ui_manager-> GetTree();
148 ::GetCommandTree(root);
149 G4cout << ::command_list << std::flush;
151 }
else if ( cmd_str ==
"help" ) {
157 std::cout << ::black_str <<
"@@ Cmd="
158 << new_command <<
"<<" << std::endl;
163 std::string reply = ::cout_stream.str();
164 size_t cout_size = reply.size();
165 zmq::message_t
message(cout_size);
166 std::strncpy((
char*)message.data(), reply.c_str(), cout_size);
167 qok = socket.send(message);
168 if ( qok ==
false ) ::ThrowException(
"G4ZMQServer: socket send error");
183 std::cout << coutString << std::flush;
186 ::cout_stream << coutString << std::flush;
195 std::cerr << cerrString << std::flush;
198 ::cout_stream << cerrString << std::flush;
206 const std::string nullstr =
"";
210 if ( cstr.length() == 0 ) {
214 }
else if ( cstr(0) ==
'#' ) {
218 }
else if ( cstr ==
"ls" || cstr.substr(0,3) ==
"ls " ) {
222 }
else if ( cstr ==
"lc" || cstr.substr(0,3) ==
"lc " ) {
226 }
else if (cstr ==
"pwd" ) {
227 G4cout <<
"Current Command Directory : "
231 }
else if ( cstr ==
"cwd" ) {
232 shell_-> ShowCurrentDirectory();
235 }
else if (cstr ==
"cd" || cstr.substr(0,3) ==
"cd " ) {
240 }
else if ( cstr ==
"help" || cstr.substr(0,5) ==
"help " ) {
244 }
else if ( cstr(0) ==
'?' ) {
248 }
else if ( cstr ==
"history" ) {
249 auto nh= ::ui_manager-> GetNumberOfHistory();
250 for (
auto i = 0; i < nh; i++) {
251 G4cout << i <<
": " << ::ui_manager->GetPreviousCommand(i) <<
G4endl;
255 }
else if ( cstr ==
"exit" ) {
266 auto rc = ::ui_manager-> ApplyCommand(command);
267 auto pcode = rc % 100;
268 auto status = rc - pcode;
277 G4cerr <<
"command <" << ::ui_manager-> SolveAlias(command)
278 <<
"> not found" <<
G4endl;
281 G4cerr <<
"illegal application state -- command refused" <<
G4endl;
287 G4cerr <<
"Parameter is out of candidate list (index "
288 << pcode <<
")" <<
G4endl;
290 << cmd-> GetParameter(pcode)-> GetParameterCandidates()
294 G4cerr <<
"Parameter is wrong type and/or is not omittable (index "
295 << pcode <<
")" <<
G4endl;
300 G4cerr <<
"command refused (" << status <<
")" <<
G4endl;
virtual void ExecuteCommand(const G4String &command)
G4String & remove(str_size)
G4String GetCommand(const G4String &input)
void message(RunManager *runmanager)
virtual G4bool GetHelpChoice(G4int &)
virtual void ExitHelp() const
virtual void PauseSessionStart(const G4String &message)
void TerminalHelp(const G4String &)
static G4UImanager * GetUIpointer()
virtual G4UIsession * SessionStart()
G4String strip(G4int strip_Type=trailing, char c=' ')
G4GLOB_DLL std::ostream G4cerr
G4UIcommand * FindCommand(const char *commandName) const
G4String GetCurrentWorkingDirectory() const
void ListDirectory(const G4String &) const
virtual G4int ReceiveG4cerr(const G4String &cerrString)
void ChangeDirectoryCommand(const G4String &)
G4GLOB_DLL std::ostream G4cout
void ShowCurrent(const G4String &) const
G4String ModifyToFullPathCommand(const char *aCommandLine) const
G4UIcommandTree * FindDirectory(const char *dirName) const
virtual G4int ReceiveG4cout(const G4String &coutString)