added nav core
[vuplus_dvbapp] / lib / service / servicemp3.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
3 #include <lib/base/ebase.h>
4 #include <string>
5 #include <lib/service/servicemp3.h>
6 #include <lib/service/service.h>
7 #include <lib/base/init_num.h>
8 #include <lib/base/init.h>
9
10 // eServiceFactoryMP3
11
12 eServiceFactoryMP3::eServiceFactoryMP3(): ref(0)
13 {
14         ePtr<eServiceCenter> sc;
15         
16         eServiceCenter::getInstance(sc);
17         if (sc)
18                 sc->addServiceFactory(eServiceFactoryMP3::id, this);
19 }
20
21 eServiceFactoryMP3::~eServiceFactoryMP3()
22 {
23         ePtr<eServiceCenter> sc;
24         
25         eServiceCenter::getInstance(sc);
26         if (sc)
27                 sc->removeServiceFactory(eServiceFactoryMP3::id);
28 }
29
30 DEFINE_REF(eServiceFactoryMP3)
31
32         // iServiceHandler
33 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
34 {
35                 // check resources...
36         ptr = new eServiceMP3(ref.path.c_str());
37         return 0;
38 }
39
40 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
41 {
42         ptr=0;
43         return -1;
44 }
45
46 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
47 {
48         ptr=0;
49         return -1;
50 }
51
52 // eServiceMP3
53
54
55 void eServiceMP3::test_end()
56 {
57         eDebug("end of mp3!");
58         stop();
59 }
60
61 eServiceMP3::eServiceMP3(const char *filename): ref(0), filename(filename), test(eApp)
62 {
63         m_state = stIdle;
64 }
65
66 eServiceMP3::~eServiceMP3()
67 {
68         if (m_state == stRunning)
69                 stop();
70 }
71
72 DEFINE_REF(eServiceMP3);        
73
74 RESULT eServiceMP3::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
75 {
76         connection = new eConnection(m_event.connect(event));
77         return 0;
78 }
79
80 RESULT eServiceMP3::start()
81 {
82         assert(m_state == stIdle);
83         
84         m_state = stRunning;
85
86         printf("mp3 starts\n");
87         printf("MP3: %s start\n", filename.c_str());
88         test.start(10000, 1);
89         CONNECT(test.timeout, eServiceMP3::test_end);
90         m_event(this, evStart);
91         return 0;
92 }
93
94 RESULT eServiceMP3::stop()
95 {
96         assert(m_state != stIdle);
97         if (m_state == stStopped)
98                 return -1;
99         test.stop();
100         printf("MP3: %s stop\n", filename.c_str());
101         m_state = stStopped;
102         m_event(this, evEnd);
103         return 0;
104 }
105
106 RESULT eServiceMP3::getIPausableService(ePtr<iPauseableService> &ptr) { ptr=this; return 0; }
107
108                 // iPausableService
109 RESULT eServiceMP3::pause() { printf("mp3 pauses!\n"); return 0; }
110 RESULT eServiceMP3::unpause() { printf("mp3 unpauses!\n"); return 0; }
111
112 RESULT eServiceMP3::getIServiceInformation(ePtr<iServiceInformation>&) { return -1; }
113
114
115 eAutoInitP0<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");