much more flexible method to get a servicelist in python..
authorAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 3 May 2006 16:06:49 +0000 (16:06 +0000)
committerAndreas Monzner <andreas.monzner@multimedia-labs.de>
Wed, 3 May 2006 16:06:49 +0000 (16:06 +0000)
lib/python/Screens/ChannelSelection.py
lib/service/iservice.h
lib/service/servicedvb.cpp
lib/service/servicedvb.h
lib/service/servicefs.cpp
lib/service/servicefs.h

index 9e29839..6bc04c8 100644 (file)
@@ -284,16 +284,13 @@ class ChannelSelectionEdit:
                                mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
                                if mutableBouquet:
                                        mutableBouquet.setListName(providerName)
                                mutableBouquet = serviceHandler.list(new_bouquet_ref).startEdit()
                                if mutableBouquet:
                                        mutableBouquet.setListName(providerName)
-                                       list = [ ]
                                        services = serviceHandler.list(provider.ref)
                                        if not services is None:
                                        services = serviceHandler.list(provider.ref)
                                        if not services is None:
-                                               if not services.getContent(list, True):
-                                                       for service in list:
-                                                               if mutableBouquet.addService(service):
-                                                                       print "add", service.toString(), "to new bouquet failed"
-                                                       mutableBouquet.flushChanges()
-                                               else:
-                                                       print "getContent failed"
+                                               list = services.getContent('R', True)
+                                               for service in list:
+                                                       if mutableBouquet.addService(service):
+                                                               print "add", service.toString(), "to new bouquet failed"
+                                               mutableBouquet.flushChanges()
                                        else:
                                                print "list provider", providerName, "failed"
                                else:
                                        else:
                                                print "list provider", providerName, "failed"
                                else:
index 3a0e32c..5ddf0cf 100644 (file)
@@ -513,7 +513,7 @@ class iListableService: public iObject
 public:
                /* legacy interface: get a list */
        virtual RESULT getContent(std::list<eServiceReference> &list, bool sorted=false)=0;
 public:
                /* legacy interface: get a list */
        virtual RESULT getContent(std::list<eServiceReference> &list, bool sorted=false)=0;
-       virtual RESULT getContent(PyObject *list, bool sorted=false)=0;
+       virtual PyObject *getContent(const char* format, bool sorted=false)=0;
 
                /* new, shiny interface: streaming. */
        virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
 
                /* new, shiny interface: streaming. */
        virtual SWIG_VOID(RESULT) getNext(eServiceReference &SWIG_OUTPUT)=0;
index fb84aa1..8efca0d 100644 (file)
@@ -350,31 +350,6 @@ RESULT eDVBServiceList::startQuery()
        return 0;
 }
 
        return 0;
 }
 
-RESULT eDVBServiceList::getContent(PyObject *list, bool sorted)
-{
-       eServiceReferenceDVB ref;
-
-       if (!m_query || !list || !PyList_Check(list))
-               return -1;
-
-       std::list<eServiceReferenceDVB> tmplist;
-
-       while (!m_query->getNextResult(ref))
-               tmplist.push_back(ref);
-
-       if (sorted)
-               tmplist.sort(iListableServiceCompare(this));
-
-       for (std::list<eServiceReferenceDVB>::iterator it(tmplist.begin());
-               it != tmplist.end(); ++it)
-       {
-               PyObject *refobj = New_eServiceReference(*it);
-               PyList_Append(list, refobj);
-               Py_DECREF(refobj);
-       }
-       return 0;
-}
-
 RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list, bool sorted)
 {
        eServiceReferenceDVB ref;
 RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list, bool sorted)
 {
        eServiceReferenceDVB ref;
@@ -391,6 +366,91 @@ RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list, bool sort
        return 0;
 }
 
        return 0;
 }
 
