summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--httpclient.c30
-rw-r--r--httpclient.h22
-rwxr-xr-xhttpresource.c11
-rw-r--r--mngurls.c33
-rw-r--r--mngurls.h3
-rw-r--r--responsememblk.c292
-rw-r--r--responsememblk.h3
-rwxr-xr-xsmarttvfactory.c125
-rw-r--r--smarttvfactory.h22
9 files changed, 417 insertions, 124 deletions
diff --git a/httpclient.c b/httpclient.c
index cdf7645..f1dd793 100644
--- a/httpclient.c
+++ b/httpclient.c
@@ -359,3 +359,33 @@ string cHttpYtPushClient::getMsgBody(int) {
return "{\"type\":\"YT\",payload:{\"id\":\"" + mVideoId +"\", \"store\":"+((mStore)?"true":"false")+"}}";
}
+//------------------------------
+//----- cHttpCfgPushClient ------
+//------------------------------
+
+cHttpCfgPushClient::cHttpCfgPushClient(int f, int id, int port, SmartTvServer* fac, string peer) : cHttpClientBase(f, id, port, fac, peer) {
+
+ createRequestMessage("");
+}
+
+cHttpCfgPushClient::~cHttpCfgPushClient() {
+}
+
+string cHttpCfgPushClient::getMsgBody(int) {
+ return "{\"type\":\"CFGADD\",payload:{\"serverAddr\":\"" + mPeer +"\"" +"}}";
+}
+
+//------------------------------
+//----- cHttpInfoClient ------
+//------------------------------
+cHttpInfoClient::cHttpInfoClient(int f, int id, int port, SmartTvServer* fac, string peer, string bdy) : cHttpClientBase(f, id, port, fac, peer), mBody(bdy) {
+
+ createRequestMessage("");
+}
+
+cHttpInfoClient::~cHttpInfoClient() {
+}
+
+string cHttpInfoClient::getMsgBody(int) {
+ return "{\"type\":\"INFO\",payload:" + mBody +"}";;
+}
diff --git a/httpclient.h b/httpclient.h
index b5a39ea..000eaa8 100644
--- a/httpclient.h
+++ b/httpclient.h
@@ -87,4 +87,26 @@ class cHttpYtPushClient : public cHttpClientBase {
};
+class cHttpCfgPushClient : public cHttpClientBase {
+ public:
+ cHttpCfgPushClient(int, int, int, SmartTvServer*, string peer);
+ virtual ~cHttpCfgPushClient();
+
+ protected:
+ string getMsgBody(int );
+
+ string mServerAddress;
+};
+
+class cHttpInfoClient : public cHttpClientBase {
+ public:
+ cHttpInfoClient(int, int, int, SmartTvServer*, string peer, string body);
+ virtual ~cHttpInfoClient();
+
+ protected:
+ string getMsgBody(int );
+
+ string mBody;
+};
+
#endif
diff --git a/httpresource.c b/httpresource.c
index e20bf00..f718816 100755
--- a/httpresource.c
+++ b/httpresource.c
@@ -92,10 +92,10 @@ cHttpResource::cHttpResource(int f, int id, int port, SmartTvServer* factory): c
setNonBlocking();
// mBlkData = new char[MAXLEN];
- //#ifndef DEBUG
+#ifndef DEBUG
*(mLog->log()) << DEBUGPREFIX
<< " cHttpResource created" << endl;
- //#endif
+#endif
}
@@ -580,6 +580,13 @@ int cHttpResource::handlePost() {
return OKAY;
}
+ if (mPath.compare("/deleteYtUrl") == 0) {
+
+ mResponse = new cResponseMemBlk(this);
+ ((cResponseMemBlk*)mResponse)->receiveDelYtUrl();
+ return OKAY;
+ }
+
if (mPath.compare("/deleteRecording.xml") == 0) {
mResponse = new cResponseMemBlk(this);
diff --git a/mngurls.c b/mngurls.c
index dabcfe7..7e7d886 100644
--- a/mngurls.c
+++ b/mngurls.c
@@ -23,11 +23,12 @@
#include "mngurls.h"
-cManageUrls::cManageUrls(string dir): mLog(), mFile(NULL), mEntries() {
+cManageUrls::cManageUrls(string dir): mLog(), mFilename(), mFile(NULL), mEntries() {
mLog = Log::getInstance();
loadEntries(dir);
- mFile = new ofstream((dir +"/urls.txt").c_str(), ios::out | ios::app);
+ mFilename = dir +"/urls.txt";
+ mFile = new ofstream(mFilename.c_str(), ios::out | ios::app);
mFile->seekp(ios_base::end);
};
@@ -63,22 +64,46 @@ void cManageUrls::appendEntry(string type, string url) {
}
-void cManageUrls::deleteEntry(string type, string url) {
+bool cManageUrls::deleteEntry(string type, string url) {
*(mLog->log()) << " cManageUrls::deleteEntry: type= " << type << "guid= " << url << endl;
bool found = false;
if (type.compare("YT") !=0) {
- return;
+ *(mLog->log()) << " cManageUrls::deleteEntry: Not a YT Url " << endl;
+ return false;
}
+
for (int i = 0; i < mEntries.size(); i ++) {
if (url.compare(mEntries[i]->mEntry) == 0) {
// delete the entry here
*(mLog->log()) << " cManageUrls::deleteEntry ... " << endl;
+ mEntries.erase(mEntries.begin() +i);
found = true;
break;
}
}
+ if (found) {
+ *(mLog->log()) << " cManageUrls::deleteEntry - rewriting urls.txt file ... " << endl;
+ if (mFile != NULL) {
+ mFile->close();
+ delete mFile;
+ }
+ mFile = new ofstream(mFilename.c_str(), ios::out);
+
+ for (int i = 0; i < mEntries.size(); i ++) {
+ appendToFile(mEntries[i]->mType+"|"+mEntries[i]->mEntry);
+ }
+
+ // close the file
+ mFile->close();
+ delete mFile;
+
+ // open for append
+ mFile = new ofstream(mFilename.c_str(), ios::out | ios::app);
+ mFile->seekp(ios_base::end);
+ }
+ return found;
}
diff --git a/mngurls.h b/mngurls.h
index d500f61..5c58d3e 100644
--- a/mngurls.h
+++ b/mngurls.h
@@ -41,7 +41,7 @@ class cManageUrls {
virtual ~cManageUrls();
void appendEntry (string type, string guid);
- void deleteEntry(string type, string guid);
+ bool deleteEntry(string type, string guid);
size_t size();
sUrlEntry* getEntry(int index);
@@ -52,6 +52,7 @@ class cManageUrls {
Log* mLog;
+ string mFilename;
ofstream* mFile;
vector<sUrlEntry*> mEntries;
diff --git a/responsememblk.c b/responsememblk.c
index a695340..843894d 100644
--- a/responsememblk.c
+++ b/responsememblk.c
@@ -143,6 +143,63 @@ int cResponseMemBlk::receiveYtUrl() {
}
+int cResponseMemBlk::receiveDelYtUrl() {
+ if (isHeadRequest())
+ return OKAY;
+
+ vector<sQueryAVP> avps;
+ mRequest->parseQueryLine(&avps);
+ string id = "";
+
+ if (mRequest->getQueryAttributeValue(&avps, "guid", id) == ERROR){
+ *(mLog->log())<< DEBUGPREFIX
+ << " ERROR in cResponseMemBlk::receiveDelYtUrl: guid not found in query."
+ << endl;
+ sendError(400, "Bad Request", NULL, "No guid in query line");
+ return OKAY;
+ }
+
+ if (mRequest->mFactory->deleteYtVideoId(id)) {
+ sendHeaders(200, "OK", NULL, NULL, -1, -1);
+ }
+ else {
+ sendError(400, "Bad Request.", NULL, "Entry not found. Deletion failed!");
+ }
+
+ return OKAY;
+
+}
+
+int cResponseMemBlk::receiveCfgServerAddrs() {
+ vector<sQueryAVP> avps;
+ mRequest->parseQueryLine(&avps);
+ string addr;
+
+ if (isHeadRequest())
+ return OKAY;
+
+ if (mRequest->getQueryAttributeValue(&avps, "addr", addr) == OKAY){
+ if (addr.compare ("") == 0) {
+ *(mLog->log())<< DEBUGPREFIX
+ << " receiveCfgServerAddrs: no server address"
+ << endl;
+
+ sendHeaders(400, "Bad Request", NULL, "TV address field empty", 0, -1);
+ return OKAY;
+ }
+
+ // mRequest->mFactory->pushYtVideoId(line, store);
+
+ sendHeaders(200, "OK", NULL, NULL, 0, -1);
+ return OKAY;
+
+ }
+
+ sendError(400, "Bad Request", NULL, "Mandatory TV address attribute not present.");
+ return OKAY;
+
+}
+
void cResponseMemBlk::receiveClientInfo() {
vector<sQueryAVP> avps;
mRequest->parseQueryLine(&avps);
@@ -176,10 +233,11 @@ void cResponseMemBlk::receiveClientInfo() {
mRequest->mFactory->updateTvClient(ip, mac, time(NULL));
}
sendHeaders(200, "OK", NULL, NULL, 0, -1);
+#ifndef DEBUG
*(mLog->log())<< DEBUGPREFIX
<< " receiveClientInfo -done "
<< endl;
-
+#endif
}
@@ -248,7 +306,8 @@ int cResponseMemBlk::receiveResume() {
}
*(mLog->log())<< DEBUGPREFIX
- << " Resume: id= " << dev_id
+ << " Resume:"
+ // << " id= " << dev_id
<< " resume= " << entry << endl;
vector<sQueryAVP> avps;
@@ -259,9 +318,10 @@ int cResponseMemBlk::receiveResume() {
if (mRequest->getQueryAttributeValue(&avps, "guid", guid) == OKAY){
entry.mFilename = cUrlEncode::doUrlSaveDecode(guid);
- *(mLog->log())<< DEBUGPREFIX
+ /* *(mLog->log())<< DEBUGPREFIX
<< " Found a id Parameter: " << guid
<< endl;
+*/
}
if (mRequest->getQueryAttributeValue(&avps, "resume", resume_str) == OKAY){
entry.mResume = atof(resume_str.c_str());
@@ -273,8 +333,13 @@ int cResponseMemBlk::receiveResume() {
#ifndef STANDALONE
cRecording *rec = Recordings.GetByName(entry.mFilename.c_str());
if (rec == NULL) {
- //Error 404
- sendError(404, "Not Found", NULL, "Failed to find recording.");
+ //Error 400
+ *(mLog->log())<< DEBUGPREFIX
+ << " ERROR in receiveResume: recording not found - filename= " << entry.mFilename
+ << " resume= " << entry.mResume
+ << endl;
+
+ sendError(400, "Bad Request", NULL, "Failed to find the recording.");
return OKAY;
}
@@ -287,12 +352,83 @@ int cResponseMemBlk::receiveResume() {
<< endl;
resume.Save(int(entry.mResume * rec->FramesPerSecond() ));
+ rec->ResetResume();
#endif
sendHeaders(200, "OK", NULL, NULL, -1, -1);
return OKAY;
}
+
+int cResponseMemBlk::sendResumeXml () {
+ if (isHeadRequest())
+ return OKAY;
+#ifndef STANDALONE
+
+ mResponseMessage = new string();
+ *mResponseMessage = "";
+ mResponseMessagePos = 0;
+
+ mRequest->mConnState = SERVING;
+
+ char f[400];
+
+ cResumeEntry entry;
+ string id;
+
+ parseResume(entry, id);
+
+ vector<sQueryAVP> avps;
+ mRequest->parseQueryLine(&avps);
+ string guid;
+
+ if (mRequest->getQueryAttributeValue(&avps, "guid", guid) == OKAY){
+ entry.mFilename = cUrlEncode::doUrlSaveDecode(guid);
+
+ *(mLog->log() )<< DEBUGPREFIX
+ << " Found guid: " << guid
+ << " filename: " << entry.mFilename
+ << endl;
+ }
+
+
+ cRecording *rec = Recordings.GetByName(entry.mFilename.c_str());
+ if (rec == NULL) {
+ //Error 404
+ *(mLog->log())<< DEBUGPREFIX
+ << " ERROR in sendResume: recording not found - filename= " << entry.mFilename << endl;
+ sendError(400, "Bad Request", NULL, "Failed to find the recording.");
+ return OKAY;
+ }
+ if (rec->IsNew()) {
+ *(mLog->log())<< DEBUGPREFIX
+ << " sendResume: file is new " << endl;
+ sendError(400, "Bad Request", NULL, "File is new.");
+ return OKAY;
+ }
+ cResumeFile resume(entry.mFilename.c_str(), rec->IsPesRecording());
+
+ *(mLog->log())<< DEBUGPREFIX
+ << " resume request for " << entry.mFilename
+ << " resume= " << resume.Read()
+ << " (" << resume.Read() *1.0 / rec->FramesPerSecond() << "sec)"
+ << endl;
+
+ *mResponseMessage += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ *mResponseMessage += "<resume>";
+ snprintf(f, sizeof(f), "%.02f", resume.Read() *1.0 / rec->FramesPerSecond());
+ *mResponseMessage += f;
+ *mResponseMessage += "</resume>\n";
+
+
+ sendHeaders(200, "OK", NULL, "application/xml", mResponseMessage->size(), -1);
+#endif
+
+ return OKAY;
+}
+
+
+
int cResponseMemBlk::receiveDelRecReq() {
if (isHeadRequest())
return OKAY;
@@ -1387,74 +1523,6 @@ int cResponseMemBlk::sendEpgXml (struct stat *statbuf) {
}
-int cResponseMemBlk::sendResumeXml () {
- if (isHeadRequest())
- return OKAY;
-#ifndef STANDALONE
-
- mResponseMessage = new string();
- *mResponseMessage = "";
- mResponseMessagePos = 0;
- // mRequest->mContentType = MEMBLOCK;
-
- mRequest->mConnState = SERVING;
-
- char f[400];
-
- cResumeEntry entry;
- string id;
-
- parseResume(entry, id);
-
- vector<sQueryAVP> avps;
- mRequest->parseQueryLine(&avps);
- string guid;
-
- if (mRequest->getQueryAttributeValue(&avps, "guid", guid) == OKAY){
- // entry.mFilename = guid;
- entry.mFilename = cUrlEncode::doUrlSaveDecode(guid);
-
- *(mLog->log() )<< DEBUGPREFIX
- << " Found guid: " << guid
- << " filename: " << entry.mFilename
- << endl;
- }
-
-
- cRecording *rec = Recordings.GetByName(entry.mFilename.c_str());
- if (rec == NULL) {
- //Error 404
- *(mLog->log())<< DEBUGPREFIX
- << " sendResume: File Not Found filename= " << entry.mFilename << endl;
- sendError(404, "Not Found", NULL, "Failed to find recording.");
- return OKAY;
- }
- if (rec->IsNew()) {
- *(mLog->log())<< DEBUGPREFIX
- << " sendResume: file is new " << endl;
- sendError(400, "Bad Request", NULL, "File is new.");
- return OKAY;
- }
- cResumeFile resume(entry.mFilename.c_str(), rec->IsPesRecording());
-
- *(mLog->log())<< DEBUGPREFIX
- << " resume request for " << entry.mFilename
- << " resume= " << resume.Read()
- << " (" << resume.Read() *1.0 / rec->FramesPerSecond() << "sec)"
- << endl;
-
- *mResponseMessage += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- *mResponseMessage += "<resume>";
- snprintf(f, sizeof(f), "%.02f", resume.Read() *1.0 / rec->FramesPerSecond());
- *mResponseMessage += f;
- *mResponseMessage += "</resume>\n";
-
-
- sendHeaders(200, "OK", NULL, "application/xml", mResponseMessage->size(), -1);
-#endif
-
- return OKAY;
-}
int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
if (isHeadRequest())
@@ -1480,6 +1548,8 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
bool has_4_hd = true;
string mode = "";
bool add_desc = true;
+ string guid = "";
+ bool single_item = false;
if (mRequest->getQueryAttributeValue(&avps, "model", model) == OKAY){
*(mLog->log())<< DEBUGPREFIX
@@ -1487,6 +1557,13 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
<< endl;
}
+ if (mRequest->getQueryAttributeValue(&avps, "guid", guid) == OKAY){
+ *(mLog->log())<< DEBUGPREFIX
+ << " Found a guid Parameter: " << guid
+ << endl;
+ single_item = true;
+ }
+
if (mRequest->getQueryAttributeValue(&avps, "type", type) == OKAY){
*(mLog->log())<< DEBUGPREFIX
<< " Found a Type Parameter: " << type
@@ -1528,30 +1605,8 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
<< " generating /recordings.xml"
<< endl;
#endif
- sendHeaders(200, "OK", NULL, "application/xml", -1, statbuf->st_mtime);
-
- string hdr = "";
- hdr += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- hdr += "<rss version=\"2.0\">\n";
- hdr+= "<channel>\n";
- hdr+= "<title>VDR Recordings List</title>\n";
-
- *mResponseMessage += hdr;
-
- /*
- if (writeXmlItem("HAS - Big Bugs Bunny", "http://192.168.1.122/sm/BBB-DASH/HAS_BigBuckTS.xml|COMPONENT=HAS", "NA", "Big Bucks Bunny - HAS",
- "-", 0, 0) == ERROR)
- return ERROR;
- if (writeXmlItem("HLS - Big Bugs Bunny", "http://192.168.1.122/sm/BBB-DASH/HLS_BigBuckTS.m3u8|COMPONENT=HLS", "NA", "Big Bucks Bunny - HLS",
- "-", 0, 0) == ERROR)
- return ERROR;
- if (writeXmlItem("HAS - Big Bugs Bunny", "http://192.168.1.122:8000/hd2/mpeg/BBB-DASH/HAS_BigBuckTS.xml|COMPONENT=HAS", "NA", "Big Bucks Bunny - HAS from own Server",
- "-", 0, 0) == ERROR)
- return ERROR;
-*/
//--------------------
- cRecordings* recordings = &Recordings;
char f[600];
#ifndef DEBUG
@@ -1589,12 +1644,31 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
<< endl;
#endif
+
+ string hdr = "";
+ hdr += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+ hdr += "<rss version=\"2.0\">\n";
+ hdr+= "<channel>\n";
+ hdr+= "<title>VDR Recordings List</title>\n";
+
+ *mResponseMessage += hdr;
+
+ int item_count = 0;
int rec_dur = 0;
- for (cRecording *recording = recordings->First(); recording; recording = recordings->Next(recording)) {
+ cRecording *recording = NULL;
+ if (single_item) {
+ recording = Recordings.GetByName(guid.c_str());
+ if (recording == NULL)
+ *(mLog->log())<< DEBUGPREFIX << " WARNING in sendRecordingsXml: recording " << guid << " not found" << endl;
+ }
+ else {
+ recording = Recordings.First();
+ }
+ // for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording)) {
+ while (recording != NULL) {
hdr = "";
if (recording->IsPesRecording() or ((recording->FramesPerSecond() > 30.0) and !has_4_hd ))
- // snprintf(f, sizeof(f), "http://%s:%d%s", mServerAddr.c_str(), mServerPort,
snprintf(f, sizeof(f), "http://%s:%d%s", own_ip.c_str(), mRequest->mServerPort,
cUrlEncode::doUrlSaveEncode(recording->FileName()).c_str());
else
@@ -1611,13 +1685,8 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
for (uint x = 0; x < act_rec.size(); x++) {
if (act_rec[x].name == name) {
- /* *(mLog->log())<< DEBUGPREFIX
- << " !!!!! Found active Recording !!! "
- << endl;
-*/
+ // *(mLog->log())<< DEBUGPREFIX << " !!!!! Found active Recording !!! " << endl;
rec_dur += (act_rec[x].startTime + act_rec[x].duration - now);
-
-
}
} // for
@@ -1631,10 +1700,15 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
cUrlEncode::doUrlSaveEncode(recording->FileName()).c_str(),
-1,
recording->Start(), rec_dur, recording->FramesPerSecond(),
- (recording->IsPesRecording() ? 0: 1), (recording->IsNew() ? 0: 1)) == ERROR)
- // Better Internal Server Error
- return ERROR;
-
+ (recording->IsPesRecording() ? 0: 1), (recording->IsNew() ? 0: 1)) == ERROR) {
+ *mResponseMessage = "";
+ sendError(500, "Internal Server Error", NULL, "writeXMLItem returned an error");
+ return OKAY;
+ }
+ item_count ++;
+ // if (!single_item)
+ // recording = Recordings.Next(recording);
+ recording = (!single_item) ? Recordings.Next(recording) : NULL;
}
hdr = "</channel>\n";
@@ -1642,8 +1716,10 @@ int cResponseMemBlk::sendRecordingsXml(struct stat *statbuf) {
*mResponseMessage += hdr;
+ *(mLog->log())<< DEBUGPREFIX << " Recording Count= " <<item_count<< endl;
#endif
+ sendHeaders(200, "OK", NULL, "application/xml", mResponseMessage->size(), statbuf->st_mtime);
return OKAY;
}
@@ -1658,7 +1734,9 @@ int cResponseMemBlk::fillDataBlk() {
}
if (mResponseMessage == NULL) {
+#ifndef DEBUG
*(mLog->log())<< DEBUGPREFIX << " mResponseMessage == NULL -> Done" << endl;
+#endif
mRequest->mConnState = TOCLOSE;
return ERROR;
}
diff --git a/responsememblk.h b/responsememblk.h
index 84491e2..091d9ae 100644
--- a/responsememblk.h
+++ b/responsememblk.h
@@ -72,6 +72,9 @@ class cResponseMemBlk : public cResponseBase {
int receiveDelRecReq();
int receiveYtUrl();
+ int receiveDelYtUrl();
+
+ int receiveCfgServerAddrs();
void writeM3U8(double duration, int bitrate, float seg_dur, int end_seg);
void writeMPD(double duration, int bitrate, float seg_dur, int end_seg);
diff --git a/smarttvfactory.c b/smarttvfactory.c
index aeee438..f721658 100755
--- a/smarttvfactory.c
+++ b/smarttvfactory.c
@@ -45,11 +45,12 @@
#include <iostream>
#include <fstream>
-
+#include <sstream>
#include "smarttvfactory.h"
#include "httpresource.h"
#include "httpclient.h"
+#include "url.h"
#ifndef STANDALONE
#define PORT 8000
@@ -72,9 +73,9 @@ void SmartTvServerStartThread(void* arg) {
pthread_exit(NULL);
}
-SmartTvServer::SmartTvServer(): mRequestCount(0), isInited(false), serverPort(PORT), mServerFd(-1),
+SmartTvServer::SmartTvServer(): cStatus(), mRequestCount(0), isInited(false), serverPort(PORT), mServerFd(-1),
mSegmentDuration(10), mHasMinBufferTime(40), mLiveChannels(20),
- clientList(), mConTvClients(), mActiveSessions(0), mHttpClients(0), mConfig(NULL), mMaxFd(0),
+ clientList(), mConTvClients(), mActiveSessions(0), mHttpClientId(0), mConfig(NULL), mMaxFd(0),
mManagedUrls(NULL){
}
@@ -85,6 +86,101 @@ SmartTvServer::~SmartTvServer() {
delete mConfig;
}
+// Status methods
+void SmartTvServer::Recording(const cDevice *Device, const char *Name, const char *FileName, bool On) {
+#ifndef DEBUG
+ *(mLog.log()) << "SmartTvServer::Recording: Recording"
+ << ((On) ? " started" : " stopped")
+ << endl;
+#endif
+ stringstream msg;
+ string name ;
+
+ if (Name == NULL) {
+ if (FileName == NULL) {
+ *(mLog.log()) << "WARNING in SmartTvServer::Recording: Name and FileName are NULL. Return. " << endl;
+ return;
+ }
+ cRecording* rec = Recordings.GetByName(FileName);
+ if (rec == NULL) {
+ *(mLog.log()) << "WARNING in SmartTvServer::Recording: No Recording Entry found. Return. " << endl;
+ return;
+ }
+ name = rec->Name();
+ }
+ else
+ name = Name;
+
+ string method = (On) ? "RECSTART" : "RECSTOP";
+ string guid = (FileName == NULL) ? "" : cUrlEncode::doUrlSaveEncode(FileName);
+
+ msg << "{\"type\":\""+method+"\",\"name\":\"" << name << "\",\"guid\":\""+guid+"\"}";
+
+ *(mLog.log()) << "SmartTvServer::Recording: Recording"
+ << ((On) ? " started" : " stopped")
+ << " Msg= " << msg.str()
+ << endl;
+
+ 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, new cHttpInfoClient(cfd, mHttpClientId, serverPort, this, mConTvClients[i]->ip, msg.str()));
+ }
+ }
+};
+
+void SmartTvServer::TimerChange(const cTimer *Timer, eTimerChange Change) {
+ #ifndef DEBUG
+ *(mLog.log()) << "SmartTvServer::TimerChange"
+ << endl;
+#endif
+
+ stringstream msg;
+ string method = "";
+ switch (Change) {
+ case tcMod:
+ method = "TCMOD";
+ break;
+ case tcAdd:
+ method = "TCADD";
+ break;
+ case tcDel:
+ method = "TCDEL";
+ break;
+ }
+
+
+ if (Timer == NULL) {
+ *(mLog.log()) << "WARNING in SmartTvServer::TimerChange - Timer is NULL. Method= " << method << ", returning" << endl;
+ return;
+ }
+
+ string name = Timer->File();
+ if (Timer->Event() != NULL) {
+ if (Timer->Event()->Title() != NULL)
+ name = Timer->Event()->Title();
+ }
+
+
+ msg << "{\"type\":\"" << method << "\",\"name\":\"" << name << "\", \"start\":" << Timer->Start() <<"}";
+
+#ifndef DEBUG
+ *(mLog.log()) << "SmartTvServer::TimerChange: Msg= " << msg.str() << endl;
+#endif
+
+ 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, new cHttpInfoClient(cfd, mHttpClientId, serverPort, this, mConTvClients[i]->ip, msg.str()));
+ }
+ }
+}
+
void SmartTvServer::cleanUp() {
// close listening ports
for (uint idx= 0; idx < clientList.size(); idx++) {
@@ -166,6 +262,15 @@ void SmartTvServer::storeYtVideoId(string guid) {
mManagedUrls->appendEntry("YT", guid);
}
+bool SmartTvServer::deleteYtVideoId(string guid) {
+ if (mManagedUrls == NULL)
+ mManagedUrls = new cManageUrls(mConfigDir);
+
+ return mManagedUrls->deleteEntry("YT", guid);
+}
+
+
+
void SmartTvServer::pushYtVideoId(string vid_id, bool store) {
for (uint i = 0; i < mConTvClients.size(); i ++) {
if ((mConTvClients[i]->ip).compare("") != 0)
@@ -214,7 +319,7 @@ void SmartTvServer::addHttpResource(int rfd, cHttpResourceBase* resource) {
FD_SET(rfd, &mWriteState);
clientList[rfd] = resource;
- mHttpClients++;
+ mHttpClientId++;
if (rfd > mMaxFd) {
mMaxFd = rfd;
}
@@ -233,8 +338,18 @@ void SmartTvServer::pushYtVideoIdToClient(string vid_id, string peer, bool store
int cfd= connectToClient(peer);
if (cfd < 0)
return;
- addHttpResource(cfd, new cHttpYtPushClient(cfd, mHttpClients, serverPort, this, peer, vid_id, 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;
+
+ int cfd= connectToClient(tv_addr);
+ if (cfd < 0)
+ return;
+ addHttpResource(cfd, new cHttpCfgPushClient(cfd, mHttpClientId, serverPort, this, tv_addr));
}
int SmartTvServer::runAsThread() {
diff --git a/smarttvfactory.h b/smarttvfactory.h
index 261f2ea..02c03ec 100644
--- a/smarttvfactory.h
+++ b/smarttvfactory.h
@@ -38,12 +38,17 @@
#ifndef STANDALONE
#include <vdr/recording.h>
+#include <vdr/status.h>
+
+#else
+class cStatus {
+};
#endif
using namespace std;
-#define PLG_VERSION "0.9.7"
-#define SERVER "SmartTvWeb/0.9.7"
+#define PLG_VERSION "0.9.8-pre"
+#define SERVER "SmartTvWeb/0.9.8-pre"
struct sClientEntry {
string mac;
@@ -52,7 +57,8 @@ struct sClientEntry {
sClientEntry(string m, string i, time_t t ): mac(m), ip(i), lastKeepAlive(t) {};
};
-class SmartTvServer {
+class SmartTvServer : public cStatus {
+
public:
SmartTvServer();
virtual ~SmartTvServer();
@@ -74,17 +80,23 @@ class SmartTvServer {
void updateTvClient(string ip, string mac, time_t upd);
void removeTvClient(string ip, string mac, time_t upd);
- void storeYtVideoId(string);
+ void storeYtVideoId(string guid);
+ bool deleteYtVideoId(string guid);
cManageUrls* getUrlsObj();
void pushYtVideoId(string, bool);
void pushYtVideoIdToClient(string vid_id, string peer, bool);
+ void pushCfgServerAddressToTv( string tv_addr);
private:
void addHttpResource(int fd, cHttpResourceBase* resource);
int connectToClient(string peer);
void setNonBlocking(int fd);
+
+ // status callbacks
+ void Recording(const cDevice *Device, const char *Name, const char *FileName, bool On);
+ void TimerChange(const cTimer *Timer, eTimerChange Change);
pthread_t mThreadId;
int mRequestCount;
@@ -99,7 +111,7 @@ class SmartTvServer {
vector<sClientEntry*> mConTvClients;
int mActiveSessions;
- int mHttpClients;
+ int mHttpClientId;
string mConfigDir;
cSmartTvConfig *mConfig;