Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
00001 #ifndef _AMQFrame_ 00002 #define _AMQFrame_ 00003 00004 /* 00005 * 00006 * Licensed to the Apache Software Foundation (ASF) under one 00007 * or more contributor license agreements. See the NOTICE file 00008 * distributed with this work for additional information 00009 * regarding copyright ownership. The ASF licenses this file 00010 * to you under the Apache License, Version 2.0 (the 00011 * "License"); you may not use this file except in compliance 00012 * with the License. You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, 00017 * software distributed under the License is distributed on an 00018 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 00019 * KIND, either express or implied. See the License for the 00020 * specific language governing permissions and limitations 00021 * under the License. 00022 * 00023 */ 00024 #include "AMQDataBlock.h" 00025 #include "AMQHeaderBody.h" 00026 #include "AMQContentBody.h" 00027 #include "AMQHeartbeatBody.h" 00028 #include "ProtocolVersion.h" 00029 #include "qpid/sys/LatencyMetric.h" 00030 #include <boost/intrusive_ptr.hpp> 00031 #include <boost/cast.hpp> 00032 #include "qpid/CommonImportExport.h" 00033 00034 namespace qpid { 00035 namespace framing { 00036 00037 class AMQFrame : public AMQDataBlock, public sys::LatencyMetricTimestamp 00038 { 00039 public: 00040 QPID_COMMON_EXTERN AMQFrame(const boost::intrusive_ptr<AMQBody>& b=0); 00041 QPID_COMMON_EXTERN AMQFrame(const AMQBody& b); 00042 QPID_COMMON_EXTERN ~AMQFrame(); 00043 00044 ChannelId getChannel() const { return channel; } 00045 void setChannel(ChannelId c) { channel = c; } 00046 00047 QPID_COMMON_EXTERN AMQBody* getBody(); 00048 QPID_COMMON_EXTERN const AMQBody* getBody() const; 00049 00050 AMQMethodBody* getMethod() { return getBody()->getMethod(); } 00051 const AMQMethodBody* getMethod() const { return getBody()->getMethod(); } 00052 00053 void setMethod(ClassId c, MethodId m); 00054 00055 template <class T> T* castBody() { 00056 return boost::polymorphic_downcast<T*>(getBody()); 00057 } 00058 00059 template <class T> const T* castBody() const { 00060 return boost::polymorphic_downcast<const T*>(getBody()); 00061 } 00062 00063 QPID_COMMON_EXTERN void encode(Buffer& buffer) const; 00064 QPID_COMMON_EXTERN bool decode(Buffer& buffer); 00065 QPID_COMMON_EXTERN uint32_t encodedSize() const; 00066 00067 // 0-10 terminology: first/last frame (in segment) first/last segment (in assembly) 00068 00069 bool isFirstSegment() const { return bof; } 00070 bool isLastSegment() const { return eof; } 00071 bool isFirstFrame() const { return bos; } 00072 bool isLastFrame() const { return eos; } 00073 00074 void setFirstSegment(bool set=true) { bof = set; } 00075 void setLastSegment(bool set=true) { eof = set; } 00076 void setFirstFrame(bool set=true) { bos = set; } 00077 void setLastFrame(bool set=true) { eos = set; } 00078 00079 // 0-9 terminology: beginning/end of frameset, beginning/end of segment. 00080 00081 bool getBof() const { return bof; } 00082 void setBof(bool isBof) { bof = isBof; } 00083 bool getEof() const { return eof; } 00084 void setEof(bool isEof) { eof = isEof; } 00085 00086 bool getBos() const { return bos; } 00087 void setBos(bool isBos) { bos = isBos; } 00088 bool getEos() const { return eos; } 00089 void setEos(bool isEos) { eos = isEos; } 00090 00091 static uint16_t DECODE_SIZE_MIN; 00092 QPID_COMMON_EXTERN static uint32_t frameOverhead(); 00094 static uint16_t decodeSize(char* data); 00095 00096 private: 00097 void init(); 00098 00099 boost::intrusive_ptr<AMQBody> body; 00100 uint16_t channel : 16; 00101 uint8_t subchannel : 8; 00102 bool bof : 1; 00103 bool eof : 1; 00104 bool bos : 1; 00105 bool eos : 1; 00106 mutable uint32_t encodedSizeCache; 00107 }; 00108 00109 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream&, const AMQFrame&); 00110 00111 }} // namespace qpid::framing 00112 00113 00114 #endif