+//   The first argument of this function is a format string to specify the order and
+//   the content of the returned list
+//   useable format options are
+//   R = Service Reference (as swig object .. this is very slow)
+//   S = Service Reference (as python string object .. same as ref.toString())
+//   N = Service Name (as python string object)
+//   when exactly one return value per service is selected in the format string,
+//   then each value is directly a list entry
+//   when more than one value is returned per service, then the list is a list of
+//   python tuples
+//   unknown format string chars are returned as python None values !
+PyObject *eDVBServiceList::getContent(const char* format, bool sorted)
+{
+       PyObject *ret=0;
+       std::list<eServiceReference> tmplist;
+       int retcount=1;
+
+       if (!format || !(retcount=strlen(format)))
+               format = "R"; // just return service reference swig object ...
+
+       if (!getContent(tmplist, sorted))
+       {
+               int services=tmplist.size();
+               ePtr<iStaticServiceInformation> sptr;
+               eServiceCenterPtr service_center;
+
+               if (strchr(format, 'N'))
+                       eServiceCenter::getPrivInstance(service_center);
+
+               ret = PyList_New(services);
+               std::list<eServiceReference>::iterator it(tmplist.begin());
+
+               for (int cnt=0; cnt < services; ++cnt)
+               {
+                       eServiceReference &ref=*it++;
+                       PyObject *tuple = retcount > 1 ? PyTuple_New(retcount) : 0;
+                       for (int i=0; i < retcount; ++i)
+                       {
+                               PyObject *tmp=0;
+                               switch(format[i])
+                               {
+                               case 'R':  // service reference (swig)object
+                                       tmp = New_eServiceReference(ref);
+                                       break;
+                               case 'S':  // service reference string
+                                       tmp = PyString_FromString(ref.toString().c_str());
+                                       break;
+                               case 'N':  // service name
+                                       if (service_center)
+                                       {
+                                               service_center->info(ref, sptr);
+                                               if (sptr)
+                                               {
+                                                       std::string name;
+                                                       sptr->getName(ref, name);
+                                                       if (name.length())
+                                                               tmp = PyString_FromString(name.c_str());
+                                               }
+                                       }
+                                       if (!tmp)
+                                               tmp = PyString_FromString("<n/a>");
+                                       break;
+                               default:
+                                       if (tuple)
+                                       {
+                                               tmp = Py_None;
+                                               Py_INCREF(Py_None);
+                                       }
+                                       break;
+                               }
+                               if (tmp)
+                               {
+                                       if (tuple)
+                                               PyTuple_SET_ITEM(tuple, i, tmp);
+                                       else
+                                               PyList_SET_ITEM(ret, cnt, tmp);
+                               }
+                       }
+                       if (tuple)
+                               PyList_SET_ITEM(ret, cnt, tuple);
+               }
+       }
+       return ret ? ret : PyList_New(0);
+}
+
 RESULT eDVBServiceList::getNext(eServiceReference &ref)
 {
        if (!m_query)
 RESULT eDVBServiceList::getNext(eServiceReference &ref)
 {
        if (!m_query)
index 4b13193..81a6b74 100644 (file)
@@ -33,8 +33,8 @@ class eDVBServiceList: public iListableService, public iMutableServiceList
 DECLARE_REF(eDVBServiceList);
 public:
        virtual ~eDVBServiceList();
 DECLARE_REF(eDVBServiceList);
 public:
        virtual ~eDVBServiceList();
+       PyObject *getContent(const char* formatstr, bool sorted=false);
        RESULT getContent(std::list<eServiceReference> &list, bool sorted=false);
        RESULT getContent(std::list<eServiceReference> &list, bool sorted=false);
-       RESULT getContent(PyObject *list, bool sorted=false);
        RESULT getNext(eServiceReference &ptr);
        int compareLessEqual(const eServiceReference &a, const eServiceReference &b);
        
        RESULT getNext(eServiceReference &ptr);
        int compareLessEqual(const eServiceReference &a, const eServiceReference &b);
        
index 3e2f97b..708825f 100644 (file)
@@ -164,27 +164,89 @@ RESULT eServiceFS::getContent(std::list<eServiceReference> &list, bool sorted)
        return 0;
 }
 
        return 0;
 }
 
