libyui
3.0.10
|
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 #include <dlfcn.h> 00027 00028 #define YUILogComponent "ui" 00029 #include "YUILog.h" 00030 00031 #include "YUIPlugin.h" 00032 #include "YPath.h" 00033 00034 #include "Libyui_config.h" 00035 00036 00037 YUIPlugin::YUIPlugin( const char * pluginLibBaseName ) 00038 { 00039 _pluginLibBaseName = std::string( pluginLibBaseName ); 00040 00041 std::string pluginFilename = pluginLibFullPath(); 00042 00043 _pluginLibHandle = dlopen( pluginFilename.c_str(), 00044 RTLD_NOW | RTLD_GLOBAL); 00045 00046 if ( ! _pluginLibHandle ) 00047 { 00048 _errorMsg = dlerror(); 00049 00050 yuiError() << "Could not load UI plugin \"" << pluginLibBaseName 00051 << "\": " << _errorMsg 00052 << std::endl; 00053 } 00054 } 00055 00056 00057 YUIPlugin::~YUIPlugin() 00058 { 00059 // This intentionally does NOT call unload(): This would be 00060 // counterproductive for almost all use cases of this class. 00061 } 00062 00063 00064 void 00065 YUIPlugin::unload() 00066 { 00067 if ( _pluginLibHandle ) 00068 dlclose( _pluginLibHandle ); 00069 } 00070 00071 00072 std::string 00073 YUIPlugin::pluginLibFullPath() const 00074 { 00075 00076 std::string pluginName = PLUGIN_PREFIX; 00077 pluginName.append( _pluginLibBaseName ); 00078 pluginName.append( PLUGIN_SUFFIX ); 00079 00080 YPath plugin( PLUGINDIR, pluginName ); 00081 00082 return plugin.path(); 00083 } 00084 00085 00086 void * YUIPlugin::locateSymbol( const char * symbol ) 00087 { 00088 if ( ! _pluginLibHandle ) 00089 return 0; 00090 00091 void * addr = dlsym( _pluginLibHandle, symbol ); 00092 00093 if ( ! addr ) 00094 { 00095 yuiError() << "Could not locate symbol \"" << symbol 00096 << "\" in " << pluginLibFullPath() 00097 << std::endl; 00098 } 00099 00100 return addr; 00101 } 00102 00103 00104 bool YUIPlugin::error() const 00105 { 00106 return _pluginLibHandle == 0; 00107 } 00108 00109 00110 bool YUIPlugin::success() const 00111 { 00112 return _pluginLibHandle != 0; 00113 } 00114 00115 00116 std::string YUIPlugin::errorMsg() const 00117 { 00118 return _errorMsg; 00119 }