noinst_LIBRARIES = libenigma_nav.a
libenigma_nav_a_SOURCES = \
- core.cpp
-
+ core.cpp playlist.cpp
+
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);
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;
}
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)
{
assert(serviceHandler);
m_servicehandler = serviceHandler;
+ m_playlist = new ePlaylist;
+
+ /* start with no current selection */
+ m_playlist->m_current = m_playlist->end();
}
eNavigation::~eNavigation()
#include <lib/base/object.h>
#include <lib/service/iservice.h>
+#include <lib/nav/playlist.h>
#include <connection.h>
class eNavigation: public iObject, public Object
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);
--- /dev/null
+#include <lib/nav/playlist.h>
+
+DEFINE_REF(ePlaylist);
+
+ePlaylist::ePlaylist(): ref(0)
+{
+}
--- /dev/null
+#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
#include <lib/service/iservice.h>
#include <lib/nav/core.h>
+#include <main/cli.h>
+
class eMain: public eApplication, public Object
{
eInit init;
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:
#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");