diff --git a/.gitignore b/.gitignore index b449adcc..52f0f31c 100644 --- a/.gitignore +++ b/.gitignore @@ -50,6 +50,8 @@ tests/testargs.log tests/testargs.trs tests/test-setup.sh tests/listing.txt +unittests/testargs +unittests/testargs.trs # others compile_commands.json .vs* diff --git a/client/main.cpp b/client/main.cpp index e4939baf..402e022c 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -496,7 +496,7 @@ int main(int argc, char **argv) string native; - if (umsg && umsg->type == M_NATIVE_ENV) { + if (umsg && *umsg == Msg::NATIVE_ENV) { native = static_cast(umsg)->nativeVersion; } @@ -600,7 +600,7 @@ int main(int argc, char **argv) /* If we can't talk to the daemon anymore we need to fall back to lock file locking. */ - if (!startme || startme->type != M_JOB_LOCAL_BEGIN) { + if (!startme || *startme != Msg::JOB_LOCAL_BEGIN) { delete startme; delete local_daemon; return build_local(job, nullptr); diff --git a/client/remote.cpp b/client/remote.cpp index 70dad4cf..c041fb4c 100644 --- a/client/remote.cpp +++ b/client/remote.cpp @@ -246,10 +246,10 @@ static UseCSMsg *get_server(MsgChannel *local_daemon) timeout = 60 * 60; Msg *umsg = local_daemon->get_msg( timeout ); - if (!umsg || umsg->type != M_USE_CS) { - log_warning() << "reply was not expected use_cs " << (umsg ? (char)umsg->type : '0') << endl; + if (!umsg || *umsg != Msg::USE_CS) { + log_warning() << "reply was not expected use_cs " << (umsg ? umsg->to_string() : Msg(Msg::UNKNOWN).to_string()) << endl; ostringstream unexpected_msg; - unexpected_msg << "Error 1 - expected use_cs reply, but got " << (umsg ? (char)umsg->type : '0') << " instead"; + unexpected_msg << "Error 1 - expected use_cs reply, but got " << (umsg ? umsg->to_string() : Msg(Msg::UNKNOWN).to_string()) << " instead"; delete umsg; throw client_error(1, unexpected_msg.str()); } @@ -260,7 +260,7 @@ static UseCSMsg *get_server(MsgChannel *local_daemon) static void check_for_failure(Msg *msg, MsgChannel *cserver) { - if (msg && msg->type == M_STATUS_TEXT) { + if (msg && *msg == Msg::STATUS_TEXT) { log_error() << "Remote status (compiled on " << cserver->name << "): " << static_cast(msg)->text << endl; throw client_error(23, "Error 23 - Remote status (compiled on " + cserver->name + ")\n" + @@ -361,11 +361,11 @@ static void receive_file(const string& output_file, MsgChannel* cserver) check_for_failure(msg, cserver); - if (msg->type == M_END) { + if (*msg == Msg::END) { break; } - if (msg->type != M_FILE_CHUNK) { + if (*msg != Msg::FILE_CHUNK) { unlink(tmp_file.c_str()); delete msg; throw client_error(20, "Error 20 - unexpected message"); @@ -482,7 +482,7 @@ static int build_remote_int(CompileJob &job, UseCSMsg *usecs, MsgChannel *local_ Msg *verify_msg = cserver->get_msg(60); - if (verify_msg && verify_msg->type == M_VERIFY_ENV_RESULT) { + if (verify_msg && *verify_msg == Msg::VERIFY_ENV_RESULT) { if (!static_cast(verify_msg)->ok) { // The remote can't handle the environment at all (e.g. kernel too old), // mark it as never to be used again for this environment. @@ -609,8 +609,8 @@ static int build_remote_int(CompileJob &job, UseCSMsg *usecs, MsgChannel *local_ check_for_failure(msg, cserver); - if (msg->type != M_COMPILE_RESULT) { - log_warning() << "waited for compile result, but got " << (char)msg->type << endl; + if (*msg != Msg::COMPILE_RESULT) { + log_warning() << "waited for compile result, but got " << msg->to_string() << endl; delete msg; throw client_error(13, "Error 13 - did not get compile response message"); } @@ -670,7 +670,7 @@ static int build_remote_int(CompileJob &job, UseCSMsg *usecs, MsgChannel *local_ // Handle pending status messages, if any. if(cserver) { while(Msg* msg = cserver->get_msg(0, true)) { - if(msg->type == M_STATUS_TEXT) + if(*msg == Msg::STATUS_TEXT) log_error() << "Remote status (compiled on " << cserver->name << "): " << static_cast(msg)->text << endl; delete msg; diff --git a/daemon/environment.cpp b/daemon/environment.cpp index 6591df8d..61f51ad9 100644 --- a/daemon/environment.cpp +++ b/daemon/environment.cpp @@ -418,7 +418,7 @@ pid_t start_install_environment(const std::string &basename, const std::string & string dirname = basename + "/target=" + target; Msg *msg = c->get_msg(30); - if (!msg || msg->type != M_FILE_CHUNK) { + if (!msg || *msg != Msg::FILE_CHUNK) { trace() << "Expected first file chunk\n"; return 0; } diff --git a/daemon/main.cpp b/daemon/main.cpp index 65cc9046..d4f2bc6b 100644 --- a/daemon/main.cpp +++ b/daemon/main.cpp @@ -1091,13 +1091,13 @@ bool Daemon::handle_file_chunk_env(Client *client, Msg *msg) the file chunk to the child, but we can't let the child handle MsgChannel itself due to MsgChannel's stupid caching layer inbetween, which causes us to lose partial - data after the M_END msg of the env transfer. */ + data after the END msg of the env transfer. */ assert(client); assert(client->status == Client::TOINSTALL || client->status == Client::WAITINSTALL); assert(client->pipe_to_child >= 0); - if (msg->type == M_FILE_CHUNK) { + if (*msg == Msg::FILE_CHUNK) { FileChunkMsg *fcmsg = static_cast(msg); ssize_t len = fcmsg->len; off_t off = 0; @@ -1129,7 +1129,7 @@ bool Daemon::handle_file_chunk_env(Client *client, Msg *msg) return true; } - if (msg->type == M_END) { + if (*msg == Msg::END) { trace() << "received end of environment, waiting for child" << endl; close(client->pipe_to_child); client->pipe_to_child = -1; @@ -1143,7 +1143,7 @@ bool Daemon::handle_file_chunk_env(Client *client, Msg *msg) } // unexpected message type - log_error() << "protocol error while receiving environment (" << msg->type << ")" << endl; + log_error() << "protocol error while receiving environment (" << msg->to_string() << ")" << endl; handle_end(client, 138); return false; } @@ -1176,7 +1176,7 @@ bool Daemon::handle_env_install_child_done(Client *client) if( !success ) return finish_transfer_env( client, true ); // cancel if( client->pipe_to_child >= 0 ) { - // we still haven't received M_END message, wait for that + // we still haven't received END message, wait for that assert( client->status == Client::TOINSTALL ); return true; } @@ -1896,37 +1896,37 @@ bool Daemon::handle_activity(Client *client) return ret; } - switch (msg->type) { - case M_GET_NATIVE_ENV: + switch (*msg) { + case Msg::GET_NATIVE_ENV: ret = handle_get_native_env(client, dynamic_cast(msg)); break; - case M_COMPILE_FILE: + case Msg::COMPILE_FILE: ret = handle_compile_file(client, msg); break; - case M_TRANFER_ENV: + case Msg::TRANFER_ENV: ret = handle_transfer_env(client, dynamic_cast(msg)); break; - case M_GET_CS: + case Msg::GET_CS: ret = handle_get_cs(client, msg); break; - case M_END: + case Msg::END: handle_end(client, 119); ret = false; break; - case M_JOB_LOCAL_BEGIN: + case Msg::JOB_LOCAL_BEGIN: ret = handle_local_job(client, msg); break; - case M_JOB_DONE: + case Msg::JOB_DONE: ret = handle_job_done(client, dynamic_cast(msg)); break; - case M_VERIFY_ENV: + case Msg::VERIFY_ENV: ret = handle_verify_env(client, dynamic_cast(msg)); break; - case M_BLACKLIST_HOST_ENV: + case Msg::BLACKLIST_HOST_ENV: ret = handle_blacklist_host_env(client, msg); break; default: - log_error() << "protocol error " << msg->type << " on client " + log_error() << "protocol error " << msg->to_string() << " on client " << client->dump() << endl; client->channel->send_msg(EndMsg()); handle_end(client, 120); @@ -2065,28 +2065,28 @@ void Daemon::answer_client_requests() ret = 0; - switch (msg->type) { - case M_PING: + switch (*msg) { + case Msg::PING: if (!IS_PROTOCOL_27(scheduler)) { ret = !send_scheduler(PingMsg()); } break; - case M_USE_CS: + case Msg::USE_CS: ret = scheduler_use_cs(static_cast(msg)); break; - case M_NO_CS: + case Msg::NO_CS: ret = scheduler_no_cs(static_cast(msg)); break; - case M_GET_INTERNALS: + case Msg::GET_INTERNALS: ret = scheduler_get_internals(); break; - case M_CS_CONF: + case Msg::CS_CONF: ret = handle_cs_conf(static_cast(msg)); break; default: - log_error() << "unknown scheduler type " << (char)msg->type << endl; + log_error() << "unknown scheduler type " << msg->to_string() << endl; ret = 1; } diff --git a/daemon/workit.cpp b/daemon/workit.cpp index d3521f19..bc9c6109 100644 --- a/daemon/workit.cpp +++ b/daemon/workit.cpp @@ -449,7 +449,7 @@ int work_it(CompileJob &j, unsigned int job_stat[], MsgChannel *client, CompileR fcmsg = nullptr; delete msg; } else { - if (msg->type == M_END) { + if (*msg == Msg::END) { input_complete = true; if (!fcmsg && sock_in[1] != -1) { @@ -460,7 +460,7 @@ int work_it(CompileJob &j, unsigned int job_stat[], MsgChannel *client, CompileR } delete msg; - } else if (msg->type == M_FILE_CHUNK) { + } else if (*msg == Msg::FILE_CHUNK) { fcmsg = static_cast(msg); off = 0; diff --git a/scheduler/scheduler.cpp b/scheduler/scheduler.cpp index 03cc15f4..4ceb7ba6 100644 --- a/scheduler/scheduler.cpp +++ b/scheduler/scheduler.cpp @@ -1722,7 +1722,7 @@ static bool handle_line(CompileServer *cs, Msg *_m) msg = it->get_msg(); } - if (msg && msg->type == M_STATUS_TEXT) { + if (msg && *msg == Msg::STATUS_TEXT) { if (!cs->send_msg(TextMsg(dynamic_cast(msg)->text))) { return false; } @@ -1757,17 +1757,17 @@ static bool try_login(CompileServer *cs, Msg *m) { bool ret = true; - switch (m->type) { - case M_LOGIN: + switch (*m) { + case Msg::LOGIN: cs->setType(CompileServer::DAEMON); ret = handle_login(cs, m); break; - case M_MON_LOGIN: + case Msg::MON_LOGIN: cs->setType(CompileServer::MONITOR); ret = handle_mon_login(cs, m); break; default: - log_info() << "Invalid first message " << (char)m->type << endl; + log_info() << "Invalid first message " << m->to_string() << endl; ret = false; break; } @@ -1898,43 +1898,43 @@ static bool handle_activity(CompileServer *cs) return try_login(cs, m); } - switch (m->type) { - case M_JOB_BEGIN: + switch (*m) { + case Msg::JOB_BEGIN: ret = handle_job_begin(cs, m); break; - case M_JOB_DONE: + case Msg::JOB_DONE: ret = handle_job_done(cs, m); break; - case M_PING: + case Msg::PING: ret = handle_ping(cs, m); break; - case M_STATS: + case Msg::STATS: ret = handle_stats(cs, m); break; - case M_END: + case Msg::END: handle_end(cs, m); ret = false; break; - case M_JOB_LOCAL_BEGIN: + case Msg::JOB_LOCAL_BEGIN: ret = handle_local_job(cs, m); break; - case M_JOB_LOCAL_DONE: + case Msg::JOB_LOCAL_DONE: ret = handle_local_job_done(cs, m); break; - case M_LOGIN: + case Msg::LOGIN: ret = handle_relogin(cs, m); break; - case M_TEXT: + case Msg::TEXT: ret = handle_line(cs, m); break; - case M_GET_CS: + case Msg::GET_CS: ret = handle_cs_request(cs, m); break; - case M_BLACKLIST_HOST_ENV: + case Msg::BLACKLIST_HOST_ENV: ret = handle_blacklist_host_env(cs, m); break; default: - log_info() << "Invalid message type arrived " << (char)m->type << endl; + log_info() << "Invalid message type arrived " << m->to_string() << endl; handle_end(cs, m); ret = false; break; diff --git a/services/comm.cpp b/services/comm.cpp index 5332f7d6..7a8be8d9 100644 --- a/services/comm.cpp +++ b/services/comm.cpp @@ -707,7 +707,7 @@ void MsgChannel::set_error(bool silent) // so try to fetch last status from the other side, if available. set_error_recursion = true; Msg* msg = get_msg( 2, true ); - if (msg && msg->type == M_STATUS_TEXT) { + if (msg && *msg == Msg::STATUS_TEXT) { log_error() << "remote status: " << static_cast(msg)->text << endl; } @@ -1144,7 +1144,7 @@ bool MsgChannel::wait_for_msg(int timeout) Msg *MsgChannel::get_msg(int timeout, bool eofAllowed) { Msg *m = nullptr; - enum MsgType type; + Msg::Value type; if (!wait_for_msg(timeout)) { // trace() << "!wait_for_msg()\n"; @@ -1171,108 +1171,108 @@ Msg *MsgChannel::get_msg(int timeout, bool eofAllowed) size_t intogo_old = intogo; if (text_based) { - type = M_TEXT; + type = Msg::TEXT; } else { uint32_t t; *this >> t; - type = (enum MsgType) t; + type = (Msg::Value) t; } switch (type) { - case M_UNKNOWN: + case Msg::UNKNOWN: set_error(); return nullptr; - case M_PING: + case Msg::PING: m = new PingMsg; break; - case M_END: + case Msg::END: m = new EndMsg; break; - case M_GET_CS: + case Msg::GET_CS: m = new GetCSMsg; break; - case M_USE_CS: + case Msg::USE_CS: m = new UseCSMsg; break; - case M_NO_CS: + case Msg::NO_CS: m = new NoCSMsg; break; - case M_COMPILE_FILE: + case Msg::COMPILE_FILE: m = new CompileFileMsg(new CompileJob, true); break; - case M_FILE_CHUNK: + case Msg::FILE_CHUNK: m = new FileChunkMsg; break; - case M_COMPILE_RESULT: + case Msg::COMPILE_RESULT: m = new CompileResultMsg; break; - case M_JOB_BEGIN: + case Msg::JOB_BEGIN: m = new JobBeginMsg; break; - case M_JOB_DONE: + case Msg::JOB_DONE: m = new JobDoneMsg; break; - case M_LOGIN: + case Msg::LOGIN: m = new LoginMsg; break; - case M_STATS: + case Msg::STATS: m = new StatsMsg; break; - case M_GET_NATIVE_ENV: + case Msg::GET_NATIVE_ENV: m = new GetNativeEnvMsg; break; - case M_NATIVE_ENV: + case Msg::NATIVE_ENV: m = new UseNativeEnvMsg; break; - case M_MON_LOGIN: + case Msg::MON_LOGIN: m = new MonLoginMsg; break; - case M_MON_GET_CS: + case Msg::MON_GET_CS: m = new MonGetCSMsg; break; - case M_MON_JOB_BEGIN: + case Msg::MON_JOB_BEGIN: m = new MonJobBeginMsg; break; - case M_MON_JOB_DONE: + case Msg::MON_JOB_DONE: m = new MonJobDoneMsg; break; - case M_MON_STATS: + case Msg::MON_STATS: m = new MonStatsMsg; break; - case M_JOB_LOCAL_BEGIN: + case Msg::JOB_LOCAL_BEGIN: m = new JobLocalBeginMsg; break; - case M_JOB_LOCAL_DONE : + case Msg::JOB_LOCAL_DONE : m = new JobLocalDoneMsg; break; - case M_MON_LOCAL_JOB_BEGIN: + case Msg::MON_LOCAL_JOB_BEGIN: m = new MonLocalJobBeginMsg; break; - case M_TRANFER_ENV: + case Msg::TRANFER_ENV: m = new EnvTransferMsg; break; - case M_TEXT: + case Msg::TEXT: m = new TextMsg; break; - case M_GET_INTERNALS: + case Msg::GET_INTERNALS: m = new GetInternalStatus; break; - case M_STATUS_TEXT: + case Msg::STATUS_TEXT: m = new StatusTextMsg; break; - case M_CS_CONF: + case Msg::CS_CONF: m = new ConfCSMsg; break; - case M_VERIFY_ENV: + case Msg::VERIFY_ENV: m = new VerifyEnvMsg; break; - case M_VERIFY_ENV_RESULT: + case Msg::VERIFY_ENV_RESULT: m = new VerifyEnvResultMsg; break; - case M_BLACKLIST_HOST_ENV: + case Msg::BLACKLIST_HOST_ENV: m = new BlacklistHostEnvMsg; break; - case M_TIMEOUT: + case Msg::TIMEOUT: break; } @@ -1286,7 +1286,7 @@ Msg *MsgChannel::get_msg(int timeout, bool eofAllowed) if (!text_based) { if( intogo - intogo_old != inmsglen ) { - log_error() << "internal error - message not read correctly, message size " << inmsglen + log_error() << "internal error - message (" << m->to_string() << ") not read correctly, message size " << inmsglen << " read " << (intogo - intogo_old) << endl; delete m; set_error(); @@ -1920,7 +1920,7 @@ void Msg::send_to_channel(MsgChannel *c) const return; } - *c << (uint32_t) type; + *c << (uint32_t) *this; } GetCSMsg::GetCSMsg(const Environments &envs, const std::string &f, @@ -1930,7 +1930,7 @@ GetCSMsg::GetCSMsg(const Environments &envs, const std::string &f, unsigned int _required_features, int _niceness, unsigned int _client_count) - : Msg(M_GET_CS) + : Msg(Msg::GET_CS) , versions(envs) , filename(f) , lang(_lang) @@ -2312,7 +2312,7 @@ void JobLocalDoneMsg::send_to_channel(MsgChannel *c) const } JobDoneMsg::JobDoneMsg(int id, int exit, unsigned int _flags, unsigned int _client_count) - : Msg(M_JOB_DONE) + : Msg(Msg::JOB_DONE) , exitcode(exit) , flags(_flags) , job_id(id) @@ -2399,7 +2399,7 @@ void JobDoneMsg::set_job_id( uint32_t jobId ) LoginMsg::LoginMsg(unsigned int myport, const std::string &_nodename, const std::string &_host_platform, unsigned int myfeatures) - : Msg(M_LOGIN) + : Msg(Msg::LOGIN) , port(myport) , max_kids(0) , noremote(false) diff --git a/services/comm.h b/services/comm.h index 3d5fa08a..132ea6cf 100644 --- a/services/comm.h +++ b/services/comm.h @@ -70,79 +70,169 @@ #define IS_PROTOCOL_43(c) ((c)->protocol >= 43) #define IS_PROTOCOL_44(c) ((c)->protocol >= 44) +class MsgChannel; + // Terms used: // S = scheduler // C = client // CS = daemon -enum MsgType { - // so far unknown - M_UNKNOWN = 'A', - - /* When the scheduler didn't get M_STATS from a CS - for a specified time (e.g. 10m), then he sends a - ping */ - M_PING, - - /* Either the end of file chunks or connection (A<->A) */ - M_END, - - M_TIMEOUT, // unused - - // C --> CS - M_GET_NATIVE_ENV, - // CS -> C - M_NATIVE_ENV, - - // C --> S - M_GET_CS, - // S --> C - M_USE_CS, // = 'H' - // C --> CS - M_COMPILE_FILE, // = 'I' - // generic file transfer - M_FILE_CHUNK, - // CS --> C - M_COMPILE_RESULT, - - // CS --> S (after the C got the CS from the S, the CS tells the S when the C asks him) - M_JOB_BEGIN, - M_JOB_DONE, // = 'M' - - // C --> CS, CS --> S (forwarded from C), _and_ CS -> C as start ping - M_JOB_LOCAL_BEGIN, // = 'N' - M_JOB_LOCAL_DONE, - - // CS --> S, first message sent - M_LOGIN, - // CS --> S (periodic) - M_STATS, - - // messages between monitor and scheduler - M_MON_LOGIN, - M_MON_GET_CS, - M_MON_JOB_BEGIN, // = 'T' - M_MON_JOB_DONE, - M_MON_LOCAL_JOB_BEGIN, - M_MON_STATS, - - M_TRANFER_ENV, // = 'X' - - M_TEXT, - M_STATUS_TEXT, // = 'Z' - M_GET_INTERNALS, - - // S --> CS, answered by M_LOGIN - M_CS_CONF, - - // C --> CS, after installing an environment - M_VERIFY_ENV, - // CS --> C - M_VERIFY_ENV_RESULT, - // C --> CS, CS --> S (forwarded from C), to not use given host for given environment - M_BLACKLIST_HOST_ENV, - // S --> CS - M_NO_CS +class Msg { +public: + enum Value: uint32_t { + // so far unknown + UNKNOWN = 'A', + + /* When the scheduler didn't get STATS from a CS + for a specified time (e.g. 10m), then he sends a + ping */ + PING, + + /* Either the end of file chunks or connection (A<->A) */ + END, + + TIMEOUT, // unused + + // C --> CS + GET_NATIVE_ENV, + // CS -> C + NATIVE_ENV, + + // C --> S + GET_CS, + // S --> C + USE_CS, // = 'H' + // C --> CS + COMPILE_FILE, // = 'I' + // generic file transfer + FILE_CHUNK, + // CS --> C + COMPILE_RESULT, + + // CS --> S (after the C got the CS from the S, the CS tells the S when the C asks him) + JOB_BEGIN, + JOB_DONE, // = 'M' + + // C --> CS, CS --> S (forwarded from C), _and_ CS -> C as start ping + JOB_LOCAL_BEGIN, // = 'N' + JOB_LOCAL_DONE, + + // CS --> S, first message sent + LOGIN, + // CS --> S (periodic) + STATS, + + // messages between monitor and scheduler + MON_LOGIN, + MON_GET_CS, + MON_JOB_BEGIN, // = 'T' + MON_JOB_DONE, + MON_LOCAL_JOB_BEGIN, + MON_STATS, + + TRANFER_ENV, // = 'X' + + TEXT, + STATUS_TEXT, // = 'Z' + GET_INTERNALS, + + // S --> CS, answered by LOGIN + CS_CONF, + + // C --> CS, after installing an environment + VERIFY_ENV, + // CS --> C + VERIFY_ENV_RESULT, + // C --> CS, CS --> S (forwarded from C), to not use given host for given environment + BLACKLIST_HOST_ENV, + // S --> CS + NO_CS + }; + + Msg() = default; + constexpr Msg(Value value) + : value_{value} + {} + + constexpr operator Value() const { return value_; } + explicit operator bool() = delete; + + std::basic_string to_string() const { + switch (value_) { + case UNKNOWN: + return "UNKNOWN"; + case PING: + return "PING"; + case END: + return "END"; + case TIMEOUT: + return "TIMEOUT"; + case GET_NATIVE_ENV: + return "GET_NATIVE_ENV"; + case NATIVE_ENV: + return "NATIVE_ENV"; + case GET_CS: + return "GET_CS"; + case USE_CS: + return "USE_CS"; + case COMPILE_FILE: + return "COMPILE_FILE"; + case FILE_CHUNK: + return "FILE_CHUNK"; + case COMPILE_RESULT: + return "COMPILE_RESULT"; + case JOB_BEGIN: + return "JOB_BEGIN"; + case JOB_DONE: + return "JOB_DONE"; + case JOB_LOCAL_BEGIN: + return "JOB_LOCAL_BEGIN"; + case JOB_LOCAL_DONE: + return "JOB_LOCAL_DONE"; + case LOGIN: + return "LOGIN"; + case STATS: + return "STATS"; + case MON_LOGIN: + return "MON_LOGIN"; + case MON_GET_CS: + return "MON_GET_CS"; + case MON_JOB_BEGIN: + return "MON_JOB_BEGIN"; + case MON_JOB_DONE: + return "MON_JOB_DONE"; + case MON_LOCAL_JOB_BEGIN: + return "MON_LOCAL_JOB_BEGIN"; + case MON_STATS: + return "MON_STATS"; + case TRANFER_ENV: + return "TRANFER_ENV"; + case TEXT: + return "TEXT"; + case STATUS_TEXT: + return "STATUS_TEXT"; + case GET_INTERNALS: + return "GET_INTERNALS"; + case CS_CONF: + return "CS_CONF"; + case VERIFY_ENV: + return "VERIFY_ENV"; + case VERIFY_ENV_RESULT: + return "VERIFY_ENV_RESULT"; + case BLACKLIST_HOST_ENV: + return "BLACKLIST_HOST_ENV"; + case NO_CS: + return "NO_CS"; + } + return nullptr; + } + + virtual ~Msg() {} + virtual void fill_from_channel(MsgChannel *c); + virtual void send_to_channel(MsgChannel *c) const; + +private: + Value value_; }; enum Compression { @@ -155,24 +245,9 @@ const int NODE_FEATURE_ENV_XZ = ( 1 << 0 ); // The remote node is capable of unpacking environment compressed as .tar.zst . const int NODE_FEATURE_ENV_ZSTD = ( 1 << 1 ); -class MsgChannel; - // a list of pairs of host platform, filename typedef std::list > Environments; -class Msg -{ -public: - Msg(enum MsgType t) - : type(t) {} - virtual ~Msg() {} - - virtual void fill_from_channel(MsgChannel *c); - virtual void send_to_channel(MsgChannel *c) const; - - enum MsgType type; -}; - class MsgChannel { public: @@ -402,21 +477,21 @@ class PingMsg : public Msg { public: PingMsg() - : Msg(M_PING) {} + : Msg(Msg::PING) {} }; class EndMsg : public Msg { public: EndMsg() - : Msg(M_END) {} + : Msg(Msg::END) {} }; class GetCSMsg : public Msg { public: GetCSMsg() - : Msg(M_GET_CS) + : Msg(Msg::GET_CS) , count(1) , arg_flags(0) , client_id(0) @@ -453,10 +528,10 @@ class UseCSMsg : public Msg { public: UseCSMsg() - : Msg(M_USE_CS) {} + : Msg(Msg::USE_CS) {} UseCSMsg(std::string platform, std::string host, unsigned int p, unsigned int id, bool gotit, unsigned int _client_id, unsigned int matched_host_jobs) - : Msg(M_USE_CS), + : Msg(Msg::USE_CS), job_id(id), hostname(host), port(p), @@ -481,9 +556,9 @@ class NoCSMsg : public Msg { public: NoCSMsg() - : Msg(M_NO_CS) {} + : Msg(Msg::NO_CS) {} NoCSMsg(unsigned int id, unsigned int _client_id) - : Msg(M_NO_CS), + : Msg(Msg::NO_CS), job_id(id), client_id(_client_id) {} @@ -498,11 +573,11 @@ class GetNativeEnvMsg : public Msg { public: GetNativeEnvMsg() - : Msg(M_GET_NATIVE_ENV) {} + : Msg(Msg::GET_NATIVE_ENV) {} GetNativeEnvMsg(const std::string &c, const std::list &e, const std::string &comp) - : Msg(M_GET_NATIVE_ENV) + : Msg(Msg::GET_NATIVE_ENV) , compiler(c) , extrafiles(e) , compression(comp) @@ -520,10 +595,10 @@ class UseNativeEnvMsg : public Msg { public: UseNativeEnvMsg() - : Msg(M_NATIVE_ENV) {} + : Msg(Msg::NATIVE_ENV) {} UseNativeEnvMsg(std::string _native) - : Msg(M_NATIVE_ENV) + : Msg(Msg::NATIVE_ENV) , nativeVersion(_native) {} virtual void fill_from_channel(MsgChannel *c); @@ -536,7 +611,7 @@ class CompileFileMsg : public Msg { public: CompileFileMsg(CompileJob *j, bool delete_job = false) - : Msg(M_COMPILE_FILE) + : Msg(Msg::COMPILE_FILE) , deleteit(delete_job) , job(j) {} @@ -562,13 +637,13 @@ class FileChunkMsg : public Msg { public: FileChunkMsg(unsigned char *_buffer, size_t _len) - : Msg(M_FILE_CHUNK) + : Msg(Msg::FILE_CHUNK) , buffer(_buffer) , len(_len) , del_buf(false) {} FileChunkMsg() - : Msg(M_FILE_CHUNK) + : Msg(Msg::FILE_CHUNK) , buffer(0) , len(0) , del_buf(true) {} @@ -592,7 +667,7 @@ class CompileResultMsg : public Msg { public: CompileResultMsg() - : Msg(M_COMPILE_RESULT) + : Msg(Msg::COMPILE_RESULT) , status(0) , was_out_of_memory(false) , have_dwo_file(false) {} @@ -611,11 +686,11 @@ class JobBeginMsg : public Msg { public: JobBeginMsg() - : Msg(M_JOB_BEGIN) + : Msg(Msg::JOB_BEGIN) , client_count(0) {} JobBeginMsg(unsigned int j, unsigned int _client_count) - : Msg(M_JOB_BEGIN) + : Msg(Msg::JOB_BEGIN) , job_id(j) , stime(time(0)) , client_count(_client_count) {} @@ -687,7 +762,7 @@ class JobLocalBeginMsg : public Msg { public: JobLocalBeginMsg(int job_id = 0, const std::string &file = "", bool full = false) - : Msg(M_JOB_LOCAL_BEGIN) + : Msg(Msg::JOB_LOCAL_BEGIN) , outfile(file) , stime(time(0)) , id(job_id) @@ -706,7 +781,7 @@ class JobLocalDoneMsg : public Msg { public: JobLocalDoneMsg(unsigned int id = 0) - : Msg(M_JOB_LOCAL_DONE) + : Msg(Msg::JOB_LOCAL_DONE) , job_id(id) {} virtual void fill_from_channel(MsgChannel *c); @@ -721,7 +796,7 @@ class LoginMsg : public Msg LoginMsg(unsigned int myport, const std::string &_nodename, const std::string &_host_platform, unsigned int my_features); LoginMsg() - : Msg(M_LOGIN) + : Msg(Msg::LOGIN) , port(0) {} virtual void fill_from_channel(MsgChannel *c); @@ -741,7 +816,7 @@ class ConfCSMsg : public Msg { public: ConfCSMsg() - : Msg(M_CS_CONF) + : Msg(Msg::CS_CONF) , max_scheduler_pong(MAX_SCHEDULER_PONG) , max_scheduler_ping(MAX_SCHEDULER_PING) {} @@ -756,7 +831,7 @@ class StatsMsg : public Msg { public: StatsMsg() - : Msg(M_STATS) + : Msg(Msg::STATS) , load(0) , client_count(0) { @@ -788,10 +863,10 @@ class EnvTransferMsg : public Msg { public: EnvTransferMsg() - : Msg(M_TRANFER_ENV) {} + : Msg(Msg::TRANFER_ENV) {} EnvTransferMsg(const std::string &_target, const std::string &_name) - : Msg(M_TRANFER_ENV) + : Msg(Msg::TRANFER_ENV) , name(_name) , target(_target) {} @@ -806,17 +881,17 @@ class GetInternalStatus : public Msg { public: GetInternalStatus() - : Msg(M_GET_INTERNALS) {} + : Msg(Msg::GET_INTERNALS) {} GetInternalStatus(const GetInternalStatus &) - : Msg(M_GET_INTERNALS) {} + : Msg(Msg::GET_INTERNALS) {} }; class MonLoginMsg : public Msg { public: MonLoginMsg() - : Msg(M_MON_LOGIN) {} + : Msg(Msg::MON_LOGIN) {} }; class MonGetCSMsg : public GetCSMsg @@ -825,7 +900,6 @@ class MonGetCSMsg : public GetCSMsg MonGetCSMsg() : GetCSMsg() { // overwrite - type = M_MON_GET_CS; clientid = job_id = 0; } @@ -833,9 +907,7 @@ class MonGetCSMsg : public GetCSMsg : GetCSMsg(Environments(), m->filename, m->lang, 1, m->target, 0, std::string(), false, m->client_count, m->niceness) , job_id(jobid) , clientid(hostid) - { - type = M_MON_GET_CS; - } + {} virtual void fill_from_channel(MsgChannel *c); virtual void send_to_channel(MsgChannel *c) const; @@ -848,13 +920,13 @@ class MonJobBeginMsg : public Msg { public: MonJobBeginMsg() - : Msg(M_MON_JOB_BEGIN) + : Msg(Msg::MON_JOB_BEGIN) , job_id(0) , stime(0) , hostid(0) {} MonJobBeginMsg(unsigned int id, unsigned int time, int _hostid) - : Msg(M_MON_JOB_BEGIN) + : Msg(Msg::MON_JOB_BEGIN) , job_id(id) , stime(time) , hostid(_hostid) {} @@ -872,25 +944,21 @@ class MonJobDoneMsg : public JobDoneMsg public: MonJobDoneMsg() : JobDoneMsg() - { - type = M_MON_JOB_DONE; - } + {} MonJobDoneMsg(const JobDoneMsg &o) : JobDoneMsg(o) - { - type = M_MON_JOB_DONE; - } + {} }; class MonLocalJobBeginMsg : public Msg { public: MonLocalJobBeginMsg() - : Msg(M_MON_LOCAL_JOB_BEGIN) {} + : Msg(Msg::MON_LOCAL_JOB_BEGIN) {} MonLocalJobBeginMsg(unsigned int id, const std::string &_file, unsigned int time, int _hostid) - : Msg(M_MON_LOCAL_JOB_BEGIN) + : Msg(Msg::MON_LOCAL_JOB_BEGIN) , job_id(id) , stime(time) , hostid(_hostid) @@ -909,10 +977,10 @@ class MonStatsMsg : public Msg { public: MonStatsMsg() - : Msg(M_MON_STATS) {} + : Msg(Msg::MON_STATS) {} MonStatsMsg(int id, const std::string &_statmsg) - : Msg(M_MON_STATS) + : Msg(Msg::MON_STATS) , hostid(id) , statmsg(_statmsg) {} @@ -927,14 +995,14 @@ class TextMsg : public Msg { public: TextMsg() - : Msg(M_TEXT) {} + : Msg(Msg::TEXT) {} TextMsg(const std::string &_text) - : Msg(M_TEXT) + : Msg(Msg::TEXT) , text(_text) {} TextMsg(const TextMsg &m) - : Msg(M_TEXT) + : Msg(Msg::TEXT) , text(m.text) {} virtual void fill_from_channel(MsgChannel *c); @@ -947,10 +1015,10 @@ class StatusTextMsg : public Msg { public: StatusTextMsg() - : Msg(M_STATUS_TEXT) {} + : Msg(Msg::STATUS_TEXT) {} StatusTextMsg(const std::string &_text) - : Msg(M_STATUS_TEXT) + : Msg(Msg::STATUS_TEXT) , text(_text) {} virtual void fill_from_channel(MsgChannel *c); @@ -963,10 +1031,10 @@ class VerifyEnvMsg : public Msg { public: VerifyEnvMsg() - : Msg(M_VERIFY_ENV) {} + : Msg(Msg::VERIFY_ENV) {} VerifyEnvMsg(const std::string &_target, const std::string &_environment) - : Msg(M_VERIFY_ENV) + : Msg(Msg::VERIFY_ENV) , environment(_environment) , target(_target) {} @@ -981,10 +1049,10 @@ class VerifyEnvResultMsg : public Msg { public: VerifyEnvResultMsg() - : Msg(M_VERIFY_ENV_RESULT) {} + : Msg(Msg::VERIFY_ENV_RESULT) {} VerifyEnvResultMsg(bool _ok) - : Msg(M_VERIFY_ENV_RESULT) + : Msg(Msg::VERIFY_ENV_RESULT) , ok(_ok) {} virtual void fill_from_channel(MsgChannel *c); @@ -997,10 +1065,10 @@ class BlacklistHostEnvMsg : public Msg { public: BlacklistHostEnvMsg() - : Msg(M_BLACKLIST_HOST_ENV) {} + : Msg(Msg::BLACKLIST_HOST_ENV) {} BlacklistHostEnvMsg(const std::string &_target, const std::string &_environment, const std::string &_hostname) - : Msg(M_BLACKLIST_HOST_ENV) + : Msg(Msg::BLACKLIST_HOST_ENV) , environment(_environment) , target(_target) , hostname(_hostname) {}