diff options
author | Alan Conway <aconway@apache.org> | 2009-04-23 11:48:32 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2009-04-23 11:48:32 +0000 |
commit | 98d144892f4214117881f5130e172a1ac74b03d5 (patch) | |
tree | d912907994bcc9cc2628e65402773cb8ec88f27e | |
parent | b2d4fade0cea9f415ffaed115c5fb9be5e78ff44 (diff) | |
download | qpid-python-98d144892f4214117881f5130e172a1ac74b03d5.tar.gz |
Apply PIMPL pattern to client::Completion and client::Future.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@767896 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/rubygen/framing.0-10/Session.rb | 3 | ||||
-rw-r--r-- | qpid/cpp/src/Makefile.am | 2 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/Completion.cpp | 38 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/Completion.h | 34 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/CompletionImpl.h | 50 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/Future.h | 13 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/SessionBase_0_10.cpp | 1 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/SessionBase_0_10.h | 1 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/client/TypedResult.h | 10 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/cluster/UpdateClient.cpp | 1 | ||||
-rw-r--r-- | qpid/cpp/src/tests/AsyncCompletion.cpp | 13 |
11 files changed, 131 insertions, 35 deletions
diff --git a/qpid/cpp/rubygen/framing.0-10/Session.rb b/qpid/cpp/rubygen/framing.0-10/Session.rb index 5abed07150..48a1608af0 100644 --- a/qpid/cpp/rubygen/framing.0-10/Session.rb +++ b/qpid/cpp/rubygen/framing.0-10/Session.rb @@ -163,6 +163,7 @@ class SessionNoKeywordGen < CppGen include "qpid/client/SessionImpl.h" include "qpid/client/MessageImpl.h" include "qpid/client/PrivateImplPrivate.h" + include "qpid/client/CompletionImpl.h" namespace(@namespace) { genl "using namespace framing;" session_methods(sync_default).each { |m| @@ -175,7 +176,7 @@ class SessionNoKeywordGen < CppGen genl "body.setSync(sync);" sendargs="body" sendargs << ", *privateImplGetPtr(content)" if m.content - async_retval="#{m.return_type(true)}(impl->send(#{sendargs}), impl)" + async_retval="#{m.return_type(true)}(new CompletionImpl(impl->send(#{sendargs}), impl))" if @async then genl "return #{async_retval};" else diff --git a/qpid/cpp/src/Makefile.am b/qpid/cpp/src/Makefile.am index 4436b507a1..ce6debd4d2 100644 --- a/qpid/cpp/src/Makefile.am +++ b/qpid/cpp/src/Makefile.am @@ -446,6 +446,8 @@ libqpidclient_la_SOURCES = \ qpid/client/FailoverListener.cpp \ qpid/client/Future.cpp \ qpid/client/FutureCompletion.cpp \ + qpid/client/Completion.cpp \ + qpid/client/CompletionImpl.h \ qpid/client/FutureResult.cpp \ qpid/client/HandlePrivate.h \ qpid/client/PrivateImplPrivate.h \ diff --git a/qpid/cpp/src/qpid/client/Completion.cpp b/qpid/cpp/src/qpid/client/Completion.cpp new file mode 100644 index 0000000000..e3676b2bde --- /dev/null +++ b/qpid/cpp/src/qpid/client/Completion.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 "Completion.h" +#include "CompletionImpl.h" +#include "HandlePrivate.h" + +namespace qpid { +namespace client { + +Completion::Completion(CompletionImpl* i) : Handle<CompletionImpl>(i) {} +Completion::~Completion() {} +Completion::Completion(const Completion& c) : Handle<CompletionImpl>(c.impl) {} +Completion& Completion::operator=(const Completion& c) { Handle<CompletionImpl>::operator=(c); return *this; } + +void Completion::wait() { impl->wait(); } +bool Completion::isComplete() { return impl->isComplete(); } +std::string Completion::getResult() { return impl->getResult(); } + +}} // namespace qpid::client diff --git a/qpid/cpp/src/qpid/client/Completion.h b/qpid/cpp/src/qpid/client/Completion.h index 5c5a0bb512..0b246b7765 100644 --- a/qpid/cpp/src/qpid/client/Completion.h +++ b/qpid/cpp/src/qpid/client/Completion.h @@ -22,13 +22,13 @@ #ifndef _Completion_ #define _Completion_ -#include <boost/shared_ptr.hpp> -#include "Future.h" +#include "Handle.h" +#include <string> namespace qpid { namespace client { -class SessionImpl; +class CompletionImpl; /** * Asynchronous commands that do not return a result will return a @@ -39,32 +39,26 @@ class SessionImpl; * *\ingroup clientapi */ -class Completion +class Completion : public Handle<CompletionImpl> { -protected: - Future future; - shared_ptr<SessionImpl> session; - public: ///@internal - Completion() {} - - ///@internal - Completion(Future f, shared_ptr<SessionImpl> s) : future(f), session(s) {} + QPID_CLIENT_EXTERN Completion(CompletionImpl* =0); + QPID_CLIENT_EXTERN ~Completion(); + QPID_CLIENT_EXTERN Completion(const Completion&); + QPID_CLIENT_EXTERN Completion& operator=(const Completion&); /** Wait for the asynchronous command that returned this *Completion to complete. * - *@exception If the command returns an error, get() throws an exception. + *@exception If the command returns an error. */ - void wait() - { - future.wait(*session); - } + QPID_CLIENT_EXTERN void wait(); + + QPID_CLIENT_EXTERN bool isComplete(); - bool isComplete() { - return future.isComplete(*session); - } + protected: + QPID_CLIENT_EXTERN std::string getResult(); }; }} diff --git a/qpid/cpp/src/qpid/client/CompletionImpl.h b/qpid/cpp/src/qpid/client/CompletionImpl.h new file mode 100644 index 0000000000..119abc093a --- /dev/null +++ b/qpid/cpp/src/qpid/client/CompletionImpl.h @@ -0,0 +1,50 @@ +#ifndef QPID_CLIENT_COMPLETIONIMPL_H +#define QPID_CLIENT_COMPLETIONIMPL_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/RefCounted.h" +#include "Future.h" + +namespace qpid { +namespace client { + +///@internal +class CompletionImpl : public RefCounted +{ +public: + CompletionImpl() {} + CompletionImpl(Future f, shared_ptr<SessionImpl> s) : future(f), session(s) {} + + bool isComplete() { return future.isComplete(*session); } + void wait() { future.wait(*session); } + std::string getResult() { return future.getResult(*session); } + +protected: + Future future; + shared_ptr<SessionImpl> session; +}; + +}} // namespace qpid::client + + +#endif /*!QPID_CLIENT_COMPLETIONIMPL_H*/ diff --git a/qpid/cpp/src/qpid/client/Future.h b/qpid/cpp/src/qpid/client/Future.h index b26af06348..28c9a2bbbd 100644 --- a/qpid/cpp/src/qpid/client/Future.h +++ b/qpid/cpp/src/qpid/client/Future.h @@ -26,7 +26,6 @@ #include <boost/shared_ptr.hpp> #include "qpid/Exception.h" #include "qpid/framing/SequenceNumber.h" -#include "qpid/framing/StructHelper.h" #include "FutureCompletion.h" #include "FutureResult.h" #include "ClientImportExport.h" @@ -35,7 +34,7 @@ namespace qpid { namespace client { /**@internal */ -class Future : private framing::StructHelper +class Future { framing::SequenceNumber command; boost::shared_ptr<FutureResult> result; @@ -45,13 +44,9 @@ public: Future() : complete(false) {} Future(const framing::SequenceNumber& id) : command(id), complete(false) {} - template <class T> void decodeResult(T& value, SessionImpl& session) - { - if (result) { - decode(value, result->getResult(session)); - } else { - throw Exception("Result not expected"); - } + std::string getResult(SessionImpl& session) { + if (result) return result->getResult(session); + else throw Exception("Result not expected"); } QPID_CLIENT_EXTERN void wait(SessionImpl& session); diff --git a/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp b/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp index 66878c7672..8a33c7393f 100644 --- a/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp +++ b/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp @@ -21,6 +21,7 @@ #include "SessionBase_0_10.h" #include "Connection.h" #include "qpid/client/SessionImpl.h" +#include "qpid/client/Future.h" #include "qpid/framing/all_method_bodies.h" namespace qpid { diff --git a/qpid/cpp/src/qpid/client/SessionBase_0_10.h b/qpid/cpp/src/qpid/client/SessionBase_0_10.h index a8c6ada5ae..d375b3ec2e 100644 --- a/qpid/cpp/src/qpid/client/SessionBase_0_10.h +++ b/qpid/cpp/src/qpid/client/SessionBase_0_10.h @@ -23,6 +23,7 @@ */ #include "qpid/SessionId.h" +#include "qpid/client/SessionImpl.h" #include "qpid/framing/amqp_structs.h" #include "qpid/client/Message.h" #include "qpid/client/Completion.h" diff --git a/qpid/cpp/src/qpid/client/TypedResult.h b/qpid/cpp/src/qpid/client/TypedResult.h index 5306997d74..2e54f9fdfc 100644 --- a/qpid/cpp/src/qpid/client/TypedResult.h +++ b/qpid/cpp/src/qpid/client/TypedResult.h @@ -23,6 +23,7 @@ #define _TypedResult_ #include "Completion.h" +#include "qpid/framing/StructHelper.h" namespace qpid { namespace client { @@ -39,7 +40,7 @@ template <class T> class TypedResult : public Completion public: ///@internal - TypedResult(Future f, shared_ptr<SessionImpl> s) : Completion(f, s), decoded(false) {} + TypedResult(CompletionImpl* c) : Completion(c), decoded(false) {} /** * Wait for the asynchronous command that returned this TypedResult to complete @@ -49,13 +50,12 @@ public: *@exception If the command returns an error, get() throws an exception. * */ - T& get() - { + T& get() { if (!decoded) { - future.decodeResult(result, *session); + framing::StructHelper helper; + helper.decode(result, getResult()); decoded = true; } - return result; } }; diff --git a/qpid/cpp/src/qpid/cluster/UpdateClient.cpp b/qpid/cpp/src/qpid/cluster/UpdateClient.cpp index 7efe84f2d7..bb4df8890a 100644 --- a/qpid/cpp/src/qpid/cluster/UpdateClient.cpp +++ b/qpid/cpp/src/qpid/cluster/UpdateClient.cpp @@ -28,6 +28,7 @@ #include "qpid/client/ConnectionAccess.h" #include "qpid/client/SessionImpl.h" #include "qpid/client/ConnectionImpl.h" +#include "qpid/client/Future.h" #include "qpid/broker/Broker.h" #include "qpid/broker/Queue.h" #include "qpid/broker/QueueRegistry.h" diff --git a/qpid/cpp/src/tests/AsyncCompletion.cpp b/qpid/cpp/src/tests/AsyncCompletion.cpp index e33b2dc35d..81189bca93 100644 --- a/qpid/cpp/src/tests/AsyncCompletion.cpp +++ b/qpid/cpp/src/tests/AsyncCompletion.cpp @@ -24,6 +24,8 @@ #include "qpid/sys/BlockingQueue.h" #include "qpid/client/AsyncSession.h" #include "qpid/sys/Time.h" +#include "qpid/framing/QueueQueryResult.h" +#include "qpid/client/TypedResult.h" using namespace std; using namespace qpid; @@ -97,4 +99,15 @@ QPID_AUTO_TEST_CASE(testWaitTillComplete) { sync.wait(); // Should complete now, all messages are completed. } +QPID_AUTO_TEST_CASE(testGetResult) { + SessionFixture fix; + AsyncSession s = fix.session; + + s.queueDeclare("q", arg::durable=true); + TypedResult<QueueQueryResult> tr = s.queueQuery("q"); + QueueQueryResult qq = tr.get(); + BOOST_CHECK_EQUAL(qq.getQueue(), "q"); + BOOST_CHECK_EQUAL(qq.getMessageCount(), 0); +} + QPID_AUTO_TEST_SUITE_END() |