provider-selection is now possible for cable and terrestrial
[enigma2.git] / lib / base / init.cpp
1 #include <stdio.h>
2 #include <lib/base/init.h>
3 #include <lib/base/eerror.h>
4
5 int eInit::rl=-1;
6 std::list<std::pair<int,eAutoInit*> > *eInit::cl;
7
8 void eInit::add(int trl, eAutoInit *c)
9 {
10         if (!cl)
11                 cl=new std::list<std::pair<int,eAutoInit*> >;
12         cl->push_back(std::pair<int,eAutoInit*>(trl, c));
13         if (rl>=trl)
14                 c->initNow();
15 }
16
17 void eInit::remove(int trl, eAutoInit *c)
18 {
19         if (!cl)
20                 return;
21         cl->remove(std::pair<int,eAutoInit*>(trl, c));
22         if (rl>=trl)
23                 c->closeNow();
24 }
25
26 eInit::eInit()
27 {
28 }
29
30 eInit::~eInit()
31 {
32         setRunlevel(-1);
33         delete cl;
34         cl=0;
35 }
36
37 void eInit::setRunlevel(int nrl)
38 {
39         while (nrl>rl)
40         {
41                 rl++;
42                         
43                 for (std::list<std::pair<int,eAutoInit*> >::iterator i(cl->begin()); i!=cl->end(); ++i)
44                 {
45                         if ((*i).first == rl)
46                         {
47                                 eDebug("+ (%d) %s", rl, (*i).second->getDescription());
48                                 (*i).second->initNow();
49                         }
50                 }
51         }
52         
53         while (nrl<rl)
54         {
55                 for (std::list<std::pair<int,eAutoInit*> >::iterator i(cl->begin()); i!=cl->end(); ++i)
56                         if ((*i).first == rl)
57                         {
58                                 eDebug("- (%d) %s", rl, (*i).second->getDescription());
59                                 (*i).second->closeNow();
60                         }
61                 rl--;
62         }
63         eDebug("reached rl %d", rl);
64 }
65
66 eAutoInit::~eAutoInit()
67 {
68 }