change eConsoleAppcontainers to using standard system shell 'sh' as suggested by...
[enigma2.git] / lib / nav / core.cpp
index b5c229c79665d5617d5f1d6ecb0f6778783cecdc..062a7d00046a48d7736eb0fd9dae146bf55fcc73 100644 (file)
@@ -1,38 +1,32 @@
 #include <lib/nav/core.h>
+#include <lib/base/eerror.h>
+#include <lib/python/python.h>
 
 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);
+}
 
-       switch (event)
+void eNavigation::recordEvent(iRecordableService* service, int event)
+{
+       if (m_recordings.find(service) == m_recordings.end())
        {
-       case iPlayableService::evEnd:
-                       /* our running main service stopped. */
-               if (!m_playlist.empty())
-                       m_playlist.erase(m_playlist.begin());
-               if (!m_playlist.empty())
-               {
-                       RESULT res;
-                       res = playService(m_playlist.front());
-                       if (res)
-                               m_event(this, evPlayFailed);
-               } else
-                       m_event(this, evPlaylistDone);
-               break;
-       case iPlayableService::evStart:
-               m_event(this, evNewService);
-               break;
-       default:
-               break;
+               eDebug("nav: event for non registered recording service");
+               return;
        }
+       m_record_event(service, event);
 }
 
 RESULT eNavigation::playService(const eServiceReference &service)
 {
+       stopService();
+       
+       assert(m_servicehandler);
        RESULT res = m_servicehandler->play(service, m_runningService);
        if (m_runningService)
        {
@@ -42,18 +36,15 @@ RESULT eNavigation::playService(const eServiceReference &service)
        return res;
 }
 
-RESULT eNavigation::enqueueService(const eServiceReference &service)
+RESULT eNavigation::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &connection)
 {
-       int doplay = m_playlist.empty();
-       m_playlist.push_back(service);
-       if (doplay)
-               return playService(m_playlist.front());
+       connection = new eConnection(this, m_event.connect(event));
        return 0;
 }
 
-RESULT eNavigation::connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection)
+RESULT eNavigation::connectRecordEvent(const Slot2<void,ePtr<iRecordableService>,int> &event, ePtr<eConnection> &connection)
 {
-       connection = new eConnection(m_event.connect(event));
+       connection = new eConnection(this, m_record_event.connect(event));
        return 0;
 }
 
@@ -63,12 +54,72 @@ RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
        return 0;
 }
 
+RESULT eNavigation::stopService(void)
+{
+               /* check if there is a running service... */
+       if (!m_runningService)
+               return 1;
+
+       ePtr<iPlayableService> tmp = m_runningService;
+       m_runningService=0;
+       tmp->stop();
+
+       /* send stop event */
+       m_event(iPlayableService::evEnd);
+
+               /* kill service. */
+       m_service_event_conn = 0;
+       return 0;
+}
+
+RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordableService> &service)
+{
+       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;
+       }
+       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);
+               /* 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)
+{
+       ePyObject 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)
                return -1;
        ePtr<iPauseableService> p;
-       if (m_runningService->getIPausableService(p))
+       if (m_runningService->pause(p))
                return -2;
        if (dop)
                return p->pause();
@@ -78,11 +129,13 @@ RESULT eNavigation::pause(int dop)
 
 eNavigation::eNavigation(iServiceHandler *serviceHandler)
 {
+       assert(serviceHandler);
        m_servicehandler = serviceHandler;
 }
 
 eNavigation::~eNavigation()
 {
+       stopService();
 }
 
 DEFINE_REF(eNavigation);