Added the client_function timeout to the code.
Also noticed a BIG bug in the screen_set code, the strcmp's never worked, they where no longer checking the results == 0.
This commit is contained in:
+29
-11
@@ -589,9 +589,9 @@ screen_set_func (client * c, int argc, char **argv)
|
||||
p = argv[i];
|
||||
if (*p == '-')
|
||||
p++;
|
||||
|
||||
|
||||
// Handle the "name" parameter
|
||||
if (strcmp (p, "name")) {
|
||||
if (strcmp (p, "name") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug ("screen_set: name=\"%s\"\n", argv[i]);
|
||||
@@ -606,7 +606,7 @@ screen_set_func (client * c, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
// Handle the "priority" parameter
|
||||
else if (strcmp (p, "priority")) {
|
||||
else if (strcmp (p, "priority") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug ("screen_set: priority=\"%s\"\n", argv[i]);
|
||||
@@ -621,7 +621,7 @@ screen_set_func (client * c, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
// Handle the "duration" parameter
|
||||
else if (strcmp (p, "duration")) {
|
||||
else if (strcmp (p, "duration") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug ("screen_set: duration=\"%s\"\n", argv[i]);
|
||||
@@ -636,7 +636,7 @@ screen_set_func (client * c, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
// Handle the "heartbeat" parameter
|
||||
else if (strcmp (p, "heartbeat")) {
|
||||
else if (strcmp (p, "heartbeat") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug ("screen_set: heartbeat=\"%s\"\n", argv[i]);
|
||||
@@ -662,7 +662,7 @@ screen_set_func (client * c, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
// Handle the "wid" parameter
|
||||
else if (strcmp (p, "wid")) {
|
||||
else if (strcmp (p, "wid") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug ("screen_set: wid=\"%s\"\n", argv[i]);
|
||||
@@ -675,9 +675,10 @@ screen_set_func (client * c, int argc, char **argv)
|
||||
} else {
|
||||
sock_send_string (c->sock, "huh? -wid requires a parameter\n");
|
||||
}
|
||||
|
||||
}
|
||||
// Handle the "hgt" parameter
|
||||
else if (strcmp (p, "hgt")) {
|
||||
else if (strcmp (p, "hgt") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
debug ("screen_set: hgt=\"%s\"\n", argv[i]);
|
||||
@@ -690,11 +691,28 @@ screen_set_func (client * c, int argc, char **argv)
|
||||
} else {
|
||||
sock_send_string (c->sock, "huh? -hgt requires a parameter\n");
|
||||
}
|
||||
} else {
|
||||
sock_send_string (c->sock, "huh? invalid parameter\n");
|
||||
}
|
||||
} // done checking argv
|
||||
|
||||
// Handle the "timeout" parameter
|
||||
else if (strcmp (p, "timeout") == 0) {
|
||||
if (argc > i + 1) {
|
||||
i++;
|
||||
syslog(LOG_NOTICE, "Setting timeout.");
|
||||
debug ("screen_set: timeout=\"%s\"\n", argv[i]);
|
||||
// set the duration...
|
||||
number = atoi (argv[i]);
|
||||
// Add the timeout value (count of TIME_UNITS)
|
||||
// to struct, TIME_UNIT is 1/8th of a second
|
||||
if (number > 0) {
|
||||
s->timeout = number;
|
||||
syslog(LOG_NOTICE, "Timeout set.");
|
||||
}
|
||||
sock_send_string(c->sock, "success\n");
|
||||
} else {
|
||||
sock_send_string (c->sock, "huh? -timeout requires a parameter\n");
|
||||
}
|
||||
}
|
||||
else sock_send_string (c->sock, "huh? invalid parameter\n");
|
||||
}// done checking argv
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -565,6 +565,8 @@ void
|
||||
do_mainloop ()
|
||||
{
|
||||
screen *s = NULL;
|
||||
char *message=NULL;
|
||||
|
||||
//char buf[64];
|
||||
|
||||
// FIXME: s should still be null from initialization.... what's happening here?!
|
||||
@@ -616,6 +618,38 @@ do_mainloop ()
|
||||
no_screen_screen (timer);
|
||||
|
||||
usleep (TIME_UNIT);
|
||||
|
||||
//Check to see if the screen has a timeout value, if it does
|
||||
//decrese it and then check to see if it has excpired.
|
||||
//Remove if expired.
|
||||
if((message = malloc(256)) == NULL)
|
||||
syslog(LOG_NOTICE, "Error allocating message string");
|
||||
else {
|
||||
snprintf(message, 256, "Screen->%s has timeout->%d", s->name, s->timeout);
|
||||
syslog(LOG_NOTICE, message);
|
||||
free(message);
|
||||
}
|
||||
if (s && s->timeout != -1) {
|
||||
|
||||
--(s->timeout);
|
||||
if((message = malloc(256)) == NULL)
|
||||
syslog(LOG_NOTICE, "Error allocating message string");
|
||||
else {
|
||||
snprintf(message, 256, "Timeout matches check, has timeout->%d", s->name, s->timeout);
|
||||
syslog(LOG_NOTICE, message);
|
||||
free(message);
|
||||
}
|
||||
if (s->timeout <= 0) {
|
||||
screen_remove (s->parent, s->id);
|
||||
if((message = malloc(256)) == NULL)
|
||||
syslog(LOG_NOTICE, "Error allocating message string");
|
||||
else {
|
||||
snprintf(message, 256, "Removing screen %s which has timeout->%d", s->name, s->timeout);
|
||||
syslog(LOG_NOTICE, message);
|
||||
free(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Quit!
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "main.h"
|
||||
|
||||
int default_duration = 0;
|
||||
int default_timeout = -1;
|
||||
|
||||
screen *
|
||||
screen_create ()
|
||||
@@ -36,6 +37,7 @@ screen_create ()
|
||||
s->keys = NULL;
|
||||
s->parent = NULL;
|
||||
s->widgets = NULL;
|
||||
s->timeout = default_timeout; //ignored unless greater than 0.
|
||||
|
||||
s->widgets = LL_new ();
|
||||
if (!s->widgets) {
|
||||
|
||||
@@ -11,6 +11,7 @@ typedef struct screen {
|
||||
int priority;
|
||||
int duration;
|
||||
int heartbeat;
|
||||
int timeout;
|
||||
char *keys;
|
||||
LinkedList *widgets;
|
||||
client *parent;
|
||||
|
||||
Reference in New Issue
Block a user