From 2b1b179702863e8e6d077c025f5244eaa461a990 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 28 Nov 2007 17:13:28 +0000 Subject: Fixed to build with boost 1.34 as well as boost 1.33 - boost::ptr_map API changed. - Boost.Test unit test framework changes. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@599067 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/broker/Connection.cpp | 19 +++--- cpp/src/qpid/broker/DtxManager.cpp | 17 +++--- cpp/src/qpid/broker/DtxManager.h | 5 +- cpp/src/qpid/ptr_map.h | 116 +++++++++++++++++++++++++++++++++++++ 4 files changed, 138 insertions(+), 19 deletions(-) create mode 100644 cpp/src/qpid/ptr_map.h (limited to 'cpp/src/qpid') diff --git a/cpp/src/qpid/broker/Connection.cpp b/cpp/src/qpid/broker/Connection.cpp index f981d47ef7..26146e80d4 100644 --- a/cpp/src/qpid/broker/Connection.cpp +++ b/cpp/src/qpid/broker/Connection.cpp @@ -18,24 +18,26 @@ * under the License. * */ -#include "qpid/log/Statement.h" -#include -#include - #include "Connection.h" #include "SessionState.h" -#include "qpid/framing/AMQP_ClientProxy.h" #include "BrokerAdapter.h" #include "SemanticHandler.h" +#include "qpid/log/Statement.h" +#include "qpid/ptr_map.h" +#include "qpid/framing/AMQP_ClientProxy.h" + #include #include +#include +#include using namespace boost; using namespace qpid::sys; using namespace qpid::framing; using namespace qpid::sys; +using namespace qpid::ptr_map; namespace qpid { namespace broker { @@ -77,9 +79,8 @@ void Connection::idleIn(){} void Connection::closed(){ // Physically closed, suspend open sessions. try { - std::for_each( - channels.begin(), channels.end(), - boost::bind(&SessionHandler::localSuspend, _1)); + for (ChannelMap::iterator i = channels.begin(); i != channels.end(); ++i) + get_pointer(i)->localSuspend(); while (!exclusiveQueues.empty()) { Queue::shared_ptr q(exclusiveQueues.front()); q->releaseExclusiveOwnership(); @@ -105,7 +106,7 @@ SessionHandler& Connection::getChannel(ChannelId id) { if (i == channels.end()) { i = channels.insert(id, new SessionHandler(*this, id)).first; } - return *i; + return *get_pointer(i); } }} diff --git a/cpp/src/qpid/broker/DtxManager.cpp b/cpp/src/qpid/broker/DtxManager.cpp index 7ac89d3a4e..1d8b64eb5b 100644 --- a/cpp/src/qpid/broker/DtxManager.cpp +++ b/cpp/src/qpid/broker/DtxManager.cpp @@ -22,10 +22,13 @@ #include "DtxTimeout.h" #include "qpid/framing/reply_exceptions.h" #include "qpid/log/Statement.h" +#include "qpid/ptr_map.h" + #include #include -using qpid::sys::Mutex; +using qpid::sys::Mutex; +using namespace qpid::ptr_map; using namespace qpid::broker; using namespace qpid::framing; @@ -81,14 +84,14 @@ void DtxManager::rollback(const std::string& xid) } } -DtxManager::WorkMap::iterator DtxManager::getWork(const std::string& xid) +DtxWorkRecord* DtxManager::getWork(const std::string& xid) { Mutex::ScopedLock locker(lock); WorkMap::iterator i = work.find(xid); if (i == work.end()) { throw InvalidArgumentException(QPID_MSG("Unrecognised xid " << xid)); } - return i; + return get_pointer(i); } void DtxManager::remove(const std::string& xid) @@ -102,20 +105,20 @@ void DtxManager::remove(const std::string& xid) } } -DtxManager::WorkMap::iterator DtxManager::createWork(std::string xid) +DtxWorkRecord* DtxManager::createWork(std::string xid) { Mutex::ScopedLock locker(lock); WorkMap::iterator i = work.find(xid); if (i != work.end()) { throw CommandInvalidException(QPID_MSG("Xid " << xid << " is already known (use 'join' to add work to an existing xid)")); } else { - return work.insert(xid, new DtxWorkRecord(xid, store)).first; + return get_pointer(work.insert(xid, new DtxWorkRecord(xid, store)).first); } } void DtxManager::setTimeout(const std::string& xid, uint32_t secs) { - WorkMap::iterator record = getWork(xid); + DtxWorkRecord* record = getWork(xid); DtxTimeout::shared_ptr timeout = record->getTimeout(); if (timeout.get()) { if (timeout->timeout == secs) return;//no need to do anything further if timeout hasn't changed @@ -140,7 +143,7 @@ void DtxManager::timedout(const std::string& xid) if (i == work.end()) { QPID_LOG(warning, "Transaction timeout failed: no record for xid"); } else { - i->timedout(); + get_pointer(i)->timedout(); //TODO: do we want to have a timed task to cleanup, or can we rely on an explicit completion? //timer.add(TimerTask::shared_ptr(new DtxCleanup(60*30/*30 mins*/, *this, xid))); } diff --git a/cpp/src/qpid/broker/DtxManager.h b/cpp/src/qpid/broker/DtxManager.h index 3db3f70685..64eae1488d 100644 --- a/cpp/src/qpid/broker/DtxManager.h +++ b/cpp/src/qpid/broker/DtxManager.h @@ -35,7 +35,6 @@ namespace broker { class DtxManager{ typedef boost::ptr_map WorkMap; - struct DtxCleanup : public TimerTask { DtxManager& mgr; @@ -51,8 +50,8 @@ class DtxManager{ Timer timer; void remove(const std::string& xid); - WorkMap::iterator getWork(const std::string& xid); - WorkMap::iterator createWork(std::string xid); + DtxWorkRecord* getWork(const std::string& xid); + DtxWorkRecord* createWork(std::string xid); public: DtxManager(TransactionalStore* const store); diff --git a/cpp/src/qpid/ptr_map.h b/cpp/src/qpid/ptr_map.h new file mode 100644 index 0000000000..c33f63767d --- /dev/null +++ b/cpp/src/qpid/ptr_map.h @@ -0,0 +1,116 @@ +#ifndef QPID_PTR_MAP +#define QPID_PTR_MAP + +/* + * + * 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 +#include + +namespace qpid { +namespace ptr_map { + +/** @file + * Workaround for API change between boost 1.33 and 1.34. + * + * To be portable across these versions, code using boost::ptr_map + * iterators should use get_pointer(i) to get the pointer from + * a boost::ptr_map iterator. + * + * Can be removed when we no longer support platforms on 1.33. + * + * @see http://www.boost.org/libs/ptr_container/doc/ptr_container.html#upgrading-from-boost-v-1-33 + */ +#if (BOOST_VERSION < 103400) + +template +typename PtrMapIter::pointer get_pointer(const PtrMapIter& i) +{ return &*i; } + +#else + +template +typename PtrMapIter::value_type::second_type get_pointer(const PtrMapIter& i) +{ return i->second; } + +#endif + +}} // namespace qpid::ptr_map + +#endif /*!QPID_PTR_MAP*/ +#ifndef QPID_PTR_MAP +#define QPID_PTR_MAP + +/* + * + * 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 +#include + +namespace qpid { +namespace ptr_map { + +/** @file + * Workaround for API change between boost 1.33 and 1.34. + * + * To be portable across these versions, code using boost::ptr_map + * iterators should use get_pointer(i) to get the pointer from + * a boost::ptr_map iterator. + * + * Can be removed when we no longer support platforms on 1.33. + * + * @see http://www.boost.org/libs/ptr_container/doc/ptr_container.html#upgrading-from-boost-v-1-33 + */ +#if (BOOST_VERSION < 103400) + +template +typename PtrMapIter::pointer get_pointer(const PtrMapIter& i) +{ return &*i; } + +#else + +template +typename PtrMapIter::value_type::second_type get_pointer(const PtrMapIter& i) +{ return i->second; } + +#endif + +}} // namespace qpid::ptr_map + +#endif /*!QPID_PTR_MAP*/ -- cgit v1.2.1