Stop outputting 200 lines of "recording service" while just verifying the list
[openblackhole/openblackhole-enigma2.git] / lib / nav / core.cpp
1 #include <lib/nav/core.h>
2 #include <lib/base/eerror.h>
3 #include <lib/python/python.h>
4
5 void eNavigation::serviceEvent(iPlayableService* service, int event)
6 {
7         if (m_runningService && service != m_runningService)
8         {
9                 eDebug("nav: event %d for other service", event);
10                 return;
11         }
12         m_event(event);
13 }
14
15 void eNavigation::recordEvent(iRecordableService* service, int event)
16 {
17         if (m_recordings.find(service) == m_recordings.end())
18         {
19                 eDebug("nav: event for non registered recording service");
20                 return;
21         }
22         m_record_event(service, event);
23 }
24
25 RESULT eNavigation::playService(const eServiceReference &service)
26 {
27         stopService();
28         
29         ASSERT(m_servicehandler);
30         RESULT res = m_servicehandler->play(service, m_runningService);
31         if (m_runningService)
32         {
33                 m_runningService->connectEvent(slot(*this, &eNavigation::serviceEvent), m_service_event_conn);
34                 res = m_runningService->start();
35         }
36         return res;
37 }
38
39 RESULT eNavigation::connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &connection)
40 {
41         connection = new eConnection(this, m_event.connect(event));
42         return 0;
43 }
44
45 RESULT eNavigation::connectRecordEvent(const Slot2<void,ePtr<iRecordableService>,int> &event, ePtr<eConnection> &connection)
46 {
47         connection = new eConnection(this, m_record_event.connect(event));
48         return 0;
49 }
50
51 RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
52 {
53         service = m_runningService;
54         return 0;
55 }
56
57 RESULT eNavigation::stopService(void)
58 {
59                 /* check if there is a running service... */
60         if (!m_runningService)
61                 return 1;
62
63         ePtr<iPlayableService> tmp = m_runningService;
64         m_runningService=0;
65         tmp->stop();
66
67         /* send stop event */
68         m_event(iPlayableService::evEnd);
69
70                 /* kill service. */
71         m_service_event_conn = 0;
72         return 0;
73 }
74
75 RESULT eNavigation::recordService(const eServiceReference &ref, ePtr<iRecordableService> &service, bool simulate)
76 {
77         ASSERT(m_servicehandler);
78         RESULT res = m_servicehandler->record(ref, service);
79         if (res)
80         {
81                 eDebug("record: %d", res);
82                 service = 0;
83         }
84         else
85         {
86                 if (simulate)
87                         m_simulate_recordings.insert(service);
88                 else
89                 {
90                         ePtr<eConnection> conn;
91                         service->connectEvent(slot(*this, &eNavigation::recordEvent), conn);
92                         m_recordings[service]=conn;
93                 }
94         }
95         return res;
96 }
97
98 RESULT eNavigation::stopRecordService(ePtr<iRecordableService> &service)
99 {
100         service->stop();
101         std::set<ePtr<iRecordableService> >::iterator it =
102                 m_simulate_recordings.find(service);
103         if (it != m_simulate_recordings.end())
104         {
105                 m_simulate_recordings.erase(it);
106                 return 0;
107         }
108         else
109         {
110                 std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it =
111                         m_recordings.find(service);
112                 if (it != m_recordings.end())
113                 {
114                         m_recordings.erase(it);
115                         /* send stop event */
116                         m_record_event(service, iRecordableService::evEnd);
117                         return 0;
118                 }
119         }
120
121         eDebug("try to stop non running recording!!");  // this should not happen
122         return -1;
123 }
124
125 PyObject *eNavigation::getRecordings(bool simulate)
126 {
127         ePyObject result = PyList_New(simulate ? m_simulate_recordings.size() : m_recordings.size());
128         int pos=0;
129         if (simulate)
130                 for (std::set<ePtr<iRecordableService> >::iterator it(m_simulate_recordings.begin()); it != m_simulate_recordings.end(); ++it)
131                         PyList_SET_ITEM(result, pos++, NEW_iRecordableServicePtr(*it));
132         else
133                 for (std::map<ePtr<iRecordableService>, ePtr<eConnection> >::iterator it(m_recordings.begin()); it != m_recordings.end(); ++it)
134                         PyList_SET_ITEM(result, pos++, NEW_iRecordableServicePtr(it->first)); 
135         return result;
136 }
137
138 RESULT eNavigation::pause(int dop)
139 {
140         if (!m_runningService)
141                 return -1;
142         ePtr<iPauseableService> p;
143         if (m_runningService->pause(p))
144                 return -2;
145         if (dop)
146                 return p->pause();
147         else
148                 return p->unpause();
149 }
150
151 eNavigation::eNavigation(iServiceHandler *serviceHandler)
152 {
153         ASSERT(serviceHandler);
154         m_servicehandler = serviceHandler;
155 }
156
157 eNavigation::~eNavigation()
158 {
159         stopService();
160 }
161
162 DEFINE_REF(eNavigation);