- eConnections holds reference to object
[enigma2.git] / lib / nav / core.cpp
1 #include <lib/nav/core.h>
2
3 void eNavigation::serviceEvent(iPlayableService* service, int event)
4 {
5         if (service != m_runningService)
6         {
7                 eDebug("nav: event for other service");
8                 return;
9         }
10
11         switch (event)
12         {
13         case iPlayableService::evEnd:
14                         /* at first, kill the running service */
15                 m_event(this, evStopService);
16                 m_runningService = 0;
17                 m_service_event_conn = 0;
18                         /* our running main service stopped. remove it from playlist */
19                 if (!m_playlist.empty())
20                         m_playlist.erase(m_playlist.begin());
21                 if (!m_playlist.empty())
22                 {
23                         RESULT res;
24                         res = playService(m_playlist.front());
25                         if (res)
26                                 m_event(this, evPlayFailed);
27                 } else
28                         m_event(this, evPlaylistDone);
29                 break;
30         case iPlayableService::evStart:
31                 m_event(this, evNewService);
32                 break;
33         default:
34                 break;
35         }
36 }
37
38 RESULT eNavigation::playService(const eServiceReference &service)
39 {
40         assert(m_servicehandler);
41         RESULT res = m_servicehandler->play(service, m_runningService);
42         if (m_runningService)
43         {
44                 m_runningService->connectEvent(slot(*this, &eNavigation::serviceEvent), m_service_event_conn);
45                 res = m_runningService->start();
46         }
47         return res;
48 }
49
50 RESULT eNavigation::enqueueService(const eServiceReference &service)
51 {
52         int doplay = m_playlist.empty();
53         m_playlist.push_back(service);
54         if (doplay)
55                 return playService(m_playlist.front());
56         return 0;
57 }
58
59 RESULT eNavigation::connectEvent(const Slot2<void,eNavigation*,int> &event, ePtr<eConnection> &connection)
60 {
61         connection = new eConnection(this, m_event.connect(event));
62         return 0;
63 }
64
65 RESULT eNavigation::getCurrentService(ePtr<iPlayableService> &service)
66 {
67         service = m_runningService;
68         return 0;
69 }
70
71 RESULT eNavigation::pause(int dop)
72 {
73         if (!m_runningService)
74                 return -1;
75         ePtr<iPauseableService> p;
76         if (m_runningService->getIPausableService(p))
77                 return -2;
78         if (dop)
79                 return p->pause();
80         else
81                 return p->unpause();
82 }
83
84 eNavigation::eNavigation(iServiceHandler *serviceHandler): ref(0)
85 {
86         assert(serviceHandler);
87         m_servicehandler = serviceHandler;
88 }
89
90 eNavigation::~eNavigation()
91 {
92 }
93
94 DEFINE_REF(eNavigation);