summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-04-01 20:42:16 +0000
committerMark Spruiell <mes@zeroc.com>2002-04-01 20:42:16 +0000
commitf8c70c81e385fd549756b4f660b4b6860a3e913c (patch)
treefe040c2fb9621655f7389ff0ddf6c55c66ce536a /cpp
parentinitial check-in (diff)
downloadice-f8c70c81e385fd549756b4f660b4b6860a3e913c.tar.bz2
ice-f8c70c81e385fd549756b4f660b4b6860a3e913c.tar.xz
ice-f8c70c81e385fd549756b4f660b4b6860a3e913c.zip
adding DynamicLibrary
Diffstat (limited to 'cpp')
-rw-r--r--cpp/include/Ice/DynamicLibrary.h52
-rw-r--r--cpp/include/Ice/DynamicLibraryF.h26
-rw-r--r--cpp/src/Ice/.depend1
-rw-r--r--cpp/src/Ice/DynamicLibrary.cpp90
-rw-r--r--cpp/src/Ice/Makefile3
5 files changed, 171 insertions, 1 deletions
diff --git a/cpp/include/Ice/DynamicLibrary.h b/cpp/include/Ice/DynamicLibrary.h
new file mode 100644
index 00000000000..a8f3f3f38ed
--- /dev/null
+++ b/cpp/include/Ice/DynamicLibrary.h
@@ -0,0 +1,52 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef ICE_DYNAMIC_LIBRARY_H
+#define ICE_DYNAMIC_LIBRARY_H
+
+#include <Ice/DynamicLibraryF.h>
+#include <IceUtil/Shared.h>
+
+namespace IceInternal
+{
+
+class DynamicLibrary : public ::IceUtil::Shared
+{
+public:
+
+ DynamicLibrary();
+ ~DynamicLibrary();
+
+ bool load(const std::string&);
+
+#ifdef WIN32
+ typedef FARPROC symbol_type;
+#else
+ typedef void* symbol_type;
+#endif
+
+ symbol_type getSymbol(const std::string&); // Returns 0 if no match found
+
+ const std::string& getErrorMessage() const; // Error message for last failure
+
+private:
+
+#ifdef WIN32
+ HINSTANCE _hnd;
+#else
+ void* _hnd;
+#endif
+
+ std::string _err;
+};
+
+}
+
+#endif
diff --git a/cpp/include/Ice/DynamicLibraryF.h b/cpp/include/Ice/DynamicLibraryF.h
new file mode 100644
index 00000000000..56c8e503d95
--- /dev/null
+++ b/cpp/include/Ice/DynamicLibraryF.h
@@ -0,0 +1,26 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef ICE_DYNAMIC_LIBRARY_F_H
+#define ICE_DYNAMIC_LIBRARY_F_H
+
+#include <Ice/Handle.h>
+
+namespace IceInternal
+{
+
+class DynamicLibrary;
+ICE_API void incRef(DynamicLibrary*);
+ICE_API void decRef(DynamicLibrary*);
+typedef Handle<DynamicLibrary> DynamicLibraryPtr;
+
+}
+
+#endif
diff --git a/cpp/src/Ice/.depend b/cpp/src/Ice/.depend
index aa80122d3ff..196f4c644aa 100644
--- a/cpp/src/Ice/.depend
+++ b/cpp/src/Ice/.depend
@@ -89,3 +89,4 @@ OpenSSLUtils.o: OpenSSLUtils.cpp ../Ice/OpenSSLUtils.h ../Ice/SystemInternalF.h
DefaultCertificateVerifier.o: DefaultCertificateVerifier.cpp ../Ice/OpenSSL.h ../Ice/DefaultCertificateVerifier.h ../../include/IceUtil/Config.h ../../include/Ice/Logger.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../Ice/TraceLevels.h ../Ice/TraceLevelsF.h ../../include/Ice/PropertiesF.h ../Ice/Instance.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/InstanceF.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LoggerF.h ../Ice/RouterInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../Ice/ObjectFactoryManagerF.h ../Ice/UserExceptionFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../../include/Ice/SystemF.h ../Ice/SystemInternalF.h ../../include/Ice/CertificateVerifierOpenSSL.h ../../include/Ice/CertificateVerifier.h ../Ice/OpenSSLUtils.h
SingleCertificateVerifier.o: SingleCertificateVerifier.cpp ../Ice/SingleCertificateVerifier.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/CertificateVerifierOpenSSL.h ../../include/Ice/CertificateVerifier.h ../Ice/SslIceUtils.h
UdpTransceiver.o: UdpTransceiver.cpp ../Ice/UdpTransceiver.h ../../include/Ice/InstanceF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../Ice/TraceLevelsF.h ../../include/Ice/LoggerF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/ObjectF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../Ice/Transceiver.h ../Ice/TransceiverF.h ../Ice/Instance.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/CommunicatorF.h ../../include/Ice/PropertiesF.h ../Ice/RouterInfoF.h ../Ice/ReferenceFactoryF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/ConnectionFactoryF.h ../Ice/ObjectFactoryManagerF.h ../Ice/UserExceptionFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../../include/Ice/SystemF.h ../Ice/SystemInternalF.h ../Ice/TraceLevels.h ../../include/Ice/LoggerUtil.h ../../include/Ice/Buffer.h ../Ice/Network.h
+DynamicLibrary.o: DynamicLibrary.cpp ../../include/Ice/DynamicLibrary.h ../../include/Ice/DynamicLibraryF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/IceUtil/Shared.h
diff --git a/cpp/src/Ice/DynamicLibrary.cpp b/cpp/src/Ice/DynamicLibrary.cpp
new file mode 100644
index 00000000000..d62154f43ec
--- /dev/null
+++ b/cpp/src/Ice/DynamicLibrary.cpp
@@ -0,0 +1,90 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Ice/DynamicLibrary.h>
+
+#ifndef WIN32
+# include <dlfcn.h>
+#endif
+
+using namespace Ice;
+using namespace IceInternal;
+using namespace std;
+
+void IceInternal::incRef(DynamicLibrary* p) { p->__incRef(); }
+void IceInternal::decRef(DynamicLibrary* p) { p->__decRef(); }
+
+IceInternal::DynamicLibrary::DynamicLibrary()
+ : _hnd(0)
+{
+}
+
+IceInternal::DynamicLibrary::~DynamicLibrary()
+{
+ if(_hnd != 0)
+ {
+#ifdef WIN32
+ FreeLibrary(_hnd);
+#else
+ dlclose(_hnd);
+#endif
+ }
+}
+
+bool
+IceInternal::DynamicLibrary::load(const string& lib)
+{
+#ifdef WIN32
+ _hnd = LoadLibrary(lib.c_str());
+#else
+ _hnd = dlopen(lib.c_str(), RTLD_NOW);
+ if (_hnd == 0)
+ {
+ //
+ // Remember the most recent error in _err.
+ //
+ const char* err = dlerror();
+ if (err)
+ {
+ _err = err;
+ }
+ }
+#endif
+ return _hnd != 0;
+}
+
+IceInternal::DynamicLibrary::symbol_type
+IceInternal::DynamicLibrary::getSymbol(const string& name)
+{
+ assert(_hnd != 0);
+#ifdef WIN32
+ return GetProcAddress(_hnd, name.c_str());
+#else
+ symbol_type result = dlsym(_hnd, name.c_str());
+ if (result == 0)
+ {
+ //
+ // Remember the most recent error in _err.
+ //
+ const char* err = dlerror();
+ if (err)
+ {
+ _err = err;
+ }
+ }
+ return result;
+#endif
+}
+
+const string&
+IceInternal::DynamicLibrary::getErrorMessage() const
+{
+ return _err;
+}
diff --git a/cpp/src/Ice/Makefile b/cpp/src/Ice/Makefile
index 6271fae3bb0..cb655b08f97 100644
--- a/cpp/src/Ice/Makefile
+++ b/cpp/src/Ice/Makefile
@@ -108,7 +108,8 @@ OBJS = Initialize.o \
OpenSSLUtils.o \
DefaultCertificateVerifier.o \
SingleCertificateVerifier.o \
- UdpTransceiver.o
+ UdpTransceiver.o \
+ DynamicLibrary.o
SRCS = $(OBJS:.o=.cpp)