summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphintuka <phintuka>2009-12-29 14:08:11 +0000
committerphintuka <phintuka>2009-12-29 14:08:11 +0000
commit94e81bd9dba191fbc8eee878c9ef7930c270355a (patch)
treec95edcace44062d42354b02a0ca57dbea24c82df
parent1eeb1b5533bb47121801bebd5bf0068648a39c63 (diff)
downloadxineliboutput-94e81bd9dba191fbc8eee878c9ef7930c270355a.tar.gz
xineliboutput-94e81bd9dba191fbc8eee878c9ef7930c270355a.tar.bz2
Added system shutdown functionality
-rw-r--r--xine_frontend.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/xine_frontend.c b/xine_frontend.c
index 216a1e78..6703b0a9 100644
--- a/xine_frontend.c
+++ b/xine_frontend.c
@@ -4,7 +4,7 @@
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
- * $Id: xine_frontend.c,v 1.105 2009-12-29 13:56:14 phintuka Exp $
+ * $Id: xine_frontend.c,v 1.106 2009-12-29 14:08:11 phintuka Exp $
*
*/
@@ -92,6 +92,19 @@ static int guess_cpu_count(void)
return cores;
}
+static void shutdown_system(char *cmd, int user_requested)
+{
+ const char *reason = user_requested ? "User requested system shutdown" : "Inactivity timer elapsed";
+
+ if (cmd) {
+ LOGMSG("%s. Executing '%s'", reason, cmd);
+ if (-1 == system(cmd))
+ LOGERR("Can't execute %s", cmd);
+ } else {
+ LOGMSG("%s, power off comand undefined!", reason);
+ }
+}
+
/*
* list available plugins
*/
@@ -744,6 +757,18 @@ static int fe_xine_init(frontend_t *this_gen, const char *audio_driver,
return 1;
}
+static void fe_shutdown_init(frontend_t *this_gen, const char *cmd, int timeout)
+{
+ fe_t *this = (fe_t*)this_gen;
+
+ free(this->shutdown_cmd);
+
+ this->shutdown_cmd = cmd ? strdup(cmd) : NULL;
+ this->shutdown_timeout = timeout;
+
+ this->shutdown_time = (timeout <= 0) ? (time_t)-1 : time(NULL) + timeout;
+}
+
/*
* fe_xine_open
*
@@ -1203,6 +1228,7 @@ static void fe_free(frontend_t *this_gen)
fe_t *this = (fe_t*)this_gen;
this->fe.fe_display_close(this_gen);
free(this->configfile);
+ free(this->shutdown_cmd);
free(this);
}
}
@@ -1223,6 +1249,14 @@ static int fe_is_finished(frontend_t *this_gen, int slave_stream)
return FE_XINE_EXIT;
}
+ /* check inactivity timer */
+ if (this->shutdown_timeout > 0) {
+ if (this->shutdown_time < time(NULL)) {
+ shutdown_system(this->shutdown_cmd, 0);
+ return FE_XINE_EXIT;
+ }
+ }
+
return FE_XINE_RUNNING;
}
@@ -1274,6 +1308,10 @@ static int fe_send_input_event(frontend_t *this_gen, const char *map,
LOGDBG("Keypress: %s %s %s %s",
map, key, repeat?"Repeat":"", release?"Release":"");
+ /* reset inactivity timer */
+ if (this->shutdown_timeout > 0)
+ this->shutdown_time = time(NULL) + this->shutdown_timeout;
+
/* local mode: --> vdr callback */
if(this->keypress) {
this->keypress(map, key);
@@ -1331,6 +1369,9 @@ static int fe_send_event(frontend_t *this_gen, const char *data)
} else if(!strncasecmp(data, "DEINTERLACE ", 12)) {
xine_set_param(this->stream, XINE_PARAM_VO_DEINTERLACE, atoi(data+12) ? 1 : 0);
+ } else if (!strcmp(data, "POWER_OFF")) {
+ shutdown_system(this->shutdown_cmd, 1);
+
} else {
LOGDBG("Event: %s", data);
@@ -1945,6 +1986,8 @@ void init_fe(fe_t *fe)
fe->fe.xine_close = fe_xine_close;
fe->fe.xine_exit = fe_xine_exit;
+ fe->fe.shutdown_init = fe_shutdown_init;
+
fe->fe.fe_free = fe_free;
fe->fe.xine_is_finished = fe_is_finished;