Author: aconway
Date: Thu Apr 23 11:48:32 2009
New Revision: 767896
URL: http://svn.apache.org/viewvc?rev=767896&view=rev
Log:
Apply PIMPL pattern to client::Completion and client::Future.
Added:
qpid/trunk/qpid/cpp/src/qpid/client/Completion.cpp (with props)
qpid/trunk/qpid/cpp/src/qpid/client/CompletionImpl.h (with props)
Modified:
qpid/trunk/qpid/cpp/rubygen/framing.0-10/Session.rb
qpid/trunk/qpid/cpp/src/Makefile.am
qpid/trunk/qpid/cpp/src/qpid/client/Completion.h
qpid/trunk/qpid/cpp/src/qpid/client/Future.h
qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp
qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.h
qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h
qpid/trunk/qpid/cpp/src/qpid/cluster/UpdateClient.cpp
qpid/trunk/qpid/cpp/src/tests/AsyncCompletion.cpp
Modified: qpid/trunk/qpid/cpp/rubygen/framing.0-10/Session.rb
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/rubygen/framing.0-10/Session.rb?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/rubygen/framing.0-10/Session.rb (original)
+++ qpid/trunk/qpid/cpp/rubygen/framing.0-10/Session.rb Thu Apr 23 11:48:32 2009
@@ -163,6 +163,7 @@
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 @@
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
Modified: qpid/trunk/qpid/cpp/src/Makefile.am
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/Makefile.am?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/src/Makefile.am Thu Apr 23 11:48:32 2009
@@ -446,6 +446,8 @@
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 \
Added: qpid/trunk/qpid/cpp/src/qpid/client/Completion.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/Completion.cpp?rev=767896&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/Completion.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/client/Completion.cpp Thu Apr 23 11:48:32 2009
@@ -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
Propchange: qpid/trunk/qpid/cpp/src/qpid/client/Completion.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/src/qpid/client/Completion.cpp
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: qpid/trunk/qpid/cpp/src/qpid/client/Completion.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/Completion.h?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/Completion.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/Completion.h Thu Apr 23 11:48:32 2009
@@ -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 @@
*
*\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);
- }
-
- bool isComplete() {
- return future.isComplete(*session);
- }
+ QPID_CLIENT_EXTERN void wait();
+
+ QPID_CLIENT_EXTERN bool isComplete();
+
+ protected:
+ QPID_CLIENT_EXTERN std::string getResult();
};
}}
Added: qpid/trunk/qpid/cpp/src/qpid/client/CompletionImpl.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/CompletionImpl.h?rev=767896&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/CompletionImpl.h (added)
+++ qpid/trunk/qpid/cpp/src/qpid/client/CompletionImpl.h Thu Apr 23 11:48:32
2009
@@ -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*/
Propchange: qpid/trunk/qpid/cpp/src/qpid/client/CompletionImpl.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/trunk/qpid/cpp/src/qpid/client/CompletionImpl.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: qpid/trunk/qpid/cpp/src/qpid/client/Future.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/Future.h?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/Future.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/Future.h Thu Apr 23 11:48:32 2009
@@ -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 client {
/*...@internal */
-class Future : private framing::StructHelper
+class Future
{
framing::SequenceNumber command;
boost::shared_ptr<FutureResult> result;
@@ -45,13 +44,9 @@
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);
Modified: qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.cpp Thu Apr 23
11:48:32 2009
@@ -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 {
Modified: qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.h?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/SessionBase_0_10.h Thu Apr 23 11:48:32
2009
@@ -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"
Modified: qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/TypedResult.h Thu Apr 23 11:48:32 2009
@@ -23,6 +23,7 @@
#define _TypedResult_
#include "Completion.h"
+#include "qpid/framing/StructHelper.h"
namespace qpid {
namespace client {
@@ -39,7 +40,7 @@
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 @@
*...@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;
}
};
Modified: qpid/trunk/qpid/cpp/src/qpid/cluster/UpdateClient.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/UpdateClient.cpp?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/UpdateClient.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/UpdateClient.cpp Thu Apr 23 11:48:32
2009
@@ -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"
Modified: qpid/trunk/qpid/cpp/src/tests/AsyncCompletion.cpp
URL:
http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/AsyncCompletion.cpp?rev=767896&r1=767895&r2=767896&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/AsyncCompletion.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/AsyncCompletion.cpp Thu Apr 23 11:48:32 2009
@@ -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 @@
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()
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]