recording service events now working
[enigma2.git] / lib / nav / core.cpp
index 9f537d35c6bf54a5616dcc81210fa23e8d16496e..7f76fa3f87dfb0199130bcfece2875d17f3a36a7 100644 (file)
@@ -1,5 +1,6 @@
 #include <lib/nav/core.h>
 #include <lib/base/eerror.h>
+#include <Python.h>
 
 void eNavigation::serviceEvent(iPlayableService* service, int event)
 {
@@ -8,24 +9,17 @@ void eNavigation::serviceEvent(iPlayableService* service, int event)
                eDebug("nav: event for other service");
                return;
        }
+       m_event(event);
+}
 
-       switch (event)
-       {       
-       case iPlayableService::evEnd:
-//             m_event(this, ev);
-               break;
-       case iPlayableService::evStart:
-               m_event(this, evNewService);
-               break;
-       case iPlayableService::evUpdatedEventInfo:
-               m_event(this, evUpdatedEventInfo);
-               break;
-       case iPlayableService::evUpdatedInfo:
-               m_event(this, evUpdatedInfo);
-               break;
-       default:
-               break;
+void eNavigation::recordEvent(iRecordableService* service, int event)
+{
+       if (m_recordings.find(service) == m_recordings.end())
+       {
+               eDebug("nav: event for non registered recording service");
+               return;
        }
+       m_record_event(service, event);
 }
 
 RESULT eNavigation::playService(const eServiceReference &service)
@@ -42,12 +36,18 @@ RESULT eNavigation::playService(const eServiceReference &service)
        return res;
 }
 
-RESULT eNavigation::connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection)
+RESULT eNavigation::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &connection)
 {
        connection = new eConnection(this, m_event.connect(event));
        return 0;
 }
 
+RESULT eNavigation::connectRecordEvent(const Slot2<void,ePtr<iRecordableService>,int> &event, ePtr<eConnection> &connection)
+{
+       connection = new eConnection(this, m_record_event.connect(event));
+       return 0;
+}
+
 RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
 {
        service = m_runningService;
@@ -60,8 +60,9 @@ RESULT eNavigation::stopService(void)
        if (!m_runningService)
                return 1;
                        /* send stop event */
-       m_event(this, evStopService);
+       m_event(iPlayableService::evEnd);
 
+       m_runningService->stop();
                /* kill service. */
        m_runningService = 0;
        m_service_event_conn = 0;
@@ -75,9 +76,40 @@ RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordable
        eDebug("record: %d", res);
        if (res)
                service = 0;
+       else
+       {
+               ePtr<eConnection> conn;
+               service->connectEvent(slot(*this, &eNavigation::recordEvent), conn);
+               m_recordings[service]=conn;
+       }
        return res;
 }
 
+RESULT eNavigation::stopRecordService(ePtr<iRecordableService> &service)
+{
+       service->stop();
+       std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it =
+               m_recordings.find(service);
+       if (it != m_recordings.end())
+       {
+               m_recordings.erase(it);
+               return 0;
+       }
+       eDebug("try to stop non running recording!!");  // this should not happen
+       return -1;
+}
+
+extern PyObject *New_iRecordableServicePtr(const ePtr<iRecordableService> &ref); // defined in enigma_python.i
+
+PyObject *eNavigation::getRecordings(void)
+{
+       PyObject *result = PyList_New(m_recordings.size());
+       int pos=0;
+       for (std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it(m_recordings.begin()); it != m_recordings.end(); ++it)
+               PyList_SET_ITEM(result, pos++, New_iRecordableServicePtr(it->first)); 
+       return result;
+}
+
 RESULT eNavigation::pause(int dop)
 {
        if (!m_runningService)
@@ -99,6 +131,7 @@ eNavigation::eNavigation(iServiceHandler *serviceHandler)
 
 eNavigation::~eNavigation()
 {
+       stopService();
 }
 
 DEFINE_REF(eNavigation);