Fawkes API  Fawkes Development Version
module.h
00001 
00002 /***************************************************************************
00003  *  module.h - interface for modules (i.e. shared object, dynamic library)
00004  *
00005  *  Generated: Wed Aug 23 15:48:23 2006
00006  *  Copyright  2006  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __UTILS_SYSTEM_DYNAMIC_MODULE_MODULE_H_
00025 #define __UTILS_SYSTEM_DYNAMIC_MODULE_MODULE_H_
00026 
00027 #include <core/exception.h>
00028 #include <string>
00029 
00030 namespace fawkes {
00031 
00032 
00033 class ModuleOpenException : public Exception
00034 {
00035  public:
00036   ModuleOpenException(const char *msg);
00037 };
00038 
00039 class Module {
00040  public:
00041 
00042   /** Flags for the loading process */
00043   typedef enum {
00044     MODULE_FLAGS_NONE   = 0,            /**< No flags */
00045     MODULE_FLAGS_DEFAULT= 0x000E,       /**< Default flags, these are
00046                                          *   MODULE_BIND_GLOBAL, MODULE_BIND_NOW and
00047                                          *   MODULE_BIND_DEEP. */
00048     MODULE_BIND_LAZY    = 0x0001,       /**< Perform lazy binding. Only resolve
00049                                          *   symbols as thecode that references
00050                                          *   them is executed. If the symbol
00051                                          *   is never referenced,then it is
00052                                          *   never resolved. (Lazy  binding is
00053                                          *   only performed for function
00054                                          *   references; references to variables
00055                                          *   are always immediately bound when
00056                                          *   the library is loaded.)
00057                                          */
00058     MODULE_BIND_NOW     = 0x0002,       /**< Resolve all symbols immediately when
00059                                          *   loading the library. It's the opposite
00060                                          *   of MODULE_BIND_LAZY. It shall be the
00061                                          *   the default (makes sense for the
00062                                          *   framework robotics).
00063                                          */
00064     MODULE_BIND_LOCAL   = 0x0000,       /**< Symbols defined in this library are
00065                                          *   not made available to resolve
00066                                          *   references in subsequently
00067                                          *   loaded libraries. It's the opposite
00068                                          *   of MODULE_BIND_GLOBAL. It shall be the
00069                                          *   default and MODULE_BIND_GLOBAL shall
00070                                          *   automatically override it.
00071                                          */
00072     MODULE_BIND_GLOBAL  = 0x0004,       /**< Symbols defined in this library are
00073                                          *   not made available to resolve
00074                                          *   references in subsequently
00075                                          *   loaded libraries.
00076                                          */
00077     MODULE_BIND_MASK    = 0x0003,       /**< Can be used to encode flags in a
00078                                          *   longer data field
00079                                          */
00080     MODULE_BIND_DEEP    = 0x0008        /**< Place the lookup scope of the symbols
00081                                          *   in this library ahead of the global
00082                                          *   scope. This means that a self-contained
00083                                          *   library will use its own symbols in
00084                                          *   preference to global symbols with the
00085                                          *   same name contained in libraries that
00086                                          *   have already been loaded.
00087                                          */
00088   } ModuleFlags;
00089 
00090   virtual ~Module();
00091 
00092   virtual void          open()                                             = 0;
00093   virtual bool          close()                                            = 0;
00094   virtual void          ref()                                              = 0;
00095   virtual void          unref()                                            = 0;
00096   virtual bool          notref()                                           = 0;
00097   virtual unsigned int  get_ref_count()                                    = 0;
00098   virtual bool          has_symbol(const char *symbol_name)                = 0;
00099   virtual void *        get_symbol(const char *symbol_name)                = 0;
00100   virtual std::string   get_filename()                                     = 0;
00101   virtual std::string   get_base_filename()                                = 0;
00102 
00103 };
00104 
00105 } // end namespace fawkes
00106 
00107 #endif