2001-12-19 02:09:58 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2011-03-19 20:14:35 -04:00
|
|
|
// Name: wx/dynload.h
|
2001-12-19 02:09:58 -05:00
|
|
|
// Purpose: Dynamic loading framework
|
|
|
|
// Author: Ron Lee, David Falkinder, Vadim Zeitlin and a cast of 1000's
|
|
|
|
// (derived in part from dynlib.cpp (c) 1998 Guilhem Lavaux)
|
|
|
|
// Modified by:
|
|
|
|
// Created: 03/12/01
|
|
|
|
// Copyright: (c) 2001 Ron Lee <ron@debian.org>
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2001-12-19 02:09:58 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_DYNAMICLOADER_H__
|
|
|
|
#define _WX_DYNAMICLOADER_H__
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_DYNAMIC_LOADER
|
|
|
|
|
2003-08-01 17:12:40 -04:00
|
|
|
#include "wx/dynlib.h"
|
2002-12-04 09:11:26 -05:00
|
|
|
#include "wx/hashmap.h"
|
2001-12-19 02:09:58 -05:00
|
|
|
#include "wx/module.h"
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxPluginLibrary;
|
2001-12-19 02:09:58 -05:00
|
|
|
|
|
|
|
|
2003-08-01 17:12:40 -04:00
|
|
|
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxPluginLibrary *, wxDLManifest,
|
2006-01-18 11:45:41 -05:00
|
|
|
class WXDLLIMPEXP_BASE);
|
2003-08-01 17:12:40 -04:00
|
|
|
typedef wxDLManifest wxDLImports;
|
2001-12-19 02:09:58 -05:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
2001-12-29 09:50:36 -05:00
|
|
|
// wxPluginLibrary
|
2001-12-19 02:09:58 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2001-12-29 09:50:36 -05:00
|
|
|
// NOTE: Do not attempt to use a base class pointer to this class.
|
|
|
|
// wxDL is not virtual and we deliberately hide some of it's
|
|
|
|
// methods here.
|
|
|
|
//
|
|
|
|
// Unless you know exacty why you need to, you probably shouldn't
|
|
|
|
// instantiate this class directly anyway, use wxPluginManager
|
|
|
|
// instead.
|
|
|
|
|
2003-07-01 21:59:24 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxPluginLibrary : public wxDynamicLibrary
|
2001-12-19 02:09:58 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-04-10 05:35:36 -04:00
|
|
|
static wxDLImports* ms_classes; // Static hash of all imported classes.
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2001-12-30 19:46:04 -05:00
|
|
|
wxPluginLibrary( const wxString &libname, int flags = wxDL_DEFAULT );
|
2001-12-29 09:50:36 -05:00
|
|
|
~wxPluginLibrary();
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2002-04-22 08:28:02 -04:00
|
|
|
wxPluginLibrary *RefLib();
|
2001-12-29 09:50:36 -05:00
|
|
|
bool UnrefLib();
|
2001-12-20 07:06:11 -05:00
|
|
|
|
|
|
|
// These two are called by the PluginSentinel on (PLUGGABLE) object
|
|
|
|
// creation/destruction. There is usually no reason for the user to
|
|
|
|
// call them directly. We have to separate this from the link count,
|
|
|
|
// since the two are not interchangeable.
|
|
|
|
|
|
|
|
// FIXME: for even better debugging PluginSentinel should register
|
|
|
|
// the name of the class created too, then we can state
|
|
|
|
// exactly which object was not destroyed which may be
|
|
|
|
// difficult to find otherwise. Also this code should
|
|
|
|
// probably only be active in DEBUG mode, but let's just
|
|
|
|
// get it right first.
|
|
|
|
|
2001-12-29 09:50:36 -05:00
|
|
|
void RefObj() { ++m_objcount; }
|
|
|
|
void UnrefObj()
|
2001-12-20 07:06:11 -05:00
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxASSERT_MSG( m_objcount > 0, wxT("Too many objects deleted??") );
|
2001-12-20 07:06:11 -05:00
|
|
|
--m_objcount;
|
|
|
|
}
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2001-12-29 09:50:36 -05:00
|
|
|
// Override/hide some base class methods
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2001-12-29 09:50:36 -05:00
|
|
|
bool IsLoaded() const { return m_linkcount > 0; }
|
|
|
|
void Unload() { UnrefLib(); }
|
2001-12-19 02:09:58 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-05-26 08:29:54 -04:00
|
|
|
// These pointers may be NULL but if they are not, then m_ourLast follows
|
|
|
|
// m_ourFirst in the linked list, i.e. can be found by calling GetNext() a
|
|
|
|
// sufficient number of times.
|
|
|
|
const wxClassInfo *m_ourFirst; // first class info in this plugin
|
|
|
|
const wxClassInfo *m_ourLast; // ..and the last one
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2001-12-20 07:06:11 -05:00
|
|
|
size_t m_linkcount; // Ref count of library link calls
|
|
|
|
size_t m_objcount; // ..and (pluggable) object instantiations.
|
|
|
|
wxModuleList m_wxmodules; // any wxModules that we initialised.
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2004-02-05 05:38:01 -05:00
|
|
|
void UpdateClasses(); // Update ms_classes
|
|
|
|
void RestoreClasses(); // Removes this library from ms_classes
|
2001-12-20 07:06:11 -05:00
|
|
|
void RegisterModules(); // Init any wxModules in the lib.
|
|
|
|
void UnregisterModules(); // Cleanup any wxModules we installed.
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxPluginLibrary);
|
2001-12-19 02:09:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-07-01 21:59:24 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxPluginManager
|
2001-12-19 02:09:58 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Static accessors.
|
|
|
|
|
2001-12-29 09:50:36 -05:00
|
|
|
static wxPluginLibrary *LoadLibrary( const wxString &libname,
|
2001-12-30 19:46:04 -05:00
|
|
|
int flags = wxDL_DEFAULT );
|
2001-12-29 09:50:36 -05:00
|
|
|
static bool UnloadLibrary(const wxString &libname);
|
|
|
|
|
2001-12-19 02:09:58 -05:00
|
|
|
// Instance methods.
|
|
|
|
|
2004-10-13 10:04:19 -04:00
|
|
|
wxPluginManager() : m_entry(NULL) {}
|
2001-12-30 19:46:04 -05:00
|
|
|
wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT)
|
2001-12-29 09:50:36 -05:00
|
|
|
{
|
|
|
|
Load(libname, flags);
|
|
|
|
}
|
2004-06-06 10:59:00 -04:00
|
|
|
~wxPluginManager() { if ( IsLoaded() ) Unload(); }
|
2001-12-29 09:50:36 -05:00
|
|
|
|
2001-12-30 19:46:04 -05:00
|
|
|
bool Load(const wxString &libname, int flags = wxDL_DEFAULT);
|
2001-12-29 09:50:36 -05:00
|
|
|
void Unload();
|
2001-12-19 02:09:58 -05:00
|
|
|
|
|
|
|
bool IsLoaded() const { return m_entry && m_entry->IsLoaded(); }
|
|
|
|
void *GetSymbol(const wxString &symbol, bool *success = 0)
|
|
|
|
{
|
|
|
|
return m_entry->GetSymbol( symbol, success );
|
|
|
|
}
|
|
|
|
|
2002-04-10 05:35:36 -04:00
|
|
|
static void CreateManifest() { ms_manifest = new wxDLManifest(wxKEY_STRING); }
|
|
|
|
static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; }
|
|
|
|
|
2001-12-19 02:09:58 -05:00
|
|
|
private:
|
2002-12-04 09:11:26 -05:00
|
|
|
// return the pointer to the entry for the library with given name in
|
|
|
|
// ms_manifest or NULL if none
|
|
|
|
static wxPluginLibrary *FindByName(const wxString& name)
|
|
|
|
{
|
|
|
|
const wxDLManifest::iterator i = ms_manifest->find(name);
|
|
|
|
|
|
|
|
return i == ms_manifest->end() ? NULL : i->second;
|
|
|
|
}
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2002-04-10 05:35:36 -04:00
|
|
|
static wxDLManifest* ms_manifest; // Static hash of loaded libs.
|
|
|
|
wxPluginLibrary* m_entry; // Cache our entry in the manifest.
|
2001-12-19 02:09:58 -05:00
|
|
|
|
|
|
|
// We could allow this class to be copied if we really
|
|
|
|
// wanted to, but not without modification.
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxPluginManager);
|
2001-12-19 02:09:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // wxUSE_DYNAMIC_LOADER
|
|
|
|
#endif // _WX_DYNAMICLOADER_H__
|
|
|
|
|