As discussed extensively (thanks Isaac...) last night on IRC, here is a patch 
to add the following protocol commands.  The generic SQL query has been 
removed.  These functions basically are just wrappers for the functions in 
mythcontext or programinfo.

QUERY_COMMBREAK -- returns a map-like structure of commercial breaks
QUERY_CUTLIST -- returns a map-like structure of the cutlist
QUERY_BOOKMARK -- returns the bookmark for the specified recording
SET_BOOKMARK -- sets a bookmark for a specific recording
QUERY_SETTING -- gets a setting from the database
SET_SETTING -- sets a setting in the database

For COMMBREAK, CUTLIST, and BOOKMARKs, you pass the channel id of a program 
and the starttime.  The starttime is represented in the number of seconds 
since January 1, 1970 in UTC.  This is the same format that is used when 
ProgramInfo uses ToStringList and FromStringList.  Returned long-long values 
(frame numbers) are encoded using the existing long-long encode and decode 
functions.

Meanwhile the protocol version number got bumped (about 2 hours ago), so there 
is no need to bump it again.  I have attached the patch for the mythweb proto 
bump, as they need to be in sync otherwise mythweb fails.

Index: libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.173
diff -u -r1.173 mythcontext.cpp
--- libs/libmyth/mythcontext.cpp	3 May 2005 21:01:35 -0000	1.173
+++ libs/libmyth/mythcontext.cpp	3 May 2005 23:15:41 -0000
@@ -1488,29 +1488,61 @@
                       "AND hostname = :HOSTNAME ;");
         query.bindValue(":KEY", key);
         query.bindValue(":HOSTNAME", d->m_localhostname);
-        
+
         if (!query.exec() || !query.isActive())
                 MythContext::DBError("Clear setting", query);
-    
+
         query.prepare("INSERT settings ( value, data, hostname ) "
                       "VALUES ( :VALUE, :DATA, :HOSTNAME );");
         query.bindValue(":VALUE", key);
         query.bindValue(":DATA", newValue);
         query.bindValue(":HOSTNAME", d->m_localhostname);
-        
+
         if (!query.exec() || !query.isActive())
                 MythContext::DBError("Save new setting", query);
     }
     else
     {
-        VERBOSE(VB_IMPORTANT, 
+        VERBOSE(VB_IMPORTANT,
+             QString("Database not open while trying to save setting: %1")
+                                .arg(key));
+    }
+
+}
+
+void MythContext::SaveSettingOnHost(const QString &key, const QString &host,
+                                    const QString &newValue)
+{
+    MSqlQuery query(MSqlQuery::InitCon());
+    if (query.isConnected())
+    {
+        query.prepare("DELETE FROM settings WHERE value = :KEY "
+                      "AND hostname = :HOSTNAME ;");
+        query.bindValue(":KEY", key);
+        query.bindValue(":HOSTNAME", host);
+
+        if (!query.exec() || !query.isActive())
+                MythContext::DBError("Clear setting", query);
+
+        query.prepare("INSERT settings ( value, data, hostname ) "
+                      "VALUES ( :VALUE, :DATA, :HOSTNAME );");
+        query.bindValue(":VALUE", key);
+        query.bindValue(":DATA", newValue);
+        query.bindValue(":HOSTNAME", host);
+
+        if (!query.exec() || !query.isActive())
+                MythContext::DBError("Save new setting on host", query);
+    }
+    else
+    {
+        VERBOSE(VB_IMPORTANT,
              QString("Database not open while trying to save setting: %1")
                                 .arg(key));
     }
 
 }
 
