Main Page   Packages   Class Hierarchy   Alphabetical List   Data Structures   File List   Namespace Members   Data Fields   Globals  

Plugin.cpp

Go to the documentation of this file.
00001 /*
00002  * $Id: Plugin.cpp,v 1.2 2002/07/15 02:53:29 mindstorm2600 Exp $
00003  */
00004 #include<Plugin.h>
00005 #include<dlfcn.h>
00006 
00007 namespace clawsoft{
00008 
00009         Plugin::Plugin(){
00010                 loaded = false;
00011                 handle = 0;
00012                 setClassName("Plugin");
00013                 dso = "Nothing loaded";
00014         }
00015         
00016         Plugin::Plugin(String plName){
00017                 loaded = false;
00018                 handle = 0;
00019                 setClassName("Plugin");
00020                 dso = plName;
00021         }
00022 
00023         void Plugin::load(){
00024                 handle = dlopen(dso.toCharPtr(), RTLD_NOW);
00025                 if(!handle){
00026                         throw CantLoadDSOException();
00027                 }
00028         }
00029 
00030         void Plugin::load(String plName){
00031                 dso = plName;
00032                 load();
00033         }
00034 
00035         void Plugin::unload(){
00036                 if(handle){
00037                         if(dlclose(handle) != 0){
00038                                 throw CantUnloadDSOException();
00039                         }
00040                         handle = 0;
00041                 }
00042         }
00043 
00044         void *Plugin::getSymbol(String sym){
00045                 void *ptr;
00046                 if(!handle)
00047                         throw DSOException("Load the DSO first!!!");
00048                 ptr = dlsym(handle, sym.toCharPtr());
00049                 if(ptr == 0){
00050                         throw DSOSymbolException();
00051                 }
00052                 return ptr;
00053         }
00054 }
00055 

Powered by:

SourceForge Logo