summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2006-03-14 11:11:43 (GMT)
committer jaromil <jaromil@949728d9-16ea-0310-a75c-cbdf8430a4b8>2006-03-14 11:11:43 (GMT)
commitba18f1e1ec7be0587c3930ff2382bfd5b5a90e9a (patch)
treef0a3dccae2b08ff64472b39dd916908faf0c531f
parentacc546c5078763ed1ae72d43901c53c8b668b78d (diff)
several important fixes to XMLRPC daemon
ready for the first employment in production in the viewing-set of the Montevideo collection git-svn-id: svn://dyne.org/montevideo/ivysync@60 949728d9-16ea-0310-a75c-cbdf8430a4b8
-rw-r--r--Makefile11
-rw-r--r--cmdline.cpp87
-rw-r--r--decoder.cpp264
-rw-r--r--decoder.h46
-rw-r--r--gui.cpp38
-rw-r--r--gui.h10
-rw-r--r--ivysync-remote.cpp142
-rwxr-xr-xivysync-remote.py6
-rw-r--r--xmlrpc.cpp99
-rw-r--r--xmlrpc.h30
10 files changed, 361 insertions, 372 deletions
diff --git a/Makefile b/Makefile
index db29f31..e31bd62 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ GTKFLAGS = `pkg-config --cflags gtk+-2.0`
GTKLIBS = `pkg-config --libs gtk+-2.0`
# debugging flags:
-CPPFLAGS = -I. -Ixmlrpc++ -Wall -ggdb -pg $(GTKFLAGS)
+CPPFLAGS = -I. -Ixmlrpc++ -Wall -g -ggdb $(GTKFLAGS)
# optimized flags:
#CPPFLAGS = -I. -Ixmlrpc++ -Wall -O2 -fomit-frame-pointer -ffast-math
@@ -21,11 +21,9 @@ CPPFLAGS = -I. -Ixmlrpc++ -Wall -ggdb -pg $(GTKFLAGS)
LIBS = xmlrpc++/libxmlrpc++.a -lpthread -lssl
-IVYSYNC_OBJ = decoder.o thread.o utils.o cmdline.o gui.o xmlrpc.o
+IVYSYNC_OBJ = decoder.o thread.o linklist.o utils.o cmdline.o gui.o xmlrpc.o
-IVYSYNC_REMOTE_OBJ = ivysync-remote.o utils.o
-
-all: xmlrpc ivysync ivysync-remote
+all: xmlrpc ivysync
xmlrpc:
cd xmlrpc++ && $(MAKE)
@@ -33,9 +31,6 @@ xmlrpc:
ivysync: $(IVYSYNC_OBJ)
$(CPP) $(CPPFLAGS) -o ivysync $(IVYSYNC_OBJ) $(LIBS) $(GTKLIBS)
-ivysync-remote: $(IVYSYNC_REMOTE_OBJ)
- $(CPP) $(CPPFLAGS) -o ivysync-remote $(IVYSYNC_REMOTE_OBJ) $(LIBS)
-
#make clean
clean:
rm -rf *.o *~ ivysync
diff --git a/cmdline.cpp b/cmdline.cpp
index 362e1c8..47e8a97 100644
--- a/cmdline.cpp
+++ b/cmdline.cpp
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
+#include <errno.h>
#include <signal.h>
#include <decoder.h>
@@ -46,8 +47,8 @@ bool rpcdaemon = false;
int rpcdaemonport = 2640;
int videobuf = 64;
-// our global vector holding all instantiated decoders
-vector<Decoder*> decoders;
+// our global linklist holding all instantiated decoders
+Linklist decoders;
// graphical interface
Gui *gui;
@@ -74,8 +75,8 @@ 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'},
+ { "buffer", required_argument, NULL, 'b'},
{ "xmlrpc", required_argument, NULL, 'x'},
{ "playmode", required_argument, NULL, 'p'},
{ "gui", no_argument, NULL, 'g'},
@@ -88,31 +89,36 @@ const struct option long_options[] = {
void quitproc (int Sig) { /* signal handling */
N("received signal %u on process %u",Sig,getpid());
A("please wait while quitting threads");
- vector<Decoder*>::iterator dec_iter;
if(graphical) gtk_main_quit();
- for( dec_iter = decoders.begin();
- dec_iter != decoders.end();
- ++dec_iter)
- (*dec_iter)->close();
+ Decoder *dec;
+ dec = (Decoder*)decoders.begin();
+ while(dec) {
+ dec->close();
+ delete dec;
+ dec = (Decoder*)decoders.begin();
+ }
}
-#define CHECK_DECODER \
- if(!dec) { \
- dec = new Decoder(); \
- if( dec->init("/dev/video16") ) { \
- decoders.push_back( dec ); \
- } else { \
- delete dec; \
- dec = NULL; \
- } \
- }
+#define CHECK_DECODER \
+if(!dec) { \
+ dec = (Decoder*)decoders[1]; \
+ if(!dec) { \
+ dec = new Decoder(); \
+ if( dec->init("/dev/video16") ) { \
+ decoders.append( dec ); \
+ } else { \
+ delete dec; \
+ dec = NULL; \
+ } \
+ } \
+}
int cmdline(int argc, char **argv) {
Decoder *dec = NULL;
- FILE *fd;
+ FILE *fd = NULL;
int c;
int res;
@@ -132,7 +138,7 @@ int cmdline(int argc, char **argv) {
dec = new Decoder();
dec->dummy = dummytest;
if( dec->init(optarg) )
- decoders.push_back( dec );
+ decoders.append( dec );
else {
E("can't initialize device %s",optarg);
delete dec;
@@ -195,6 +201,10 @@ int cmdline(int argc, char **argv) {
dec->playmode = RAND;
+ } else if( strncasecmp(optarg,"single",6) ==0 ) {
+
+ dec->playmode = SINGLE;
+
} else
E("unrecognized playmode: %s",optarg);
@@ -223,11 +233,16 @@ int cmdline(int argc, char **argv) {
case 1:
fd = fopen(optarg,"rb");
- if(fd) {
+ if(!fd) {
+
+ E("file %s is not readable: %s",optarg, strerror(errno));
+
+ } else {
+
CHECK_DECODER;
dec->append( optarg );
fclose(fd);
- } else E("file %s is not readable",optarg);
+ }
break;
@@ -242,7 +257,6 @@ int cmdline(int argc, char **argv) {
int main(int argc, char **argv) {
- vector<Decoder*>::iterator dec_iter;
Decoder *dec;
set_debug(1);
@@ -264,7 +278,7 @@ int main(int argc, char **argv) {
cmdline(argc, argv);
- if( !decoders.size() ) {
+ if( !decoders.len() ) {
E("no decoder device is initialized, aborting operations");
exit(0);
}
@@ -324,12 +338,11 @@ int main(int argc, char **argv) {
////////////////////////////////
/// Syncstart!
- for( dec_iter = decoders.begin();
- dec_iter != decoders.end();
- ++dec_iter) {
+ dec = (Decoder*)decoders.begin();
+ while(dec) {
- dec = *dec_iter;
dec->setup( &syncstart, videobuf );
+
dec->launch();
if( ! rpcdaemon ) {
@@ -338,10 +351,11 @@ int main(int argc, char **argv) {
dec->play();
}
+ dec = (Decoder*)dec->next;
}
if( ! rpcdaemon ) {
- N("Syncing %i players...",decoders.size());
+ N("Syncing %i players...",decoders.len());
jsleep(0,500);
A("Start!");
@@ -364,17 +378,20 @@ int main(int argc, char **argv) {
} else {
// run until all the channels are at the end
- int still_running = decoders.size();
+ int still_running = decoders.len();
while(still_running) {
+
still_running = 0;
- for( dec_iter = decoders.begin();
- dec_iter != decoders.end();
- ++dec_iter) {
-
- dec = *dec_iter;
+ dec = (Decoder*)decoders.begin();
+
+ while(dec) {
+
if(dec->playing) still_running++;
+
jsleep(1,0); // 1 second delay check
+
+ dec = (Decoder*)dec->next;
}
}
}
diff --git a/decoder.cpp b/decoder.cpp
index 8aee540..b128d2f 100644
--- a/decoder.cpp
+++ b/decoder.cpp
@@ -31,12 +31,15 @@
#include <utils.h>
#include <gui.h>
+
+
Decoder::Decoder()
- : Thread() {
+ : Thread(), Entry() {
fd = 0;
- playmode = PLAY;
+ playmode = SINGLE;
position = -1;
playing = false;
+ stopped = false;
dummy = false;
gui = false;
quit = true;
@@ -45,6 +48,8 @@ Decoder::Decoder()
filepos = 0L;
newfilepos = 0L;
+ playlist_fd = 0;
+
buffo = NULL;
}
@@ -60,7 +65,6 @@ bool Decoder::init(char *dev) {
if(dummy) {
N("running in dummy test run - no device opened");
- device = dev;
} else {
@@ -72,8 +76,10 @@ bool Decoder::init(char *dev) {
}
+ // save the path to the device
+ strncpy(device, dev, MAXPATH);
+
// parse the last 2 cyphers of the device path
- device = dev;
len = strlen(dev);
// last two chars of the device name are the number
device_num = atoi(&dev[len-2]);
@@ -106,33 +112,44 @@ bool Decoder::setup(bool *sync, int bufsize) {
void Decoder::close() {
playing = false;
quit = true;
+
if(running) {
D("thread was running, waiting to join...");
join();
}
if(fd) ::close(fd);
+
+ position = -1;
+
+ // delete playlist entries
+ empty();
+
+
}
void Decoder::update() {
if(position<0) { // first time we play from the playlist
- position = 0;
+
+ position = 1;
+
} else {
switch(playmode) {
case PLAY: // next
- if( position+1 > (int)playlist.size()-1 )
- stop();
- else
- position++;
+ position++;
+
+ if( position > playlist.len() ) {
+ // stop();
+ position = 1;
+ }
- D("update: position is now %u", position);
break;
case CONT: // next or first if at the end
- if( position+1 > (int)playlist.size()-1 ) position = 1;
+ if( position >= (int)playlist.len() ) position = 1;
else position++;
break;
@@ -145,6 +162,10 @@ void Decoder::update() {
// play a random one
break;
+ case SINGLE:
+ stop();
+ break;
+
default:
stop();
// just stop
@@ -154,7 +175,17 @@ void Decoder::update() {
}
// current movie is now in playlist[position];
-
+ if( ! playlist.len() ) D("playlist empty");
+ else {
+ D("current playlist at position %u:", position);
+ int c;
+ for(c=1; c<=playlist.len(); c++) {
+ D("%s[%u] %s",
+ (c==position)?"->":" ",
+ c, playlist[c]->name);
+ }
+ }
+
// refresh the GUI if present
if(gui) gui->refresh();
@@ -165,7 +196,8 @@ void Decoder::update() {
void Decoder::run() {
int in, written, writing;
uint8_t *buf;
- string movie;
+ Entry *movie;
+
if(!fd && !dummy) {
E("thread %u falling down: no device opened",pthread_self());
@@ -176,7 +208,7 @@ void Decoder::run() {
D("thread %u launched",pthread_self());
- // set max realtime priority
+// set max realtime priority
// if( set_rtpriority(true) )
// A("thread %u running on max realtime priority",pthread_self());
@@ -184,62 +216,94 @@ void Decoder::run() {
update();
- // if is not playling, sleep
- while(!playing && !quit)
- jsleep(0,1);
if(quit) break;
+
+ if(stopped) {
+ stopped = false;
+ playing = false;
+ }
+
+ // if is not playing, sleep
+ while(!playing && !quit) jsleep(0,100);
///////////////////////////
+ // check it out from the playlist
movie = playlist[position];
+ if(!movie) {
+ E("no movie at position %i", position);
+ playing = false;
+ continue;
+ }
- playlist_fd = fopen( movie.c_str(), "rb" );
+ // just to be sure
+ if(playlist_fd) fclose(playlist_fd);
+
+ // STAT METHOD FOR FILESIZE
+// // check if it exists and ackowledge filesize
+// if( stat(movie->name, &moviestat) < 0 ) {
+// E("error %u on movie %s: %s", errno, movie->name, strerror(errno));
+// if(errno == 75) // value too large for defined datatype
+// // we just deactivate seek and position handling
+// filesize = 0x0;
+// else
+// continue;
+// } else
+// filesize = moviestat.st_size;
+
+ playlist_fd = fopen( movie->name, "rb" );
if(!playlist_fd) {
- E("can't open %s: %s (%i)", movie.c_str(), strerror(errno), errno);
+ E("can't open %s: %s (%i)", movie->name, strerror(errno), errno);
if(errno==27) { // EOVERFLOW - file too large on Linux/Glibc
int tmpfd;
- tmpfd = open( movie.c_str(), O_RDONLY|O_LARGEFILE);
+ tmpfd = open( movie->name, O_RDONLY|O_LARGEFILE);
if(!tmpfd) {
E("failed opening with largefile support: %s",strerror(errno));
- update();
continue;
} else playlist_fd = fdopen( tmpfd , "rb" );
} else {
- update();
continue;
}
}
- N("now playing %s",movie.c_str());
+ N("now playing %s",movie->name);
// read the total length of movie file
fseek(playlist_fd, 0L, SEEK_END);
filesize = ftell(playlist_fd);
- fseek(playlist_fd, 0L, SEEK_SET);
- filepos = 0L; // set position at the beginning
+ // set position at the beginning
+ filepos = 0L;
+ fseek(playlist_fd, filepos, SEEK_SET);
+ //////////////////////////////////////
+
+ // ??? or should we use:
+ // fgetpos(playlist_fd, &filesize);
+ // fsetpos(playlist_fd, &filepos);
+ // none seem to work with files > 2GB
- A("movie length: %lu (bytes)",filesize);
+ if(filesize)
+ A("movie length: %lu KB",filesize/1024);
+ else
+ A("movie is too large to be seekable");
do { // inner reading loop
// update the GUI
if(gui) gui->refresh();
-
- // if is not playling, sleep
- while(!playing && !quit) {
- jsleep(0,200);
- }
-
- if(quit) break;
- ///////////////////////////
+ // process asynchronous flags
+ if(quit || stopped) break;
+ while(!playing && !quit) jsleep(0,100);
+ //////////////////////////////
+
+ // read in the data
in = fread(buffo, 1, buffo_size, playlist_fd);
if( feof(playlist_fd) || in<1 ) { // EOF
- D("end of file: %s",movie.c_str());
+ D("end of file %s",movie->name);
break;
}
@@ -248,7 +312,7 @@ void Decoder::run() {
buf = buffo;
if(!*syncstart) {
- unlock();
+ // unlock();
while(!*syncstart) jsleep(0,1); // check every nanosecond
}
@@ -256,7 +320,7 @@ void Decoder::run() {
buf += written;
- if(quit) break;
+ // if(quit || stopped) break;
if(dummy) // emulation mode with no device (for devel)
written = writing;
@@ -276,16 +340,23 @@ void Decoder::run() {
} while(in>0 && !quit); // read/write inner loop
- fclose(playlist_fd);
- playlist_fd = 0;
clear();
+ // close the file playing
+ A("end of movie %s", movie->name);
+ if(playlist_fd) {
+ fclose(playlist_fd);
+ playlist_fd = 0;
+ }
} // run() thread loop
- if(playlist_fd)
- fclose(playlist_fd); // be sure we close
- playlist_fd = 0;
clear();
+ // close the file playing
+ if(playlist_fd) {
+ fclose(playlist_fd);
+ playlist_fd = 0;
+ }
+ A("quitting decoder for %s",device);
D("thread %u finished", pthread_self());
return;
@@ -315,13 +386,15 @@ void Decoder::flush() {
bool Decoder::play() {
playing = true;
+ stopped = false;
return true;
}
bool Decoder::stop() {
- newfilepos = 1;
- clear();
- playing = false;
+ // newfilepos = 1;
+ // clear();
+ // playing = false;
+ stopped = true;
return true;
}
@@ -333,39 +406,43 @@ bool Decoder::pause() {
bool Decoder::clear() {
if(!fd) return false;
+ // close the device
flush();
- ::close(fd);
+ ::close(fd); // *BLANK*
+
- fd = ::open(device.c_str(), O_WRONLY|O_NDELAY,S_IWUSR|S_IWGRP|S_IWOTH);
+ // reopen the device again
+ fd = ::open(device, O_WRONLY|O_NDELAY,S_IWUSR|S_IWGRP|S_IWOTH);
if(fd<0) {
- D("error opening device %s: %s",device.c_str(),strerror(errno));
+ D("error opening device %s: %s",device,strerror(errno));
return false;
}
return true;
}
-bool Decoder::restart() {
- playing = false;
- position = 0;
- return true;
-}
int Decoder::getpos() {
// filesize : 100 = filepos : x
// filesize : filepos = 100 : x
int percent;
- percent = (filepos * 100) / filesize;
- // D("movie %s at position %u %% (%lu byte)",
- // movie.c_str(), percent, filepos);
+ if(!playlist_fd) return 0;
+ if(!filesize) return 0;
+
+ percent = (int) ( (filepos * 100) / filesize );
+ D("movie %s at position %u %% (%lu byte)",
+ playlist[position]->name, percent, filepos);
return percent;
}
void Decoder::setpos(int pos) {
// filesize : 100 = x : pos
+ if(!playlist_fd) return;
+ if(!filesize) return;
+
newfilepos = (filesize * pos) / 100;
D("Decoder::setpos(%u) : newfilepos = %lu",
@@ -374,30 +451,34 @@ void Decoder::setpos(int pos) {
bool Decoder::prepend(char *file) {
- playlist.insert( playlist.begin(), file );
+
+ Entry *ent = new Entry();
+
+ ent->set_name(file);
+
+ playlist.prepend( ent );
+
return true;
}
bool Decoder::append(char *file) {
- playlist.push_back(file);
+
+ Entry *ent = new Entry();
+
+ ent->set_name(file);
+
+ playlist.append( ent );
+
return true;
}
bool Decoder::insert(char *file, int pos) {
- if(pos > (int)playlist.size() ) {
-
- // playlist is smaller than pos: append at the end
- playlist.push_back(file);
-
- } else {
+ Entry *ent = new Entry();
- vector<string>::iterator pl_iter;
- int c;
- for( pl_iter = playlist.begin(), c=1;
- c<pos; ++pl_iter, c++ );
- playlist.insert( pl_iter, file );
+ ent->set_name(file);
+
+ playlist.insert( ent, pos );
- }
return true;
}
@@ -408,23 +489,26 @@ bool Decoder::remove(char *file) {
}
*/
bool Decoder::remove(int pos) {
- vector<string>::iterator pl_iter;
- int c;
+ Entry *ent;
- for( pl_iter = playlist.begin(), c=1;
- pl_iter != playlist.end();
- ++pl_iter, c++ )
- if(c==pos) {
- playlist.erase(pl_iter);
- return true;
- }
+ ent = playlist[pos];
- return false;
+ if(!ent) return false;
+
+ delete ent;
+
+ return true;
}
bool Decoder::empty() {
- playlist.clear();
- position = 0;
+ Entry *ent = playlist.begin();
+ while(ent) {
+ ent->rem();
+ delete ent;
+ ent = playlist.begin();
+ }
+ // playlist.clear()
+ position = 1;
return true;
}
@@ -586,15 +670,17 @@ int Decoder::save() {
E("can't save to %s: %s", path, strerror(errno));
return -1;
}
- D("saving to configuration file %s",path);
- for(c=1, pl_iter = playlist.begin();
- pl_iter != playlist.end();
- ++pl_iter, c++) {
- pl = *pl_iter;
- fputs(pl.c_str(),fd);
+ D("saving to configuration file %s",path);
+ Entry *ent;
+ ent = playlist.begin();
+ c = 0;
+ while(ent) {
+ fputs(ent->name, fd);
fputs("\n",fd);
- D("%u. %s",c,pl.c_str());
+ D("%u - %s", c, ent->name);
+ ent = ent->next;
+ c++;
}
fflush(fd);
fclose(fd);
diff --git a/decoder.h b/decoder.h
index 96530f2..56b53b2 100644
--- a/decoder.h
+++ b/decoder.h
@@ -24,25 +24,31 @@
#define __DECODER_H__
#include <iostream>
-#include <string>
-#include <vector>
#include <pthread.h>
#include <inttypes.h>
+#include <linklist.h>
#include <thread.h>
-using namespace std;
-using namespace __gnu_cxx;
+/* On many architectures both off_t and long are 32-bit types, but
+ compilation with #define _FILE_OFFSET_BITS 64 will turn off_t into
+ a 64-bit type. - see man fseeko(3) */
+#define _FILE_OFFSET_BITS 64
+
// playmode values
-#define PLAY 1
-#define CONT 2
-#define LOOP 3
-#define RAND 4
+#define PLAY 1
+#define CONT 2
+#define LOOP 3
+#define RAND 4
+#define SINGLE 5
+
+// maximum path lenght
+#define MAXPATH 512
class Playlist; // graphical interface
-class Decoder : public Thread {
+class Decoder : public Thread, public Entry {
public:
Decoder();
@@ -68,25 +74,29 @@ class Decoder : public Thread {
int playmode; ///< PLAY, CONT, LOOP or RAND
int position; ///< current position in playlist (read-only)
- string current; ///< path of movie currently playing
+
bool play();
bool stop();
bool pause();
bool clear();
- bool restart();
- int getpos();
- void setpos(int pos);
+ int getpos();
+ void setpos(int pos);
+ /** state flags for use in the inner loop
+ the following booleans are changed by asynchronous calls
+ then behaviour is synched and executed in the main loop */
bool playing;
+ bool stopped;
bool *syncstart;
- string device;
+ char device[MAXPATH];
int device_num;
- vector<string> playlist;
+ Linklist playlist;
+ Entry *current; ///< path of movie currently playing
Playlist *gui; ///< pointer to the GUI, NULL if none
@@ -98,9 +108,9 @@ class Decoder : public Thread {
void flush();
- long long filesize; // current file playing, size in bytes
- long long filepos; // current file playing, position in bytes
- long long newfilepos; // new position to skip in file
+ uint64_t filesize; // current file playing, size in bytes
+ uint64_t filepos; // current file playing, position in bytes
+ uint64_t newfilepos; // new position to skip in file
int fd;
FILE *playlist_fd;
diff --git a/gui.cpp b/gui.cpp
index 0d903f1..5180682 100644
--- a/gui.cpp
+++ b/gui.cpp
@@ -239,13 +239,14 @@ gboolean DND_drop(GtkWidget *w, GdkDragContext *dc, gint x, gint y,
for(p = (char*)pl->draglist->data; *p!='\0'; p++)
if(!isdigit(*p)) *p=' ';
numpos = atoi((char*)pl->draglist->data);
- D("move entry %u:%s into slot %u",numpos, (char*)pl->decoder->playlist[numpos-1].c_str(),row+1);
+ D("move entry %u:%s into slot %u",numpos,
+ (char*)pl->decoder->playlist[numpos-1]->name,row+1);
numpos--;
if(row>numpos) row++;
pl->decoder->insert
- ( (char*)pl->decoder->playlist[numpos].c_str(), row );
+ ( (char*)pl->decoder->playlist[numpos]->name, row );
if(row<numpos) numpos++; // if moves up then the source shifts down one pos
@@ -489,29 +490,28 @@ Playlist::~Playlist() {
// read again the playlist from the decoder and fill it up
int Playlist::refresh() {
GtkTreeIter iter; // static
- vector<string>::iterator pl_iter;
- string pl;
+ Entry *ent;
char tmp[16];
int c;
gtk_tree_store_clear(treestore);
- for(c=1, pl_iter = decoder->playlist.begin();
- pl_iter != decoder->playlist.end();
- ++pl_iter, c++) {
-
- pl = *pl_iter;
-
+ c = 0;
+ ent = decoder->playlist.begin();
+ while(ent) {
gtk_tree_store_append(treestore,&iter,NULL);
-
+
snprintf(tmp,15,"%s%u",
((decoder->position+1)==c)?"->":" ",
c);
+
gtk_tree_store_set(treestore,&iter,
POSITION, tmp,
- FILENAME, pl.c_str(),
+ FILENAME, ent->name,
-1);
+ ent = ent->next;
+ c++;
}
return 1;
@@ -557,17 +557,15 @@ Gui::~Gui() {
gtk_widget_destroy(window);
}
-bool Gui::init(vector<Decoder*> *devices) {
- vector<Decoder*>::iterator dev_iter;
+bool Gui::init(Linklist *devices) {
Decoder *dec;
Playlist *pl;
int c;
- for(c=1, dev_iter = devices->begin();
- dev_iter != devices->end();
- ++dev_iter, c++) {
+ c = 1;
+ dec = (Decoder*)devices->begin();
+ while(dec) {
- dec = *dev_iter;
dec->syncstart = &syncstart;
pl = new Playlist(c);
@@ -582,8 +580,10 @@ bool Gui::init(vector<Decoder*> *devices) {
char tmp[256];
snprintf(tmp,255,"/dev/video%u",dec->device_num);
gtk_notebook_set_tab_label_text ((GtkNotebook*)notebook,
- gtk_notebook_get_nth_page((GtkNotebook*)notebook, c-1), tmp);
+ gtk_notebook_get_nth_page((GtkNotebook*)notebook,
+ c-1), tmp);
+ c++;
}
return true;
}
diff --git a/gui.h b/gui.h
index a082671..58de6db 100644
--- a/gui.h
+++ b/gui.h
@@ -2,11 +2,19 @@
#ifndef __GUI_H__
#define __GUI_H__
+
+
#include <decoder.h>
#include <utils.h>
#include <gtk/gtk.h>
+// damn STL
+#include <vector>
+using namespace std;
+using namespace __gnu_cxx;
+
+
class Playlist {
public:
Playlist(int num);
@@ -69,7 +77,7 @@ class Gui {
Gui();
~Gui();
- bool init(vector<Decoder*> *devices);
+ bool init(Linklist *devices);
void start();
bool syncstart;
diff --git a/ivysync-remote.cpp b/ivysync-remote.cpp
deleted file mode 100644
index 00905b4..0000000
--- a/ivysync-remote.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/* IvySync - Video SyncStarter
- *
- * (c) Copyright 2004-2005 Denis Roio aka jaromil <jaromil@dyne.org>
- * Nederlands Instituut voor Mediakunst
- *
- * This source code is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * This source code is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * Please refer to the GNU Public License for more details.
- *
- * You should have received a copy of the GNU Public License along with
- * this source code; if not, write to:
- * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include <cstdio>
-#include <iostream>
-#include <fstream>
-#include <stdlib.h>
-#include <getopt.h>
-
-#include <XmlRpc.h>
-
-#include <utils.h>
-
-using namespace XmlRpc;
-using namespace std;
-
-char *help =
-"Usage: ivysync-remote [-s server:port] command [arguments]\n"
-" -h --help show this help\n"
-" -D --debug print verbos debugging messages\n"
-" -s --server server address to connect (default localhost)\n"
-" -p --port server port to connect (default 264)\n"
-" -i --inspect inspect methods available on host\n";
-
-char *short_options = "-hD:s:p:i";
-const struct option long_options[] = {
- { "help", no_argument, NULL, 'h'},
- { "debug", required_argument, NULL, 'D'},
- { "server", required_argument, NULL, 's'},
- { "port", required_argument, NULL, 'p'},
- { "inspect", no_argument, NULL, 'i'},
- {0, 0, 0, 0}
-};
-
-
-bool inspect = false;
-char server[512];
-int port;
-char uri[256];
-
-int cmdline(int argc, char **argv) {
-
- int res;
- int c;
-
- N("IvySync 0.3 / (c)2004-2005 Denis Rojo <jaromil@dyne.org>");
-
- strcpy(server,"localhost");
- port = 264;
-
- do {
- res = getopt_long(argc, argv, short_options, long_options, NULL);
-
- switch(res) {
-
- case 'h':
- fprintf(stderr,"%s",help);
- exit(1);
- break;
-
- case 'i':
- inspect = true;
- break;
-
- case 's':
- c = sscanf(optarg,"%s",server);
- if(c != 1) {
- E("error parsing server option: %s",optarg);
- E("malformed syntax, please specify hostname");
- exit(0);
- }
- break;
-
- case 'p':
- port = atoi(optarg);
- break;
-
- case 'D':
- set_debug( atoi(optarg) );
- break;
-
- default: break;
-
- }
-
- } while(res > 0);
-
- return res;
-}
-
-
-int main(int argc, char* argv[]) {
-
- set_debug(1);
-
- cmdline(argc, argv);
-
- N("connecting to %s:%u",server,port);
-
- XmlRpcValue params;
- XmlRpcValue result;
- // XmlRpc::setVerbosity(5);
-
- sprintf(uri,"/RPC2");
- XmlRpcClient c((const char*)server, (int)port, (const char*)uri, true );
-
- if(inspect) {
-
- A("inspecting methods on %s:%i", server, port);
- c.execute("system.listMethods", params, result);
-
- if( c.isFault() ) {
- E("error calling system.listMethods on %s:%i", server, port);
- exit(1);
- }
-
- cout << "\nMethods:\n" << result << "\n\n";
-
- }
-
- N("TODO");
- exit(1);
-
-}
diff --git a/ivysync-remote.py b/ivysync-remote.py
index 5391447..5b04aeb 100755
--- a/ivysync-remote.py
+++ b/ivysync-remote.py
@@ -8,7 +8,7 @@
import sys
from string import atoi
-# Medusa and xmlrpclib client functions
+# xmlrpclib client functions
from socket import gethostname
from xmlrpclib import Transport, dumps
@@ -57,7 +57,11 @@ if __name__ == '__main__':
connection = xmlrpc_connection()
+# if(sys.argc):
+# cmd = "none"
+# else:
cmd = sys.argv[1]
+
if not cmd in commands:
diff --git a/xmlrpc.cpp b/xmlrpc.cpp
index bab8c32..9946096 100644
--- a/xmlrpc.cpp
+++ b/xmlrpc.cpp
@@ -36,11 +36,11 @@ IvySyncDaemon::IvySyncDaemon(XmlRpcServer *srv) {
}
bool IvySyncDaemon::init(int port) {
- // guess where this number comes from ? ;)
+
if( ! xmlrpc->bindAndListen(port) ) return false;
- // let's be introspective so we list our own methods
- xmlrpc->enableIntrospection(true);
+ // to be introspective we can list our own methods
+ // xmlrpc->enableIntrospection(true);
return true;
}
@@ -60,53 +60,51 @@ void IvySyncDaemon::run(double mstime) {
}
-Play::Play(XmlRpcServer* srv, vector<Decoder*> *decoders)
+Play::Play(XmlRpcServer* srv, Linklist *decoders)
: XmlRpcServerMethod("Play", srv),
IvySyncPublicMethod(decoders)
{ }
-Stop::Stop(XmlRpcServer* srv, vector<Decoder*> *decoders)
+Stop::Stop(XmlRpcServer* srv, Linklist *decoders)
: XmlRpcServerMethod("Stop", srv),
IvySyncPublicMethod(decoders)
{ }
-Pause::Pause(XmlRpcServer* srv, vector<Decoder*> *decoders)
+Pause::Pause(XmlRpcServer* srv, Linklist *decoders)
: XmlRpcServerMethod("Pause", srv),
IvySyncPublicMethod(decoders)
{ }
-GetPos::GetPos(XmlRpcServer* srv, vector<Decoder*> *decoders)
+GetPos::GetPos(XmlRpcServer* srv, Linklist *decoders)
: XmlRpcServerMethod("GetPos", srv),
IvySyncPublicMethod(decoders)
{ }
-SetPos::SetPos(XmlRpcServer* srv, vector<Decoder*> *decoders)
+SetPos::SetPos(XmlRpcServer* srv, Linklist *decoders)
: XmlRpcServerMethod("SetPos", srv),
IvySyncPublicMethod(decoders)
{ }
-Open::Open(XmlRpcServer* src, vector<Decoder*> *decoders)
+Open::Open(XmlRpcServer* src, Linklist *decoders)
: XmlRpcServerMethod("Open", src),
IvySyncPublicMethod(decoders)
{ }
-Quit::Quit(XmlRpcServer* src, vector<Decoder*> *decoders)
+Quit::Quit(XmlRpcServer* src, Linklist *decoders)
: XmlRpcServerMethod("Quit", src),
IvySyncPublicMethod(decoders)
{ }
void Quit::execute(XmlRpcValue &params, XmlRpcValue &result) {
Decoder *dec;
- vector<Decoder*>::iterator iter;
+
+ dec = (Decoder*)decoders->begin();
+ while(dec) {
- for(iter = decoders->begin();
- iter != decoders->end();
- ++iter) {
-
- dec = *iter;
dec->stop();
dec->close();
-
+
+ dec = (Decoder*)dec->next;
}
result = 1.0;
@@ -126,13 +124,15 @@ void Open::execute(XmlRpcValue &params, XmlRpcValue &result) {
}
// get out the decoder parameter
- decnum = (int) params[0] -1;
- Decoder *dec = get_decoder( decnum );
- if(!dec) { result = 0.0; return; }
+ decnum = (int) params[0];
+ Decoder *dec = (Decoder*) (*decoders)[decnum];
+ if(!dec) {
+ E("video decoder %i not present", decnum);
+ result = 0.0; return; }
// get out the path to the file to be opened
path = (char*) (std::string(params[1])).c_str();
- D("XMLRPC: Open decoder %u file %s", decnum+1, path);
+ D("XMLRPC: Open decoder %u file %s", decnum, path);
FILE *fd;
fd = fopen(path, "r");
@@ -140,7 +140,8 @@ void Open::execute(XmlRpcValue &params, XmlRpcValue &result) {
result = 0.0;
return;
} else fclose(fd);
-
+
+ dec->stop();
dec->empty();
dec->append(path);
result = 1.0;
@@ -157,11 +158,13 @@ void Play::execute(XmlRpcValue &params, XmlRpcValue &result) {
return;
}
- decnum = (int) params[0] -1;
- Decoder *dec = get_decoder( decnum );
- if(!dec) { result = 0.0; return; }
+ decnum = (int) params[0];
+ Decoder *dec = (Decoder*) (*decoders)[decnum];
+ if(!dec) {
+ E("video decoder %i not present", decnum);
+ result = 0.0; return; }
- D("XMLRPC: Play decoder %u", decnum+1 );
+ D("XMLRPC: Play decoder %u", decnum );
result = (double) dec->play();
}
@@ -177,11 +180,13 @@ void Stop::execute(XmlRpcValue &params, XmlRpcValue &result) {
return;
}
- decnum = (int) params[0] -1;
- Decoder *dec = get_decoder( decnum );
- if(!dec) { result = 0.0; return; }
+ decnum = (int) params[0];
+ Decoder *dec = (Decoder*) (*decoders)[decnum];
+ if(!dec) {
+ E("video decoder %i not present", decnum);
+ result = 0.0; return; }
- D("XMLRPC: Stop decoder %u", decnum+1);
+ D("XMLRPC: Stop decoder %u", decnum);
result = (double) dec->stop();
}
@@ -195,11 +200,13 @@ void Pause::execute(XmlRpcValue &params, XmlRpcValue &result) {
return;
}
- decnum = (int) params[0] -1;
- Decoder *dec = get_decoder( decnum );
- if(!dec) { result = 0.0; return; }
+ decnum = (int) params[0];
+ Decoder *dec = (Decoder*) (*decoders)[decnum];
+ if(!dec) {
+ E("video decoder %i not present", decnum);
+ result = 0.0; return; }
- D("XMLRPC: Pause decoder %u", decnum+1);
+ D("XMLRPC: Pause decoder %u", decnum);
result = (double) dec->pause();
}
@@ -214,18 +221,21 @@ void GetPos::execute(XmlRpcValue &params, XmlRpcValue &result) {
return;
}
- decnum = (int) params[0] -1;
- Decoder *dec = get_decoder( decnum );
- if(!dec) { result = 0.0; return; }
+ decnum = (int) params[0];
+ Decoder *dec = (Decoder*) (*decoders)[decnum];
+ if(!dec) {
+ E("video decoder %i not present", decnum);
+ result = 0.0; return; }
pos = (double) dec->getpos();
result = pos;
- D("XMLRPC: GetPos decoder %u returns %d", decnum+1, pos);
+ // D("XMLRPC: GetPos decoder %u returns %u", decnum, pos);
}
void SetPos::execute(XmlRpcValue &params, XmlRpcValue &result) {
int decnum;
+ int pos;
if( params.size() < 2) {
E("XMLRPC: SetPos called with invalid number of arguments (%u)",
@@ -233,11 +243,14 @@ void SetPos::execute(XmlRpcValue &params, XmlRpcValue &result) {
return;
}
- decnum = (int) params[0] -1;
- Decoder *dec = get_decoder( decnum );
- if(!dec) { result = 0.0; return; }
+ decnum = (int) params[0];
+ Decoder *dec = (Decoder*) (*decoders)[decnum];
+ if(!dec) {
+ E("video decoder %i not present", decnum);
+ result = 0.0; return; }
- D("XMLRPC: SetPos decoder %u", decnum+1);
- dec->setpos( (int) params[1] );
+ pos = (int) params[1];
+ D("XMLRPC: SetPos decoder %u to position %i", decnum, pos);
+ dec->setpos( pos );
}
diff --git a/xmlrpc.h b/xmlrpc.h
index 202a3fc..c604e10 100644
--- a/xmlrpc.h
+++ b/xmlrpc.h
@@ -31,6 +31,11 @@
using namespace XmlRpc;
+// damn STL
+#include <vector>
+using namespace std;
+using namespace __gnu_cxx;
+
// METHODS:
class Open;
@@ -60,20 +65,13 @@ private:
class IvySyncPublicMethod {
public:
- IvySyncPublicMethod(vector<Decoder*> *decs) {
+ IvySyncPublicMethod(Linklist *decs) {
decoders = decs;
}
~IvySyncPublicMethod() { };
- Decoder *get_decoder(int num) {
- vector<Decoder*>::iterator dec_iter;
- dec_iter = decoders->begin();
- dec_iter += num;
- return *dec_iter;
- }
-
- vector<Decoder*> *decoders;
+ Linklist *decoders;
};
@@ -84,7 +82,7 @@ public:
class Play : public XmlRpcServerMethod, IvySyncPublicMethod {
public:
- Play(XmlRpcServer* srv, vector<Decoder*> *decoders);
+ Play(XmlRpcServer* srv, Linklist *decoders);
~Play() { };
@@ -99,7 +97,7 @@ public:
class Stop : public XmlRpcServerMethod, IvySyncPublicMethod {
public:
- Stop(XmlRpcServer* srv, vector<Decoder*> *decoders);
+ Stop(XmlRpcServer* srv, Linklist *decoders);
~Stop() { };
@@ -113,7 +111,7 @@ public:
class Pause : public XmlRpcServerMethod, IvySyncPublicMethod {
public:
- Pause(XmlRpcServer* srv, vector<Decoder*> *decoders);
+ Pause(XmlRpcServer* srv, Linklist *decoders);
~Pause() { };
@@ -127,7 +125,7 @@ public:
class GetPos : public XmlRpcServerMethod, IvySyncPublicMethod {
public:
- GetPos(XmlRpcServer* srv, vector<Decoder*> *decoders);
+ GetPos(XmlRpcServer* srv, Linklist *decoders);
~GetPos() { };
@@ -142,7 +140,7 @@ public:
class SetPos : public XmlRpcServerMethod, IvySyncPublicMethod {
public:
- SetPos(XmlRpcServer* srv, vector<Decoder*> *decoders);
+ SetPos(XmlRpcServer* srv, Linklist *decoders);
~SetPos() { };
@@ -156,7 +154,7 @@ class SetPos : public XmlRpcServerMethod, IvySyncPublicMethod {
class Open : public XmlRpcServerMethod, IvySyncPublicMethod {
public:
- Open(XmlRpcServer* srv, vector<Decoder*> *decoders);
+ Open(XmlRpcServer* srv, Linklist *decoders);
~Open() { };
@@ -170,7 +168,7 @@ class Open : public XmlRpcServerMethod, IvySyncPublicMethod {
class Quit : public XmlRpcServerMethod, IvySyncPublicMethod {
public:
- Quit(XmlRpcServer* srv, vector<Decoder*> *decoders);
+ Quit(XmlRpcServer* srv, Linklist *decoders);
~Quit() { };