More debug cosmetics
[openblackhole/openblackhole-enigma2.git] / main / enigma-playlist.cpp
1 #include <stdio.h>
2 #include <libsig_comp.h>
3 #include <lib/base/ebase.h>
4 #include <lib/base/eerror.h>
5 #include <lib/base/init.h>
6 #include <lib/base/init_num.h>
7
8 #include <lib/dvb/dvb.h>
9 #include <lib/dvb/db.h>
10 #include <lib/dvb/isection.h>
11 #include <lib/dvb/esection.h>
12 #include <dvbsi++/program_map_section.h>
13 #include <lib/dvb/scan.h>
14 #include <unistd.h>
15
16 #include <lib/service/iservice.h>
17 #include <lib/nav/core.h>
18
19 class eMain: public eApplication, public Object
20 {
21         eInit init;
22
23         ePtr<eDVBResourceManager> m_mgr;
24         ePtr<iDVBChannel> m_channel;
25         ePtr<eDVBDB> m_dvbdb;
26
27         ePtr<iPlayableService> m_playservice;
28         ePtr<eNavigation> m_nav;
29         ePtr<eConnection> m_conn_event;
30         ePtr<iServiceInformation> m_serviceInformation;
31 public:
32         eMain()
33         {
34                 init.setRunlevel(eAutoInitNumbers::main);
35                 m_dvbdb = new eDVBDB();
36                 m_mgr = new eDVBResourceManager();
37                 m_mgr->setChannelList(m_dvbdb);
38
39                 ePtr<eServiceCenter> service_center;
40                 eServiceCenter::getInstance(service_center);
41
42                 assert(service_center);
43                 m_nav = new eNavigation(service_center);
44 #if 0
45                 if (service_center)
46                 {
47                         eServiceReference ref("2:0:1:0:0:0:0:0:0:0:/");
48                         ePtr<iListableService> lst;
49                         if (service_center->list(ref, lst))
50                                 eDebug("[eMain playlist] no list available!");
51                         else
52                         {
53                                 std::list<eServiceReference> list;
54                                 if (lst->getContent(list))
55                                         eDebug("[eMain playlist] list itself SUCKED AROUND!!!");
56                                 else
57                                         for (std::list<eServiceReference>::const_iterator i(list.begin());
58                                                 i != list.end(); ++i)
59                                                 eDebug("[eMain playlist] %s", i->toString().c_str());
60                         }
61                 }
62 #endif
63                 m_nav->connectEvent(slot(*this, &eMain::event), m_conn_event);
64
65 //              eServiceReference ref("1:0:1:6de2:44d:1:c00000:0:0:0:");
66                 eServiceReference ref("4097:47:0:0:0:0:0:0:0:0:/sine_60s_100.mp3");
67                 eServiceReference ref1("4097:47:0:0:0:0:0:0:0:0:/sine_60s_100.mp31");
68                 eServiceReference ref2("4097:47:0:0:0:0:0:0:0:0:/sine_60s_100.mp32");
69
70                 if (m_nav->enqueueService(ref))
71                         eDebug("[eMain playlist] play sucked around!");
72                 else
73                         eDebug("[eMain playlist] play r00lz!");
74
75                 m_nav->enqueueService(ref1);
76                 m_nav->enqueueService(ref2);
77                 m_nav->enqueueService(ref1);
78         }
79
80         void event(eNavigation *nav, int ev)
81         {
82                 assert(nav);
83
84                 ePtr<ePlaylist> playlist;
85                 nav->getPlaylist(playlist);
86                 if (playlist)
87                 {
88                         eDebug("[eMain playlist] PLAYLIST:");
89                         ePlaylist::iterator i;
90                         for (i=playlist->begin(); i != playlist->end(); ++i)
91                                 eDebug("[eMain playlist] %s %s", i == playlist->m_current ? "-->" : "   ", i->toString().c_str());
92                 }
93
94                 switch (ev)
95                 {
96                 case eNavigation::evStopService:
97                                 /* very important: the old service should be deallocated, so clear *all* references to it */
98                         m_serviceInformation = 0;
99                         eDebug("[eMain playlist] STOP service!");
100                         break;
101                 case eNavigation::evNewService:
102                 {
103                         ePtr<iPlayableService> service;
104                         nav->getCurrentService(service);
105                         if (!service)
106                         {
107                                 eDebug("[eMain playlist] no running service!");
108                                 break;
109                         }
110                         if (service->getIServiceInformation(m_serviceInformation))
111                         {
112                                 eDebug("[eMain playlist] failed to get iserviceinformation");
113                                 break;
114                         }
115                         std::string name;
116                         m_serviceInformation->getName(name);
117                         eDebug("[eMain playlist] NEW running service: %s", name.c_str());
118                         break;
119                 }
120                 case eNavigation::evPlayFailed:
121                         eDebug("[eMain playlist] play failed!");
122                         break;
123                 case eNavigation::evPlaylistDone:
124                         eDebug("[eMain playlist] playlist done");
125                         quit();
126                         break;
127                 default:
128                         eDebug("[eMain playlist] Navigation event %d", ev);
129                         break;
130                 }
131         }
132
133         ~eMain()
134         {
135         }
136 };
137
138 #ifdef OBJECT_DEBUG
139 int object_total_remaining;
140
141 void object_dump()
142 {
143         printf("%d items left\n", object_total_remaining);
144 }
145 #endif
146
147 int main()
148 {
149 #ifdef OBJECT_DEBUG
150         atexit(object_dump);
151 #endif
152
153         eMain app;
154         int res = app.exec();
155         eDebug("[MAIN playlist] after exec");
156         return res;
157 }
158