diff --git a/include/command.h b/include/command.h new file mode 100644 index 0000000000000000000000000000000000000000..f65284c0a756c817882721012223b1c315d1915e --- /dev/null +++ b/include/command.h @@ -0,0 +1,37 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/* + * File: command.h + * Author: Eckl Máté <ecklm94@gmail.com> + * + * Created on 2016. május 26., 14:50 + */ + +#ifndef COMMAND_H +#define COMMAND_H + +enum command +{ + MONITOR, STATISTICS, KILL +}; + +/** + * Returns the readable version of command + * @param c command to convert to string + * @return The string command or "" by default + */ +const char *get_readable_command(command c) { + switch(c) + { + case MONITOR: return "monitor"; + case STATISTICS: return "statistics"; + case KILL: return "kill"; + default: return ""; + } +} + +#endif /* COMMAND_H */ diff --git a/main.cpp b/main.cpp index b1aa7e47515c27591c7e4d34febdc1c536dc413a..cd5b0d318aef9b74daad14c906a0ea71b8bf1e9d 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,7 @@ #include "include/exceptions/db_exception.h" #include "include/logger.h" #include "include/IPC_US_communicator.h" +#include "include/command.h" #define WORKING_DIR "/home/mate/Dokumentumok/Egyetem/Tárgyak/2016 tavasz/Linux programozás/HF/DNS_server" #define COMM_SOCK_PATH "/var/run/ecklm-dns/" @@ -32,6 +33,7 @@ int main(int argc, char *argv[]) { int cli_option; bool run_as_daemon = false; + std::vector<command> command_list; while((cli_option = getopt (argc, argv, "dmskvh")) != -1) { switch(cli_option) @@ -40,13 +42,13 @@ int main(int argc, char *argv[]) run_as_daemon = true; break; case 'm': - throw "Not implemented"; + command_list.push_back(MONITOR); break; case 's': - throw "Not implemented"; + command_list.push_back(STATISTICS); break; case 'k': - throw "Not implemented"; + command_list.push_back(KILL); break; case 'v': verbose = true; @@ -107,8 +109,16 @@ int main(int argc, char *argv[]) IPC_US_communicator comm_link(COMM_SOCK_PATH, run_as_daemon); if(!run_as_daemon) { - comm_link.send_data("shutdown"); - log_on_demand(LOG_INFO, "Answer received: %s", comm_link.recv_data().c_str()); + if(command_list.empty()) + { + log_on_demand(LOG_ERR, "In this mode you must specify at least one command!"); + exit(EXIT_FAILURE); + } + for(command c : command_list) + { + comm_link.send_data(get_readable_command(c)); + log_on_demand(LOG_INFO, "Answer received: %s", comm_link.recv_data().c_str()); + } exit(EXIT_SUCCESS); } @@ -187,4 +197,4 @@ Options: void kill_handler(int x) { log_on_demand(LOG_INFO, "SIGTERM received"); exit(EXIT_SUCCESS); -} \ No newline at end of file +}