add playlists
authorFelix Domke <tmbinc@elitedvb.net>
Thu, 27 May 2004 11:43:17 +0000 (11:43 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Thu, 27 May 2004 11:43:17 +0000 (11:43 +0000)
lib/nav/Makefile.am
lib/nav/core.cpp
lib/nav/core.h
lib/nav/playlist.cpp [new file with mode: 0644]
lib/nav/playlist.h [new file with mode: 0644]
main/enigma.cpp

index a180e0b..9060369 100644 (file)
@@ -4,5 +4,5 @@ INCLUDES = \
 noinst_LIBRARIES = libenigma_nav.a
 
 libenigma_nav_a_SOURCES = \
-       core.cpp
-       
+       core.cpp playlist.cpp
+
index 9314d2c..c9dcb50 100644 (file)
@@ -11,21 +11,31 @@ void eNavigation::serviceEvent(iPlayableService* service, int event)
        switch (event)
        {
        case iPlayableService::evEnd:
+               assert(m_playlist); /* we need to have a playlist */
+               
                        /* at first, kill the running service */
                m_event(this, evStopService);
                m_runningService = 0;
                m_service_event_conn = 0;
-                       /* our running main service stopped. remove it from playlist */
-               if (!m_playlist.empty())
-                       m_playlist.erase(m_playlist.begin());
-               if (!m_playlist.empty())
+                       /* our running main service stopped. identify what to do next. */
+                       
+                       /* unless the playlist current position is invalid (because there was */
+                       /* playlist, for example when the service was engaged with playService */
+               if (m_playlist->m_current != m_playlist->end())
+                       ++m_playlist->m_current;
+                       
+                       /* was the current service the last one? */
+               if (m_playlist->m_current == m_playlist->end())
                {
-                       RESULT res;
-                       res = playService(m_playlist.front());
-                       if (res)
-                               m_event(this, evPlayFailed);
-               } else
                        m_event(this, evPlaylistDone);
+                       break;
+               }
+
+                       /* there is another service in the playlist. play it. */
+               RESULT res;
+               res = playService(*m_playlist->m_current);
+               if (res)
+                       m_event(this, evPlayFailed);
                break;
        case iPlayableService::evStart:
                m_event(this, evNewService);
@@ -49,10 +59,20 @@ RESULT eNavigation::playService(const eServiceReference &service)
 
 RESULT eNavigation::enqueueService(const eServiceReference &service)
 {
-       int doplay = m_playlist.empty();
-       m_playlist.push_back(service);
+       assert(m_playlist);
+               /* check if we need to play after the service was enqueued. */
+       int doplay = m_playlist->m_current == m_playlist->end();
+       
+               /* add the service to the playlist. the playlist's m_current */
+               /* points either to a service before the last or 'doplay' is set. */
+       m_playlist->push_back(service);
+
        if (doplay)
-               return playService(m_playlist.front());
+       {
+               m_playlist->m_current = m_playlist->end();
+               --m_playlist->m_current;
+               return playService(*m_playlist->m_current);
+       }
        return 0;
 }
 
@@ -68,6 +88,14 @@ RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
        return 0;
 }
 
+RESULT eNavigation::getPlaylist(ePtr<ePlaylist> &playlist)
+{
+       if (!m_playlist)
+               return -1;
+       playlist = m_playlist;
+       return 0;
+}
+
 RESULT eNavigation::pause(int dop)
 {
        if (!m_runningService)
@@ -85,6 +113,10 @@ eNavigation::eNavigation(iServiceHandler *serviceHandler): ref(0)
 {
        assert(serviceHandler);
        m_servicehandler = serviceHandler;
+       m_playlist = new ePlaylist;
+
+               /* start with no current selection */
+       m_playlist->m_current = m_playlist->end();
 }
 
 eNavigation::~eNavigation()
index 99cf75a..db43841 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <lib/base/object.h>
 #include <lib/service/iservice.h>
+#include <lib/nav/playlist.h>
 #include <connection.h>
 
 class eNavigation: public iObject, public Object
@@ -15,20 +16,22 @@ private:
        ePtr<eConnection> m_service_event_conn;
        void serviceEvent(iPlayableService* service, int event);
        
-       std::list<eServiceReference> m_playlist;
+       ePtr<ePlaylist> m_playlist;
 public:
        enum
        {
                evStopService,  /** the "current" service was just stopped and likes to be deallocated (clear refs!) */
-               evNewService, /** a new "current" service was just started */
-               evPlayFailed,
-               evPlaylistDone
+               evNewService,   /** a new "current" service was just started */
+               evPlayFailed,   /** the next service (in playlist) or the one given in playService failed to play */
+               evPlaylistDone  /** the last service in the playlist was just played */
        };
+       
        RESULT playService(const eServiceReference &service);
        RESULT enqueueService(const eServiceReference &service);
        RESULT connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection);
 /*     int connectServiceEvent(const Slot1<void,iPlayableService*,int> &event, ePtr<eConnection> &connection); */
        RESULT getCurrentService(ePtr<iPlayableService> &service);
+       RESULT getPlaylist(ePtr<ePlaylist> &playlist);
        
        RESULT pause(int p);
        eNavigation(iServiceHandler *serviceHandler);
diff --git a/lib/nav/playlist.cpp b/lib/nav/playlist.cpp
new file mode 100644 (file)
index 0000000..4891992
--- /dev/null
@@ -0,0 +1,7 @@
+#include <lib/nav/playlist.h>
+
+DEFINE_REF(ePlaylist);
+
+ePlaylist::ePlaylist(): ref(0)
+{
+}
diff --git a/lib/nav/playlist.h b/lib/nav/playlist.h
new file mode 100644 (file)
index 0000000..f07ecb4
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef __lib_nav_playlist_h
+#define __lib_nav_playlist_h
+
+#include <list>
+#include <lib/base/object.h>
+#include <lib/service/iservice.h>
+
+class ePlaylist: public virtual iObject, public std::list<eServiceReference>
+{
+DECLARE_REF;
+public:
+       ePlaylist();
+       std::list<eServiceReference>::iterator m_current;
+};
+
+#endif
index 668c7c5..7b30f6b 100644 (file)
@@ -16,6 +16,8 @@
 #include <lib/service/iservice.h>
 #include <lib/nav/core.h>
 
+#include <main/cli.h>
+
 class eMain: public eApplication, public Object
 {
        eInit init;
@@ -79,6 +81,18 @@ public:
        
        void event(eNavigation *nav, int ev)
        {
+               assert(nav);
+               
+               ePtr<ePlaylist> playlist;
+               nav->getPlaylist(playlist);
+               if (playlist)
+               {
+                       eDebug("PLAYLIST:");
+                       ePlaylist::iterator i;
+                       for (i=playlist->begin(); i != playlist->end(); ++i)
+                               eDebug("%s %s", i == playlist->m_current ? "-->" : "   ", i->toString().c_str());
+               }
+               
                switch (ev)
                {
                case eNavigation::evStopService:
@@ -137,6 +151,21 @@ int main()
 #ifdef OBJECT_DEBUG
        atexit(object_dump);
 #endif
+
+#if 0
+       eCLI cli;
+       eString res;
+       
+       while (1)
+       {
+               char line[1024];
+               if (!fgets(line, 1024, stdin))
+                       break;
+               line[strlen(line)-1]=0;
+               int rn = cli.doCommand(res, line);
+               eDebug("%s%d", res.c_str(), rn);
+       }
+#endif
        eMain app;
        int res = app.exec();
        eDebug("after exec");