Skip to content

Commit

Permalink
Fixing conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mendelgusmao committed Mar 9, 2012
2 parents 55ea5b7 + 225b9de commit dd8b77e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ CONFIGURING
> The first section is [cgi4lcd]. It has the following attributes:
> * interval (numeric, milliseconds)
> * interval (numeric, seconds)
> Value to tell the server of how often a command it will be executed
> * timeout (numeric, milliseconds)
> * timeout (numeric, seconds)
> Value to tell the server of how long after the command is not requested anymore by the plugin to be removed from the queue
> * refresh (numeric, milliseconds)
> * refresh (numeric, seconds)
> Value to tell LCD Smartie how often it will request data from plugin
> * port (numeric, 1-65535)
Expand All @@ -65,9 +65,6 @@ CONFIGURING
> * default_extension (text)
> The default file extension to be considered by the plugin if not specified in the filename passed to $dll
> * show_window (boolean, 0-1)
> If the value is 1, the server window will appear when it's executed, showing the queue processing and incoming requests
> * add_and_run (boolean, 0-1)
> If the value is 1, the server will execute the command right after it is added to the queue. If not, the server will await the configured interval to run the command and will be returning an empty response until it happens.
Expand Down Expand Up @@ -102,7 +99,7 @@ CONFIGURING
> * version
> Command line to get the interpreter version
> CGI4LCD comes with the basic settings to run PHP, Ruby, Python and Perl scripts. You must only change the interpreter path and it will be ready to use.
> CGI4LCD comes with the basic settings to run PHP, Ruby, Python, Lua and Perl scripts. You must only change the interpreter path and it will be ready to use.
USING
-----
Expand Down Expand Up @@ -168,7 +165,7 @@ BUNDLED LANGUAGES (ROUTERS + BASIC CONFIGURATION)

> ### PHP · PYTHON · RUBY · PERL · LUA
> Or... Write your own. I'll be glad to add your contribution to the project
> Or... Write your own. I'll be glad to add your contribution to the project.
LANGUAGE SPECIFICS
------------------
Expand All @@ -182,7 +179,7 @@ LANGUAGE SPECIFICS
> `from routers import main`
> ### Lua
> The interpreter can't load a module by its full path using the "-l" command line parameter. Copy **[*LCD Smartie installation dir*]\scripts\router\lua.lua** to *[Lua installation dir]*\lua before using CGI4LCD with lua.
> The interpreter can't load a module by its full path using the "-l" command line parameter. Copy **[*LCD Smartie installation dir*]\scripts\router\lua.lua** to *[Lua installation dir]*\lua before using CGI4LCD with Lua.
> ### Perl
> The interpreter can't load a module by its full path. Instead, the path to routers directory is passed using "-I" parameter. When writing a Perl script, put on the first line:
Expand All @@ -202,7 +199,7 @@ TODO
> * Add better support to Unicode strings
> * Rewrite almost every function or method to use char* instead of strings
> * Make the plugin run cgi4lcd.exe if it's not being executed
> * In the future, abandon the server and begin using threads
> * In the future, drop the server-client architecture and make the plugin use threads to do the server work
> * Allow configuration of interval/timeout per-language, per-script and per-function
> * *[Your suggestion here]*
Expand Down
6 changes: 3 additions & 3 deletions scripts/cgi4lcd.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[cgi4lcd]
timeout=30000
interval=15000
timeout=30
interval=15
refresh=1
port=65432
default_extension="php"
show_window=0
add_and_run=1

[php]
Expand Down
8 changes: 4 additions & 4 deletions src/Common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

using std::string;

Command::Command() :
timer(0),
cleanup_timer(0)
{}
Command::Command() {
time(&last_execution);
time(&last_request);
}

string Command::line() {
return executable + " " + arguments;
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Command {
string arguments;
unsigned int timeout;
unsigned int interval;
unsigned int timer;
unsigned int cleanup_timer;
time_t last_execution;
time_t last_request;
string response;
bool is_malformed;
bool is_internal;
Expand Down
21 changes: 12 additions & 9 deletions src/Server/Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ Queue::Queue(boost::asio::io_service& io_service) :
void Queue::add(Command &cmd) {

map<string, Command>::iterator it = _commands.find(cmd.line());
time_t now;
time(&now);

if (it == _commands.end()) {
cmd.response = "";
cmd.last_request = now;

_commands[cmd.line()] = cmd;

if (cmd.add_and_run) {
_commands[cmd.line()].run();
}
}
else {
_commands[cmd.line()].cleanup_timer = 0;
_commands[cmd.line()].last_request = now;
}
}

void Queue::run() {

map<string, Command>::iterator it;
Command cmd;
int queue_size = _commands.size();

_timer.expires_at(_timer.expires_at() + boost::posix_time::seconds(1));
_timer.async_wait(boost::bind(&Queue::run, this));
Expand All @@ -49,25 +52,25 @@ void Queue::run() {
for (it = _commands.begin(); it != _commands.end(); ++it) {
cmd = it->second;

cmd.timer += 1000;
cmd.cleanup_timer += 1000;
time_t now;
time(&now);

echo("Command '" << cmd.line() << "'");
echo("Cleanup/Timeout: " << cmd.cleanup_timer << "/" << cmd.timeout);
echo("Timer/Interval: " << cmd.timer << "/" << cmd.interval);
echo("Cleanup Time: " << cmd.last_request << " + " << cmd.timeout);
echo("Next Execution: " << cmd.last_execution << " + " << cmd.interval);
echo("Cached Response: '" << cmd.response << "'");

if (cmd.cleanup_timer >= cmd.timeout) {
if (now >= cmd.last_request + cmd.timeout) {
echo("Erasing '" << cmd.line() << "'");

_commands.erase(it);
return;
}
else if (cmd.timer >= cmd.interval) {
else if (now >= cmd.last_execution + cmd.interval) {
echo("Running '" << cmd.line() << "'");

cmd.run();
cmd.timer = 0;
time(&cmd.last_execution);

echo(cmd.response);

Expand Down

0 comments on commit dd8b77e

Please sign in to comment.