Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "class_loader/class_loader.h"
00031
00032 namespace class_loader
00033 {
00034
00035 bool ClassLoader::has_unmananged_instance_been_created_ = false;
00036
00037 bool ClassLoader::hasUnmanagedInstanceBeenCreated()
00038 {
00039 return ClassLoader::has_unmananged_instance_been_created_;
00040 }
00041
00042 std::string systemLibrarySuffix()
00043 {
00044 return(Poco::SharedLibrary::suffix());
00045 }
00046
00047 ClassLoader::ClassLoader(const std::string& library_path, bool ondemand_load_unload) :
00048 ondemand_load_unload_(ondemand_load_unload),
00049 library_path_(library_path),
00050 load_ref_count_(0),
00051 plugin_ref_count_(0)
00052 {
00053 logDebug("class_loader.ClassLoader: Constructing new ClassLoader (%p) bound to library %s.", this, library_path.c_str());
00054 if(!isOnDemandLoadUnloadEnabled())
00055 loadLibrary();
00056 }
00057
00058 ClassLoader::~ClassLoader()
00059 {
00060 logDebug("class_loader.ClassLoader: Destroying class loader, unloading associated library...\n");
00061 unloadLibrary();
00062 }
00063
00064 bool ClassLoader::isLibraryLoaded()
00065 {
00066 return(class_loader::class_loader_private::isLibraryLoaded(getLibraryPath(), this));
00067 }
00068
00069 bool ClassLoader::isLibraryLoadedByAnyClassloader()
00070 {
00071 return(class_loader::class_loader_private::isLibraryLoadedByAnybody(getLibraryPath()));
00072 }
00073
00074 void ClassLoader::loadLibrary()
00075 {
00076 boost::recursive_mutex::scoped_lock lock(load_ref_count_mutex_);
00077 load_ref_count_ = load_ref_count_ + 1;
00078 class_loader::class_loader_private::loadLibrary(getLibraryPath(), this);
00079 }
00080
00081 int ClassLoader::unloadLibrary()
00082 {
00083 return(unloadLibraryInternal(true));
00084 }
00085
00086 int ClassLoader::unloadLibraryInternal(bool lock_plugin_ref_count)
00087 {
00088 boost::recursive_mutex::scoped_lock load_ref_lock(load_ref_count_mutex_);
00089 boost::recursive_mutex::scoped_lock plugin_ref_lock;
00090 if(lock_plugin_ref_count)
00091 plugin_ref_lock = boost::recursive_mutex::scoped_lock(plugin_ref_count_mutex_);
00092
00093 if(plugin_ref_count_ > 0)
00094 logWarn("class_loader.ClassLoader: SEVERE WARNING!!! Attempting to unload library while objects created by this loader exist in the heap! You should delete your objects before attempting to unload the library or destroying the ClassLoader. The library will NOT be unloaded.");
00095 else
00096 {
00097 load_ref_count_ = load_ref_count_ - 1;
00098 if(load_ref_count_ == 0)
00099 class_loader::class_loader_private::unloadLibrary(getLibraryPath(), this);
00100 else if(load_ref_count_ < 0)
00101 load_ref_count_ = 0;
00102 }
00103 return(load_ref_count_);
00104 }
00105
00106 }