Apache Qpid C++ API
Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation

qpid/framing/AMQFrame.h

Go to the documentation of this file.
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 
00033 namespace qpid {
00034 namespace framing {
00035 
00036 class AMQFrame : public AMQDataBlock, public sys::LatencyMetricTimestamp
00037 {
00038   public:
00039     AMQFrame(const boost::intrusive_ptr<AMQBody>& b=0);
00040     AMQFrame(const AMQBody& b);
00041     ~AMQFrame();
00042 
00043     ChannelId getChannel() const { return channel; }
00044     void setChannel(ChannelId c) { channel = c; }
00045 
00046     AMQBody* getBody();
00047     const AMQBody* getBody() const;
00048 
00049     AMQMethodBody* getMethod() { return getBody()->getMethod(); }
00050     const AMQMethodBody* getMethod() const { return getBody()->getMethod(); }
00051 
00052     void setMethod(ClassId c, MethodId m);
00053 
00054     template <class T> T* castBody() {
00055         return boost::polymorphic_downcast<T*>(getBody());
00056     }
00057 
00058     template <class T> const T* castBody() const {
00059         return boost::polymorphic_downcast<const T*>(getBody());
00060     }
00061 
00062     void encode(Buffer& buffer) const; 
00063     bool decode(Buffer& buffer); 
00064     uint32_t encodedSize() const;
00065 
00066     // 0-10 terminology: first/last frame (in segment) first/last segment (in assembly)
00067 
00068     bool isFirstSegment() const { return bof; }
00069     bool isLastSegment() const { return eof; }
00070     bool isFirstFrame() const { return bos; }
00071     bool isLastFrame() const { return eos; }
00072 
00073     void setFirstSegment(bool set=true) { bof = set; }
00074     void setLastSegment(bool set=true) { eof = set; }
00075     void setFirstFrame(bool set=true) { bos = set; }
00076     void setLastFrame(bool set=true) { eos = set; }
00077 
00078     // 0-9 terminology: beginning/end of frameset, beginning/end of segment.
00079 
00080     bool getBof() const { return bof; }
00081     void setBof(bool isBof) { bof = isBof; }
00082     bool getEof() const { return eof; }
00083     void setEof(bool isEof) { eof = isEof; }
00084 
00085     bool getBos() const { return bos; }
00086     void setBos(bool isBos) { bos = isBos; }
00087     bool getEos() const { return eos; }
00088     void setEos(bool isEos) { eos = isEos; }
00089 
00090     static uint16_t DECODE_SIZE_MIN;
00091     static uint32_t frameOverhead();
00093     static uint16_t decodeSize(char* data);
00094 
00095   private:
00096     void init();
00097 
00098     boost::intrusive_ptr<AMQBody> body;
00099     uint16_t channel : 16;
00100     uint8_t subchannel : 8;
00101     bool bof : 1;
00102     bool eof : 1;
00103     bool bos : 1;
00104     bool eos : 1;
00105     mutable uint32_t encodedSizeCache;
00106 };
00107 
00108 std::ostream& operator<<(std::ostream&, const AMQFrame&);
00109 
00110 }} // namespace qpid::framing
00111 
00112 
00113 #endif

Qpid C++ API Reference
Generated on Tue Dec 8 15:39:36 2009 for Qpid C++ Client API by doxygen 1.4.7