Graphite  Version 3
An experimental 3D geometry processing program
modmgr.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 #ifndef H_OGF_BASIC_MODULES_MODMGR_H
38 #define H_OGF_BASIC_MODULES_MODMGR_H
39 
43 #include <string>
44 #include <vector>
45 #include <map>
46 
47 
57 typedef void (*ModuleInitFunc)() ;
58 
62 typedef void (*ModuleTerminateFunc)() ;
63 
64 //____________________________________________________________________________
65 
66 namespace OGF {
67 
71  class BASIC_API ModuleManager : public Environment {
72  public:
73 
77  typedef void (*function_ptr)();
78 
83  static void initialize() ;
84 
89  static void terminate() ;
90 
96  static void terminate_dynamic_modules() ;
97 
103 
116  bool load_module(const std::string& module_name, bool quiet = false) ;
117 
118 
130  const std::string& module_name, Module* module
131  ) ;
132 
140  bool unbind_module(const std::string& module_name) ;
141 
148  Module* resolve_module(const std::string& module_name) ;
149 
159  virtual bool get_local_value(
160  const std::string& name, std::string& value
161  ) const;
162 
172  virtual bool set_local_value(
173  const std::string& name, const std::string& value
174  );
175 
184  static function_ptr resolve_function(const std::string& name);
185 
194  static void* resolve_symbol(const std::string& name);
195 
196 
204  static void append_dynamic_libraries_path(const std::string& path);
205 
206  protected:
211 
216 
221 
222  private:
223  std::vector<ModuleTerminateFunc> to_terminate_ ;
224  std::vector<void*> module_handles_ ;
225  std::map<std::string, Module_var> modules_ ;
226  static ModuleManager* instance_ ;
227  } ;
228 
229 //____________________________________________________________________________
230 
231 }
232 
233 #endif
Application environment.
Definition: environment.h:211
Manages dynamically loadable modules.
Definition: modmgr.h:71
bool load_module(const std::string &module_name, bool quiet=false)
Loads a dynamic module.
Module * resolve_module(const std::string &module_name)
Retreives a Module object by name.
ModuleManager()
Forbids construction by client code.
bool bind_module(const std::string &module_name, Module *module)
Declares a Module object to the ModuleManager.
static ModuleManager * instance()
Gets a pointer to the ModuleManager instance.
~ModuleManager()
Forbids destruction by client code.
void do_terminate_modules()
Terminates all the modules registered in the system.
static void append_dynamic_libraries_path(const std::string &path)
Adds a path where dynamic libraries can be loaded.
virtual bool set_local_value(const std::string &name, const std::string &value)
overloads Environment::set_local_value()
static void initialize()
Initializes the ModuleManager system.
static void terminate()
Terminates the ModuleManager system.
static void * resolve_symbol(const std::string &name)
Finds a pointer to a symbol by its name.
virtual bool get_local_value(const std::string &name, std::string &value) const
overloads Environment::get_local_value()
static void terminate_dynamic_modules()
Terminates the dynamic modules.
bool unbind_module(const std::string &module_name)
Removes a Module object from the ModuleManager.
static function_ptr resolve_function(const std::string &name)
Finds a pointer to a function by its name.
Represents information associated with a module (i.e. a plugin).
Definition: module.h:57
Provides a mechanism to store global variables, retrieve them by their names and attach observers to ...
void(* ModuleInitFunc)()
Function pointer to a module initialization function.
Definition: modmgr.h:57
void(* ModuleTerminateFunc)()
Function pointer to a module termination function.
Definition: modmgr.h:62
Class to represent information about a Graphite/// module (i.e. a plugin).
Global Graphite namespace.
Definition: common.h:76
Definitions common to all include files in the basic library.