#include "G4ZMQServer.hh"
Definition at line 36 of file G4ZMQServer.hh.
G4ZMQServer::G4ZMQServer |
( |
| ) |
|
Definition at line 74 of file G4ZMQServer.cc.
References endpoint_, qdebug_, and shell_.
79 shell_-> SetLsColor(BLUE, RED);
81 ::ui_manager = G4UImanager::GetUIpointer();
82 ::ui_manager-> SetSession(
this);
83 ::ui_manager-> SetCoutDestination(
this);
G4ZMQServer::~G4ZMQServer |
( |
| ) |
|
void G4ZMQServer::ExecuteCommand |
( |
const G4String & |
command | ) |
|
|
privatevirtual |
Definition at line 263 of file G4ZMQServer.cc.
Referenced by SessionStart().
265 auto rc = ::ui_manager-> ApplyCommand(command);
266 auto pcode = rc % 100;
267 auto status = rc - pcode;
269 G4UIcommand* cmd =
nullptr;
270 if( status != fCommandSucceeded ) cmd = FindCommand(command);
273 case fCommandSucceeded:
275 case fCommandNotFound:
276 G4cerr <<
"command <" << ::ui_manager-> SolveAlias(command)
277 <<
"> not found" << G4endl;
279 case fIllegalApplicationState:
280 G4cerr <<
"illegal application state -- command refused" << G4endl;
282 case fParameterOutOfRange:
283 G4cerr <<
"Parameter is out of range" << G4endl;
285 case fParameterOutOfCandidates:
286 G4cerr <<
"Parameter is out of candidate list (index " 287 << pcode <<
")" << G4endl;
288 G4cerr <<
"Candidates : " 289 << cmd-> GetParameter(pcode)-> GetParameterCandidates()
292 case fParameterUnreadable:
293 G4cerr <<
"Parameter is wrong type and/or is not omittable (index " 294 << pcode <<
")" << G4endl;
299 G4cerr <<
"command refused (" << status <<
")" << G4endl;
void G4ZMQServer::ExitHelp |
( |
| ) |
const |
|
privatevirtual |
Definition at line 203 of file G4ZMQServer.cc.
References shell_.
Referenced by SessionStart().
205 const std::string nullstr =
"";
208 G4String cstr = cmdstr.strip(G4String::leading);
209 if ( cstr.length() == 0 ) {
213 }
else if ( cstr(0) ==
'#' ) {
214 G4cout << cstr << G4endl;
217 }
else if ( cstr ==
"ls" || cstr.substr(0,3) ==
"ls " ) {
221 }
else if ( cstr ==
"lc" || cstr.substr(0,3) ==
"lc " ) {
222 shell_-> ListCommand(cstr.remove(0,2));
225 }
else if (cstr ==
"pwd" ) {
226 G4cout <<
"Current Command Directory : " 227 << GetCurrentWorkingDirectory() << G4endl;
230 }
else if ( cstr ==
"cwd" ) {
231 shell_-> ShowCurrentDirectory();
234 }
else if (cstr ==
"cd" || cstr.substr(0,3) ==
"cd " ) {
235 ChangeDirectoryCommand(cstr);
236 shell_-> SetCurrentDirectory(GetCurrentWorkingDirectory());
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" ) {
259 return ModifyToFullPathCommand(cmdstr);
G4String G4ZMQServer::GetEndpoint |
( |
| ) |
const |
|
inline |
G4bool G4ZMQServer::GetHelpChoice |
( |
G4int & |
| ) |
|
|
privatevirtual |
void G4ZMQServer::PauseSessionStart |
( |
const G4String & |
message | ) |
|
|
virtual |
G4int G4ZMQServer::ReceiveG4cerr |
( |
const G4String & |
cerrString | ) |
|
|
virtual |
Definition at line 191 of file G4ZMQServer.cc.
References qdebug_.
194 std::cerr << cerrString << std::flush;
197 ::cout_stream << cerrString << std::flush;
G4int G4ZMQServer::ReceiveG4cout |
( |
const G4String & |
coutString | ) |
|
|
virtual |
Definition at line 179 of file G4ZMQServer.cc.
References qdebug_.
182 std::cout << coutString << std::flush;
185 ::cout_stream << coutString << std::flush;
G4UIsession * G4ZMQServer::SessionStart |
( |
| ) |
|
|
virtual |
Definition at line 95 of file G4ZMQServer.cc.
References endpoint_, ExecuteCommand(), GetCommand(), message(), and qdebug_.
97 zmq::context_t context(1);
98 zmq::socket_t socket( context, ZMQ_REP );
101 enum { kBufferSize = 4096 };
102 char buffer[kBufferSize];
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" ) {
127 G4cout <<
"pong" << G4endl;
129 }
else if ( cmd_str ==
"@@debug") {
131 G4cout <<
"G4ZMQ debug activated" << G4endl;
133 }
else if ( cmd_str ==
"@@nodebug") {
135 G4cout <<
"G4ZMQ debug deactivated" << G4endl;
137 }
else if ( cmd_str ==
"@@get_command_tree" ) {
138 auto cwd_name = GetCurrentWorkingDirectory();
139 auto cwd_tree = FindDirectory(cwd_name.c_str());
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" ) {
151 G4cout <<
"help <command>" << G4endl;
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);
167 if ( qok ==
false ) ::ThrowException(
"G4ZMQServer: socket send error");
virtual void ExecuteCommand(const G4String &command)
G4String GetCommand(const G4String &input)
void message(RunManager *runmanager)
void G4ZMQServer::SetDebug |
( |
G4bool |
flag | ) |
|
|
inline |
void G4ZMQServer::SetEndpoint |
( |
const G4String & |
endpoint | ) |
|
|
inline |
G4bool G4ZMQServer::qdebug_ |
|
private |
G4UItcsh* G4ZMQServer::shell_ |
|
private |
The documentation for this class was generated from the following files: