14#include "arcane/utils/String.h"
15#include "arcane/utils/PlatformUtils.h"
16#include "arcane/utils/ArrayView.h"
17#include "arcane/utils/IDynamicLibraryLoader.h"
36class ARCANE_IMPL_EXPORT GlibDynamicLibrary
41 : m_manager(mng), m_gmodule(gmodule){}
43 void close()
override;
55class ARCANE_IMPL_EXPORT GlibDynamicLibraryLoader
59 GlibDynamicLibraryLoader() : m_is_verbose(
false){}
67 if (s==
"1" || s==
"true")
79 dl = _tryOpen(directory, name +
".dll");
82 dl = _tryOpen(directory,
"lib" + name +
".dylib");
87 dl = _tryOpen(
".", name);
93 dl = _tryOpen(
".", name +
".dll");
96 dl = _tryOpen(
".",
"lib" + name +
".dylib");
104 const gchar* gdirectory =
reinterpret_cast<const gchar*
>(directory.
utf8().data());
105 const gchar* gname =
reinterpret_cast<const gchar*
>(name.
utf8().data());
106 gchar* full_path = g_module_build_path(gdirectory, gname);
108 std::cout <<
"** Load Dynamic Library '" << full_path <<
"'...";
110 GModule* gmodule = g_module_open(full_path, GModuleFlags());
114 std::cout <<
" NOT FOUND\n";
116 std::cout <<
" OK\n";
121 auto lib =
new GlibDynamicLibrary(
this,gmodule);
122 m_opened_libraries.insert(lib);
129 std::vector<GlibDynamicLibrary*> libs(m_opened_libraries.begin(),m_opened_libraries.end());
130 for(
auto lib : libs ){
138 auto iter = m_opened_libraries.find(lib);
139 if (iter!=m_opened_libraries.end())
140 m_opened_libraries.erase(iter);
146 std::set<GlibDynamicLibrary*> m_opened_libraries;
157 bool is_ok = g_module_close(m_gmodule);
160 std::cerr <<
"WARNING: can not unload module\n";
161 m_manager->removeInstance(
this);
174 const gchar* gname =
reinterpret_cast<const gchar*
>(symbol_name.
utf8().data());
175 void* symbol_addr =
nullptr;
176 bool r = ::g_module_symbol(m_gmodule,gname,&symbol_addr);
186createGlibDynamicLibraryLoader()
Interface d'une chargeur dynamique de bibliothèque.
IDynamicLibrary * open(const String &directory, const String &name) override
Charge une bibliothèque dynamique.
virtual ~GlibDynamicLibraryLoader()
Libère les ressources.
void closeLibraries() override
Ferme toutes les bibliothèques ouvertes via open()
void close() override
Ferme la bibliothèque dynamique.
void * getSymbolAddress(const String &symbol_name, bool *is_found) override
Retourne l'adresse du symbol de nom symbol_name.
Interface d'une chargeur dynamique de bibliothèque.
Interface d'une bibliothèque dynamique.
Chaîne de caractères unicode.
ByteConstArrayView utf8() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-