00001 #include "cleanup.h" 00002 00003 #include <mythtv/mythcontext.h> 00004 00005 #include <list> 00006 #include <algorithm> 00007 00008 CleanupProc::~CleanupProc() 00009 { 00010 } 00011 00012 class CleanupHooksImp 00013 { 00014 private: 00015 typedef std::list<CleanupProc *> clean_list; 00016 00017 private: 00018 clean_list m_clean_list; 00019 00020 public: 00021 void addHook(CleanupProc *clean_proc) 00022 { 00023 m_clean_list.push_back(clean_proc); 00024 } 00025 00026 void removeHook(CleanupProc *clean_proc) 00027 { 00028 clean_list::iterator p = std::find(m_clean_list.begin(), 00029 m_clean_list.end(), clean_proc); 00030 if (p != m_clean_list.end()) 00031 { 00032 m_clean_list.erase(p); 00033 } 00034 } 00035 00036 void cleanup() 00037 { 00038 for (clean_list::iterator p = m_clean_list.begin(); 00039 p != m_clean_list.end();++p) 00040 { 00041 (*p)->doClean(); 00042 } 00043 m_clean_list.clear(); 00044 } 00045 }; 00046 00047 namespace 00048 { 00049 CleanupHooks *g_cleanup_hooks = 0; 00050 } 00051 00052 CleanupHooks *CleanupHooks::getInstance() 00053 { 00054 if (!g_cleanup_hooks) 00055 { 00056 g_cleanup_hooks = new CleanupHooks(); 00057 } 00058 return g_cleanup_hooks; 00059 } 00060 00061 void CleanupHooks::addHook(CleanupProc *clean_proc) 00062 { 00063 m_imp->addHook(clean_proc); 00064 } 00065 00066 void CleanupHooks::removeHook(CleanupProc *clean_proc) 00067 { 00068 m_imp->removeHook(clean_proc); 00069 } 00070 00071 void CleanupHooks::cleanup() 00072 { 00073 m_imp->cleanup(); 00074 delete g_cleanup_hooks; 00075 g_cleanup_hooks = 0; 00076 } 00077 00078 CleanupHooks::CleanupHooks() 00079 { 00080 m_imp = new CleanupHooksImp(); 00081 } 00082 00083 CleanupHooks::~CleanupHooks() 00084 { 00085 delete m_imp; 00086 }
1.5.5