You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2007/07/04 05:24:50 UTC

svn commit: r553056 - in /incubator/qpid/trunk/qpid/cpp/src: ./ qpid/ qpid/broker/ qpid/sys/ qpid/sys/apr/ qpid/sys/posix/ tests/

Author: aconway
Date: Tue Jul  3 20:24:48 2007
New Revision: 553056

URL: http://svn.apache.org/viewvc?view=rev&rev=553056
Log:

 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

Added:
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.h   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Shlib.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Shlib.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/tests/Shlib.cpp   (with props)
    incubator/qpid/trunk/qpid/cpp/src/tests/shlibtest.cpp   (with props)
Removed:
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Module.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Module.h
Modified:
    incubator/qpid/trunk/qpid/cpp/src/Makefile.am
    incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.h
    incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
    incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
    incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp
    incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am

Modified: incubator/qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/Makefile.am?view=diff&rev=553056&r1=553055&r2=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/Makefile.am Tue Jul  3 20:24:48 2007
@@ -48,11 +48,12 @@
 apr_plat_src = \
   qpid/sys/apr/Socket.cpp \
   qpid/sys/apr/Time.cpp \
-  qpid/sys/apr/Thread.cpp
+  qpid/sys/apr/Thread.cpp \
+  qpid/sys/apr/Shlib.cpp
+
 
 apr_plat_hdr = \
   qpid/sys/apr/Condition.h \
-  qpid/sys/apr/Module.h \
   qpid/sys/apr/Mutex.h \
   qpid/sys/apr/Socket.h \
   qpid/sys/apr/Thread.h
@@ -74,13 +75,13 @@
   qpid/sys/posix/Socket.cpp \
   qpid/sys/posix/AsynchIO.cpp \
   qpid/sys/posix/Time.cpp \
-  qpid/sys/posix/Thread.cpp
+  qpid/sys/posix/Thread.cpp \
+  qpid/sys/posix/Shlib.cpp
 
 posix_plat_hdr = \
   qpid/sys/posix/check.h \
   qpid/sys/posix/Condition.h \
   qpid/sys/posix/PrivatePosix.h \
-  qpid/sys/posix/Module.h \
   qpid/sys/posix/Mutex.h \
   qpid/sys/posix/Socket.h \
   qpid/sys/posix/Thread.h
@@ -167,6 +168,8 @@
   qpid/Url.cpp \
   qpid/QpidError.cpp \
   qpid/sys/Runnable.cpp \
+  qpid/sys/Shlib.h \
+  qpid/sys/Shlib.cpp \
   qpid/sys/ProducerConsumer.cpp \
   qpid/Options.cpp \
   qpid/Options.h \

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.cpp?view=diff&rev=553056&r1=553055&r2=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.cpp Tue Jul  3 20:24:48 2007
@@ -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 @@
 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

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.h?view=diff&rev=553056&r1=553055&r2=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/Plugin.h Tue Jul  3 20:24:48 2007
@@ -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 @@
     virtual void use(const shared_ptr<Plugin>& plugin) = 0;
 };
 
-
 /**
  * Base for classes that provide plug-ins.
  */
