2001-12-19 02:09:58 -05: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 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
2001-12-19 02:09:58 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_DYNAMICLOADER_H__
|
|
|
|
#define _WX_DYNAMICLOADER_H__
|
|
|
|
|
2003-08-09 08:38:21 -04:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
2001-12-19 02:09:58 -05:00
|
|
|
#pragma interface "dynload.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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"
|
|
|
|
|
2003-07-01 21:59:24 -04:00
|
|
|
class WXDLLIMPEXP_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,
|
|
|
|
class WXDLLIMPEXP_BASE);
|
|
|
|
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
|
|
|
{
|
|
|
|
wxASSERT_MSG( m_objcount > 0, _T("Too many objects deleted??") );
|
|
|
|
--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:
|
|
|
|
|
2001-12-20 07:06:11 -05:00
|
|
|
wxClassInfo *m_before; // sm_first before loading this lib
|
|
|
|
wxClassInfo *m_after; // ..and after.
|
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
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
DECLARE_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);
|
|
|
|
|
|
|
|
// This is used by wxDllLoader. It's wrapped in the compatibility
|
|
|
|
// macro because it's of arguable use outside of that.
|
|
|
|
|
|
|
|
#if WXWIN_COMPATIBILITY_2_2
|
|
|
|
static wxPluginLibrary *GetObjectFromHandle(wxDllType handle);
|
|
|
|
#endif
|
2001-12-19 02:09:58 -05:00
|
|
|
|
|
|
|
// Instance methods.
|
|
|
|
|
2002-12-04 09:11:26 -05: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.
|
2002-12-04 09:11:26 -05:00
|
|
|
DECLARE_NO_COPY_CLASS(wxPluginManager)
|
2001-12-19 02:09:58 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // wxUSE_DYNAMIC_LOADER
|
|
|
|
#endif // _WX_DYNAMICLOADER_H__
|
|
|
|
|