mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
backport SharedLibrary changes from 1.4.2-p1
This commit is contained in:
parent
5084562770
commit
97ec3f5bf6
@ -66,6 +66,24 @@ class Foundation_API SharedLibrary: private SharedLibraryImpl
|
||||
/// loads shared libraries at run-time.
|
||||
{
|
||||
public:
|
||||
enum Flags
|
||||
{
|
||||
SHLIB_GLOBAL = 1,
|
||||
/// On platforms that use dlopen(), use RTLD_GLOBAL. This is the default
|
||||
/// if no flags are given.
|
||||
///
|
||||
/// This flag is ignored on platforms that do not use dlopen().
|
||||
|
||||
SHLIB_LOCAL = 2
|
||||
/// On platforms that use dlopen(), use RTLD_LOCAL instead of RTLD_GLOBAL.
|
||||
///
|
||||
/// Note that if this flag is specified, RTTI (including dynamic_cast and throw) will
|
||||
/// not work for types defined in the shared library with GCC and possibly other
|
||||
/// compilers as well. See http://gcc.gnu.org/faq.html#dso for more information.
|
||||
///
|
||||
/// This flag is ignored on platforms that do not use dlopen().
|
||||
};
|
||||
|
||||
SharedLibrary();
|
||||
/// Creates a SharedLibrary object.
|
||||
|
||||
@ -73,6 +91,11 @@ public:
|
||||
/// Creates a SharedLibrary object and loads a library
|
||||
/// from the given path.
|
||||
|
||||
SharedLibrary(const std::string& path, int flags);
|
||||
/// Creates a SharedLibrary object and loads a library
|
||||
/// from the given path, using the given flags.
|
||||
/// See the Flags enumeration for valid values.
|
||||
|
||||
virtual ~SharedLibrary();
|
||||
/// Destroys the SharedLibrary. The actual library
|
||||
/// remains loaded.
|
||||
@ -84,6 +107,15 @@ public:
|
||||
/// Throws a LibraryLoadException if the library
|
||||
/// cannot be loaded.
|
||||
|
||||
void load(const std::string& path, int flags);
|
||||
/// Loads a shared library from the given path,
|
||||
/// using the given flags. See the Flags enumeration
|
||||
/// for valid values.
|
||||
/// Throws a LibraryAlreadyLoadedException if
|
||||
/// a library has already been loaded.
|
||||
/// Throws a LibraryLoadException if the library
|
||||
/// cannot be loaded.
|
||||
|
||||
void unload();
|
||||
/// Unloads a shared library.
|
||||
|
||||
|
@ -53,7 +53,7 @@ class Foundation_API SharedLibraryImpl
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
|
@ -50,9 +50,15 @@ namespace Poco {
|
||||
class Foundation_API SharedLibraryImpl
|
||||
{
|
||||
protected:
|
||||
enum Flags
|
||||
{
|
||||
SHLIB_GLOBAL_IMPL = 1,
|
||||
SHLIB_LOCAL_IMPL = 2
|
||||
};
|
||||
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
|
@ -52,7 +52,7 @@ class Foundation_API SharedLibraryImpl
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
|
@ -53,7 +53,7 @@ class Foundation_API SharedLibraryImpl
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
|
@ -52,7 +52,7 @@ class Foundation_API SharedLibraryImpl
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
|
@ -52,7 +52,7 @@ class Foundation_API SharedLibraryImpl
|
||||
protected:
|
||||
SharedLibraryImpl();
|
||||
~SharedLibraryImpl();
|
||||
void loadImpl(const std::string& path);
|
||||
void loadImpl(const std::string& path, int flags);
|
||||
void unloadImpl();
|
||||
bool isLoadedImpl() const;
|
||||
void* findSymbolImpl(const std::string& name);
|
||||
|
@ -63,7 +63,13 @@ SharedLibrary::SharedLibrary()
|
||||
|
||||
SharedLibrary::SharedLibrary(const std::string& path)
|
||||
{
|
||||
loadImpl(path);
|
||||
loadImpl(path, 0);
|
||||
}
|
||||
|
||||
|
||||
SharedLibrary::SharedLibrary(const std::string& path, int flags)
|
||||
{
|
||||
loadImpl(path, flags);
|
||||
}
|
||||
|
||||
|
||||
@ -74,7 +80,13 @@ SharedLibrary::~SharedLibrary()
|
||||
|
||||
void SharedLibrary::load(const std::string& path)
|
||||
{
|
||||
loadImpl(path);
|
||||
loadImpl(path, 0);
|
||||
}
|
||||
|
||||
|
||||
void SharedLibrary::load(const std::string& path, int flags)
|
||||
{
|
||||
loadImpl(path, flags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -55,7 +55,7 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
|
@ -62,16 +62,17 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int flags)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
if (_handle) throw LibraryAlreadyLoadedException(path);
|
||||
int flags = RTLD_LAZY | RTLD_GLOBAL;
|
||||
#if defined(RTLD_DEEPBIND)
|
||||
flags |= RTLD_DEEPBIND;
|
||||
#endif
|
||||
_handle = dlopen(path.c_str(), flags);
|
||||
int realFlags = RTLD_LAZY;
|
||||
if (flags & SHLIB_LOCAL_IMPL)
|
||||
realFlags |= RTLD_LOCAL;
|
||||
else
|
||||
realFlags |= RTLD_GLOBAL;
|
||||
_handle = dlopen(path.c_str(), realFlags);
|
||||
if (!_handle)
|
||||
{
|
||||
const char* err = dlerror();
|
||||
|
@ -59,7 +59,7 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
|
@ -82,7 +82,7 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
|
@ -56,7 +56,7 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
|
@ -57,7 +57,7 @@ SharedLibraryImpl::~SharedLibraryImpl()
|
||||
}
|
||||
|
||||
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path)
|
||||
void SharedLibraryImpl::loadImpl(const std::string& path, int /*flags*/)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
|
@ -260,6 +260,8 @@ public:
|
||||
///
|
||||
/// Does nothing if the key does not exist.
|
||||
|
||||
void setPropertyEventingMode(bool enabled);
|
||||
/// Enable/Disable property eventing.
|
||||
protected:
|
||||
virtual bool getRaw(const std::string& key, std::string& value) const = 0;
|
||||
/// If the property with the given key exists, stores the property's value
|
||||
@ -301,6 +303,8 @@ private:
|
||||
mutable int _depth;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
|
||||
bool _propertyEventing;
|
||||
|
||||
friend class LayeredConfiguration;
|
||||
friend class ConfigurationView;
|
||||
friend class ConfigurationMapper;
|
||||
|
@ -55,7 +55,7 @@ namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
AbstractConfiguration::AbstractConfiguration(): _depth(0)
|
||||
AbstractConfiguration::AbstractConfiguration(): _depth(0), _propertyEventing(true)
|
||||
{
|
||||
}
|
||||
|
||||
@ -292,13 +292,13 @@ std::string AbstractConfiguration::expand(const std::string& value) const
|
||||
|
||||
void AbstractConfiguration::remove(const std::string& key)
|
||||
{
|
||||
propertyRemoving(this, key);
|
||||
if (_propertyEventing) propertyRemoving(this, key);
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
removeRaw(key);
|
||||
}
|
||||
propertyRemoved(this, key);
|
||||
if (_propertyEventing) propertyRemoved(this, key);
|
||||
}
|
||||
|
||||
|
||||
@ -386,14 +386,18 @@ bool AbstractConfiguration::parseBool(const std::string& value)
|
||||
void AbstractConfiguration::setRawWithEvent(const std::string& key, std::string value)
|
||||
{
|
||||
KeyValue kv(key, value);
|
||||
propertyChanging(this, kv);
|
||||
if (_propertyEventing) propertyChanging(this, kv);
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
setRaw(key, value);
|
||||
}
|
||||
propertyChanged(this, kv);
|
||||
if (_propertyEventing) propertyChanged(this, kv);
|
||||
}
|
||||
|
||||
void AbstractConfiguration::setPropertyEventingMode(bool enabled)
|
||||
{
|
||||
_propertyEventing = enabled;
|
||||
}
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
Loading…
x
Reference in New Issue
Block a user