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  using clean_list = std::list<CleanupProc *>;
10 
11  private:
13 
14  public:
15  void addHook(CleanupProc *clean_proc)
16  {
17  m_cleanList.push_back(clean_proc);
18  }
19 
20  void removeHook(CleanupProc *clean_proc)
21  {
22  auto p = std::find(m_cleanList.begin(), m_cleanList.end(), clean_proc);
23  if (p != m_cleanList.end())
24  {
25  m_cleanList.erase(p);
26  }
27  }
28 
29  void cleanup()
30  {
31  for (auto & item : m_cleanList)
32  item->doClean();
33  m_cleanList.clear();
34  }
35 };
36 
37 namespace
38 {
39  CleanupHooks *g_cleanup_hooks = nullptr;
40 }
41 
43 {
44  if (!g_cleanup_hooks)
45  {
46  g_cleanup_hooks = new CleanupHooks();
47  }
48  return g_cleanup_hooks;
49 }
50 
52 {
53  m_imp->addHook(clean_proc);
54 }
55 
57 {
58  m_imp->removeHook(clean_proc);
59 }
60 
62 {
63  m_imp->cleanup();
64  delete g_cleanup_hooks;
65  g_cleanup_hooks = nullptr;
66 }
67 
69 {
70  m_imp = new CleanupHooksImp();
71 }
72 
74 {
75  delete m_imp;
76 }
void removeHook(CleanupProc *clean_proc)
Definition: cleanup.cpp:56
void addHook(CleanupProc *clean_proc)
Definition: cleanup.cpp:51
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)
std::list< CleanupProc * > clean_list
Definition: cleanup.cpp:9
clean_list m_cleanList
Definition: cleanup.cpp:12
void addHook(CleanupProc *clean_proc)
Definition: cleanup.cpp:15
static CleanupHooks * getInstance()
Definition: cleanup.cpp:42
void cleanup()
Definition: cleanup.cpp:61
void cleanup()
Definition: cleanup.cpp:29