Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/class_loader/class_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ class ClassLoader

Base * obj = class_loader::impl::createInstance<Base>(derived_class_name, this,
std::forward<Args>(args)...);
assert(obj != NULL); // Unreachable assertion if createInstance() throws on failure.

if (managed) {
std::lock_guard<std::recursive_mutex> lock(plugin_ref_count_mutex_);
Expand Down Expand Up @@ -378,7 +377,7 @@ class ClassLoader
std::recursive_mutex load_ref_count_mutex_;
int plugin_ref_count_;
std::recursive_mutex plugin_ref_count_mutex_;
static bool has_unmananged_instance_been_created_;
static bool has_unmanaged_instance_been_created_;
};

} // namespace class_loader
Expand Down
2 changes: 1 addition & 1 deletion include/class_loader/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace class_loader
{

/**
* @class ClassLoader sException
* @class ClassLoaderException
* @brief A base class for all class_loader exceptions that inherits from std::runtime_exception
*/
class ClassLoaderException : public std::runtime_error
Expand Down
3 changes: 2 additions & 1 deletion include/class_loader/multi_library_class_loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader
* @return A vector<string> of the available classes in the passed library
*/
template<class Base>
std::vector<std::string> getAvailableClassesForLibrary(const std::string & library_path)
std::vector<std::string> getAvailableClassesForLibrary(const std::string & library_path) const
{
ClassLoader * loader = getClassLoaderForLibrary(library_path);
if (nullptr == loader) {
Expand Down Expand Up @@ -345,6 +345,7 @@ class CLASS_LOADER_PUBLIC MultiLibraryClassLoader
* @return A pointer to the ClassLoader*, == nullptr if not found
*/
ClassLoader * getClassLoaderForLibrary(const std::string & library_path);
const ClassLoader * getClassLoaderForLibrary(const std::string & library_path) const;

/// Gets a handle to the class loader corresponding to a specific class.
/**
Expand Down
6 changes: 3 additions & 3 deletions src/class_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
namespace class_loader
{

bool ClassLoader::has_unmananged_instance_been_created_ = false;
bool ClassLoader::has_unmanaged_instance_been_created_ = false;

bool ClassLoader::hasUnmanagedInstanceBeenCreated()
{
return ClassLoader::has_unmananged_instance_been_created_;
return ClassLoader::has_unmanaged_instance_been_created_;
}

void ClassLoader::setUnmanagedInstanceBeenCreated(bool state)
{
ClassLoader::has_unmananged_instance_been_created_ = state;
ClassLoader::has_unmanaged_instance_been_created_ = state;
}

std::string systemLibraryFormat(const std::string & library_name)
Expand Down
18 changes: 7 additions & 11 deletions src/class_loader_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,8 @@ void hasANonPurePluginLibraryBeenOpened(bool hasIt)
MetaObjectVector allMetaObjects(const FactoryMap & factories)
{
MetaObjectVector all_meta_objs;
for (
FactoryMap::const_iterator factoryItr = factories.begin();
factoryItr != factories.end(); factoryItr++
)
{
all_meta_objs.push_back(factoryItr->second);
for (const auto & factory_entry : factories) {
all_meta_objs.push_back(factory_entry.second);
}
return all_meta_objs;
}
Expand Down Expand Up @@ -495,17 +491,17 @@ void unloadLibrary(const std::string & library_path, ClassLoader * loader)
LibraryVector::iterator itr = findLoadedLibrary(library_path);
if (itr != open_libraries.end()) {
auto library = itr->second;
std::string library_path = itr->first;
const std::string & lib_path = itr->first;
try {
destroyMetaObjectsForLibrary(library_path, loader);
destroyMetaObjectsForLibrary(lib_path, loader);

// Remove from loaded library list as well if no more factories associated with said library
if (!areThereAnyExistingMetaObjectsForLibrary(library_path)) {
if (!areThereAnyExistingMetaObjectsForLibrary(lib_path)) {
CONSOLE_BRIDGE_logDebug(
"class_loader.impl: "
"There are no more MetaObjects left for %s so unloading library and "
"removing from loaded library vector.\n",
library_path.c_str());
lib_path.c_str());

library->unload_library();
itr = open_libraries.erase(itr);
Expand All @@ -514,7 +510,7 @@ void unloadLibrary(const std::string & library_path, ClassLoader * loader)
"class_loader.impl: "
"MetaObjects still remain in memory meaning other ClassLoaders are still using library"
", keeping library %s open.",
library_path.c_str());
lib_path.c_str());
}
return;
} catch (const std::runtime_error & e) {
Expand Down
10 changes: 10 additions & 0 deletions src/multi_library_class_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ ClassLoader * MultiLibraryClassLoader::getClassLoaderForLibrary(const std::strin
return impl_->active_class_loaders_[library_path];
}

const ClassLoader *
MultiLibraryClassLoader::getClassLoaderForLibrary(const std::string & library_path) const
{
auto it = impl_->active_class_loaders_.find(library_path);
if (it == impl_->active_class_loaders_.end()) {
return nullptr;
}
return it->second;
}

ClassLoaderVector MultiLibraryClassLoader::getAllAvailableClassLoaders() const
{
ClassLoaderVector loaders;
Expand Down
Loading