2001-12-19 07:09:58 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dynload.h
|
|
|
|
// 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
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2001 Ron Lee <ron@debian.org>
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
2001-12-19 07:09:58 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_DYNAMICLOADER_H__
|
|
|
|
#define _WX_DYNAMICLOADER_H__
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_DYNAMIC_LOADER
|
|
|
|
|
2003-08-01 21:12:40 +00:00
|
|
|
#include "wx/dynlib.h"
|
2002-12-04 14:11:26 +00:00
|
|
|
#include "wx/hashmap.h"
|
2001-12-19 07:09:58 +00:00
|
|
|
#include "wx/module.h"
|
|
|
|
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxPluginLibrary;
|
2001-12-19 07:09:58 +00:00
|
|
|
|
|
|
|
|
2003-08-01 21:12:40 +00:00
|
|
|
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxPluginLibrary *, wxDLManifest,
|
2006-01-18 16:45:41 +00:00
|
|
|
class WXDLLIMPEXP_BASE);
|
2003-08-01 21:12:40 +00:00
|
|
|
typedef wxDLManifest wxDLImports;
|
2001-12-19 07:09:58 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
2001-12-29 14:50:36 +00:00
|
|
|
// wxPluginLibrary
|
2001-12-19 07:09:58 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2001-12-29 14:50:36 +00: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-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxPluginLibrary : public wxDynamicLibrary
|
2001-12-19 07:09:58 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-04-10 09:35:36 +00:00
|
|
|
static wxDLImports* ms_classes; // Static hash of all imported classes.
|
2001-12-19 07:09:58 +00:00
|
|
|
|
2001-12-31 00:46:04 +00:00
|
|
|
wxPluginLibrary( const wxString &libname, int flags = wxDL_DEFAULT );
|
2001-12-29 14:50:36 +00:00
|
|
|
~wxPluginLibrary();
|
2001-12-19 07:09:58 +00:00
|
|
|
|
2002-04-22 12:28:02 +00:00
|
|
|
wxPluginLibrary *RefLib();
|
2001-12-29 14:50:36 +00:00
|
|
|
bool UnrefLib();
|
2001-12-20 12:06:11 +00: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 14:50:36 +00:00
|
|
|
void RefObj() { ++m_objcount; }
|
|
|
|
void UnrefObj()
|
2001-12-20 12:06:11 +00:00
|
|
|
{
|
2009-07-23 20:30:22 +00:00
|
|
|
wxASSERT_MSG( m_objcount > 0, wxT("Too many objects deleted??") );
|
2001-12-20 12:06:11 +00:00
|
|
|
--m_objcount;
|
|
|
|
}
|
2001-12-19 07:09:58 +00:00
|
|
|
|
2001-12-29 14:50:36 +00:00
|
|
|
// Override/hide some base class methods
|
2001-12-19 07:09:58 +00:00
|
|
|
|
2001-12-29 14:50:36 +00:00
|
|
|
bool IsLoaded() const { return m_linkcount > 0; }
|
|
|
|
void Unload() { UnrefLib(); }
|
2001-12-19 07:09:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2007-04-15 11:43:37 +00:00
|
|
|
const wxClassInfo *m_before; // sm_first before loading this lib
|
|
|
|
const wxClassInfo *m_after; // ..and after.
|
2001-12-19 07:09:58 +00:00
|
|
|
|
2001-12-20 12:06:11 +00: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 07:09:58 +00:00
|
|
|
|
2004-02-05 10:38:01 +00:00
|
|
|
void UpdateClasses(); // Update ms_classes
|
|
|
|
void RestoreClasses(); // Removes this library from ms_classes
|
2001-12-20 12:06:11 +00:00
|
|
|
void RegisterModules(); // Init any wxModules in the lib.
|
|
|
|
void UnregisterModules(); // Cleanup any wxModules we installed.
|
2001-12-19 07:09:58 +00:00
|
|
|
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxPluginLibrary);
|
2001-12-19 07:09:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-07-02 01:59:24 +00:00
|
|
|
class WXDLLIMPEXP_BASE wxPluginManager
|
2001-12-19 07:09:58 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Static accessors.
|
|
|
|
|
2001-12-29 14:50:36 +00:00
|
|
|
static wxPluginLibrary *LoadLibrary( const wxString &libname,
|
2001-12-31 00:46:04 +00:00
|
|
|
int flags = wxDL_DEFAULT );
|
2001-12-29 14:50:36 +00:00
|
|
|
static bool UnloadLibrary(const wxString &libname);
|
|
|
|
|
2001-12-19 07:09:58 +00:00
|
|
|
// Instance methods.
|
|
|
|
|
2004-10-13 14:04:19 +00:00
|
|
|
wxPluginManager() : m_entry(NULL) {}
|
2001-12-31 00:46:04 +00:00
|
|
|
wxPluginManager(const wxString &libname, int flags = wxDL_DEFAULT)
|
2001-12-29 14:50:36 +00:00
|
|
|
{
|
|
|
|
Load(libname, flags);
|
|
|
|
}
|
2004-06-06 14:59:00 +00:00
|
|
|
~wxPluginManager() { if ( IsLoaded() ) Unload(); }
|
2001-12-29 14:50:36 +00:00
|
|
|
|
2001-12-31 00:46:04 +00:00
|
|
|
bool Load(const wxString &libname, int flags = wxDL_DEFAULT);
|
2001-12-29 14:50:36 +00:00
|
|
|
void Unload();
|
2001-12-19 07:09:58 +00: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 09:35:36 +00:00
|
|
|
static void CreateManifest() { ms_manifest = new wxDLManifest(wxKEY_STRING); }
|
|
|
|
static void ClearManifest() { delete ms_manifest; ms_manifest = NULL; }
|
|
|
|
|
2001-12-19 07:09:58 +00:00
|
|
|
private:
|
2002-12-04 14:11:26 +00: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 07:09:58 +00:00
|
|
|
|
2002-04-10 09:35:36 +00:00
|
|
|
static wxDLManifest* ms_manifest; // Static hash of loaded libs.
|
|
|
|
wxPluginLibrary* m_entry; // Cache our entry in the manifest.
|
2001-12-19 07:09:58 +00:00
|
|
|
|
|
|
|
// We could allow this class to be copied if we really
|
|
|
|
// wanted to, but not without modification.
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxPluginManager);
|
2001-12-19 07:09:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // wxUSE_DYNAMIC_LOADER
|
|
|
|
#endif // _WX_DYNAMICLOADER_H__
|
|
|
|
|