00001 /***************************** License ********************************** 00002 00003 Copyright (C) 2008 by Communicative Machines 00004 http://www.cmlabs.com All rights reserved. 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 ************************************************************************/ 00021 00022 00023 // OutputText.h: interface for the OutputText class. 00024 // 00025 ////////////////////////////////////////////////////////////////////// 00026 00027 #ifndef _DYNAMICLOADER_H_ 00028 #define _DYNAMICLOADER_H_ 00029 00030 #include "standard.h" 00031 #include <string.h> 00032 #include <stdio.h> 00033 00034 #include "Object.h" 00035 #include "JString.h" 00036 #include "ObjectDictionary.h" 00037 00038 #include "dll.h" 00039 00040 #ifdef Darwin 00041 #ifndef dlopen 00042 #define dlopen dllopen 00043 #define dladdr dlladdr 00044 #define dlclose dllclose 00045 #define dlerror dllerror 00046 #define dlsym dllsym 00047 #endif 00048 #endif 00049 00050 namespace cmlabs { 00051 00052 class LibHandle : public Object 00053 { 00054 public: 00055 LibHandle(); 00056 virtual ~LibHandle(); 00057 Object* clone() const {return NULL;} 00058 00059 JString name; 00060 DLLHandle handle; 00061 }; 00062 00063 class DynamicLoader : public Object 00064 { 00065 public: 00066 DynamicLoader(); 00067 virtual ~DynamicLoader(); 00068 00069 Object* clone() const {return NULL;} 00070 DLLHandle openHandle(JString libname); 00071 bool closeHandle(DLLHandle handle); 00072 bool closeAllHandles(); 00073 bool clearErrors(); 00074 00075 bool loadLibrary(JString libname); 00076 bool unloadLibrary(JString libname); 00077 00078 DLLFunction getFunction(JString libname, JString funcname); 00079 DLLFunction getFunction(JString funcname); 00080 DLLFunction getFunction(DLLHandle handle, JString funcname); 00081 00082 bool checkLibraryVersion(const JString& libname); 00083 00084 bool didErrorHappen(); 00085 JString getLastErrorMessage(); 00086 00087 bool setTestLib(JString lib); 00088 bool unitTest(); 00089 00090 protected: 00091 00092 ObjectDictionary libHandles; 00093 JString lastErrorMessage; 00094 JString testlib; 00095 JMutex libMutex; 00096 }; 00097 00098 } // namespace cmlabs 00099 00100 #endif // _DYNAMICLOADER_H_