disable some debug output
[enigma2.git] / lib / service / servicedvb.cpp
index ca08d481bd52c1b6c012aada84b1154bf1e7e3ea..1779d4dcd334a26116cc3f49ed1f819b092f8ecb 100644 (file)
 #include <lib/dvb/metaparser.h>
 #include <lib/dvb/tstools.h>
 
+class eStaticServiceDVBInformation: public iStaticServiceInformation
+{
+       DECLARE_REF(eStaticServiceDVBInformation);
+public:
+       RESULT getName(const eServiceReference &ref, std::string &name);
+       int getLength(const eServiceReference &ref);
+};
+
+DEFINE_REF(eStaticServiceDVBInformation);
+
+RESULT eStaticServiceDVBInformation::getName(const eServiceReference &ref, std::string &name)
+{
+       if ( ref.name.length() )
+       {
+               name = ref.name;
+               return 0;
+       }
+       else
+               return -1;
+}
+
+int eStaticServiceDVBInformation::getLength(const eServiceReference &ref)
+{
+       return -1;
+}
+
+class eStaticServiceDVBBouquetInformation: public iStaticServiceInformation
+{
+       DECLARE_REF(eStaticServiceDVBBouquetInformation);
+public:
+       RESULT getName(const eServiceReference &ref, std::string &name);
+       int getLength(const eServiceReference &ref);
+};
+
+DEFINE_REF(eStaticServiceDVBBouquetInformation);
+
+RESULT eStaticServiceDVBBouquetInformation::getName(const eServiceReference &ref, std::string &name)
+{
+       ePtr<iDVBChannelList> db;
+       ePtr<eDVBResourceManager> res;
+
+       int err;
+       if ((err = eDVBResourceManager::getInstance(res)) != 0)
+       {
+               eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no resource manager!");
+               return err;
+       }
+       if ((err = res->getChannelList(db)) != 0)
+       {
+               eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no channel list!");
+               return err;
+       }
+
+       const eBouquet *bouquet=0;
+       if ((err = db->getBouquet(ref, bouquet)) != 0)
+       {
+               eDebug("eStaticServiceDVBBouquetInformation::getName failed.. getBouquet failed!");
+               return -1;
+       }
+
+       if ( bouquet && bouquet->m_bouquet_name.length() )
+       {
+               name = "[Bouquet] " + bouquet->m_bouquet_name;
+               return 0;
+       }
+       else
+               return -1;
+}
+
+int eStaticServiceDVBBouquetInformation::getLength(const eServiceReference &ref)
+{
+       return -1;
+}
+
 class eStaticServiceDVBPVRInformation: public iStaticServiceInformation
 {
        DECLARE_REF(eStaticServiceDVBPVRInformation);
@@ -36,6 +110,7 @@ RESULT eStaticServiceDVBPVRInformation::getName(const eServiceReference &ref, st
 {
        ASSERT(ref == m_ref);
        name = m_parser.m_name.size() ? m_parser.m_name : ref.path;
+       return 0;
 }
 
 int eStaticServiceDVBPVRInformation::getLength(const eServiceReference &ref)
@@ -133,7 +208,7 @@ eDVBServiceList::~eDVBServiceList()
 {
 }
 
-RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list)
+RESULT eDVBServiceList::startQuery()
 {
        ePtr<iDVBChannelList> db;
        ePtr<eDVBResourceManager> res;
@@ -150,30 +225,50 @@ RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list)
                return err;
        }
        
-       ePtr<iDVBChannelListQuery> query;
-       
        ePtr<eDVBChannelQuery> q;
        
        if (m_parent.path.size())
+       {
                eDVBChannelQuery::compile(q, m_parent.path);
+               if (!q)
+               {
+                       eDebug("compile query failed");
+                       return err;
+               }
+       }
        
-       if ((err = db->startQuery(query, q)) != 0)
+       if ((err = db->startQuery(m_query, q, m_parent)) != 0)
        {
                eDebug("startQuery failed");
                return err;
        }