@@ -97,15 +98,6 @@
     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*/

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?view=diff&rev=553056&r1=553055&r2=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Tue Jul  3 20:24:48 2007
@@ -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>

Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h?view=diff&rev=553056&r1=553055&r2=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Module.h Tue Jul  3 20:24:48 2007
@@ -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*/

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.cpp?view=auto&rev=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.cpp Tue Jul  3 20:24:48 2007
@@ -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

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.h?view=auto&rev=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.h (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.h Tue Jul  3 20:24:48 2007
@@ -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*/

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/Shlib.h
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Shlib.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Shlib.cpp?view=auto&rev=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Shlib.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Shlib.cpp Tue Jul  3 20:24:48 2007
@@ -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

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Shlib.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/apr/Shlib.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Shlib.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Shlib.cpp?view=auto&rev=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Shlib.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Shlib.cpp Tue Jul  3 20:24:48 2007
@@ -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

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Shlib.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Shlib.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp?view=diff&rev=553056&r1=553055&r2=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Cluster.cpp Tue Jul  3 20:24:48 2007
@@ -16,13 +16,17 @@
  *
  */
 
-#define BOOST_AUTO_TEST_MAIN    // Must come before #include<boost/test/*>
-#include <boost/test/auto_unit_test.hpp>
-#include "test_tools.h"
 #include "Cluster.h"
+#include "test_tools.h"
+
 #include "qpid/framing/ChannelPingBody.h"
 #include "qpid/framing/ChannelOkBody.h"
 #include "qpid/cluster/ClassifierHandler.h"
+
+#define BOOST_AUTO_TEST_MAIN    // Must come before #include<boost/test/*>
+#include <boost/test/auto_unit_test.hpp>
+
+#include <sys/wait.h>
 
 static const ProtocolVersion VER;
 

Modified: incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am?view=diff&rev=553056&r1=553055&r2=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Makefile.am Tue Jul  3 20:24:48 2007
@@ -11,6 +11,7 @@
 # Initialize variables that are incremented with +=
 # 
 check_PROGRAMS=
+check_LTLIBRARIES=
 TESTS=
 EXTRA_DIST=
 
@@ -32,6 +33,15 @@
 Uuid_SOURCES=Uuid.cpp test_tools.h
 Uuid_LDADD=-lboost_unit_test_framework $(lib_common) 
 
+check_LTLIBRARIES += libshlibtest.la
+libshlibtest_la_LDFLAGS = -module -rpath $(abs_builddir)
+libshlibtest_la_SOURCES = shlibtest.cpp
+
+TESTS+=Shlib
+check_PROGRAMS+=Shlib
+Shlib_SOURCES=Shlib.cpp
+Shlib_LDADD=-lboost_unit_test_framework $(lib_common)
+
 include cluster.mk
 
 # NB: CppUnit test libraries below will be migrated to boost test programs.
@@ -112,24 +122,23 @@
 include gen.mk
 
 check_LTLIBRARIES += libdlclose_noop.la
-libdlclose_noop_la_LDFLAGS = -module -rpath /home/aconway/svn/qpid/cpp/tests
+libdlclose_noop_la_LDFLAGS = -module -rpath $(abs_builddir)
 libdlclose_noop_la_SOURCES = dlclose_noop.c
 
 gen.mk: Makefile.am
-	(					\
-	  for i in $(testprogs); do		\
-	    echo $${i}_SOURCES = $$i.cpp;	\
-	    echo $${i}_LDADD = '$$(lib_client) $$(lib_common) $$(extra_libs)'; \
-	  done;					\
-	  libs=;				\
-	  for i in $(unit_tests); do		\
-	    libs="$$libs $${i}.la";		\
-	    echo $${i}_la_SOURCES = $$i.cpp;	\
-	    echo $${i}_la_LIBADD = '$$(lib_common) $$(lib_client)';	\
-	    echo $${i}_la_LIBADD += '$$(lib_broker) $$(extra_libs)';	\
-	    echo $${i}_la_LDFLAGS = "-module -rpath `pwd`";	\
-	  done;					\
-	  echo "check_LTLIBRARIES =$$libs";	\
+	(									\
+	  for i in $(testprogs); do						\
+	    echo $${i}_SOURCES = $$i.cpp;					\
+	    echo $${i}_LDADD = '$$(lib_client) $$(lib_common) $$(extra_libs)';	\
+	  done;									\
+	  libs=;								\
+	  for i in $(unit_tests); do						\
+	    echo "check_LTLIBRARIES +=$${i}.la";				\
+	    echo $${i}_la_SOURCES = $$i.cpp;					\
+	    echo $${i}_la_LIBADD = '$$(lib_common) $$(lib_client)';		\
+	    echo $${i}_la_LIBADD += '$$(lib_broker) $$(extra_libs)';		\
+	    echo $${i}_la_LDFLAGS = "-module -rpath `pwd`";			\
+	  done;									\
 	)					\
 	> $@-t
 	mv $@-t $@
@@ -138,7 +147,7 @@
 	$(MAKE) check TESTS=$(UNIT_TESTS) run-unit-tests
 
 # Make sure valgrind files are generated.
-all: .valgrind.supp .valgrindrc
+all-am: .valgrind.supp .valgrindrc
 
 # Create a copy so that can be modified without risk of committing the changes.
 .valgrindrc: .valgrindrc-default

Added: incubator/qpid/trunk/qpid/cpp/src/tests/Shlib.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/Shlib.cpp?view=auto&rev=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/Shlib.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/Shlib.cpp Tue Jul  3 20:24:48 2007
@@ -0,0 +1,56 @@
+/*
+ * 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 "test_tools.h"
+#include "qpid/sys/Shlib.h"
+
+#define BOOST_AUTO_TEST_MAIN    // Must come before #include<boost/test/*>
+#include <boost/test/auto_unit_test.hpp>
+
+using namespace qpid::sys;
+typedef void (*CallMe)(int*);
+
+BOOST_AUTO_TEST_CASE(testShlib) {
+    Shlib sh(".libs/libshlibtest.so");
+    // Double cast to avoid ISO warning.
+    CallMe callMe=sh.getSymbol<CallMe>("callMe");
+    BOOST_REQUIRE(callMe != 0);
+    int unloaded=0;
+    callMe(&unloaded);
+    sh.unload();
+    BOOST_CHECK_EQUAL(42, unloaded);
+    try {
+        sh.getSymbol("callMe");
+        BOOST_FAIL("Expected exception");
+    }
+    catch (...) {}
+}
+    
+BOOST_AUTO_TEST_CASE(testAutoShlib) {
+    int unloaded = 0;
+    {
+        AutoShlib sh(".libs/libshlibtest.so");
+        CallMe callMe=sh.getSymbol<CallMe>("callMe");
+        BOOST_REQUIRE(callMe != 0);
+        callMe(&unloaded);
+    }
+    BOOST_CHECK_EQUAL(42, unloaded);
+}
+    

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/Shlib.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/Shlib.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/qpid/trunk/qpid/cpp/src/tests/shlibtest.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/tests/shlibtest.cpp?view=auto&rev=553056
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/tests/shlibtest.cpp (added)
+++ incubator/qpid/trunk/qpid/cpp/src/tests/shlibtest.cpp Tue Jul  3 20:24:48 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ *
+ */
+
+int* loaderData = 0;
+extern "C" void callMe(int *i) { loaderData=i; }
+
+struct OnUnload { ~OnUnload() { *loaderData=42; } };
+OnUnload unloader;              // For destructor.
+
+
+

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/shlibtest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/qpid/trunk/qpid/cpp/src/tests/shlibtest.cpp
------------------------------------------------------------------------------
    svn:keywords = Rev Date