-QString MythContext::GetSetting(const QString &key, const QString &defaultval) 
+QString MythContext::GetSetting(const QString &key, const QString &defaultval)
 {
     bool found = false;
     QString value;
Index: libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.196
diff -u -r1.196 mythcontext.h
--- libs/libmyth/mythcontext.h	3 May 2005 18:58:58 -0000	1.196
+++ libs/libmyth/mythcontext.h	3 May 2005 23:15:41 -0000
@@ -251,6 +251,8 @@
     void SaveSetting(const QString &key, int newValue);
     void SaveSetting(const QString &key, const QString &newValue);
     QString GetSetting(const QString &key, const QString &defaultval = "");
+    void SaveSettingOnHost(const QString &key, const QString &host,
+                           const QString &newValue);
 
     // Convenience setting query methods
     int GetNumSetting(const QString &key, int defaultval = 0);
Index: programs/mythbackend/mainserver.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythbackend/mainserver.cpp,v
retrieving revision 1.198
diff -u -r1.198 mainserver.cpp
--- programs/mythbackend/mainserver.cpp	3 May 2005 20:14:12 -0000	1.198
+++ programs/mythbackend/mainserver.cpp	3 May 2005 23:15:44 -0000
@@ -422,7 +422,48 @@
             VERBOSE(VB_ALL, "Bad QUERY_IS_ACTIVE_BACKEND");
         else
             HandleIsActiveBackendQuery(listline, 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 == "QUERY_SETTING")
+    {
+        if (tokens.size() != 3)
+            VERBOSE(VB_ALL, "Bad QUERY_SETTING");
+        else
+            HandleSettingQuery(tokens, pbs);
+    }
+    else if (command == "SET_SETTING")
+    {
+        if (tokens.size() != 4)
+            VERBOSE(VB_ALL, "Bad SET_SETTING");
+        else
+            HandleSetSetting(tokens, pbs);
     }
     else if (command == "SHUTDOWN_NOW")
     {
@@ -2581,11 +2622,218 @@
     }
     else
         retlist << "TRUE";
-    
+
     SendResponse(pbs->getSocket(), retlist);
-} 
+}
+
+void MainServer::HandleCommBreakQuery(QString &chanid,
+                                      QString &starttime,
+                                      PlaybackSock *pbs)
+{
+// Commercial break query
+// Format:  QUERY_COMMBREAK <chanid> <starttime>
+// chanid is chanid, starttime is startime of prorgram in
+//   # of seconds since Jan 1, 1970, in UTC time.  Same format as in
+//   a ProgramInfo structure in a string list.
+// Return structure is [number of rows] followed by a triplet of values:
+//   each triplet : [type] [long portion 1] [long portion 2]
+// type is the value in the map, right now 4 = commbreak start, 5= end
+
+    QSocket *pbssock = NULL;
+    if (pbs)
+        pbssock = pbs->getSocket();
+
+    QMap<long long, int> commBreakMap;
+    QMap<long long, int>::Iterator it;
+    QDateTime startdt;
+    startdt.setTime_t((uint)atoi(starttime));
+    QStringList retlist;
+    int rowcnt = 0;
+
+    ProgramInfo *pginfo = ProgramInfo::GetProgramFromRecorded(chanid,
+                                                              startdt);
+    pginfo->GetCommBreakList(commBreakMap);
+
+    for (it = commBreakMap.begin(); it != commBreakMap.end(); ++it)
+    {
+        rowcnt++;
+        QString intstr = QString("%1").arg(it.data());
+        retlist << intstr;
+        encodeLongLong(retlist,it.key());
+    }
+
+    if (rowcnt > 1)
+        retlist.prepend(QString("%1").arg(rowcnt));
+    else
+        retlist << "-1";
+
+    if (pbssock)
+        SendResponse(pbssock, retlist);
+
+    return;
+}
+
+void MainServer::HandleCutlistQuery(QString &chanid,
+                                    QString &starttime,
+                                    PlaybackSock *pbs)
+{
+// Cutlist query
+// Format:  QUERY_CUTLIST <chanid> <starttime>
+// chanid is chanid, starttime is startime of prorgram in
+//   # of seconds since Jan 1, 1970, in UTC time.  Same format as in
+//   a ProgramInfo structure in a string list.
+// Return structure is [number of rows] followed by a triplet of values:
+//   each triplet : [type] [long portion 1] [long portion 2]
+// type is the value in the map, right now 0 = commbreak start, 1 = end
+
+    QSocket *pbssock = NULL;
+    if (pbs)
+        pbssock = pbs->getSocket();
+
+    QMap<long long, int> cutlistMap;
+    QMap<long long, int>::Iterator it;
+    QDateTime startdt;
+    startdt.setTime_t((uint)atoi(starttime));
+    QStringList retlist;
+    int rowcnt = 0;
+
+    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());
+        rowcnt++;
+    }
+
+    if (rowcnt > 0)
+        retlist.prepend(QString("%1").arg(rowcnt));
+    else
+        retlist << "-1";
+
+    if (pbssock)
+        SendResponse(pbssock, retlist);
+
+    return;
+}
+
+
+void MainServer::HandleBookmarkQuery(QString &chanid,
+                                     QString &starttime,
+                                     PlaybackSock *pbs)
+// Bookmark query
+// Format:  QUERY_BOOKMARK <chanid> <starttime>
+// chanid is chanid, starttime is startime of prorgram in
+//   # of seconds since Jan 1, 1970, in UTC time.  Same format as in
+//   a ProgramInfo structure in a string list.
+// Return value is a long-long encoded as two separate values
+{
+    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)
+{
+// Bookmark query
+// Format:  SET_BOOKMARK <chanid> <starttime> <long part1> <long part2>
+// chanid is chanid, starttime is startime of prorgram in
+//   # of seconds since Jan 1, 1970, in UTC time.  Same format as in
+//   a ProgramInfo structure in a string list.  The two longs are the two
+//   portions of the bookmark value to set.
+
+    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::HandleSettingQuery(QStringList &tokens, PlaybackSock *pbs)
+{
+// Format: QUERY_SETTING <hostname> <setting>
+// Returns setting value as a string
+
+    QSocket *pbssock = NULL;
+    if (pbs)
+        pbssock = pbs->getSocket();
+
+    QString hostname = tokens[1];
+    QString setting = tokens[2];
+    QStringList retlist;
+
+    QString retvalue = gContext->GetSettingOnHost(setting, hostname, "-1");
+
+    retlist << retvalue;
+    if (pbssock)
+        SendResponse(pbssock, retlist);
+
+    return;
+}
+
+void MainServer::HandleSetSetting(QStringList &tokens,
+                                    PlaybackSock *pbs)
+{
+// Format: SET_SETTING <hostname> <setting> <value>
+    QSocket *pbssock = NULL;
+    if (pbs)
+        pbssock = pbs->getSocket();
+
+    QString hostname = tokens[1];
+    QString setting = tokens[2];
+    QString svalue = tokens[3];
+    QStringList retlist;
+
+    gContext->SaveSettingOnHost(setting, hostname, svalue);
+
+    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	3 May 2005 23:15:44 -0000
@@ -104,6 +104,15 @@
                              PlaybackSock *pbs);
     void HandleLockTuner(PlaybackSock *pbs);
     void HandleFreeTuner(int cardid, 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 HandleSettingQuery(QStringList &tokens, PlaybackSock *pbs);
+    void HandleSetSetting(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

Reply via email to