-       
+
+       return 0;
+}
+
+RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list)
+{
        eServiceReferenceDVB ref;
        
-       while (!query->getNextResult(ref))
+       if (!m_query)
+               return -1;
+       
+       while (!m_query->getNextResult(ref))
                list.push_back(ref);
        return 0;
 }
 
-RESULT eDVBServiceList::getNext(eServiceReference &)
+RESULT eDVBServiceList::getNext(eServiceReference &ref)
 {
-               /* implement me */
-       return -1;
+       if (!m_query)
+               return -1;
+       
+       return m_query->getNextResult((eServiceReferenceDVB&)ref);
+}
+
+int eDVBServiceList::compareLessEqual(const eServiceReference &a, const eServiceReference &b)
+{
+       return m_query->compareLessEqual((const eServiceReferenceDVB&)a, (const eServiceReferenceDVB&)b);
 }
 
 RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
@@ -195,25 +290,39 @@ RESULT eServiceFactoryDVB::record(const eServiceReference &ref, ePtr<iRecordable
 
 RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
 {
-       ptr = new eDVBServiceList(ref);
+       ePtr<eDVBServiceList> list = new eDVBServiceList(ref);
+       if (list->startQuery())
+       {
+               ptr = 0;
+               return -1;
+       }
+       
+       ptr = list;
        return 0;
 }
 
 RESULT eServiceFactoryDVB::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
 {
                /* do we have a PVR service? */
-       if (ref.path.size())
+       if (ref.flags & eServiceReference::flagDirectory) // bouquet
+       {
+               ptr = new eStaticServiceDVBBouquetInformation;
+               return 0;
+       }
+       else if (ref.path.size())
        {
                ptr = new eStaticServiceDVBPVRInformation(ref);
                return 0;
-       } else
+       }
+       else
        {
                ePtr<eDVBService> service;
                int r = lookupService(service, ref);
                if (r)
-                       return r;
+                       ptr = new eStaticServiceDVBInformation;
+               else
                        /* eDVBService has the iStaticServiceInformation interface, so we pass it here. */
-               ptr = service;
+                       ptr = service;
                return 0;
        }
 }
@@ -256,18 +365,16 @@ RESULT eServiceFactoryDVB::lookupService(ePtr<eDVBService> &service, const eServ
 }
 
 eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref, eDVBService *service): 
-       m_reference(ref), m_dvb_service(service)
+       m_reference(ref), m_dvb_service(service), m_service_handler(0)
 {
        m_is_pvr = !ref.path.empty();
        
        CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
        CONNECT(m_event_handler.m_eit_changed, eDVBServicePlay::gotNewEvent);
-       eDebug("DVB start (play)");
 }
 
 eDVBServicePlay::~eDVBServicePlay()
 {
-       eDebug("DVB stop (play)");
 }
 
 void eDVBServicePlay::gotNewEvent()
@@ -288,7 +395,6 @@ void eDVBServicePlay::gotNewEvent()
 
 void eDVBServicePlay::serviceEvent(int event)
 {
-       eDebug("service event %d", event);
        switch (event)
        {
        case eDVBServicePMTHandler::eventTuned:
@@ -298,8 +404,7 @@ void eDVBServicePlay::serviceEvent(int event)
                {
 //                     eventStartedEventAcquisition
                        m_event_handler.start(m_demux, ((eServiceReferenceDVB&)m_reference).getServiceID().get());
-               } else
-                       eDebug("no event data available :( ");
+               }
 //                     eventNoEvent
                break;
        }
@@ -389,6 +494,7 @@ RESULT eDVBServicePlay::start()
        eDebug("starting DVB service");
        r = m_service_handler.tune((eServiceReferenceDVB&)m_reference);
        m_event(this, evStart);
+       return 0;
 }
 
 RESULT eDVBServicePlay::stop()
@@ -459,8 +565,11 @@ RESULT eDVBServicePlay::info(ePtr<iServiceInformation> &ptr)
 RESULT eDVBServicePlay::getName(std::string &name)
 {
        if (m_dvb_service)
+       {
                m_dvb_service->getName(m_reference, name);
-       else
+               if (name.empty())
+                       name = "(...)";
+       } else
                name = "DVB service";
        return 0;
 }