/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/framing/AMQFrame.h

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 "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     bool getBof() const { return bof; }
00084     void setBof(bool isBof) { bof = isBof; }
00085     bool getEof() const { return eof; }
00086     void setEof(bool isEof) { eof = isEof; }
00087 
00088     bool getBos() const { return bos; }
00089     void setBos(bool isBos) { bos = isBos; }
00090     bool getEos() const { return eos; }
00091     void setEos(bool isEos) { eos = isEos; }
00092 
00093     static uint32_t frameOverhead();
00094 
00095   private:
00096     void init() { bof = eof = bos = eos = true; subchannel=0; channel=0; }
00097 
00098     boost::intrusive_ptr<BodyHolder> 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 };
00106 
00107 std::ostream& operator<<(std::ostream&, const AMQFrame&);
00108 
00109 }} // namespace qpid::framing
00110 
00111 
00112 #endif

Generated on Thu Apr 10 11:08:18 2008 for Qpid by  doxygen 1.4.7