summaryrefslogtreecommitdiff
path: root/cpp/lib/common
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2007-02-02 22:03:10 +0000
committerAlan Conway <aconway@apache.org>2007-02-02 22:03:10 +0000
commitb5c270f10496f522ef6a03a8fa60f85d55c9187d (patch)
tree714e7abf7ba591d00232d821440e51461175cb9e /cpp/lib/common
parent750f272ac99e8c830807affb3ae68ab0beeca63f (diff)
downloadqpid-python-b5c270f10496f522ef6a03a8fa60f85d55c9187d.tar.gz
* cpp/lib/common/framing/MethodContext.h: Reduced MethodContext to
ChannelAdapter and Method Body. Request ID comes from body, ChannelAdapter is used to send frames, not OutputHandler. * cpp/lib/common/framing/ChannelAdapter.h,.cpp: Removed context member. Context is per-method not per-channel. * cpp/lib/broker/*: Replace direct use of OutputHandler and ChannelId with MethodContext (for responses) or ChannelAdapter (for requests.) Use context request-ID to construct responses, send all bodies via ChannelAdapter. * cpp/lib/broker/BrokerAdapter.cpp: Link broker::Channel to BrokerAdapter. * cpp/lib/broker/*: Remove unnecessary ProtocolVersion parameters. Fix bogus signatures: ProtocolVersion* -> const ProtocolVersion& * Cosmetic changes, many files: - fixed indentation, broke long lines. - removed unnecessary qpid:: prefixes. * broker/BrokerAdapter,BrokerChannel: Merged BrokerAdapter into broker::channel. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@502767 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/lib/common')
-rw-r--r--cpp/lib/common/framing/AMQMethodBody.cpp4
-rw-r--r--cpp/lib/common/framing/AMQMethodBody.h7
-rw-r--r--cpp/lib/common/framing/AMQRequestBody.h2
-rw-r--r--cpp/lib/common/framing/AMQResponseBody.cpp7
-rw-r--r--cpp/lib/common/framing/AMQResponseBody.h8
-rw-r--r--cpp/lib/common/framing/ChannelAdapter.cpp16
-rw-r--r--cpp/lib/common/framing/ChannelAdapter.h21
-rw-r--r--cpp/lib/common/framing/MethodContext.h59
-rw-r--r--cpp/lib/common/framing/ProtocolVersion.cpp5
9 files changed, 45 insertions, 84 deletions
diff --git a/cpp/lib/common/framing/AMQMethodBody.cpp b/cpp/lib/common/framing/AMQMethodBody.cpp
index 17138a401e..ab1e15f845 100644
--- a/cpp/lib/common/framing/AMQMethodBody.cpp
+++ b/cpp/lib/common/framing/AMQMethodBody.cpp
@@ -56,8 +56,4 @@ void AMQMethodBody::decode(Buffer& buffer, u_int32_t /*size*/) {
decodeContent(buffer);
}
-void AMQMethodBody::send(const MethodContext& context) {
- context.out->send(new AMQFrame(version, context.channelId, this));
-}
-
}} // namespace qpid::framing
diff --git a/cpp/lib/common/framing/AMQMethodBody.h b/cpp/lib/common/framing/AMQMethodBody.h
index b21ae379dc..492571c83c 100644
--- a/cpp/lib/common/framing/AMQMethodBody.h
+++ b/cpp/lib/common/framing/AMQMethodBody.h
@@ -57,11 +57,8 @@ class AMQMethodBody : public AMQBody
return amqpClassId()==T::CLASS_ID && amqpMethodId()==T::METHOD_ID;
}
- /**
- * Wrap this method in a frame and send using the current context.
- * Note the frame takes ownership of the body, it will be deleted.
- */
- virtual void send(const MethodContext& context);
+ /** Return request ID or response correlationID */
+ virtual RequestId getRequestId() const { return 0; }
protected:
static u_int32_t baseSize() { return 4; }
diff --git a/cpp/lib/common/framing/AMQRequestBody.h b/cpp/lib/common/framing/AMQRequestBody.h
index 390fe77881..9b8fc1d663 100644
--- a/cpp/lib/common/framing/AMQRequestBody.h
+++ b/cpp/lib/common/framing/AMQRequestBody.h
@@ -58,8 +58,8 @@ class AMQRequestBody : public AMQMethodBody
Data& getData() { return data; }
RequestId getRequestId() const { return data.requestId; }
- void setRequestId(RequestId id) { data.requestId=id; }
ResponseId getResponseMark() const { return data.responseMark; }
+ void setRequestId(RequestId id) { data.requestId=id; }
void setResponseMark(ResponseId mark) { data.responseMark=mark; }
protected:
diff --git a/cpp/lib/common/framing/AMQResponseBody.cpp b/cpp/lib/common/framing/AMQResponseBody.cpp
index da70e24cd4..7da71a5d25 100644
--- a/cpp/lib/common/framing/AMQResponseBody.cpp
+++ b/cpp/lib/common/framing/AMQResponseBody.cpp
@@ -62,11 +62,4 @@ void AMQResponseBody::printPrefix(std::ostream& out) const {
<< ",batch=" << data.batchOffset << "): ";
}
-void AMQResponseBody::send(const MethodContext& context) {
- setRequestId(context.requestId);
- assert(context.out);
- context.out->send(
- new AMQFrame(version, context.channelId, this));
-}
-
}} // namespace qpid::framing
diff --git a/cpp/lib/common/framing/AMQResponseBody.h b/cpp/lib/common/framing/AMQResponseBody.h
index 2520a481f2..3954836ec8 100644
--- a/cpp/lib/common/framing/AMQResponseBody.h
+++ b/cpp/lib/common/framing/AMQResponseBody.h
@@ -62,15 +62,13 @@ class AMQResponseBody : public AMQMethodBody
void encode(Buffer& buffer) const;
Data& getData() { return data; }
- ResponseId getResponseId() { return data.responseId; }
- RequestId getRequestId() { return data.requestId; }
- BatchOffset getBatchOffset() { return data.batchOffset; }
+ ResponseId getResponseId() const { return data.responseId; }
+ RequestId getRequestId() const { return data.requestId; }
+ BatchOffset getBatchOffset() const { return data.batchOffset; }
void setResponseId(ResponseId id) { data.responseId = id; }
void setRequestId(RequestId id) { data.requestId = id; }
void setBatchOffset(BatchOffset id) { data.batchOffset = id; }
- virtual void send(const MethodContext& context);
-
protected:
static const u_int32_t baseSize() { return AMQMethodBody::baseSize()+20; }
void printPrefix(std::ostream& out) const;
diff --git a/cpp/lib/common/framing/ChannelAdapter.cpp b/cpp/lib/common/framing/ChannelAdapter.cpp
index 225e5e3393..149c8144b4 100644
--- a/cpp/lib/common/framing/ChannelAdapter.cpp
+++ b/cpp/lib/common/framing/ChannelAdapter.cpp
@@ -32,12 +32,10 @@ void ChannelAdapter::init(
id = i;
out = &o;
version = v;
- context = MethodContext(id, this);
}
-void ChannelAdapter::send(AMQFrame* frame) {
+void ChannelAdapter::send(AMQBody::shared_ptr body) {
assertChannelOpen();
- AMQBody::shared_ptr body = frame->getBody();
switch (body->type()) {
case REQUEST_BODY: {
AMQRequestBody::shared_ptr request =
@@ -52,18 +50,13 @@ void ChannelAdapter::send(AMQFrame* frame) {
break;
}
}
- out->send(frame);
-}
-
-void ChannelAdapter::send(AMQBody::shared_ptr body) {
- send(new AMQFrame(getVersion(), getId(), body));
+ out->send(new AMQFrame(getVersion(), getId(), body));
}
void ChannelAdapter::handleRequest(AMQRequestBody::shared_ptr request) {
assertMethodOk(*request);
responder.received(request->getData());
- context =MethodContext(id, request, this, request->getRequestId());
- handleMethodInContext(request, context);
+ handleMethodInContext(request, MethodContext(this, request));
}
void ChannelAdapter::handleResponse(AMQResponseBody::shared_ptr response) {
@@ -76,8 +69,7 @@ void ChannelAdapter::handleResponse(AMQResponseBody::shared_ptr response) {
void ChannelAdapter::handleMethod(AMQMethodBody::shared_ptr method) {
assertMethodOk(*method);
- context = MethodContext(id, method, this);
- handleMethodInContext(method, context);
+ handleMethodInContext(method, MethodContext(this, method));
}
void ChannelAdapter::assertMethodOk(AMQMethodBody& method) const {
diff --git a/cpp/lib/common/framing/ChannelAdapter.h b/cpp/lib/common/framing/ChannelAdapter.h
index f0b3d2469a..26cac76aae 100644
--- a/cpp/lib/common/framing/ChannelAdapter.h
+++ b/cpp/lib/common/framing/ChannelAdapter.h
@@ -27,7 +27,7 @@
#include "BodyHandler.h"
#include "Requester.h"
#include "Responder.h"
-#include "OutputHandler.h"
+#include "framing/amqp_types.h"
namespace qpid {
namespace framing {
@@ -37,24 +37,26 @@ class MethodContext;
/**
* Base class for client and broker channel adapters.
*
- * As BodyHandler:
+ * BodyHandler::handl*
* - receives frame bodies from the network.
* - Updates request/response data.
* - Dispatches requests with a MethodContext for responses.
*
- * As OutputHandler:
+ * send()
* - Updates request/resposne ID data.
* - Forwards frame to the peer.
*
* Thread safety: OBJECT UNSAFE. Instances must not be called
* concurrently. AMQP defines channels to be serialized.
*/
-class ChannelAdapter : public BodyHandler, public OutputHandler {
+class ChannelAdapter : public BodyHandler {
public:
/**
*@param output Processed frames are forwarded to this handler.
*/
- ChannelAdapter() : context(0, 0), id(0), out(0) {}
+ ChannelAdapter(ChannelId id_=0, OutputHandler* out_=0,
+ const ProtocolVersion& ver=ProtocolVersion())
+ : id(id_), out(out_), version(ver) {}
/** Initialize the channel adapter. */
void init(ChannelId, OutputHandler&, const ProtocolVersion&);
@@ -63,12 +65,6 @@ class ChannelAdapter : public BodyHandler, public OutputHandler {
const ProtocolVersion& getVersion() const { return version; }
/**
- * Do request/response-id processing and then forward to
- * handler provided to constructor. Response frames should
- * have their request-id set before calling send.
- */
- void send(AMQFrame* frame);
- /**
* Wrap body in a frame and send the frame.
* Takes ownership of body.
*/
@@ -92,9 +88,6 @@ class ChannelAdapter : public BodyHandler, public OutputHandler {
RequestId getRequestInProgress() { return requestInProgress; }
- protected:
- MethodContext context;
-
private:
ChannelId id;
OutputHandler* out;
diff --git a/cpp/lib/common/framing/MethodContext.h b/cpp/lib/common/framing/MethodContext.h
index 454025e377..d9717d90a0 100644
--- a/cpp/lib/common/framing/MethodContext.h
+++ b/cpp/lib/common/framing/MethodContext.h
@@ -19,6 +19,8 @@
*
*/
+#include <boost/shared_ptr.hpp>
+
#include "OutputHandler.h"
#include "ProtocolVersion.h"
@@ -29,54 +31,41 @@ namespace framing {
class BodyHandler;
class AMQMethodBody;
+class ChannelAdapter;
/**
* Invocation context for an AMQP method.
- * Some of the context information is related to the channel, some
- * to the specific invocation - e.g. requestId.
- *
- * All generated proxy and handler functions take a MethodContext parameter.
*
- * The user does not need to create MethodContext objects explicitly,
- * the constructor will implicitly create one from a channel ID.
- *
- * Other context members are for internal use.
+ * It provides the method being processed and the channel on which
+ * it arrived.
+ *
+ * All Handler functions take a MethodContext as the last parameter.
*/
struct MethodContext
{
- /**
- * Passing a integer channel-id in place of a MethodContext
- * will automatically construct the MethodContext.
- */
- MethodContext(ChannelId channel,
- OutputHandler* output=0, RequestId request=0)
- : channelId(channel), out(output), requestId(request)
- {}
-
- MethodContext(ChannelId channel,
- boost::shared_ptr<AMQMethodBody> method,
- OutputHandler* output=0, RequestId request=0)
- : channelId(channel), out(output), requestId(request),
- methodBody(method)
- {}
-
- /** \internal Channel on which the method is sent. */
- ChannelId channelId;
+ typedef boost::shared_ptr<AMQMethodBody> BodyPtr;
- /** Output handler for responses in this context */
- OutputHandler* out;
+ MethodContext(ChannelAdapter* ch=0, BodyPtr method=BodyPtr())
+ : channel(ch), methodBody(method) {}
- /** \internal If we are in the context of processing an incoming request,
- * this is the ID. Otherwise it is 0.
- */
- RequestId requestId;
+ /**
+ * Channel on which the method being processed arrived.
+ * 0 if the method was constructed by the caller
+ * rather than received from a channel.
+ */
+ ChannelAdapter* channel;
- /** \internal This is the Method Body itself
- * It's useful for passing around instead of unpacking all its parameters
+ /**
+ * Body of the method being processed.
+ * It's useful for passing around instead of unpacking all its parameters.
+ * It's also provides the request ID when constructing a response.
*/
- boost::shared_ptr<AMQMethodBody> methodBody;
+ BodyPtr methodBody;
};
+// FIXME aconway 2007-02-01: Method context only required on Handler
+// functions, not on Proxy functions.
+
}} // namespace qpid::framing
diff --git a/cpp/lib/common/framing/ProtocolVersion.cpp b/cpp/lib/common/framing/ProtocolVersion.cpp
index 69ff89ec32..e65c8b79b8 100644
--- a/cpp/lib/common/framing/ProtocolVersion.cpp
+++ b/cpp/lib/common/framing/ProtocolVersion.cpp
@@ -20,10 +20,13 @@
*/
#include <ProtocolVersion.h>
#include <sstream>
+#include "AMQP_HighestVersion.h"
using namespace qpid::framing;
-ProtocolVersion::ProtocolVersion() {}
+ProtocolVersion::ProtocolVersion() {
+ *this = highestProtocolVersion;
+}
ProtocolVersion::ProtocolVersion(u_int8_t _major, u_int8_t _minor) :
major_(_major),