1 #include <lib/nav/core.h>
2 #include <lib/base/eerror.h>
4 void eNavigation::serviceEvent(iPlayableService* service, int event)
6 if (service != m_runningService)
8 eDebug("nav: event for other service");
14 case iPlayableService::evEnd:
15 assert(m_playlist); /* we need to have a playlist */
17 /* at first, kill the running service */
20 /* our running main service stopped. identify what to do next. */
22 /* unless the playlist current position is invalid (because there was */
23 /* playlist, for example when the service was engaged with playService */
24 if (m_playlist->m_current != m_playlist->end())
25 ++m_playlist->m_current;
27 /* was the current service the last one? */
28 if (m_playlist->m_current == m_playlist->end())
30 m_event(this, evPlaylistDone);
34 /* there is another service in the playlist. play it. */
36 res = playService(*m_playlist->m_current);
38 m_event(this, evPlayFailed);
40 case iPlayableService::evStart:
41 m_event(this, evNewService);
43 case iPlayableService::evUpdatedEventInfo:
44 m_event(this, evUpdatedEventInfo);
51 RESULT eNavigation::playService(const eServiceReference &service)
55 assert(m_servicehandler);
56 RESULT res = m_servicehandler->play(service, m_runningService);
59 m_runningService->connectEvent(slot(*this, &eNavigation::serviceEvent), m_service_event_conn);
60 res = m_runningService->start();
65 RESULT eNavigation::enqueueService(const eServiceReference &service)
68 /* check if we need to play after the service was enqueued. */
69 int doplay = m_playlist->m_current == m_playlist->end();
71 /* add the service to the playlist. the playlist's m_current */
72 /* points either to a service before the last or 'doplay' is set. */
73 m_playlist->push_back(service);
77 m_playlist->m_current = m_playlist->end();
78 --m_playlist->m_current;
79 return playService(*m_playlist->m_current);
84 RESULT eNavigation::connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection)
86 connection = new eConnection(this, m_event.connect(event));
90 RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
92 service = m_runningService;
96 RESULT eNavigation::getPlaylist(ePtr<ePlaylist> &playlist)
100 playlist = m_playlist;
104 RESULT eNavigation::stopService(void)
106 /* check if there is a running service... */
107 if (!m_runningService)
109 /* send stop event */
110 m_event(this, evStopService);
113 m_runningService = 0;
114 m_service_event_conn = 0;
118 RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordableService> &service)
120 assert(m_servicehandler);
121 RESULT res = m_servicehandler->record(ref, service);
122 eDebug("record: %d", res);
128 RESULT eNavigation::pause(int dop)
130 if (!m_runningService)
132 ePtr<iPauseableService> p;
133 if (m_runningService->pause(p))
141 eNavigation::eNavigation(iServiceHandler *serviceHandler)
143 assert(serviceHandler);
144 m_servicehandler = serviceHandler;
145 m_playlist = new ePlaylist;
147 /* start with no current selection */
148 m_playlist->m_current = m_playlist->end();
151 eNavigation::~eNavigation()
155 DEFINE_REF(eNavigation);