diff --git a/src/Common/Command.h b/src/Common/Command.h index af2f1c9..8d08d45 100644 --- a/src/Common/Command.h +++ b/src/Common/Command.h @@ -19,6 +19,7 @@ class Command { bool is_malformed; bool is_internal; bool do_not_queue; + bool add_and_run; Command(); string line(); diff --git a/src/Common/Protocol.cpp b/src/Common/Protocol.cpp index 4bbe43a..ebdbd2c 100644 --- a/src/Common/Protocol.cpp +++ b/src/Common/Protocol.cpp @@ -30,6 +30,7 @@ Command Protocol::parse(const string &data) { cmd.interval = lexical_cast(packet[3]); cmd.timeout = lexical_cast(packet[4]); cmd.do_not_queue = packet[5] == "1"; + cmd.add_and_run = packet[6] == "1"; cmd.is_malformed = false; } } @@ -48,6 +49,7 @@ string Protocol::build(const Command &cmd) { packet.push_back(lexical_cast(cmd.interval)); packet.push_back(lexical_cast(cmd.timeout)); packet.push_back(cmd.do_not_queue ? "1" : "0"); + packet.push_back(cmd.add_and_run ? "1" : "0"); packet.push_back(""); return join(packet, PROTOCOL_DELIMITER); diff --git a/src/Common/Protocol.h b/src/Common/Protocol.h index 8a44db8..86ae975 100644 --- a/src/Common/Protocol.h +++ b/src/Common/Protocol.h @@ -6,7 +6,7 @@ #define PROTOCOL_HEADER "cgi4lcd" #define PROTOCOL_DELIMITER "|" -#define PROTOCOL_EXPECTED_SIZE 7 +#define PROTOCOL_EXPECTED_SIZE 8 using namespace std; diff --git a/src/Plugin/Client.cpp b/src/Plugin/Client.cpp index c87c2c0..e4acf90 100644 --- a/src/Plugin/Client.cpp +++ b/src/Plugin/Client.cpp @@ -16,6 +16,7 @@ unsigned int Client::_execution_interval(0); unsigned int Client::_execution_timeout(0); int Client::_refresh_interval(0); string Client::_default_extension(""); +bool Client::_add_and_run(false); void Client::start() { _app_path = Utils::app_path(); @@ -26,6 +27,7 @@ void Client::start() { _execution_timeout = lexical_cast(Utils::ini_read(_ini_file, "cgi4lcd.timeout", "30000")); _default_extension = Utils::ini_read(_ini_file, "cgi4lcd.default_extension", ""); _refresh_interval = lexical_cast(Utils::ini_read(_ini_file, "cgi4lcd.refresh", "1000")); + _add_and_run = Utils::ini_read(_ini_file, "cgi4lcd.add_and_run", "1") == "1"; } string Client::execute(string script, const string ¶meters, bool version, bool do_not_queue) { @@ -97,6 +99,7 @@ string Client::request(const string &interpreter, const string &arguments, unsig cmd.interval = interval; cmd.timeout = timeout; cmd.do_not_queue = do_not_queue; + cmd.add_and_run = _add_and_run; string buffer(""); diff --git a/src/Plugin/Client.h b/src/Plugin/Client.h index a23772f..50411d1 100644 --- a/src/Plugin/Client.h +++ b/src/Plugin/Client.h @@ -17,6 +17,7 @@ class Client { static unsigned int _execution_timeout; static int _refresh_interval; static string _default_extension; + static bool _add_and_run; static void start(); static string execute(string script, const string ¶meters, bool version=false, bool do_not_queue=false); diff --git a/src/Server/Queue.cpp b/src/Server/Queue.cpp index 2bbf08d..56a4272 100644 --- a/src/Server/Queue.cpp +++ b/src/Server/Queue.cpp @@ -12,7 +12,7 @@ Queue::Queue(boost::asio::io_service& io_service) : } -void Queue::add(Command &cmd, bool add_and_run) { +void Queue::add(Command &cmd) { map::iterator it = _commands.find(cmd.line()); @@ -20,7 +20,7 @@ void Queue::add(Command &cmd, bool add_and_run) { cmd.response = ""; _commands[cmd.line()] = cmd; - if (add_and_run) { + if (cmd.add_and_run) { _commands[cmd.line()].run(); } } diff --git a/src/Server/Queue.h b/src/Server/Queue.h index f422c80..37655ca 100644 --- a/src/Server/Queue.h +++ b/src/Server/Queue.h @@ -11,7 +11,7 @@ class Queue { public: Queue(boost::asio::io_service& io_service); - void add(Command &cmd, bool add_and_run); + void add(Command &cmd); void run(); Command get(const string& line); diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index e0dfef1..e8d5a59 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -6,11 +6,10 @@ using namespace std; -Server::Server(boost::asio::io_service& io_service, short port, bool add_and_run) : +Server::Server(boost::asio::io_service& io_service, short port) : _io_service(io_service), _socket(io_service, udp::endpoint(boost::asio::ip::address::from_string("127.0.0.1"), port)), - _queue(io_service), - _add_and_run(add_and_run) + _queue(io_service) { receive(); @@ -29,7 +28,7 @@ void Server::handle_receive_from(const boost::system::error_code& error, size_t cmd.run(); } else { - _queue.add(cmd, _add_and_run); + _queue.add(cmd); cmd = _queue.get(cmd.line()); } diff --git a/src/Server/Server.h b/src/Server/Server.h index 9aa874c..433a5cb 100644 --- a/src/Server/Server.h +++ b/src/Server/Server.h @@ -15,11 +15,10 @@ class Server udp::socket _socket; Queue _queue; udp::endpoint _sender_endpoint; - bool _add_and_run; enum { max_length = 1024 }; char _data[max_length]; - Server(boost::asio::io_service& io_service, short port, bool add_and_run); + Server(boost::asio::io_service& io_service, short port); void handle_receive_from(const boost::system::error_code& error, size_t bytes_recvd); void handle_send_to(const boost::system::error_code& error, size_t bytes_sent); void receive(); diff --git a/src/Server/main.cpp b/src/Server/main.cpp index 28c8fe4..b31b1e8 100644 --- a/src/Server/main.cpp +++ b/src/Server/main.cpp @@ -8,7 +8,6 @@ int main(int argc, char* argv[]) { string ini_file(Utils::app_path() + "\\..\\scripts\\cgi4lcd.ini"); unsigned int port = lexical_cast(Utils::ini_read(ini_file, "cgi4lcd.port", "65432")); - bool add_and_run = Utils::ini_read(ini_file, "cgi4lcd.add_and_run", "1") == "1"; #ifndef DEBUG HWND hWnd = GetConsoleWindow(); @@ -17,7 +16,7 @@ int main(int argc, char* argv[]) { try { boost::asio::io_service io_service; - Server s(io_service, port, add_and_run); + Server s(io_service, port); io_service.run(); } catch (std::exception& e) {