1 #include <lib/nav/core.h>
2 #include <lib/base/eerror.h>
3 #include <lib/python/python.h>
5 void eNavigation::serviceEvent(iPlayableService* service, int event)
7 if (m_runningService && service != m_runningService)
9 eDebug("nav: event %d for other service", event);
15 void eNavigation::recordEvent(iRecordableService* service, int event)
17 if (m_recordings.find(service) == m_recordings.end())
19 eDebug("nav: event for non registered recording service");
22 m_record_event(service, event);
25 RESULT eNavigation::playService(const eServiceReference &service)
29 ASSERT(m_servicehandler);
30 RESULT res = m_servicehandler->play(service, m_runningService);
33 m_runningService->connectEvent(slot(*this, &eNavigation::serviceEvent), m_service_event_conn);
34 res = m_runningService->start();
39 RESULT eNavigation::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &connection)
41 connection = new eConnection(this, m_event.connect(event));
45 RESULT eNavigation::connectRecordEvent(const Slot2<void,ePtr<iRecordableService>,int> &event, ePtr<eConnection> &connection)
47 connection = new eConnection(this, m_record_event.connect(event));
51 RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
53 service = m_runningService;
57 RESULT eNavigation::stopService(void)
59 /* check if there is a running service... */
60 if (!m_runningService)
63 ePtr<iPlayableService> tmp = m_runningService;
68 m_event(iPlayableService::evEnd);
71 m_service_event_conn = 0;
75 RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordableService> &service, bool simulate)
77 ASSERT(m_servicehandler);
78 RESULT res = m_servicehandler->record(ref, service);
79 eDebug("record: %d", res);
85 m_simulate_recordings.insert(service);
88 ePtr<eConnection> conn;
89 service->connectEvent(slot(*this, &eNavigation::recordEvent), conn);
90 m_recordings[service]=conn;
96 RESULT eNavigation::stopRecordService(ePtr<iRecordableService> &service)
99 std::set<ePtr<iRecordableService> >::iterator it =
100 m_simulate_recordings.find(service);
101 if (it != m_simulate_recordings.end())
103 m_simulate_recordings.erase(it);
108 std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it =
109 m_recordings.find(service);
110 if (it != m_recordings.end())
112 m_recordings.erase(it);
113 /* send stop event */
114 m_record_event(service, iRecordableService::evEnd);
119 eDebug("try to stop non running recording!!"); // this should not happen
123 PyObject *eNavigation::getRecordings(bool simulate)
125 ePyObject result = PyList_New(simulate ? m_simulate_recordings.size() : m_recordings.size());
128 for (std::set<ePtr<iRecordableService> >::iterator it(m_simulate_recordings.begin()); it != m_simulate_recordings.end(); ++it)
129 PyList_SET_ITEM(result, pos++, NEW_iRecordableServicePtr(*it));
131 for (std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it(m_recordings.begin()); it != m_recordings.end(); ++it)
132 PyList_SET_ITEM(result, pos++, NEW_iRecordableServicePtr(it->first));
136 RESULT eNavigation::pause(int dop)
138 if (!m_runningService)
140 ePtr<iPauseableService> p;
141 if (m_runningService->pause(p))
149 eNavigation::eNavigation(iServiceHandler *serviceHandler)
151 ASSERT(serviceHandler);
152 m_servicehandler = serviceHandler;
155 eNavigation::~eNavigation()
160 DEFINE_REF(eNavigation);