/home/aconway/svn/qpid/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 <boost/cast.hpp>
00025 
00026 #include "amqp_types.h"
00027 #include "AMQBody.h"
00028 #include "AMQDataBlock.h"
00029 #include "AMQMethodBody.h"
00030 #include "AMQHeaderBody.h"
00031 #include "AMQContentBody.h"
00032 #include "AMQHeartbeatBody.h"
00033 #include "qpid/framing/AMQP_MethodVersionMap.h"
00034 #include "qpid/framing/AMQP_HighestVersion.h"
00035 #include "Buffer.h"
00036 
00037 namespace qpid {
00038 namespace framing {
00039 
00040         
00041 class AMQFrame : public AMQDataBlock
00042 {
00043   public:
00044     AMQFrame(ProtocolVersion _version = highestProtocolVersion);
00045     AMQFrame(ProtocolVersion _version, uint16_t channel, AMQBody* body);
00046     AMQFrame(ProtocolVersion _version, uint16_t channel, const AMQBody::shared_ptr& body);    
00047     virtual ~AMQFrame();
00048     virtual void encode(Buffer& buffer); 
00049     virtual bool decode(Buffer& buffer); 
00050     virtual uint32_t size() const;
00051     uint16_t getChannel();
00052     AMQBody::shared_ptr getBody();
00053 
00055     template <class T> boost::shared_ptr<T> castBody() {
00056         assert(dynamic_cast<T*>(getBody().get()));
00057         boost::static_pointer_cast<T>(getBody());
00058     }
00059 
00060     uint32_t decodeHead(Buffer& buffer); 
00061     void decodeBody(Buffer& buffer, uint32_t size); 
00062 
00063   private:
00064         static AMQP_MethodVersionMap versionMap;
00065     ProtocolVersion version;
00066             
00067     uint16_t channel;
00068     uint8_t type;
00069     AMQBody::shared_ptr body;
00070             
00071 
00072   friend std::ostream& operator<<(std::ostream& out, const AMQFrame& body);
00073 };
00074 
00075 }} // namespace qpid::framing
00076 
00077 
00078 #endif

Generated on Tue Apr 17 14:22:03 2007 for Qpid by  doxygen 1.4.7