MythTV  master
cleanup.cpp
Go to the documentation of this file.
1 #include <list>
2 #include <algorithm>
3 
4 #include "cleanup.h"
5 
7 {
8  private:
9  typedef std::list<CleanupProc *> clean_list;
10 
11  private:
13 
14  public:
15  void addHook(CleanupProc *clean_proc)
16  {
17  m_clean_list.push_back(clean_proc);
18  }
19 
20  void removeHook(CleanupProc *clean_proc)
21  {
22  clean_list::iterator p = std::find(m_clean_list.begin(),
23  m_clean_list.end(), clean_proc);
24  if (p != m_clean_list.end())
25  {
26  m_clean_list.erase(p);
27  }
28  }
29 
30  void cleanup()
31  {
32  for (clean_list::iterator p = m_clean_list.begin();
33  p != m_clean_list.end();++p)
34  {
35  (*p)->doClean();
36  }
37  m_clean_list.clear();
38  }
39 };
40 
41 namespace
42 {
43  CleanupHooks *g_cleanup_hooks = nullptr;
44 }
45 
47 {
48  if (!g_cleanup_hooks)
49  {
50  g_cleanup_hooks = new CleanupHooks();
51  }
52  return g_cleanup_hooks;
53 }
54 
56 {
57  m_imp->addHook(clean_proc);
58 }
59 
61 {
62  m_imp->removeHook(clean_proc);
63 }
64 
66 {
67  m_imp->cleanup();
68  delete g_cleanup_hooks;
69  g_cleanup_hooks = nullptr;
70 }
71 
73 {
74  m_imp = new CleanupHooksImp();
75 }
76 
78 {
79  delete m_imp;
80 }
void removeHook(CleanupProc *clean_proc)
Definition: cleanup.cpp:60
void addHook(CleanupProc *clean_proc)
Definition: cleanup.cpp:55
void removeHook(CleanupProc *clean_proc)
Definition: cleanup.cpp:20
class CleanupHooksImp * m_imp
Definition: cleanup.h:26
static pid_list_t::iterator find(const PIDInfoMap &map, pid_list_t &list, pid_list_t::iterator begin, pid_list_t::iterator end, bool find_open)
clean_list m_clean_list
Definition: cleanup.cpp:12
void addHook(CleanupProc *clean_proc)
Definition: cleanup.cpp:15
std::list< CleanupProc * > clean_list
Definition: cleanup.cpp:9
static CleanupHooks * getInstance()
Definition: cleanup.cpp:46
void cleanup()
Definition: cleanup.cpp:65
void cleanup()
Definition: cleanup.cpp:30