remove lib/content
[enigma2.git] / lib / nav / core.cpp
1 #include <lib/nav/core.h>
2 #include <lib/base/eerror.h>
3
4 void eNavigation::serviceEvent(iPlayableService* service, int event)
5 {
6         if (service != m_runningService)
7         {
8                 eDebug("nav: event for other service");
9                 return;
10         }
11
12         switch (event)
13         {
14         case iPlayableService::evEnd:
15                 assert(m_playlist); /* we need to have a playlist */
16                 
17                         /* at first, kill the running service */
18                 m_event(this, evStopService);
19                 m_runningService = 0;
20                 m_service_event_conn = 0;
21                         /* our running main service stopped. identify what to do next. */
22                         
23                         /* unless the playlist current position is invalid (because there was */
24                         /* playlist, for example when the service was engaged with playService */
25                 if (m_playlist->m_current != m_playlist->end())
26                         ++m_playlist->m_current;
27                         
28                         /* was the current service the last one? */
29                 if (m_playlist->m_current == m_playlist->end())
30                 {
31                         m_event(this, evPlaylistDone);
32                         break;
33                 }
34
35                         /* there is another service in the playlist. play it. */
36                 RESULT res;
37                 res = playService(*m_playlist->m_current);
38                 if (res)
39                         m_event(this, evPlayFailed);
40                 break;
41         case iPlayableService::evStart:
42                 m_event(this, evNewService);
43                 break;
44         default:
45                 break;
46         }
47 }
48
49 RESULT eNavigation::playService(const eServiceReference &service)
50 {
51         assert(m_servicehandler);
52         RESULT res = m_servicehandler->play(service, m_runningService);
53         if (m_runningService)
54         {
55                 m_runningService->connectEvent(slot(*this, &eNavigation::serviceEvent), m_service_event_conn);
56                 res = m_runningService->start();
57         }
58         return res;
59 }
60
61 RESULT eNavigation::enqueueService(const eServiceReference &service)
62 {
63         assert(m_playlist);
64                 /* check if we need to play after the service was enqueued. */
65         int doplay = m_playlist->m_current == m_playlist->end();
66         
67                 /* add the service to the playlist. the playlist's m_current */
68                 /* points either to a service before the last or 'doplay' is set. */
69         m_playlist->push_back(service);
70
71         if (doplay)
72         {
73                 m_playlist->m_current = m_playlist->end();
74                 --m_playlist->m_current;
75                 return playService(*m_playlist->m_current);
76         }
77         return 0;
78 }
79
80 RESULT eNavigation::connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection)
81 {
82         connection = new eConnection(this, m_event.connect(event));
83         return 0;
84 }
85
86 RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
87 {
88         service = m_runningService;
89         return 0;
90 }
91
92 RESULT eNavigation::getPlaylist(ePtr<ePlaylist> &playlist)
93 {
94         if (!m_playlist)
95                 return -1;
96         playlist = m_playlist;
97         return 0;
98 }
99
100 RESULT eNavigation::pause(int dop)
101 {
102         if (!m_runningService)
103                 return -1;
104         ePtr<iPauseableService> p;
105         if (m_runningService->getIPausableService(p))
106                 return -2;
107         if (dop)
108                 return p->pause();
109         else
110                 return p->unpause();
111 }
112
113 eNavigation::eNavigation(iServiceHandler *serviceHandler)
114 {
115         assert(serviceHandler);
116         m_servicehandler = serviceHandler;
117         m_playlist = new ePlaylist;
118
119                 /* start with no current selection */
120         m_playlist->m_current = m_playlist->end();
121 }
122
123 eNavigation::~eNavigation()
124 {
125 }
126
127 DEFINE_REF(eNavigation);