1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/module.cpp
3 // Purpose: Modules initialization/destruction
4 // Author: Wolfram Gloger/adapted by Guilhem Lavaux
8 // Copyright: (c) Wolfram Gloger and Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/module.h"
27 #include "wx/listimpl.cpp"
29 #define TRACE_MODULE _T("module")
31 WX_DEFINE_LIST(wxModuleList
)
33 IMPLEMENT_CLASS(wxModule
, wxObject
)
35 wxModuleList
wxModule::m_modules
;
37 void wxModule::RegisterModule(wxModule
* module)
39 m_modules
.Append(module);
42 void wxModule::UnregisterModule(wxModule
* module)
44 m_modules
.DeleteObject(module);
48 // Collect up all module-derived classes, create an instance of each,
50 void wxModule::RegisterModules()
52 wxHashTable::compatibility_iterator node
;
53 wxClassInfo
* classInfo
;
55 wxClassInfo::sm_classTable
->BeginFind();
56 node
= wxClassInfo::sm_classTable
->Next();
59 classInfo
= (wxClassInfo
*)node
->GetData();
60 if ( classInfo
->IsKindOf(CLASSINFO(wxModule
)) &&
61 (classInfo
!= (& (wxModule::ms_classInfo
))) )
63 wxLogTrace(TRACE_MODULE
, wxT("Registering module %s"),
64 classInfo
->GetClassName());
65 wxModule
* module = (wxModule
*)classInfo
->CreateObject();
66 RegisterModule(module);
68 node
= wxClassInfo::sm_classTable
->Next();
72 bool wxModule::InitializeModules()
74 // Initialize user-defined modules
75 wxModuleList::compatibility_iterator node
;
76 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
78 wxModule
*module = node
->GetData();
79 if ( !module->Init() )
81 wxLogError(_("Module \"%s\" initialization failed"),
82 module->GetClassInfo()->GetClassName());
84 // clean up already initialized modules - process in reverse order
85 wxModuleList::compatibility_iterator n
;
86 for ( n
= node
->GetPrevious(); n
; n
= n
->GetPrevious() )
88 n
->GetData()->OnExit();
98 void wxModule::CleanUpModules()
100 // Cleanup user-defined modules
101 wxModuleList::compatibility_iterator node
;
102 for ( node
= m_modules
.GetFirst(); node
; node
= node
->GetNext() )
104 wxLogTrace(TRACE_MODULE
, wxT("Cleanup module %s"),
105 node
->GetData()->GetClassInfo()->GetClassName());
106 node
->GetData()->Exit();
109 WX_CLEAR_LIST(wxModuleList
, m_modules
);