set foregroundcolor of non tuneable services in servicelist to gray (for linked tuner...
[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::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
94 {
95         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
96         if (i == handler.end())
97         {
98                 ptr = 0;
99                 return -1;
100         }
101         return i->second->info(ref, ptr);
102 }
103
104 RESULT eServiceCenter::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
105 {
106         std::map<int,ePtr<iServiceHandler> >::iterator i = handler.find(ref.type);
107         if (i == handler.end())
108         {
109                 ptr = 0;
110                 return -1;
111         }
112         return i->second->offlineOperations(ref, ptr);
113 }
114
115 RESULT eServiceCenter::addServiceFactory(int id, iServiceHandler *hnd)
116 {
117         handler.insert(std::pair<int,ePtr<iServiceHandler> >(id, hnd));
118         return 0;
119 }
120
121 RESULT eServiceCenter::removeServiceFactory(int id)
122 {
123         handler.erase(id);
124         return 0;
125 }
126
127         /* default handlers */
128 RESULT iServiceHandler::info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr)
129 {
130         ptr = 0;
131         return -1;
132 }
133
134 #include <lib/service/event.h>
135
136 RESULT iServiceInformation::getEvent(ePtr<eServiceEvent> &evt, int m_nownext)
137 {       
138         evt = 0;
139         return -1;
140 }
141
142 int iServiceInformation::getInfo(int w)
143 {
144         return -1;
145 }
146
147 std::string iServiceInformation::getInfoString(int w)
148 {
149         return "";
150 }
151
152 eAutoInitPtr<eServiceCenter> init_eServiceCenter(eAutoInitNumbers::service, "eServiceCenter");