summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/DynamicLibrary.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/src/Ice/DynamicLibrary.cpp
parentinitial check-in (diff)
downloadice-f8c70c81e385fd549756b4f660b4b6860a3e913c.tar.bz2
ice-f8c70c81e385fd549756b4f660b4b6860a3e913c.tar.xz
ice-f8c70c81e385fd549756b4f660b4b6860a3e913c.zip
adding DynamicLibrary
Diffstat (limited to 'cpp/src/Ice/DynamicLibrary.cpp')
-rw-r--r--cpp/src/Ice/DynamicLibrary.cpp90
1 files changed, 90 insertions, 0 deletions
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;
+}