diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.txt | 12 | ||||
-rwxr-xr-x | httpresource.c | 6 | ||||
-rw-r--r-- | log.c | 2 | ||||
-rw-r--r-- | responsememblk.c | 81 | ||||
-rwxr-xr-x | smarttvfactory.c | 41 | ||||
-rw-r--r-- | smarttvfactory.h | 5 |
7 files changed, 120 insertions, 29 deletions
@@ -31,7 +31,7 @@ TMPDIR = /tmp ### Allow user defined options to overwrite defaults: -#-include $(VDRDIR)/Make.config +-include $(VDRDIR)/Make.config ### read standlone settings if there -include .standalone @@ -7,3 +7,15 @@ smarttv-client: Contains the source code of the Smart TV widget release: Contains Smart TV Widget files ready for deplyoment. Check http://projects.vdr-developer.org/projects/plg-smarttvweb/wiki for a description, installation instructions and configuration instructions. + + +History: + +Widget Version 0.9.5: +* new widget.conf element playKeyBehavior, which is of Type Integer. 0: key value * 100 is target percentage, 1: key value is skip duration +* new Server Select Menu item, which allows the re-selection of the VDR server +* timezone correction + +Plugin Version 0.9.8: +* provide server timestamp + diff --git a/httpresource.c b/httpresource.c index e29358b..545e7ba 100755 --- a/httpresource.c +++ b/httpresource.c @@ -455,6 +455,12 @@ int cHttpResource::processRequest() { ok_to_serve = true; } + if (mPath.compare(0, strlen(VideoDirectory), VideoDirectory) == 0) { + *(mLog->log())<< DEBUGPREFIX + << " Found video dir request. serving " << mPath << endl; + ok_to_serve = true; + } + if (stat(mPath.c_str(), &statbuf) < 0) { // checking, whether the file or directory exists *(mLog->log())<< DEBUGPREFIX @@ -44,7 +44,7 @@ Log* Log::getInstance() { int Log::init(string fileName) { char timebuf[128]; time_t now = time(NULL); - strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&now)); + strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", localtime(&now)); if (fileName != "") { mLogFile = new ofstream(); diff --git a/responsememblk.c b/responsememblk.c index cb90599..a2c8636 100644 --- a/responsememblk.c +++ b/responsememblk.c @@ -744,6 +744,7 @@ void cResponseMemBlk::writeMPD(double duration, int bitrate, float seg_dur, int sendHeaders(200, "OK", NULL, "application/x-mpegURL", mResponseMessage->size(), -1); } + void cResponseMemBlk::receiveAddTimerReq() { if (isHeadRequest()) return ; @@ -754,6 +755,7 @@ void cResponseMemBlk::receiveAddTimerReq() { mRequest->parseQueryLine(&avps); //guid=<guid>&evid=<event_id> + // evid is optional. If not present, the plugin looks up the current event id for the channel // later //guid=<guid>&wd=<weekdays>&dy=<day>&st=<start>&sp=<stop>&f=<url_enc_filename> @@ -825,20 +827,15 @@ void cResponseMemBlk::receiveAddTimerReq() { return; } - if (ev_id == 0) { - // no event id -> not implemented - sendError(501, "Not Implemented", NULL, "001 Not Implemented. evid shall be present."); - return ; - } + const cEvent *ev = NULL; - // have an event id cSchedulesLock * lock = new cSchedulesLock(false, 500); const cSchedules *schedules = cSchedules::Schedules(*lock); - + const cSchedule *schedule = schedules->GetSchedule(chan_id); if (schedule == NULL) { *(mLog->log())<< DEBUGPREFIX - << " ERROR: Schedule is zero for guid= " << guid + << "ERROR: Schedule is zero for guid= " << guid << endl; delete mResponseMessage; delete lock; @@ -846,22 +843,64 @@ void cResponseMemBlk::receiveAddTimerReq() { sendError(500, "Internal Server Error", NULL, "001 Schedule is zero."); return; } + + if (ev_id == 0) { + // no event id: Use the current running event + + time_t now = time(NULL); + for(cEvent* e = schedule->Events()->First(); e; e = schedule->Events()->Next(e)) { + if ( (e->StartTime() <= now) && (e->EndTime() > now)) { + ev = e; + + } else if (e->StartTime() > now + 3600) { + break; + } + } + + if (ev == NULL) { + *(mLog->log())<< DEBUGPREFIX + << "ERROR: Event is zero for guid= " << guid + << endl; + delete mResponseMessage; + delete lock; + + mResponseMessage = NULL; + sendError(500, "Internal Server Error", NULL, "002 Event is zero."); + return; + } + } + + else { + // have an event id - // time_t now = time(NULL); - const cEvent *ev = schedule->GetEvent(ev_id); - - if (ev == NULL) { + ev = schedule->GetEvent(ev_id); + + if (ev == NULL) { + *(mLog->log())<< DEBUGPREFIX + << " ERROR: Event not found for guid= " << guid + << " and ev_id= " << ev_id + << endl; + delete mResponseMessage; + delete lock; + mResponseMessage = NULL; + sendError(500, "Internal Server Error", NULL, "002 Event is zero."); + return; + } + } + + if (Timers.GetMatch(ev) != NULL) { *(mLog->log())<< DEBUGPREFIX - << "ERROR: Event not found for guid= " << guid + << " WARING: Timer already created guid= " << guid << " and ev_id= " << ev_id << endl; - delete mResponseMessage; - delete lock; - mResponseMessage = NULL; - sendError(500, "Internal Server Error", NULL, "002 Event is zero."); - return; + + delete mResponseMessage; + delete lock; + mResponseMessage = NULL; + sendError(400, "Bad Request", NULL, "014 Timer already defined."); + return; } - + // now, create a new timer if (ev->Title() == NULL) { *(mLog->log())<< DEBUGPREFIX @@ -910,9 +949,6 @@ void cResponseMemBlk::receiveAddTimerReq() { sendHeaders(200, "OK", NULL, "application/xml", mResponseMessage->size(), -1); return; - - - } void cResponseMemBlk::receiveDelTimerReq() { @@ -2025,6 +2061,7 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) { << " Active Timer: " << ti->File() << " Start= " << ti->StartTime() << " Duration= " << (ti->StopTime() - ti->StartTime()) + << " Now= " << now << endl; act_rec.push_back(sTimerEntry(ti->File(), ti->StartTime(), (ti->StopTime() - ti->StartTime()))); } diff --git a/smarttvfactory.c b/smarttvfactory.c index 763baeb..27f957a 100755 --- a/smarttvfactory.c +++ b/smarttvfactory.c @@ -121,6 +121,7 @@ void SmartTvServer::Recording(const cDevice *Device, const char *Name, const cha << " Msg= " << msg.str() << endl; + for (uint i = 0; i < mConTvClients.size(); i ++) { if ((mConTvClients[i]->ip).compare("") != 0) { @@ -132,6 +133,19 @@ void SmartTvServer::Recording(const cDevice *Device, const char *Name, const cha } }; +//thlo: Try to clean up +void SmartTvServer::pushToClients(cHttpResourceBase* resource) { + for (uint i = 0; i < mConTvClients.size(); i ++) { + if ((mConTvClients[i]->ip).compare("") != 0) { + + int cfd= connectToClient(mConTvClients[i]->ip); + if (cfd < 0) + continue; + addHttpResource(cfd, resource); + } + } +} + void SmartTvServer::TimerChange(const cTimer *Timer, eTimerChange Change) { #ifndef DEBUG @@ -291,12 +305,20 @@ bool SmartTvServer::deleteYtVideoId(string guid) { void SmartTvServer::pushYtVideoId(string vid_id, bool store) { + time_t now = time(NULL); for (uint i = 0; i < mConTvClients.size(); i ++) { - if ((mConTvClients[i]->ip).compare("") != 0) - pushYtVideoIdToClient(vid_id, mConTvClients[i]->ip, store); + if ((mConTvClients[i]->ip).compare("") != 0) { + // pushYtVideoIdToClient(vid_id, mConTvClients[i]->ip, store); + int cfd= connectToClient(mConTvClients[i]->ip); + if (cfd < 0) + return; + addHttpResource(cfd, new cHttpYtPushClient(cfd, mHttpClientId, serverPort, this, mConTvClients[i]->ip, vid_id, store)); + } } } + + int SmartTvServer::connectToClient(string peer) { *(mLog.log()) << " SmartTvServer::connectToClient: client= " << peer << endl; @@ -350,6 +372,7 @@ void SmartTvServer::addHttpResource(int rfd, cHttpResourceBase* resource) { } } +/* // obsolete void SmartTvServer::pushYtVideoIdToClient(string vid_id, string peer, bool store) { *(mLog.log()) << " SmartTvServer::pushYtVideoIdToClient vid_id= " << vid_id << " client= " << peer << endl; @@ -360,7 +383,7 @@ void SmartTvServer::pushYtVideoIdToClient(string vid_id, string peer, bool store addHttpResource(cfd, new cHttpYtPushClient(cfd, mHttpClientId, serverPort, this, peer, vid_id, store)); } - +*/ void SmartTvServer::pushCfgServerAddressToTv( string tv_addr) { *(mLog.log()) << " SmartTvServer::pushCfgServerAddressToTv TV= " << tv_addr << endl; @@ -588,7 +611,17 @@ void SmartTvServer::loop() { } // org bracket int SmartTvServer::isServing() { - return (mActiveSessions != 0 ? true : false); + *(mLog.log()) << "SmartTvServer::isServing" << endl; + time_t now = time(NULL); + bool connected_tv = false; + for (uint i = 0; i < mConTvClients.size(); i++) { + if ( (now - mConTvClients[i]->lastKeepAlive) < 60) { + *(mLog.log()) << "SmartTvServer::isServing: Found a connected TV" << endl; + connected_tv = true; + break; + } + } + return (mActiveSessions != 0 ? true : false) or connected_tv; } void SmartTvServer::initServer(string dir) { diff --git a/smarttvfactory.h b/smarttvfactory.h index 5fb29d0..01a2035 100644 --- a/smarttvfactory.h +++ b/smarttvfactory.h @@ -86,11 +86,14 @@ class SmartTvServer : public cStatus { cManageUrls* getUrlsObj(); void pushYtVideoId(string, bool); - void pushYtVideoIdToClient(string vid_id, string peer, bool); + // void pushYtVideoIdToClient(string vid_id, string peer, bool); void pushCfgServerAddressToTv( string tv_addr); + private: void addHttpResource(int fd, cHttpResourceBase* resource); + void pushToClients(cHttpResourceBase* resource); + int connectToClient(string peer); void setNonBlocking(int fd); |