From d0caf9185b801e0474814a2727b51be96aaf54b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eckl=2C=20M=C3=A1t=C3=A9?= <ecklm94@gmail.com> Date: Thu, 26 May 2016 14:55:38 +0200 Subject: [PATCH] =?UTF-8?q?Utas=C3=ADt=C3=A1sok=20=C3=A1ltal=C3=A1nos?= =?UTF-8?q?=C3=ADt=C3=A1sa=20(#1)(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/command.h | 37 +++++++++++++++++++++++++++++++++++++ main.cpp | 22 ++++++++++++++++------ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 include/command.h diff --git a/include/command.h b/include/command.h new file mode 100644 index 0000000..f65284c --- /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 b1aa7e4..cd5b0d3 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 +} -- GitLab