import of enigma2
[enigma2.git] / lib / service / servicemp3.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
3 #include <string>
4 #include <lib/service/servicemp3.h>
5 #include <lib/service/service.h>
6 #include <lib/base/init_num.h>
7 #include <lib/base/init.h>
8
9 // eServiceFactoryMP3
10
11 eServiceFactoryMP3::eServiceFactoryMP3(): ref(0)
12 {
13         ePtr<eServiceCenter> sc;
14         
15         eServiceCenter::getInstance(sc);
16         if (sc)
17                 sc->addServiceFactory(eServiceFactoryMP3::id, this);
18 }
19
20 eServiceFactoryMP3::~eServiceFactoryMP3()
21 {
22         ePtr<eServiceCenter> sc;
23         
24         eServiceCenter::getInstance(sc);
25         if (sc)
26                 sc->removeServiceFactory(eServiceFactoryMP3::id);
27 }
28
29 DEFINE_REF(eServiceFactoryMP3)
30
31         // iServiceHandler
32 RESULT eServiceFactoryMP3::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
33 {
34         RESULT res;
35                 // check resources...
36         ptr = new eServiceMP3(ref.path.c_str());
37         res = ptr->start();
38         if (res)
39         {
40                 ptr = 0;
41                 return res;
42         }
43         return 0;
44 }
45
46 RESULT eServiceFactoryMP3::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
47 {
48         ptr=0;
49         return -1;
50 }
51
52 RESULT eServiceFactoryMP3::list(const eServiceReference &, ePtr<iListableService> &ptr)
53 {
54         ptr=0;
55         return -1;
56 }
57
58 // eServiceMP3
59
60 eServiceMP3::eServiceMP3(const char *filename): filename(filename), ref(0)
61 {
62         printf("MP3: %s start\n", filename);
63 }
64
65 eServiceMP3::~eServiceMP3()
66 {
67         printf("MP3: %s stop\n", filename.c_str());
68 }
69         
70 void eServiceMP3::AddRef()
71 {
72         ++ref;
73 }
74
75 void eServiceMP3::Release()
76 {
77         if (!--ref)
78                 delete this;
79 }
80
81 RESULT eServiceMP3::start() { printf("mp3 starts\n"); return 0; }
82 RESULT eServiceMP3::getIPausableService(ePtr<iPauseableService> &ptr) { ptr=this; return 0; }
83
84                 // iPausableService
85 RESULT eServiceMP3::pause() { printf("mp3 pauses!\n"); return 0; }
86 RESULT eServiceMP3::unpause() { printf("mp3 unpauses!\n"); return 0; }
87
88
89 eAutoInitP0<eServiceFactoryMP3> init_eServiceFactoryMP3(eAutoInitNumbers::service+1, "eServiceFactoryMP3");