42 std::stringstream cout_stream;
43 std::string black_str =
"\033[30m";
44 std::string command_list =
"";
46 void ThrowException(
const std::string&
message)
49 ss <<
"[ERROR] " << message << std::endl;
50 throw std::runtime_error(ss.str());
56 command_list += (ctree-> GetPathName() +
" ");
58 auto n_cmd = ctree-> GetCommandEntry();
59 for (
auto icmd = 1; icmd <= n_cmd; icmd++ ) {
60 auto cmd_path = ctree-> GetCommand(icmd)-> GetCommandPath();
61 command_list += (cmd_path +
" ");
64 auto n_tree = ctree-> GetTreeEntry();
65 for (
auto itr = 1; itr <= n_tree ; itr++ ) {
67 ::GetCommandTree(atree);
82 ::ui_manager-> SetSession(
this);
83 ::ui_manager-> SetCoutDestination(
this);
98 zmq::socket_t
socket( context, ZMQ_REP );
101 enum { kBufferSize = 4096 };
104 while ( ! ::qexit ) {
106 std::cout <<
"@@ Waiting..." << std::endl;
110 zmq::message_t request;
111 G4bool qok = socket.recv(&request);
112 if ( qok ==
false ) ::ThrowException(
"G4ZMQSever: socket recv error");
113 auto end_pos = request.size();
114 if ( end_pos >= kBufferSize ) end_pos = kBufferSize - 1;
115 std::memcpy(buffer, request.data(), end_pos);
116 buffer[end_pos] =
'\0';
117 std::string cmd_str =
buffer;
120 std::cout <<
"@@ Recv=" << cmd_str <<
"<<" << std::endl;
124 ::cout_stream.str(
"");
126 if ( cmd_str ==
"@@ping" ) {
129 }
else if ( cmd_str ==
"@@debug") {
133 }
else if ( cmd_str ==
"@@nodebug") {
137 }
else if ( cmd_str ==
"@@get_command_tree" ) {
141 ::GetCommandTree(cwd_tree);
142 G4cout << ::command_list << std::flush;
144 }
else if ( cmd_str ==
"@@get_fullcommand_tree" ) {
145 auto root = ::ui_manager-> GetTree();
147 ::GetCommandTree(root);
148 G4cout << ::command_list << std::flush;
150 }
else if ( cmd_str ==
"help" ) {
156 std::cout << ::black_str <<
"@@ Cmd="
157 << new_command <<
"<<" << std::endl;
162 std::string reply = ::cout_stream.str();
163 size_t cout_size = reply.size();
164 zmq::message_t
message(cout_size);
165 std::strncpy((
char*)message.data(), reply.c_str(), cout_size);
166 qok = socket.send(message);
167 if ( qok ==
false ) ::ThrowException(
"G4ZMQServer: socket send error");
182 std::cout << coutString << std::flush;
185 ::cout_stream << coutString << std::flush;
194 std::cerr << cerrString << std::flush;
197 ::cout_stream << cerrString << std::flush;
205 const std::string nullstr =
"";
209 if ( cstr.length() == 0 ) {
213 }
else if ( cstr(0) ==
'#' ) {
217 }
else if ( cstr ==
"ls" || cstr.substr(0,3) ==
"ls " ) {
221 }
else if ( cstr ==
"lc" || cstr.substr(0,3) ==
"lc " ) {
225 }
else if (cstr ==
"pwd" ) {
226 G4cout <<
"Current Command Directory : "
230 }
else if ( cstr ==
"cwd" ) {
231 shell_-> ShowCurrentDirectory();
234 }
else if (cstr ==
"cd" || cstr.substr(0,3) ==
"cd " ) {
239 }
else if ( cstr ==
"help" || cstr.substr(0,5) ==
"help " ) {
243 }
else if ( cstr(0) ==
'?' ) {
247 }
else if ( cstr ==
"history" ) {
248 auto nh= ::ui_manager-> GetNumberOfHistory();
249 for (
auto i = 0; i < nh; i++) {
250 G4cout << i <<
": " << ::ui_manager->GetPreviousCommand(i) <<
G4endl;
254 }
else if ( cstr ==
"exit" ) {
265 auto rc = ::ui_manager-> ApplyCommand(command);
266 auto pcode = rc % 100;
267 auto status = rc - pcode;
276 G4cerr <<
"command <" << ::ui_manager-> SolveAlias(command)
277 <<
"> not found" <<
G4endl;
280 G4cerr <<
"illegal application state -- command refused" <<
G4endl;
286 G4cerr <<
"Parameter is out of candidate list (index "
287 << pcode <<
")" <<
G4endl;
289 << cmd-> GetParameter(pcode)-> GetParameterCandidates()
293 G4cerr <<
"Parameter is wrong type and/or is not omittable (index "
294 << pcode <<
")" <<
G4endl;
299 G4cerr <<
"command refused (" << status <<
")" <<
G4endl;