summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2006-02-10 17:01:19 (GMT)
committer jaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2006-02-10 17:01:19 (GMT)
commit86c84b29c8e491d419555997a53480ad0f4db696 (patch)
treed109c778c10b0ba0da6859ab08453a7a48eda65c
parent09ebdde9e1a56c6cb83a4b98c1c2d9a22244097c (diff)
now the xmlrpc daemon runs continuously listening for commands:
playlist can be modified at runtime, play/stop on channels etc. (still needs some more testing) git-svn-id: svn://dyne.org/montevideo/ivysync@57 949728d9-16ea-0310-a75c-cbdf8430a4b8
-rw-r--r--cmdline.cpp104
-rw-r--r--decoder.cpp2
-rw-r--r--xmlrpc.cpp61
-rw-r--r--xmlrpc.h23
4 files changed, 138 insertions, 52 deletions
diff --git a/cmdline.cpp b/cmdline.cpp
index 8b0ce4f..047e885 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -43,6 +43,7 @@ bool syncstart = false;
bool graphical = false;
bool dummytest = false;
bool rpcdaemon = false;
+int rpcdaemonport;
int videobuf = 64;
// our global vector holding all instantiated decoders
@@ -55,7 +56,7 @@ Gui *gui;
XmlRpcServer *xmlrpc;
// Threaded daemon
-IvySyncDaemon *daemonthread;
+IvySyncDaemon *ivydaemon;
char *help =
"Usage: ivysync [-hsDgt] [ -d /dev/video16 [ -p playmode files ] ]\n"
@@ -66,16 +67,16 @@ char *help =
" -d --device activate a device (i.e. /dev/video16)\n"
" -b --buffer size of video buffer in KB (default 64)\n"
" -p --playmode playlist mode (play|cont|loop|rand)\n"
-" -x --xmlrpc run XmlRpc daemon for remote control\n"
+" -x --xmlrpc run XmlRpc daemon on a network port\n"
" -g --gui start the graphical user interface\n";
-char *short_options = "-hd:sb:xp:gtD:";
+char *short_options = "-hd:sb:x:p:gtD:";
const struct option long_options[] = {
{ "help", no_argument, NULL, 'h'},
{ "device", required_argument, NULL, 'd'},
{ "buffer", required_argument, NULL, 'b'},
{ "scan", no_argument, NULL, 's'},
- { "xmlrpc", no_argument, NULL, 'x'},
+ { "xmlrpc", required_argument, NULL, 'x'},
{ "playmode", required_argument, NULL, 'p'},
{ "gui", no_argument, NULL, 'g'},
{ "test", no_argument, NULL, 't'},
@@ -178,21 +179,30 @@ int cmdline(int argc, char **argv) {
case 'p':
CHECK_DECODER;
- if( strncasecmp(optarg,"play",4) ==0 )
+ if( strncasecmp(optarg,"play",4) ==0 ) {
+
dec->playmode = PLAY;
- else if( strncasecmp(optarg,"cont",4) ==0 )
+
+ } else if( strncasecmp(optarg,"cont",4) ==0 ) {
+
dec->playmode = CONT;
- else if( strncasecmp(optarg,"loop",4) ==0 )
+
+ } else if( strncasecmp(optarg,"loop",4) ==0 ) {
+
dec->playmode = LOOP;
- else if( strncasecmp(optarg,"rand",4) ==0 )
+
+ } else if( strncasecmp(optarg,"rand",4) ==0 ) {
+
dec->playmode = RAND;
- else
+
+ } else
E("unrecognized playmode: %s",optarg);
break;
case 'x':
rpcdaemon = true;
+ rpcdaemonport = atoi(optarg);
break;
case 'g':
@@ -284,18 +294,27 @@ int main(int argc, char **argv) {
////////////////////////////////
/// setup the XMLRPC interface
if(rpcdaemon) {
+
xmlrpc = new XmlRpcServer();
+
// instantiate all classes
new Play (xmlrpc, &decoders);
new Stop (xmlrpc, &decoders);
new GetPos(xmlrpc, &decoders);
new SetPos(xmlrpc, &decoders);
new Open (xmlrpc, &decoders);
-
- // instantiate and launch the threaded daemon
- daemonthread = new IvySyncDaemon(xmlrpc);
- daemonthread->launch();
-
+ new Quit (xmlrpc, &decoders);
+
+ ivydaemon = new IvySyncDaemon(xmlrpc);
+
+ if( ! ivydaemon->init( rpcdaemonport) ) {
+ E("can't initialize daemon listening");
+ delete ivydaemon;
+ delete xmlrpc;
+ rpcdaemon = false;
+ } else
+ N("XMLRPC daemon listening for commands on port %u",
+ rpcdaemonport);
}
////////////////////////////////
@@ -311,32 +330,51 @@ int main(int argc, char **argv) {
dec = *dec_iter;
dec->setup( &syncstart, videobuf );
dec->launch();
- dec->play();
+
+ if( ! rpcdaemon ) {
+ // try to load the playlist
+ dec->load();
+ dec->play();
+ }
}
-
- N("Syncing %i players...",decoders.size());
-
- jsleep(0,500);
- A("Start!");
+
+ if( ! rpcdaemon ) {
+ N("Syncing %i players...",decoders.size());
+
+ jsleep(0,500);
+ A("Start!");
+ }
+
syncstart = 1;
////////////////////////////////
- int still_running = decoders.size();
+
- // if(daemonize) while(true); // loop infinitely
- // else
-
- while(still_running) {
- still_running = 0;
- for( dec_iter = decoders.begin();
- dec_iter != decoders.end();
- ++dec_iter) {
-
- dec = *dec_iter;
- if(dec->playing) still_running++;
- jsleep(1,0); // 1 second delay check
+ if(rpcdaemon) {
+
+ // run as a daemon: quit only when requested
+ while( ! ivydaemon->quit ) {
+ ivydaemon->run(1.0);
+ jsleep(0,10);
+ }
+
+ } else {
+
+ // run until all the channels are at the end
+ int still_running = decoders.size();
+
+ while(still_running) {
+ still_running = 0;
+ for( dec_iter = decoders.begin();
+ dec_iter != decoders.end();
+ ++dec_iter) {
+
+ dec = *dec_iter;
+ if(dec->playing) still_running++;
+ jsleep(1,0); // 1 second delay check
+ }
}
}
diff --git a/decoder.cpp b/decoder.cpp
index f42c9d1..482f00c 100644
--- a/decoder.cpp
+++ b/decoder.cpp
@@ -78,8 +78,6 @@ bool Decoder::init(char *dev) {
// last two chars of the device name are the number
device_num = atoi(&dev[len-2]);
- // try to load the playlist
- load();
return true;
}
diff --git a/xmlrpc.cpp b/xmlrpc.cpp
index 225233f..9872359 100644
--- a/xmlrpc.cpp
+++ b/xmlrpc.cpp
@@ -23,29 +23,40 @@
#include <xmlrpc.h>
#include <utils.h>
-IvySyncDaemon::IvySyncDaemon(XmlRpcServer *srv)
- : Thread() {
+static bool quit;
+
+IvySyncDaemon::IvySyncDaemon(XmlRpcServer *srv) {
xmlrpc = srv;
xmlrpc->_ssl = false;
xmlrpc->_ssl_ssl = NULL;
-}
+ quit = false;
-void IvySyncDaemon::run() {
- running = true;
- unlock();
+}
- D("thread %u launched",pthread_self());
-
+bool IvySyncDaemon::init(int port) {
// guess where this number comes from ? ;)
- xmlrpc->bindAndListen(264);
-
+ if( ! xmlrpc->bindAndListen(port) ) return false;
+
// let's be introspective so we list our own methods
xmlrpc->enableIntrospection(true);
+
+ return true;
+}
+
+void IvySyncDaemon::run(double mstime) {
+ // running = true;
+ // unlock();
+
+ if(::quit) {
+ quit = true;
+ return;
+ }
+
+ // run for amount of milliseconds (-1.0 for infinite)
+ xmlrpc->work( mstime );
- // work indefinitely (TODO: FIX this for proper quit)
- xmlrpc->work(-1.0);
}
@@ -74,16 +85,38 @@ Open::Open(XmlRpcServer* src, vector<Decoder*> *decoders)
IvySyncPublicMethod(decoders)
{ }
+Quit::Quit(XmlRpcServer* src, vector<Decoder*> *decoders)
+ : XmlRpcServerMethod("Quit", src),
+ IvySyncPublicMethod(decoders)
+{ }
+
+void Quit::execute(XmlRpcValue &params, XmlRpcValue &result) {
+ Decoder *dec;
+ vector<Decoder*>::iterator iter;
+
+ for(iter = decoders->begin();
+ iter != decoders->end();
+ ++iter) {
+
+ dec = *iter;
+ dec->stop();
+ dec->close();
+
+ }
+
+ ::quit = true;
+}
+
void Open::execute(XmlRpcValue &params, XmlRpcValue &result) {
int decnum;
char *path;
- if( params.size() != 1) {
+ if( params.size() != 2) {
E("XMLRPC: Open called with invalid number of arguments(%u)",
params.size() );
return;
}
-
+
// get out the decoder parameter
decnum = (int) params[0] -1;
Decoder *dec = get_decoder( decnum );
diff --git a/xmlrpc.h b/xmlrpc.h
index a5d6fe3..28585ad 100644
--- a/xmlrpc.h
+++ b/xmlrpc.h
@@ -31,15 +31,20 @@
using namespace XmlRpc;
-class IvySyncDaemon : public Thread {
+class IvySyncDaemon {
public:
IvySyncDaemon(XmlRpcServer *srv);
~IvySyncDaemon() { };
- void run();
+ bool init(int port);
+ void run(double mstime);
+ bool quit;
+
private:
+
XmlRpcServer *xmlrpc;
+
};
class IvySyncPublicMethod {
@@ -58,7 +63,6 @@ public:
return *dec_iter;
}
- private:
vector<Decoder*> *decoders;
};
@@ -140,5 +144,18 @@ class Open : public XmlRpcServerMethod, IvySyncPublicMethod {
};
+class Quit : public XmlRpcServerMethod, IvySyncPublicMethod {
+ public:
+
+ Quit(XmlRpcServer* srv, vector<Decoder*> *decoders);
+
+ ~Quit() { };
+
+ void execute(XmlRpcValue &params, XmlRpcValue &result);
+
+ std::string help() {
+ return std::string("Quit the ivysync from running"); }
+
+};
#endif