libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YUIPlugin.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         YUIPlugin.h
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #ifndef YUIPlugin_h
00027 #define YUIPlugin_h
00028 
00029 #include <string>
00030 
00031 
00032 /**
00033  * Wrapper class for dlopen() and related.
00034  **/
00035 class YUIPlugin
00036 {
00037 public:
00038 
00039     /**
00040      * Constructor: Load the specified plugin library
00041      * from the standard UI plugin directory (/usr/lib/yui/).
00042      **/
00043     YUIPlugin( const char * pluginLibBaseName );
00044 
00045     /**
00046      * Destructor.
00047      *
00048      * Please note that this will NOT attempt to unload the plugin library
00049      * since this is usually counterproductive. If unloading the plugin is
00050      * desired, call unload() manually.
00051      **/
00052     virtual ~YUIPlugin();
00053 
00054     /**
00055      * Unload this plugin. This calls dlclose() which will unload the plugin
00056      * library if it is no longer used, i.e. if the reference count dlopen()
00057      * uses reaches 0.
00058      **/
00059     void unload();
00060 
00061     /**
00062      * Try to locate the specified symbol (function or global variable) in the
00063      * plugin library.
00064      *
00065      * Returns the in-memory address of that symbol or 0 if it could not be
00066      * found or if loading the plugin library had failed in the constructor.
00067      **/
00068     void * locateSymbol( const char * symbol );
00069 
00070     /**
00071      * Returns 'true' if there was an error loading the plugin.
00072      **/
00073     bool error() const;
00074 
00075     /**
00076      * Returns 'true' if there was no error loading the plugin.
00077      **/
00078     bool success() const;
00079 
00080     /**
00081      * Returns a human readable (but in most cases untranslated) error message
00082      * if there was an error.
00083      **/
00084     std::string errorMsg() const;
00085 
00086 protected:
00087 
00088     /**
00089      * Returns the dlopen() handle of the plugin library.
00090      **/
00091     void * pluginLibHandle() { return _pluginLibHandle; }
00092 
00093     /**
00094      * Returns the base name of the plugin library.
00095      **/
00096     std::string pluginLibBaseName() const { return _pluginLibBaseName; }
00097 
00098     /**
00099      * Returns the full path of the plugin library.
00100      **/
00101     std::string pluginLibFullPath() const;
00102 
00103 private:
00104 
00105     std::string _pluginLibBaseName;
00106     void *      _pluginLibHandle;
00107     std::string _errorMsg;
00108 };
00109 
00110 
00111 #endif // YUIPlugin_h
 All Classes Functions Variables Enumerations Friends