openATV enigma2
openATV is an open source SetTopBox Graphical user interface.
init.h
Go to the documentation of this file.
1 #ifndef __init_h
2 #define __init_h
3 
4 #include <list>
5 #include <utility>
6 #include <lib/base/object.h>
7 
8 class eAutoInit;
9 
10 class eInit
11 {
12  static std::list<std::pair<int,eAutoInit*> > *cl;
13  friend class eAutoInit;
14  static int rl;
15  static bool paused;
16 public:
17  eInit();
18  ~eInit();
19  static void setRunlevel(int rlev);
20  static void add(int trl, eAutoInit *c);
21  static void remove(int trl, eAutoInit *c);
22  static void pauseInit();
23  static void resumeInit();
24 };
25 
26 class eAutoInit
27 {
28  friend class eInit;
29  virtual void initNow()=0;
30  virtual void closeNow()=0;
31 protected:
32  int rl;
33  const char *description;
34 public:
36  {
37  }
38  virtual ~eAutoInit();
39  const char *getDescription() const { return description; };
40 };
41 
42 template<class T1, class T2> class
43 eAutoInitP1: protected eAutoInit
44 {
45  T1 *t;
46  const T2 &arg;
47  void initNow()
48  {
49  if (t == nullptr)
50  {
51  eDebug("[eInit] + (%d) %s", rl, getDescription());
52  t = new T1(arg);
53  }
54  }
55  void closeNow()
56  {
57  delete t;
58  t = nullptr;
59  }
60 public:
61  operator T1*()
62  {
63  return t;
64  }
65  eAutoInitP1(const T2 &arg, int runl, const char *description): eAutoInit(runl, description), t(nullptr), arg(arg)
66  {
67  eInit::add(rl, this);
68  }
70  {
71  eInit::remove(rl, this);
72  }
73 };
74 
75 template<class T1> class
76 eAutoInitP0: protected eAutoInit
77 {
78  T1 *t;
79  void initNow()
80  {
81  if (t == nullptr)
82  {
83  eDebug("[eInit] + (%d) %s", rl, getDescription());
84  t = new T1();
85  }
86  }
87  void closeNow()
88  {
89  delete t;
90  t = nullptr;
91  }
92 public:
93  operator T1*()
94  {
95  return t;
96  }
97  T1 *operator->()
98  {
99  return t;
100  }
101  eAutoInitP0(int runl, const char *description): eAutoInit(runl, description), t(nullptr)
102  {
103  eInit::add(rl, this);
104  }
106  {
107  eInit::remove(rl, this);
108  }
109 };
110 
111 template<class T1> class
112 eAutoInitPtr: protected eAutoInit
113 {
114  ePtr<T1> t;
115  void initNow()
116  {
117  if (t == nullptr)
118  {
119  eDebug("[eInit] + (%d) %s", rl, getDescription());
120  t = new T1();
121  }
122  }
123  void closeNow()
124  {
125  t = nullptr;
126  }
127 public:
128  operator T1*()
129  {
130  return t;
131  }
133  {
134  return t;
135  }
136  eAutoInitPtr(int runl, const char *description): eAutoInit(runl, description), t(nullptr)
137  {
138  eInit::add(rl, this);
139  }
141  {
142  eInit::remove(rl, this);
143  }
144 };
145 
146 #endif
Definition: init.h:27
virtual ~eAutoInit()
Definition: init.cpp:93
const char * description
Definition: init.h:33
int rl
Definition: init.h:32
eAutoInit(int rl, const char *description)
Definition: init.h:35
const char * getDescription() const
Definition: init.h:39
Definition: init.h:77
eAutoInitP0(int runl, const char *description)
Definition: init.h:101
~eAutoInitP0()
Definition: init.h:105
T1 * operator->()
Definition: init.h:97
Definition: init.h:44
eAutoInitP1(const T2 &arg, int runl, const char *description)
Definition: init.h:65
~eAutoInitP1()
Definition: init.h:69
Definition: init.h:113
~eAutoInitPtr()
Definition: init.h:140
eAutoInitPtr(int runl, const char *description)
Definition: init.h:136
T1 * operator->()
Definition: init.h:132
Definition: init.h:11
~eInit()
Definition: init.cpp:36
static void add(int trl, eAutoInit *c)
Definition: init.cpp:9
static void resumeInit()
Definition: init.cpp:76
eInit()
Definition: init.cpp:32
static void remove(int trl, eAutoInit *c)
Definition: init.cpp:23
static void pauseInit()
Definition: init.cpp:71
static void setRunlevel(int rlev)
Definition: init.cpp:43
description
Definition: MovieSelection.py:85
arg
Definition: UnitConversions.py:88
eDebug("[ePicLoad] deprecated loadPic function used!!! please use the non blocking version! you can see demo code in Pictureplayer plugin... this function is removed in the near future!")