fix libsigc++ crash
[vuplus_dvbapp] / 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         if (logConnection.connected()) {
36                 logConnection.disconnect();
37         }
38 }
39
40 void eInit::setRunlevel(int nrl)
41 {
42         while (nrl>rl)
43         {
44                 rl++;
45                         
46                 for (std::list<std::pair<int,eAutoInit*> >::iterator i(cl->begin()); i!=cl->end(); ++i)
47                 {
48                         if ((*i).first == rl)
49                         {
50                                 eDebug("+ (%d) %s", rl, (*i).second->getDescription());
51                                 (*i).second->initNow();
52                         }
53                 }
54         }
55         
56         while (nrl<rl)
57         {
58                 for (std::list<std::pair<int,eAutoInit*> >::iterator i(cl->begin()); i!=cl->end(); ++i)
59                         if ((*i).first == rl)
60                         {
61                                 eDebug("- (%d) %s", rl, (*i).second->getDescription());
62                                 (*i).second->closeNow();
63                         }
64                 rl--;
65         }
66         eDebug("reached rl %d", rl);
67 }
68
69 eAutoInit::~eAutoInit()
70 {
71 }