00001 #ifndef _AMQFrame_
00002 #define _AMQFrame_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "AMQDataBlock.h"
00025 #include "AMQHeaderBody.h"
00026 #include "AMQContentBody.h"
00027 #include "AMQHeartbeatBody.h"
00028 #include "ProtocolVersion.h"
00029 #include "BodyHolder.h"
00030
00031 #include <boost/intrusive_ptr.hpp>
00032 #include <boost/cast.hpp>
00033
00034 namespace qpid {
00035 namespace framing {
00036
00037 class BodyHolder;
00038
00039 class AMQFrame : public AMQDataBlock
00040 {
00041 public:
00042 AMQFrame(boost::intrusive_ptr<BodyHolder> b=0) : body(b) { init(); }
00043 AMQFrame(const AMQBody& b) { setBody(b); init(); }
00044 ~AMQFrame();
00045
00046 template <class InPlace>
00047 AMQFrame(const InPlace& ip, typename EnableInPlace<InPlace>::type* =0) {
00048 init(); setBody(ip);
00049 }
00050
00051 ChannelId getChannel() const { return channel; }
00052 void setChannel(ChannelId c) { channel = c; }
00053
00054 boost::intrusive_ptr<BodyHolder> getHolder() { return body; }
00055
00056 AMQBody* getBody() { return body ? body->get() : 0; }
00057 const AMQBody* getBody() const { return body ? body->get() : 0; }
00058
00059 AMQMethodBody* getMethod() { return getBody()->getMethod(); }
00060 const AMQMethodBody* getMethod() const { return getBody()->getMethod(); }
00061
00062 void setBody(const AMQBody& b);
00063
00064 template <class InPlace>
00065 typename EnableInPlace<InPlace>::type setBody(const InPlace& ip) {
00066 body = new BodyHolder(ip);
00067 }
00068
00069 void setMethod(ClassId c, MethodId m);
00070
00071 template <class T> T* castBody() {
00072 return boost::polymorphic_downcast<T*>(getBody());
00073 }
00074
00075 template <class T> const T* castBody() const {
00076 return boost::polymorphic_downcast<const T*>(getBody());
00077 }
00078
00079 void encode(Buffer& buffer) const;
00080 bool decode(Buffer& buffer);
00081 uint32_t size() const;
00082
00083
00084
00085 bool isFirstSegment() const { return bof; }
00086 bool isLastSegment() const { return eof; }
00087 bool isFirstFrame() const { return bos; }
00088 bool isLastFrame() const { return eos; }
00089
00090 void setFirstSegment(bool set=true) { bof = set; }
00091 void setLastSegment(bool set=true) { eof = set; }
00092 void setFirstFrame(bool set=true) { bos = set; }
00093 void setLastFrame(bool set=true) { eos = set; }
00094
00095
00096
00097 bool getBof() const { return bof; }
00098 void setBof(bool isBof) { bof = isBof; }
00099 bool getEof() const { return eof; }
00100 void setEof(bool isEof) { eof = isEof; }
00101
00102 bool getBos() const { return bos; }
00103 void setBos(bool isBos) { bos = isBos; }
00104 bool getEos() const { return eos; }
00105 void setEos(bool isEos) { eos = isEos; }
00106
00107 static uint32_t frameOverhead();
00108 private:
00109 void init() { bof = eof = bos = eos = true; subchannel=0; channel=0; }
00110
00111 boost::intrusive_ptr<BodyHolder> body;
00112 uint16_t channel : 16;
00113 uint8_t subchannel : 8;
00114 bool bof : 1;
00115 bool eof : 1;
00116 bool bos : 1;
00117 bool eos : 1;
00118 };
00119
00120 std::ostream& operator<<(std::ostream&, const AMQFrame&);
00121
00122 }}
00123
00124
00125 #endif