Merge branch 'master' of git.opendreambox.org:/git/enigma2
[enigma2.git] / lib / nav / core.cpp
index a687eab..ad77766 100644 (file)
@@ -4,9 +4,9 @@
 
 void eNavigation::serviceEvent(iPlayableService* service, int event)
 {
-       if (service != m_runningService)
+       if (m_runningService && service != m_runningService)
        {
-               eDebug("nav: event for other service");
+               eDebug("nav: event %d for other service", event);
                return;
        }
        m_event(event);
@@ -26,7 +26,7 @@ RESULT eNavigation::playService(const eServiceReference &service)
 {
        stopService();
        
-       assert(m_servicehandler);
+       ASSERT(m_servicehandler);
        RESULT res = m_servicehandler->play(service, m_runningService);
        if (m_runningService)
        {
@@ -59,28 +59,36 @@ RESULT eNavigation::stopService(void)
                /* check if there is a running service... */
        if (!m_runningService)
                return 1;
-                       /* send stop event */
+
+       ePtr<iPlayableService> tmp = m_runningService;
+       m_runningService=0;
+       tmp->stop();
+
+       /* send stop event */
        m_event(iPlayableService::evEnd);
 
-       m_runningService->stop();
                /* kill service. */
-       m_runningService = 0;
        m_service_event_conn = 0;
        return 0;
 }
 
-RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordableService> &service)
+RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordableService> &service, bool simulate)
 {
-       assert(m_servicehandler);
+       ASSERT(m_servicehandler);
        RESULT res = m_servicehandler->record(ref, service);
        eDebug("record: %d", res);
        if (res)
                service = 0;
        else
        {
-               ePtr<eConnection> conn;
-               service->connectEvent(slot(*this, &eNavigation::recordEvent), conn);
-               m_recordings[service]=conn;
+               if (simulate)
+                       m_simulate_recordings.insert(service);
+               else
+               {
+                       ePtr<eConnection> conn;
+                       service->connectEvent(slot(*this, &eNavigation::recordEvent), conn);
+                       m_recordings[service]=conn;
+               }
        }
        return res;
 }
@@ -88,23 +96,40 @@ RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordable
 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())
+       std::set<ePtr<iRecordableService> >::iterator it =
+               m_simulate_recordings.find(service);
+       if (it != m_simulate_recordings.end())
        {
-               m_recordings.erase(it);
+               m_simulate_recordings.erase(it);
                return 0;
        }
+       else
+       {
+               std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it =
+                       m_recordings.find(service);
+               if (it != m_recordings.end())
+               {
+                       m_recordings.erase(it);
+                       /* send stop event */
+                       m_record_event(service, iRecordableService::evEnd);
+                       return 0;
+               }
+       }
+
        eDebug("try to stop non running recording!!");  // this should not happen
        return -1;
 }
 
-PyObject *eNavigation::getRecordings(void)
+PyObject *eNavigation::getRecordings(bool simulate)
 {
-       ePyObject result = PyList_New(m_recordings.size());
+       ePyObject result = PyList_New(simulate ? m_simulate_recordings.size() : 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)); 
+       if (simulate)
+               for (std::set<ePtr<iRecordableService> >::iterator it(m_simulate_recordings.begin()); it != m_simulate_recordings.end(); ++it)
+                       PyList_SET_ITEM(result, pos++, NEW_iRecordableServicePtr(*it));
+       else
+               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;
 }
 
@@ -123,7 +148,7 @@ RESULT eNavigation::pause(int dop)
 
 eNavigation::eNavigation(iServiceHandler *serviceHandler)
 {
-       assert(serviceHandler);
+       ASSERT(serviceHandler);
        m_servicehandler = serviceHandler;
 }