summaryrefslogtreecommitdiff
path: root/cpp/src/qpid
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-07-04 03:24:48 +0000
committerAlan Conway <aconway@apache.org>2007-07-04 03:24:48 +0000
commitae896d73d4914fa96f053a0443f6b05003c12b35 (patch)
tree0aac1abf592704282ab5860a0f69dcfd9610f2cd /cpp/src/qpid
parent7865fcf6689f96219365995e8ad09b3332205176 (diff)
downloadqpid-python-ae896d73d4914fa96f053a0443f6b05003c12b35.tar.gz
2007-07-02 <aconway@redhat.com
* qpid/sys/Shlib.h, .cpp: Portable shared library abstraction. - Shlib: load, unload, getSymbol - AutoShlib: unload in destructor. * qpid/sys/apr/Shlib.cpp sys/posix/Shlib.cpp: APR/Posix impls * qpid/sys/Module.h: Reimplemented Module in terms of AutoShlib. * qpid/Plugin.cpp, .h: Removed dlopen - use Shlib instead. * qpid/broker/Broker.cpp: Added missing #include "qpid/log/Statement.h" * tests/Shlib.cpp, shlibtest.cpp: Unit test git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@553056 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid')
-rw-r--r--cpp/src/qpid/Plugin.cpp59
-rw-r--r--cpp/src/qpid/Plugin.h36
-rw-r--r--cpp/src/qpid/broker/Broker.cpp14
-rw-r--r--cpp/src/qpid/sys/Module.h37
-rw-r--r--cpp/src/qpid/sys/Shlib.cpp38
-rw-r--r--cpp/src/qpid/sys/Shlib.h82
-rw-r--r--cpp/src/qpid/sys/apr/Module.h114
-rw-r--r--cpp/src/qpid/sys/apr/Shlib.cpp49
-rw-r--r--cpp/src/qpid/sys/posix/Module.h127
-rw-r--r--cpp/src/qpid/sys/posix/Shlib.cpp60
10 files changed, 293 insertions, 323 deletions
diff --git a/cpp/src/qpid/Plugin.cpp b/cpp/src/qpid/Plugin.cpp
index 31fab65995..c6513d33e8 100644
--- a/cpp/src/qpid/Plugin.cpp
+++ b/cpp/src/qpid/Plugin.cpp
@@ -1,18 +1,20 @@
/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Copyright (c) 2006 The Apache Software Foundation
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*
*/
@@ -34,38 +36,5 @@ Options* PluginProvider::getOptions() { return 0; }
const std::vector<PluginProvider*>& PluginProvider::getProviders() {
return providers;
}
-} // namespace qpid
-
-// TODO aconway 2007-06-28: GNU lib has portable dlopen if we go that way.
-#ifdef USE_APR_PLATFORM
-
-#include "qpid/sys/apr/APRBase.h"
-#include "qpid/sys/apr/APRPool.h"
-#include <apr_dso.h>
-
-namespace qpid {
-void dlopen(const char* name) {
- apr_dso_handle_t* handle;
- CHECK_APR_SUCCESS(
- apr_dso_load(&handle, name, sys::APRPool::get()));
-}
} // namespace qpid
-
-#else // Posix
-
-#include "qpid/sys/posix/check.h"
-#include <dlfcn.h>
-
-namespace qpid {
-void dlopen(const char* name) {
- ::dlerror();
- ::dlopen(name, RTLD_NOW);
- const char* error = ::dlerror();
- if (error) {
- THROW_QPID_ERROR(INTERNAL_ERROR, error);
- }
-}
-} // namespace qpidpp
-
-#endif // USE_APR_PLATFORM
diff --git a/cpp/src/qpid/Plugin.h b/cpp/src/qpid/Plugin.h
index 48fb16a541..f50e97eb00 100644
--- a/cpp/src/qpid/Plugin.h
+++ b/cpp/src/qpid/Plugin.h
@@ -2,20 +2,22 @@
#define QPID_PLUGIN_H
/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Copyright (c) 2006 The Apache Software Foundation
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*
*/
@@ -53,7 +55,6 @@ struct PluginUser : boost::noncopyable {
virtual void use(const shared_ptr<Plugin>& plugin) = 0;
};
-
/**
* Base for classes that provide plug-ins.
*/
@@ -97,15 +98,6 @@ class PluginProvider : boost::noncopyable
static std::vector<PluginProvider*> providers;
};
-/** Load a shared library, registering any PluginProvider it contains.
- *
- * This is just a convenient portable wrapper for normal shared
- * library loading. A global PluginProvider instance loaded or
- * linked in any way will get registered.
- */
-void dlopen(const char* libname);
-
-
} // namespace qpid
#endif /*!QPID_PLUGIN_H*/
diff --git a/cpp/src/qpid/broker/Broker.cpp b/cpp/src/qpid/broker/Broker.cpp
index 43a5567b3d..9c8e98ec9a 100644
--- a/cpp/src/qpid/broker/Broker.cpp
+++ b/cpp/src/qpid/broker/Broker.cpp
@@ -21,22 +21,24 @@
#include "Broker.h"
-#include "qpid/framing/AMQFrame.h"
-#include "qpid/framing/HandlerUpdater.h"
+#include "Connection.h"
#include "DirectExchange.h"
-#include "TopicExchange.h"
#include "FanOutExchange.h"
#include "HeadersExchange.h"
#include "MessageStoreModule.h"
#include "NullMessageStore.h"
-#include "qpid/framing/ProtocolInitiation.h"
#include "RecoveryManagerImpl.h"
-#include "Connection.h"
+#include "TopicExchange.h"
+
+#include "qpid/log/Statement.h"
+#include "qpid/Url.h"
+#include "qpid/framing/AMQFrame.h"
+#include "qpid/framing/HandlerUpdater.h"
+#include "qpid/framing/ProtocolInitiation.h"
#include "qpid/sys/Acceptor.h"
#include "qpid/sys/ConnectionInputHandler.h"
#include "qpid/sys/ConnectionInputHandlerFactory.h"
#include "qpid/sys/TimeoutHandler.h"
-#include "qpid/Url.h"
#include <iostream>
#include <memory>
diff --git a/cpp/src/qpid/sys/Module.h b/cpp/src/qpid/sys/Module.h
index e812f57d7a..79793ed0ca 100644
--- a/cpp/src/qpid/sys/Module.h
+++ b/cpp/src/qpid/sys/Module.h
@@ -1,5 +1,5 @@
-#ifndef _sys_Module_h
-#define _sys_Module_h
+#ifndef QPID_SYS_MODULE_H
+#define QPID_SYS_MODULE_H
/*
*
@@ -21,11 +21,30 @@
* under the License.
*
*/
-
-#ifdef USE_APR_PLATFORM
-#include "apr/Module.h"
-#else
-#include "posix/Module.h"
-#endif
-#endif //ifndef _sys_Module_h
+#include "qpid/sys/Shlib.h"
+#include <boost/noncopyable.hpp>
+
+namespace qpid {
+namespace sys {
+
+template <class T> class Module : public AutoShlib, private boost::noncopyable
+{
+ public:
+ Module(const std::string& name) :
+ AutoShlib(name),
+ ptr(getSymbol<T*(*)()>("create")()) {}
+
+ T* get() { return ptr; }
+ T* operator->() { return ptr; }
+ ~Module() throw() {
+ getSymbol<void (*)(T*)>("destroy")(ptr);
+ }
+
+ private:
+ T* ptr;
+};
+
+}}
+
+#endif /*!QPID_SYS_MODULE_H*/
diff --git a/cpp/src/qpid/sys/Shlib.cpp b/cpp/src/qpid/sys/Shlib.cpp
new file mode 100644
index 0000000000..8fd3f42cc6
--- /dev/null
+++ b/cpp/src/qpid/sys/Shlib.cpp
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "Shlib.h"
+
+#include "qpid/log/Statement.h"
+
+namespace qpid {
+namespace sys {
+
+AutoShlib::~AutoShlib() throw() {
+ try {
+ unload();
+ } catch(const std::exception& e) {
+ QPID_LOG(error, "Unloading shared library: " << e.what());
+ }
+}
+
+// Note: Other functions are defined in apr/Shlib.cpp or posix/Shlib.cpp.
+
+}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/Shlib.h b/cpp/src/qpid/sys/Shlib.h
new file mode 100644
index 0000000000..debf231125
--- /dev/null
+++ b/cpp/src/qpid/sys/Shlib.h
@@ -0,0 +1,82 @@
+#ifndef QPID_SYS_SHLIB_H
+#define QPID_SYS_SHLIB_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <boost/noncopyable.hpp>
+#include <iostream>
+#include <dlfcn.h>
+
+namespace qpid {
+namespace sys {
+
+/** Encapsulates a shared library handle.
+ *@see AutoShlib
+ */
+class Shlib {
+ public:
+ /** Load a shared library */
+ Shlib(const char* libname) { load(libname); }
+
+ /** Load a shared library */
+ Shlib(const std::string& libname) { load(libname.c_str()); }
+
+ /** Unload shared library. */
+ void unload();
+
+ /** Look up symbol. */
+ void* getSymbol(const char* symbol);
+
+ /** Look up symbol in shared library, cast it to the desired
+ * pointer type, void* by default.
+ */
+ template <class T>
+ T getSymbol(const char* symbol) {
+ // Double cast avoids warning about casting object to function pointer
+ return reinterpret_cast<T>(reinterpret_cast<intptr_t>(
+ this->getSymbol(symbol)));
+ }
+
+ /** Look up symbol in shared library. */
+ template <class T*>
+ void* getSymbol(const std::string& symbol) {
+ return getSymbol<T>(symbol.c_str());
+ }
+
+ private:
+ void* handle;
+ void load(const char* libname);
+};
+
+/** A shared library handle that unloads the shlib in it's dtor */
+class AutoShlib : public Shlib {
+ public:
+ /** Load shared library */
+ AutoShlib(const std::string& libname) : Shlib(libname) {}
+ /** Calls unload() */
+ ~AutoShlib() throw();
+};
+
+
+}} // namespace qpid::sys
+
+#endif /*!QPID_SYS_SHLIB_H*/
diff --git a/cpp/src/qpid/sys/apr/Module.h b/cpp/src/qpid/sys/apr/Module.h
deleted file mode 100644
index ff93a0eaf0..0000000000
--- a/cpp/src/qpid/sys/apr/Module.h
+++ /dev/null
@@ -1,114 +0,0 @@
-#ifndef _sys_apr_Module_h
-#define _sys_apr_Module_h
-
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-#include "qpid/log/Statement.h"
-#include "qpid/QpidError.h"
-#include "APRBase.h"
-#include "APRPool.h"
-
-#include <boost/noncopyable.hpp>
-#include <iostream>
-#include <apr_dso.h>
-
-namespace qpid {
-namespace sys {
-
-typedef apr_dso_handle_t* dso_handle_t;
-
-template <class T> class Module : private boost::noncopyable
-{
- typedef T* create_t();
- typedef void destroy_t(T*);
-
- dso_handle_t handle;
- destroy_t* destroy;
- T* ptr;
-
- void load(const std::string& name);
- void unload();
- void* getSymbol(const std::string& name);
-
-public:
- Module(const std::string& name);
- T* operator->();
- T* get();
- ~Module() throw();
-};
-
-template <class T> Module<T>::Module(const std::string& module) : destroy(0), ptr(0)
-{
- load(module);
- //TODO: need a better strategy for symbol names to allow multiple
- //modules to be loaded without clashes...
-
- //Note: need the double cast to avoid errors in casting from void* to function pointer with -pedantic
- create_t* create = reinterpret_cast<create_t*>(reinterpret_cast<intptr_t>(getSymbol("create")));
- destroy = reinterpret_cast<destroy_t*>(reinterpret_cast<intptr_t>(getSymbol("destroy")));
- ptr = create();
-}
-
-template <class T> T* Module<T>::operator->()
-{
- return ptr;
-}
-
-template <class T> T* Module<T>::get()
-{
- return ptr;
-}
-
-template <class T> Module<T>::~Module() throw()
-{
- try {
- if (handle && ptr) {
- destroy(ptr);
- }
- if (handle) unload();
- } catch (std::exception& e) {
- QPID_LOG(error, "Error while destroying module: " << e.what());
- }
- destroy = 0;
- handle = 0;
- ptr = 0;
-}
-
-template <class T> void Module<T>::load(const std::string& name)
-{
- CHECK_APR_SUCCESS(apr_dso_load(&handle, name.c_str(), APRPool::get()));
-}
-
-template <class T> void Module<T>::unload()
-{
- CHECK_APR_SUCCESS(apr_dso_unload(handle));
-}
-
-template <class T> void* Module<T>::getSymbol(const std::string& name)
-{
- apr_dso_handle_sym_t symbol;
- CHECK_APR_SUCCESS(apr_dso_sym(&symbol, handle, name.c_str()));
- return (void*) symbol;
-}
-
-}}
-#endif //ifndef _sys_apr_Module_h
-
diff --git a/cpp/src/qpid/sys/apr/Shlib.cpp b/cpp/src/qpid/sys/apr/Shlib.cpp
new file mode 100644
index 0000000000..b0ba706713
--- /dev/null
+++ b/cpp/src/qpid/sys/apr/Shlib.cpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/sys/Shlib.h"
+#include "APRBase.h"
+#include "APRPool.h"
+#include <apr_dso.h>
+
+namespace qpid {
+namespace sys {
+
+void Shlib::load(const char* libname) {
+ apr_dso_handle_t* aprHandle;
+ CHECK_APR_SUCCESS(
+ apr_dso_load(&aprHandle, libname, APRPool::get()));
+ handle=aprHandle;
+}
+
+void Shlib::unload() {
+ CHECK_APR_SUCCESS(
+ apr_dso_unload(static_cast<apr_dso_handle_t*>(handle)));
+}
+
+void* Shlib::getSymbol(const char* name) {
+ apr_dso_handle_sym_t symbol;
+ CHECK_APR_SUCCESS(apr_dso_sym(&symbol,
+ static_cast<apr_dso_handle_t*>(handle),
+ name));
+ return (void*) symbol;
+}
+
+}} // namespace qpid::sys
diff --git a/cpp/src/qpid/sys/posix/Module.h b/cpp/src/qpid/sys/posix/Module.h
deleted file mode 100644
index 5a0358a748..0000000000
--- a/cpp/src/qpid/sys/posix/Module.h
+++ /dev/null
@@ -1,127 +0,0 @@
-#ifndef _sys_posix_Module_h
-#define _sys_posix_Module_h
-
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-#include "qpid/QpidError.h"
-#include "qpid/log/Statement.h"
-
-#include <boost/noncopyable.hpp>
-#include <iostream>
-#include <dlfcn.h>
-
-namespace qpid {
-namespace sys {
-
-typedef void* dso_handle_t;
-
-template <class T> class Module : private boost::noncopyable
-{
- typedef T* create_t();
- typedef void destroy_t(T*);
-
- dso_handle_t handle;
- destroy_t* destroy;
- T* ptr;
-
- void load(const std::string& name);
- void unload();
- void* getSymbol(const std::string& name);
-
-public:
- Module(const std::string& name);
- T* operator->();
- T* get();
- ~Module() throw();
-};
-
-template <class T> Module<T>::Module(const std::string& module) : destroy(0), ptr(0)
-{
- load(module);
- //TODO: need a better strategy for symbol names to allow multiple
- //modules to be loaded without clashes...
-
- //Note: need the double cast to avoid errors in casting from void* to function pointer with -pedantic
- create_t* create = reinterpret_cast<create_t*>(reinterpret_cast<intptr_t>(getSymbol("create")));
- destroy = reinterpret_cast<destroy_t*>(reinterpret_cast<intptr_t>(getSymbol("destroy")));
- ptr = create();
-}
-
-template <class T> T* Module<T>::operator->()
-{
- return ptr;
-}
-
-template <class T> T* Module<T>::get()
-{
- return ptr;
-}
-
-template <class T> Module<T>::~Module() throw()
-{
- try {
- if (handle && ptr) {
- destroy(ptr);
- }
- if (handle) unload();
- } catch (std::exception& e) {
- QPID_LOG(error, "Error while destroying module: " << e.what());
- }
- destroy = 0;
- handle = 0;
- ptr = 0;
-}
-
-template <class T> void Module<T>::load(const std::string& name)
-{
- ::dlerror();
- handle = ::dlopen(name.c_str(), RTLD_NOW);
- const char* error = ::dlerror();
- if (error) {
- THROW_QPID_ERROR(INTERNAL_ERROR, error);
- }
-}
-
-template <class T> void Module<T>::unload()
-{
- dlerror();
- dlclose(handle);
- const char* error = dlerror();
- if (error) {
- THROW_QPID_ERROR(INTERNAL_ERROR, error);
- }
-}
-
-template <class T> void* Module<T>::getSymbol(const std::string& name)
-{
- dlerror();
- void* sym = dlsym(handle, name.c_str());
- const char* error = dlerror();
- if (error) {
- THROW_QPID_ERROR(INTERNAL_ERROR, error);
- }
- return sym;
-}
-
-}}
-#endif //ifndef _sys_posix_Module_h
-
diff --git a/cpp/src/qpid/sys/posix/Shlib.cpp b/cpp/src/qpid/sys/posix/Shlib.cpp
new file mode 100644
index 0000000000..2630337408
--- /dev/null
+++ b/cpp/src/qpid/sys/posix/Shlib.cpp
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/sys/Shlib.h"
+
+#include <qpid/QpidError.h>
+#include <dlfcn.h>
+
+
+namespace qpid {
+namespace sys {
+
+void Shlib::load(const char* name) {
+ dlerror();
+ handle = ::dlopen(name, RTLD_NOW);
+ const char* error = ::dlerror();
+ if (error) {
+ THROW_QPID_ERROR(INTERNAL_ERROR, error);
+ }
+}
+
+void Shlib::unload() {
+ if (handle) {
+ ::dlerror();
+ ::dlclose(handle);
+ const char* error = ::dlerror();
+ if (error) {
+ THROW_QPID_ERROR(INTERNAL_ERROR, error);
+ }
+ handle = 0;
+ }
+}
+
+void* Shlib::getSymbol(const char* name) {
+ ::dlerror();
+ void* sym = ::dlsym(handle, name);
+ const char* error = ::dlerror();
+ if (error)
+ THROW_QPID_ERROR(INTERNAL_ERROR, error);
+ return sym;
+}
+
+}} // namespace qpid::sys