Skip to content
Snippets Groups Projects
Commit d0caf918 authored by dnsadmin's avatar dnsadmin
Browse files

Utasítások általánosítása (#1)(#8)

parent 263d9123
No related branches found
No related tags found
No related merge requests found
/*
* 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 */
......@@ -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");
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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment