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
|
#include <lib/nav/core.h>
#include <lib/base/eerror.h>
#include <lib/python/python.h>
void eNavigation::serviceEvent(iPlayableService* service, int event)
{
if (m_runningService && service != m_runningService)
{
eDebug("nav: event %d for other service", event);
return;
}
m_event(event);
}
void eNavigation::recordEvent(iRecordableService* service, int event)
{
if (m_recordings.find(service) == m_recordings.end())
{
eDebug("nav: event for non registered recording service");
return;
}
m_record_event(service, event);
}
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::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &connection)
{
connection = new eConnection(this, m_event.connect(event));
return 0;
}
RESULT eNavigation::connectRecordEvent(const Slot2<void,ePtr<iRecordableService>,int> &event, ePtr<eConnection> &connection)
{
connection = new eConnection(this, m_record_event.connect(event));
return 0;
}
RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
{
service = m_runningService;
return 0;
}
RESULT eNavigation::stopService(void)
{
/* check if there is a running service... */
if (!m_runningService)
return 1;
ePtr<iPlayableService> tmp = m_runningService;
m_runningService=0;
tmp->stop();
/* send stop event */
m_event(iPlayableService::evEnd);
/* kill service. */
m_service_event_conn = 0;
return 0;
}
RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordableService> &service)
{
assert(m_servicehandler);
RESULT res = m_servicehandler->record(ref, service);
eDebug("record: %d", res);
if (res)
service = 0;
else
{
ePtr<eConnection> conn;
service->connectEvent(slot(*this, &eNavigation::recordEvent), conn);
m_recordings[service]=conn;
}
return res;
}
RESULT eNavigation::stopRecordService(ePtr<iRecordableService> &service)
{
service->stop();
std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it =
m_recordings.find(service);
if (it != m_recordings.end())
{
m_recordings.erase(it);
/* send stop event */
m_record_event(service, iRecordableService::evEnd);
return 0;
}
eDebug("try to stop non running recording!!"); // this should not happen
return -1;
}
PyObject *eNavigation::getRecordings(void)
{
ePyObject result = PyList_New(m_recordings.size());
int pos=0;
for (std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it(m_recordings.begin()); it != m_recordings.end(); ++it)
PyList_SET_ITEM(result, pos++, NEW_iRecordableServicePtr(it->first));
return result;
}
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;
}
eNavigation::~eNavigation()
{
stopService();
}
DEFINE_REF(eNavigation);
|