-RESULT eServiceFS::getContent(PyObject *list, bool sorted)
+//   The first argument of this function is a format string to specify the order and
+//   the content of the returned list
+//   useable format options are
+//   R = Service Reference (as swig object .. this is very slow)
+//   S = Service Reference (as python string object .. same as ref.toString())
+//   N = Service Name (as python string object)
+//   when exactly one return value per service is selected in the format string,
+//   then each value is directly a list entry
+//   when more than one value is returned per service, then the list is a list of
+//   python tuples
+//   unknown format string chars are returned as python None values !
+PyObject *eServiceFS::getContent(const char* format, bool sorted)
 {
 {
-       if (!list || !PyList_Check(list))
-               return -1;
-
+       PyObject *ret=0;
        std::list<eServiceReference> tmplist;
        std::list<eServiceReference> tmplist;
+       int retcount=1;
 
 
-       getContent(tmplist, sorted);
-
-       if (sorted)
-               tmplist.sort(iListableServiceCompare(this));
+       if (!format || !(retcount=strlen(format)))
+               format = "R"; // just return service reference swig object ...
 
 
-       for (std::list<eServiceReference>::iterator it(tmplist.begin());
-               it != tmplist.end(); ++it)
+       if (!getContent(tmplist, sorted))
        {
        {
-               PyObject *refobj = New_eServiceReference(*it);
-               PyList_Append(list, refobj);
-               Py_DECREF(refobj);
-       }
+               int services=tmplist.size();
+               ePtr<iStaticServiceInformation> sptr;
+               eServiceCenterPtr service_center;
 
 
-       return 0;
+               if (strchr(format, 'N'))
+                       eServiceCenter::getPrivInstance(service_center);
+
+               ret = PyList_New(services);
+               std::list<eServiceReference>::iterator it(tmplist.begin());
+
+               for (int cnt=0; cnt < services; ++cnt)
+               {
+                       eServiceReference &ref=*it++;
+                       PyObject *tuple = retcount > 1 ? PyTuple_New(retcount) : 0;
+                       for (int i=0; i < retcount; ++i)
+                       {
+                               PyObject *tmp=0;
+                               switch(format[i])
+                               {
+                               case 'R':  // service reference (swig)object
+                                       tmp = New_eServiceReference(ref);
+                                       break;
+                               case 'S':  // service reference string
+                                       tmp = PyString_FromString(ref.toString().c_str());
+                                       break;
+                               case 'N':  // service name
+                                       if (service_center)
+                                       {
+                                               service_center->info(ref, sptr);
+                                               if (sptr)
+                                               {
+                                                       std::string name;
+                                                       sptr->getName(ref, name);
+                                                       if (name.length())
+                                                               tmp = PyString_FromString(name.c_str());
+                                               }
+                                       }
+                                       if (!tmp)
+                                               tmp = PyString_FromString("<n/a>");
+                                       break;
+                               default:
+                                       if (tuple)
+                                       {
+                                               tmp = Py_None;
+                                               Py_INCREF(Py_None);
+                                       }
+                                       break;
+                               }
+                               if (tmp)
+                               {
+                                       if (tuple)
+                                               PyTuple_SET_ITEM(tuple, i, tmp);
+                                       else
+                                               PyList_SET_ITEM(ret, cnt, tmp);
+                               }
+                       }
+                       if (tuple)
+                               PyList_SET_ITEM(ret, cnt, tuple);
+               }
+       }
+       return ret ? ret : PyList_New(0);
 }
 
 RESULT eServiceFS::getNext(eServiceReference &ptr)
 }
 
 RESULT eServiceFS::getNext(eServiceReference &ptr)
index 4257f2a..abd10f3 100644 (file)
@@ -36,6 +36,7 @@ public:
        
        RESULT getContent(std::list<eServiceReference> &list, bool sorted=false);
        RESULT getContent(PyObject *list, bool sorted=false);
        
        RESULT getContent(std::list<eServiceReference> &list, bool sorted=false);
        RESULT getContent(PyObject *list, bool sorted=false);
+       PyObject *getContent(const char *format, bool sorted=false);
        RESULT getNext(eServiceReference &ptr);
        int compareLessEqual(const eServiceReference &, const eServiceReference &);
        RESULT startEdit(ePtr<iMutableServiceList> &);
        RESULT getNext(eServiceReference &ptr);
        int compareLessEqual(const eServiceReference &, const eServiceReference &);
        RESULT startEdit(ePtr<iMutableServiceList> &);