OK, I've decided to go ahead and complete the protocol extensions that I would
need for most playback functions from alternate frontends. Here are the
additional commands and how they work:
QUERY_SQL [query statement]
Returns all rows and columns of the resultset in []:[] delimited form
QUERY_COMMBREAK [chanid] [starttime in seconds since 1/1/1970]
Returns the set of all commercial breaks. Each set has 3 values:
[4 or 5] -- commercial break type (4 = start, 5 = stop)
2 values representing a long-long encoded in usual fashion
All values are []:[] delimited
QUERY_CUTLIST [chanid] [starttime in seconds since 1/1/1970]
As above, but returns the cutlist. 0 = start, 1 = stop of each section
QUERY_BOOKMARK [chanid] [starttime in seconds since 1/1/1970]
Returns a long-long, encoded as usual with 2 values []:[] separated
SET_BOOKMARK [chanid] [starttime] [long value 1] [long value 2]
Sets the bookmark, using the 2 values to form one long-long
All commands (except QUERY_SQL) use the ProgramInfo functions to get/set the
data, so the logic is still in one place.
Comments,thoughts before I proceed? Next steps would be to add functions to
get guide data, in order to emulate the front-end guide, then add a function
to schedule a recording. Scheduling the recording is a pretty vital one. If
we can make that a protocol function, then MythWeb could use it as well, so
that there would be much less dependence on the database structure for adding
a scheduled program.
Thanks.
I've re-attached the mythweb protocol version update as well.
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.194
diff -u -r1.194 mythcontext.h
--- libs/libmyth/mythcontext.h 23 Apr 2005 15:56:53 -0000 1.194
+++ libs/libmyth/mythcontext.h 1 May 2005 04:25:47 -0000
@@ -163,7 +163,7 @@
};
#define MYTH_BINARY_VERSION "0.18.20050423-1"
-#define MYTH_PROTO_VERSION "15"
+#define MYTH_PROTO_VERSION "16"
extern int print_verbose_messages;
Index: programs/mythbackend/mainserver.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/mainserver.cpp,v
retrieving revision 1.196
diff -u -r1.196 mainserver.cpp
--- programs/mythbackend/mainserver.cpp 29 Apr 2005 05:08:13 -0000 1.196
+++ programs/mythbackend/mainserver.cpp 1 May 2005 04:25:49 -0000
@@ -408,7 +408,38 @@
VERBOSE(VB_ALL, "Bad QUERY_IS_ACTIVE_BACKEND");
else
HandleIsActiveBackendQuery(listline, pbs);
-
+ }
+ else if (command == "QUERY_SQL")
+ {
+ HandleSQLQuery(line,pbs);
+ }
+ else if (command == "QUERY_COMMBREAK")
+ {
+ if (tokens.size() != 3)
+ VERBOSE(VB_ALL, "Bad QUERY_COMMBREAK");
+ else
+ HandleCommBreakQuery(tokens[1],tokens[2],pbs);
+ }
+ else if (command == "QUERY_CUTLIST")
+ {
+ if (tokens.size() != 3)
+ VERBOSE(VB_ALL, "Bad QUERY_CUTLIST");
+ else
+ HandleCutlistQuery(tokens[1],tokens[2],pbs);
+ }
+ else if (command == "QUERY_BOOKMARK")
+ {
+ if (tokens.size() != 3)
+ VERBOSE(VB_ALL, "Bad QUERY_BOOKMARK");
+ else
+ HandleBookmarkQuery(tokens[1],tokens[2],pbs);
+ }
+ else if (command == "SET_BOOKMARK")
+ {
+ if (tokens.size() != 5)
+ VERBOSE(VB_ALL, "Bad SET_BOOKMARK");
+ else
+ HandleSetBookmark(tokens,pbs);
}
else if (command == "SHUTDOWN_NOW")
{
@@ -2562,11 +2593,178 @@
}
else
retlist << "TRUE";
-
+
SendResponse(pbs->getSocket(), retlist);
-}
+}
+
+
+void MainServer::HandleSQLQuery(QString &str,
+ PlaybackSock *pbs)
+{
+ QStringList retlist;
+
+ if (str.length() < 12)
+ {
+ VERBOSE(VB_ALL,QString("Invalid QUERY_SQL call: %1").arg(str));
+ return;
+ }
+
+ QString qrystr = str.mid(10,str.length());
+ MSqlQuery query(MSqlQuery::InitCon());
+ query.prepare(qrystr);
+ if (query.exec() && query.isActive() && query.numRowsAffected())
+ {
+ while (query.next())
+ {
+ int i = 0;
+ while (query.value(i).isValid())
+ {
+ retlist << query.value(i).toString();
+ i++;
+ }
+ }
+ }
+ else
+ {
+ VERBOSE(VB_ALL,QString("QUERY_SQL failed: %1").arg(qrystr));
+ retlist << "-1";
+ }
+ SendResponse(pbs->getSocket(), retlist);
+
+}
+
+
+void MainServer::HandleCommBreakQuery(QString &chanid,
+ QString &starttime,
+ PlaybackSock *pbs)
+{
+ QSocket *pbssock = NULL;
+ if (pbs)
+ pbssock = pbs->getSocket();
+ bool has_commbreaks = FALSE;
+
+ QMap<long long, int> commBreakMap;
+ QMap<long long, int>::Iterator it;
+ QDateTime startdt;
+ startdt.setTime_t((uint)atoi(starttime));
+ QStringList retlist;
+
+ ProgramInfo *pginfo = ProgramInfo::GetProgramFromRecorded(chanid,
+ startdt);
+ pginfo->GetCommBreakList(commBreakMap);
+
+ for (it = commBreakMap.begin(); it != commBreakMap.end(); ++it)
+ {
+ QString intstr = QString("%1").arg(it.data());
+ retlist << intstr;
+ encodeLongLong(retlist,it.key());
+ has_commbreaks = TRUE;
+ }
+
+ if (!has_commbreaks)
+ retlist << "-1";
+
+ if (pbssock)
+ SendResponse(pbssock, retlist);
+
+ return;
+}
+
+
+void MainServer::HandleCutlistQuery(QString &chanid,
+ QString &starttime,
+ PlaybackSock *pbs)
+{
+ QSocket *pbssock = NULL;
+ if (pbs)
+ pbssock = pbs->getSocket();
+ bool has_cutlist = FALSE;
+
+ QMap<long long, int> cutlistMap;
+ QMap<long long, int>::Iterator it;
+ QDateTime startdt;
+ startdt.setTime_t((uint)atoi(starttime));
+ QStringList retlist;
+
+ ProgramInfo *pginfo = ProgramInfo::GetProgramFromRecorded(chanid,
+ startdt);
+ pginfo->GetCutList(cutlistMap);
+
+ for (it = cutlistMap.begin(); it != cutlistMap.end(); ++it)
+ {
+ QString intstr = QString("%1").arg(it.data());
+ retlist << intstr;
+ encodeLongLong(retlist,it.key());
+ has_cutlist = TRUE;
+ }
+
+ if (!has_cutlist)
+ retlist << "-1";
+
+ if (pbssock)
+ SendResponse(pbssock, retlist);
+
+ return;
+}
+
+
+void MainServer::HandleBookmarkQuery(QString &chanid,
+ QString &starttime,
+ PlaybackSock *pbs)
+{
+ QSocket *pbssock = NULL;
+ if (pbs)
+ pbssock = pbs->getSocket();
+
+ QDateTime startdt;
+ startdt.setTime_t((uint)atoi(starttime));
+ QStringList retlist;
+ long long bookmark;
+
+ ProgramInfo *pginfo = ProgramInfo::GetProgramFromRecorded(chanid,
+ startdt);
+ bookmark = pginfo->GetBookmark();
+
+ encodeLongLong(retlist,bookmark);
+
+ if (pbssock)
+ SendResponse(pbssock, retlist);
+
+ return;
+}
+
+
+void MainServer::HandleSetBookmark(QStringList &tokens,
+ PlaybackSock *pbs)
+{
+ QSocket *pbssock = NULL;
+ if (pbs)
+ pbssock = pbs->getSocket();
+
+ QString chanid = tokens[1];
+ QString starttime = tokens[2];
+ QStringList bookmarklist;
+ bookmarklist << tokens[3];
+ bookmarklist << tokens[4];
+
+ QDateTime startdt;
+ startdt.setTime_t((uint)atoi(starttime));
+ QStringList retlist;
+ long long bookmark = decodeLongLong(bookmarklist, 0);
+
+ ProgramInfo *pginfo = ProgramInfo::GetProgramFromRecorded(chanid,
+ startdt);
+ pginfo->SetBookmark(bookmark);
+
+ retlist << "OK";
+ if (pbssock)
+ SendResponse(pbssock, retlist);
+
+ return;
+}
+
-void MainServer::HandleFileTransferQuery(QStringList &slist,
+void MainServer::HandleFileTransferQuery(QStringList &slist,
QStringList &commands,
PlaybackSock *pbs)
{
Index: programs/mythbackend/mainserver.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/mainserver.h,v
retrieving revision 1.58
diff -u -r1.58 mainserver.h
--- programs/mythbackend/mainserver.h 29 Apr 2005 03:20:55 -0000 1.58
+++ programs/mythbackend/mainserver.h 1 May 2005 04:25:49 -0000
@@ -104,6 +104,14 @@
PlaybackSock *pbs);
void HandleLockTuner(PlaybackSock *pbs);
void HandleFreeTuner(int cardid, PlaybackSock *pbs);
+ void HandleSQLQuery(QString &str, PlaybackSock *pbs);
+ void HandleCommBreakQuery(QString &chanid, QString &starttime,
+ PlaybackSock *pbs);
+ void HandleCutlistQuery(QString &chanid, QString &starttime,
+ PlaybackSock *pbs);
+ void HandleBookmarkQuery(QString &chanid, QString &starttime,
+ PlaybackSock *pbs);
+ void HandleSetBookmark(QStringList &tokens, PlaybackSock *pbs);
void HandleVersion(QSocket *socket, QString version);
void HandleBackendRefresh(QSocket *socket);
void HandleQueryLoad(PlaybackSock *pbs);
? mythwebproto.diff
Index: mythweb/includes/mythbackend.php
===================================================================
RCS file: /var/lib/mythcvs/mythplugins/mythweb/includes/mythbackend.php,v
retrieving revision 1.51
diff -u -r1.51 mythbackend.php
--- mythweb/includes/mythbackend.php 23 Mar 2005 18:28:27 -0000 1.51
+++ mythweb/includes/mythbackend.php 1 May 2005 00:39:12 -0000
@@ -14,7 +14,7 @@
// MYTH_PROTO_VERSION is defined in libmyth in mythtv/libs/libmyth/mythcontext.h
// and should be the current MythTV protocol version.
- define('MYTH_PROTO_VERSION', 15);
+ define('MYTH_PROTO_VERSION', 16);
// NUMPROGRAMLINES is defined in mythtv/libs/libmythtv/programinfo.h and is
// the number of items in a ProgramInfo QStringList group used by
_______________________________________________
mythtv-dev mailing list
[email protected]
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev