1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#include <lib/nav/core.h>
#include <lib/base/eerror.h>
void eNavigation::serviceEvent(iPlayableService* service, int event)
{
if (service != m_runningService)
{
eDebug("nav: event for other service");
return;
}
switch (event)
{
case iPlayableService::evEnd:
assert(m_playlist); /* we need to have a playlist */
/* at first, kill the running service */
stopService();
/* 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())
{
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);
break;
case iPlayableService::evUpdatedEventInfo:
m_event(this, evUpdatedEventInfo);
break;
default:
break;
}
}
RESULT eNavigation::playService(const eServiceReference &service)
{
stopService();
assert(m_servicehandler);
RESULT res = m_servicehandler->play(service, m_runningService);
if (m_runningService)
{
m_runningService->connectEvent(slot(*this, &eNavigation::serviceEvent), m_service_event_conn);
res = m_runningService->start();
}
return res;
}
RESULT eNavigation::enqueueService(const eServiceReference &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)
{
m_playlist->m_current = m_playlist->end();
--m_playlist->m_current;
return playService(*m_playlist->m_current);
}
return 0;
}
RESULT eNavigation::connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection)
{
connection = new eConnection(this, m_event.connect(event));
return 0;
}
RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
{
service = m_runningService;
return 0;
}
RESULT eNavigation::getPlaylist(ePtr<ePlaylist> &playlist)
{
if (!m_playlist)
return -1;
playlist = m_playlist;
return 0;
}
RESULT eNavigation::stopService(void)
{
/* check if there is a running service... */
if (!m_runningService)
return 1;
/* send stop event */
m_event(this, evStopService);
/* kill service. */
m_runningService = 0;
m_service_event_conn = 0;
return 0;
}
RESULT eNavigation::pause(int dop)
{
if (!m_runningService)
return -1;
ePtr<iPauseableService> p;
if (m_runningService->pause(p))
return -2;
if (dop)
return p->pause();
else
return p->unpause();
}
eNavigation::eNavigation(iServiceHandler *serviceHandler)
{
assert(serviceHandler);
m_servicehandler = serviceHandler;
m_playlist = new ePlaylist;
/* start with no current selection */
m_playlist->m_current = m_playlist->end();
}
eNavigation::~eNavigation()
{
}
DEFINE_REF(eNavigation);
|