1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-08-31 15:31:43 -04:00
|
|
|
// Name: wx/module.h
|
1998-05-20 10:01:55 -04:00
|
|
|
// Purpose: Modules handling
|
|
|
|
// Author: Wolfram Gloger/adapted by Guilhem Lavaux
|
|
|
|
// Modified by:
|
|
|
|
// Created: 04/11/98
|
|
|
|
// Copyright: (c) Wolfram Gloger and Guilhem Lavaux
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
#ifndef _WX_MODULE_H_
|
|
|
|
#define _WX_MODULE_H_
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/list.h"
|
2007-11-17 09:04:44 -05:00
|
|
|
#include "wx/arrstr.h"
|
2006-06-11 18:19:12 -04:00
|
|
|
#include "wx/dynarray.h"
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-01-17 17:44:04 -05:00
|
|
|
// declare a linked list of modules
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxModule;
|
2003-07-04 14:18:11 -04:00
|
|
|
WX_DECLARE_USER_EXPORTED_LIST(wxModule, wxModuleList, WXDLLIMPEXP_BASE);
|
1999-01-17 17:44:04 -05:00
|
|
|
|
2006-06-11 18:19:12 -04:00
|
|
|
// and an array of class info objects
|
|
|
|
WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxClassInfo *, wxArrayClassInfo,
|
|
|
|
class WXDLLIMPEXP_BASE);
|
|
|
|
|
|
|
|
|
1999-01-17 17:44:04 -05:00
|
|
|
// declaring a class derived from wxModule will automatically create an
|
|
|
|
// instance of this class on program startup, call its OnInit() method and call
|
|
|
|
// OnExit() on program termination (but only if OnInit() succeeded)
|
2003-07-01 21:59:24 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxModule : public wxObject
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
|
|
|
public:
|
1999-01-17 17:44:04 -05:00
|
|
|
wxModule() {}
|
|
|
|
virtual ~wxModule() {}
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
// if module init routine returns false the application
|
|
|
|
// will fail to startup
|
2001-12-19 02:09:58 -05:00
|
|
|
|
1999-01-17 17:44:04 -05:00
|
|
|
bool Init() { return OnInit(); }
|
|
|
|
void Exit() { OnExit(); }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
// Override both of these
|
|
|
|
|
1999-01-17 17:44:04 -05:00
|
|
|
// called on program startup
|
2001-12-19 02:09:58 -05:00
|
|
|
|
1999-01-17 17:44:04 -05:00
|
|
|
virtual bool OnInit() = 0;
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
// called just before program termination, but only if OnInit()
|
1999-01-17 17:44:04 -05:00
|
|
|
// succeeded
|
2004-05-11 16:41:43 -04:00
|
|
|
|
1999-01-17 17:44:04 -05:00
|
|
|
virtual void OnExit() = 0;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
static void RegisterModule(wxModule *module);
|
1999-01-17 17:44:04 -05:00
|
|
|
static void RegisterModules();
|
|
|
|
static bool InitializeModules();
|
2006-06-11 18:19:12 -04:00
|
|
|
static void CleanUpModules() { DoCleanUpModules(m_modules); }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
// used by wxObjectLoader when unloading shared libs's
|
2001-12-19 02:09:58 -05:00
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
static void UnregisterModule(wxModule *module);
|
2001-12-19 02:09:58 -05:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
protected:
|
1999-01-17 17:44:04 -05:00
|
|
|
static wxModuleList m_modules;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2006-06-11 18:19:12 -04:00
|
|
|
// the function to call from constructor of a deriving class add module
|
|
|
|
// dependency which will be initialized before the module and unloaded
|
|
|
|
// after that
|
|
|
|
void AddDependency(wxClassInfo *dep)
|
|
|
|
{
|
2009-07-23 16:30:22 -04:00
|
|
|
wxCHECK_RET( dep, wxT("NULL module dependency") );
|
2006-06-11 18:19:12 -04:00
|
|
|
|
|
|
|
m_dependencies.Add(dep);
|
|
|
|
}
|
|
|
|
|
2007-11-16 19:12:01 -05:00
|
|
|
// same as the version above except it will look up wxClassInfo by name on
|
|
|
|
// its own
|
|
|
|
void AddDependency(const char *className)
|
|
|
|
{
|
|
|
|
m_namedDependencies.Add(className);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-11 18:19:12 -04:00
|
|
|
private:
|
|
|
|
// initialize module and Append it to initializedModules list recursively
|
|
|
|
// calling itself to satisfy module dependencies if needed
|
|
|
|
static bool
|
|
|
|
DoInitializeModule(wxModule *module, wxModuleList &initializedModules);
|
|
|
|
|
|
|
|
// cleanup the modules in the specified list (which may not contain all
|
|
|
|
// modules if we're called during initialization because not all modules
|
|
|
|
// could be initialized) and also empty m_modules itself
|
|
|
|
static void DoCleanUpModules(const wxModuleList& modules);
|
|
|
|
|
2007-11-16 19:12:01 -05:00
|
|
|
// resolve all named dependencies and add them to the normal m_dependencies
|
|
|
|
bool ResolveNamedDependencies();
|
|
|
|
|
2006-06-11 18:19:12 -04:00
|
|
|
|
2007-11-16 19:12:01 -05:00
|
|
|
// module dependencies: contains wxClassInfo pointers for all modules which
|
|
|
|
// must be initialized before this one
|
2006-06-11 18:19:12 -04:00
|
|
|
wxArrayClassInfo m_dependencies;
|
|
|
|
|
2007-11-16 19:12:01 -05:00
|
|
|
// and the named dependencies: those will be resolved during run-time and
|
|
|
|
// added to m_dependencies
|
|
|
|
wxArrayString m_namedDependencies;
|
|
|
|
|
|
|
|
// used internally while initializing/cleaning up modules
|
2006-06-11 18:19:12 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
State_Registered, // module registered but not initialized yet
|
|
|
|
State_Initializing, // we're initializing this module but not done yet
|
|
|
|
State_Initialized // module initialized successfully
|
|
|
|
} m_state;
|
|
|
|
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_CLASS(wxModule);
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
2004-05-11 16:41:43 -04:00
|
|
|
#endif // _WX_MODULE_H_
|