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