1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Dynamic loading framework
4 // Author: Ron Lee, David Falkinder, Vadim Zeitlin and a cast of 1000's
5 // (derived in part from dynlib.cpp (c) 1998 Guilhem Lavaux)
9 // Copyright: (c) 2001 Ron Lee <ron@debian.org>
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef _WX_DYNAMICLOADER_H__
14 #define _WX_DYNAMICLOADER_H__
16 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
17 #pragma interface "dynload.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
26 #if wxUSE_DYNAMIC_LOADER
28 #include "wx/dynlib.h"
29 #include "wx/hashmap.h"
30 #include "wx/module.h"
32 class WXDLLIMPEXP_BASE wxPluginLibrary
;
35 WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxPluginLibrary
*, wxDLManifest
,
36 class WXDLLIMPEXP_BASE
);
37 typedef wxDLManifest wxDLImports
;
39 // ---------------------------------------------------------------------------
41 // ---------------------------------------------------------------------------
43 // NOTE: Do not attempt to use a base class pointer to this class.
44 // wxDL is not virtual and we deliberately hide some of it's
47 // Unless you know exacty why you need to, you probably shouldn't
48 // instantiate this class directly anyway, use wxPluginManager
51 class WXDLLIMPEXP_BASE wxPluginLibrary
: public wxDynamicLibrary
55 static wxDLImports
* ms_classes
; // Static hash of all imported classes.
57 wxPluginLibrary( const wxString
&libname
, int flags
= wxDL_DEFAULT
);
60 wxPluginLibrary
*RefLib();
63 // These two are called by the PluginSentinel on (PLUGGABLE) object
64 // creation/destruction. There is usually no reason for the user to
65 // call them directly. We have to separate this from the link count,
66 // since the two are not interchangeable.
68 // FIXME: for even better debugging PluginSentinel should register
69 // the name of the class created too, then we can state
70 // exactly which object was not destroyed which may be
71 // difficult to find otherwise. Also this code should
72 // probably only be active in DEBUG mode, but let's just
73 // get it right first.
75 void RefObj() { ++m_objcount
; }
78 wxASSERT_MSG( m_objcount
> 0, _T("Too many objects deleted??") );
82 // Override/hide some base class methods
84 bool IsLoaded() const { return m_linkcount
> 0; }
85 void Unload() { UnrefLib(); }
89 wxClassInfo
*m_before
; // sm_first before loading this lib
90 wxClassInfo
*m_after
; // ..and after.
92 size_t m_linkcount
; // Ref count of library link calls
93 size_t m_objcount
; // ..and (pluggable) object instantiations.
94 wxModuleList m_wxmodules
; // any wxModules that we initialised.
96 void RegisterModules(); // Init any wxModules in the lib.
97 void UnregisterModules(); // Cleanup any wxModules we installed.
99 DECLARE_NO_COPY_CLASS(wxPluginLibrary
)
103 class WXDLLIMPEXP_BASE wxPluginManager
109 static wxPluginLibrary
*LoadLibrary( const wxString
&libname
,
110 int flags
= wxDL_DEFAULT
);
111 static bool UnloadLibrary(const wxString
&libname
);
113 // This is used by wxDllLoader. It's wrapped in the compatibility
114 // macro because it's of arguable use outside of that.
116 #if WXWIN_COMPATIBILITY_2_2
117 static wxPluginLibrary
*GetObjectFromHandle(wxDllType handle
);
122 wxPluginManager() : m_entry(NULL
) {};
123 wxPluginManager(const wxString
&libname
, int flags
= wxDL_DEFAULT
)
125 Load(libname
, flags
);
127 ~wxPluginManager() { Unload(); }
129 bool Load(const wxString
&libname
, int flags
= wxDL_DEFAULT
);
132 bool IsLoaded() const { return m_entry
&& m_entry
->IsLoaded(); }
133 void *GetSymbol(const wxString
&symbol
, bool *success
= 0)
135 return m_entry
->GetSymbol( symbol
, success
);
138 static void CreateManifest() { ms_manifest
= new wxDLManifest(wxKEY_STRING
); }
139 static void ClearManifest() { delete ms_manifest
; ms_manifest
= NULL
; }
142 // return the pointer to the entry for the library with given name in
143 // ms_manifest or NULL if none
144 static wxPluginLibrary
*FindByName(const wxString
& name
)
146 const wxDLManifest::iterator i
= ms_manifest
->find(name
);
148 return i
== ms_manifest
->end() ? NULL
: i
->second
;
151 static wxDLManifest
* ms_manifest
; // Static hash of loaded libs.
152 wxPluginLibrary
* m_entry
; // Cache our entry in the manifest.
154 // We could allow this class to be copied if we really
155 // wanted to, but not without modification.
156 DECLARE_NO_COPY_CLASS(wxPluginManager
)
160 #endif // wxUSE_DYNAMIC_LOADER
161 #endif // _WX_DYNAMICLOADER_H__