- add python, missing gui
[enigma2.git] / lib / service / service.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/base/estring.h>
3 #include <lib/service/service.h>
4 #include <lib/base/init_num.h>
5 #include <lib/base/init.h>
6
7 eServiceReference::eServiceReference(const std::string &string)
8 {
9         const char *c=string.c_str();
10         int pathl=-1;
11         
12         if ( sscanf(c, "%d:%d:%x:%x:%x:%x:%x:%x:%x:%x:%n", &type, &flags, &data[0], &data[1], &data[2], &data[3], &data[4], &data[5], &data[6], &data[7], &pathl) < 8 )
13         {
14                 memset( data, 0, sizeof(data) );
15                 eDebug("find old format eServiceReference string");
16                 sscanf(c, "%d:%d:%x:%x:%x:%x:%n", &type, &flags, &data[0], &data[1], &data[2], &data[3], &pathl);
17         }
18
19         if (pathl)
20                 path=c+pathl;
21 }
22
23 std::string eServiceReference::toString() const
24 {
25         std::string ret;
26         ret += getNum(type);
27         ret += ":";
28         ret += getNum(flags);
29         for (unsigned int i=0; i<sizeof(data)/sizeof(*data); ++i)
30         {
31                 ret+=":"+ getNum(data[i], 0x10);
32         }
33         ret+=":"+path;
34         return ret;
35 }
36
37
38 eServiceCenter *eServiceCenter::instance;
39
40 eServiceCenter::eServiceCenter()
41 {
42         if (!instance)
43         {
44                 eDebug("settings instance.");
45                 instance = this;
46         }
47 }
48
49 eServiceCenter::~eServiceCenter()
50 {
51         if (instance == this)
52         {
53                 eDebug("clear instance");
54                 instance = 0;
55         }
56 }
57
58 DEFINE_REF(eServiceCenter);
59
60 RESULT eServiceCenter::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
61 {
62         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
63         if (i == handler.end())
64         {
65                 ptr = 0;
66                 return -1;
67         }
68         return i->second->play(ref, ptr);
69 }
70
71 RESULT eServiceCenter::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
72 {
73         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
74         if (i == handler.end())
75         {
76                 ptr = 0;
77                 return -1;
78         }
79         return i->second->record(ref, ptr);
80 }
81
82 RESULT eServiceCenter::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
83 {
84         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
85         if (i == handler.end())
86         {
87                 ptr = 0;
88                 return -1;
89         }
90         return i->second->list(ref, ptr);
91 }
92
93 RESULT eServiceCenter::addServiceFactory(int id, iServiceHandler *hnd)
94 {
95         handler.insert(std::pair<int,ePtr<iServiceHandler> >(id, hnd));
96         return 0;
97 }
98
99 RESULT eServiceCenter::removeServiceFactory(int id)
100 {
101         handler.erase(id);
102         return 0;
103 }
104
105 eAutoInitPtr<eServiceCenter> init_eServiceCenter(eAutoInitNumbers::service, "eServiceCenter");