]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dynload.h
Use wxGetTranslation() instead of _() in the public headers.
[wxWidgets.git] / include / wx / dynload.h
CommitLineData
0b9ab0bd 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/dynload.h
0b9ab0bd
RL
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)
6// Modified by:
7// Created: 03/12/01
0b9ab0bd 8// Copyright: (c) 2001 Ron Lee <ron@debian.org>
65571936 9// Licence: wxWindows licence
0b9ab0bd
RL
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DYNAMICLOADER_H__
13#define _WX_DYNAMICLOADER_H__
14
0b9ab0bd
RL
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19#include "wx/defs.h"
20
21#if wxUSE_DYNAMIC_LOADER
22
1948bb32 23#include "wx/dynlib.h"
2b5f62a0 24#include "wx/hashmap.h"
0b9ab0bd
RL
25#include "wx/module.h"
26
b5dbe15d 27class WXDLLIMPEXP_FWD_BASE wxPluginLibrary;
0b9ab0bd 28
0b9ab0bd 29
1948bb32 30WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxPluginLibrary *, wxDLManifest,
3f5c62f9 31 class WXDLLIMPEXP_BASE);
1948bb32 32typedef wxDLManifest wxDLImports;
0b9ab0bd
RL
33
34// ---------------------------------------------------------------------------
4f89dbc4 35// wxPluginLibrary
0b9ab0bd
RL
36// ---------------------------------------------------------------------------
37
4f89dbc4
RL
38// NOTE: Do not attempt to use a base class pointer to this class.
39// wxDL is not virtual and we deliberately hide some of it's
40// methods here.
41//
42// Unless you know exacty why you need to, you probably shouldn't
43// instantiate this class directly anyway, use wxPluginManager
44// instead.
45
bddd7a8d 46class WXDLLIMPEXP_BASE wxPluginLibrary : public wxDynamicLibrary
0b9ab0bd
RL
47{
48public:
49
dabd1377 50 static wxDLImports* ms_classes; // Static hash of all imported classes.
0b9ab0bd 51
23213f18 52 wxPluginLibrary( const wxString &libname, int flags = wxDL_DEFAULT );
4f89dbc4 53 ~wxPluginLibrary();
0b9ab0bd 54
d0fcccc4 55 wxPluginLibrary *RefLib();
4f89dbc4 56 bool UnrefLib();
7c1e2b44
RL
57
58 // These two are called by the PluginSentinel on (PLUGGABLE) object
59 // creation/destruction. There is usually no reason for the user to
60 // call them directly. We have to separate this from the link count,
61 // since the two are not interchangeable.
62
63 // FIXME: for even better debugging PluginSentinel should register
64 // the name of the class created too, then we can state
65 // exactly which object was not destroyed which may be
66 // difficult to find otherwise. Also this code should
67 // probably only be active in DEBUG mode, but let's just
68 // get it right first.
69
4f89dbc4
RL
70 void RefObj() { ++m_objcount; }
71 void UnrefObj()
7c1e2b44 72 {
9a83f860 73 wxASSERT_MSG( m_objcount > 0, wxT("Too many objects deleted??") );
7c1e2b44
RL
74 --m_objcount;
75 }
0b9ab0bd 76
4f89dbc4 77 // Override/hide some base class methods
0b9ab0bd 78
4f89dbc4
RL
79 bool IsLoaded() const { return m_linkcount > 0; }
80 void Unload() { UnrefLib(); }
0b9ab0bd
RL
81
82private:
83
7ed9cd28
VZ
84 // These pointers may be NULL but if they are not, then m_ourLast follows
85 // m_ourFirst in the linked list, i.e. can be found by calling GetNext() a
86 // sufficient number of times.
87 const wxClassInfo *m_ourFirst; // first class info in this plugin
88 const wxClassInfo *m_ourLast; // ..and the last one
0b9ab0bd 89
7c1e2b44
RL
90 size_t m_linkcount; // Ref count of library link calls
91 size_t m_objcount; // ..and (pluggable) object instantiations.
92 wxModuleList m_wxmodules; // any wxModules that we initialised.
0b9ab0bd 93
2d4957f2
VS
94 void UpdateClasses(); // Update ms_classes
95 void RestoreClasses(); // Removes this library from ms_classes
7c1e2b44
RL
96 void RegisterModules(); // Init any wxModules in the lib.
97 void UnregisterModules(); // Cleanup any wxModules we installed.
0b9ab0bd 98
c0c133e1 99 wxDECLARE_NO_COPY_CLASS(wxPluginLibrary);
0b9ab0bd
RL
100};
101
102
bddd7a8d 103class WXDLLIMPEXP_BASE wxPluginManager
0b9ab0bd
RL
104{
105public:
106
107 // Static accessors.
108
4f89dbc4 109 static wxPluginLibrary *LoadLibrary( const wxString &libname,
23213f18 110 int flags = wxDL_DEFAULT );
4f89dbc4
RL
111 static bool UnloadLibrary(const wxString &libname);
112
0b9ab0bd
RL
113 // Instance methods.
114
6fb99eb3 115 wxPluginManager() : m_entry(NULL) {}
23213f18 116 wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT)
4f89dbc4
RL
117 {
118 Load(libname, flags);
119 }
e5e2612a 120 ~wxPluginManager() { if ( IsLoaded() ) Unload(); }
4f89dbc4 121
23213f18 122 bool Load(const wxString &libname, int flags = wxDL_DEFAULT);
4f89dbc4 123 void Unload();
0b9ab0bd
RL
124
125 bool IsLoaded() const { return m_entry && m_entry->IsLoaded(); }
126 void *GetSymbol(const wxString &symbol, bool *success = 0)
127 {
128 return m_entry->GetSymbol( symbol, success );
129 }
130
dabd1377
JS
131 static void CreateManifest() { ms_manifest = new wxDLManifest(wxKEY_STRING); }
132 static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; }
133
0b9ab0bd 134private:
2b5f62a0
VZ
135 // return the pointer to the entry for the library with given name in
136 // ms_manifest or NULL if none
137 static wxPluginLibrary *FindByName(const wxString& name)
138 {
139 const wxDLManifest::iterator i = ms_manifest->find(name);
140
141 return i == ms_manifest->end() ? NULL : i->second;
142 }
0b9ab0bd 143
dabd1377
JS
144 static wxDLManifest* ms_manifest; // Static hash of loaded libs.
145 wxPluginLibrary* m_entry; // Cache our entry in the manifest.
0b9ab0bd
RL
146
147 // We could allow this class to be copied if we really
148 // wanted to, but not without modification.
c0c133e1 149 wxDECLARE_NO_COPY_CLASS(wxPluginManager);
0b9ab0bd
RL
150};
151
152
153#endif // wxUSE_DYNAMIC_LOADER
154#endif // _WX_DYNAMICLOADER_H__
155