/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/amqp_0_10/FrameHeader.h

00001 #ifndef QPID_AMQP_0_10_FRAMEHEADER_H
00002 #define QPID_AMQP_0_10_FRAMEHEADER_H
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 
00025 #include "qpid/amqp_0_10/built_in_types.h"
00026 #include <boost/shared_array.hpp>
00027 #include <string.h>
00028 #include <assert.h>
00029 #include <iosfwd>
00030 
00031 namespace qpid {
00032 namespace amqp_0_10 {
00033 
00034 enum FrameFlags { FIRST_SEGMENT=8, LAST_SEGMENT=4, FIRST_FRAME=2, LAST_FRAME=1 };
00035 
00036 class FrameHeader {
00037   public:
00038     static const size_t SIZE=12;
00039     static uint8_t trackFor(SegmentType type) { return type == 0 ? 0 : 1; }
00040     
00041     FrameHeader(uint8_t flags_=0, SegmentType type_=SegmentType(), uint16_t size_=0, uint8_t track_=0, uint16_t channel_=0)
00042         : flags(flags_), type(type_), size(size_), track(track_), channel(channel_)
00043     {}
00044 
00045     uint8_t getFlags() const { return flags; }
00046     SegmentType getType() const { return type; }
00048     uint16_t getSize() const { return size; }
00050     uint16_t getDataSize() const { return size - SIZE; }
00051     uint8_t getTrack() const { return track; }
00052     uint16_t getChannel() const { return channel; }
00053 
00054     void setFlags(uint8_t flags_) { flags=flags_; }
00056     void setType(SegmentType type_)  { type=type_; track=trackFor(type); }
00058     void setSize(uint16_t size_) { size = size_; }
00060     void setDataSize(uint16_t size_) { size = size_+SIZE; }
00061     void setChannel(uint8_t channel_) { channel=channel_; }
00062 
00063     bool allFlags(uint8_t f) const { return (flags & f) == f; }
00064     bool anyFlags(uint8_t f) const { return (flags & f); }
00065 
00066     void raiseFlags(uint8_t f) { flags |= f; }
00067     void clearFlags(uint8_t f) { flags &= ~f; }
00068 
00069     bool isComplete() const { return allFlags(FIRST_FRAME | LAST_FRAME); }
00070 
00071     bool operator==(const FrameHeader&) const;
00072 
00073     template <class S> void serialize(S& s) {
00074         uint8_t pad8=0; uint32_t pad32=0;
00075         s(flags)(type)(size)(pad8)(track)(channel)(pad32);
00076     }
00077 
00078   private:
00079     uint8_t flags;
00080     SegmentType type;
00081     uint16_t size;
00082     uint8_t track;
00083     uint16_t channel;
00084 };
00085 
00086 std::ostream& operator<<(std::ostream&, const FrameHeader&);
00087 
00088 }} // namespace qpid::amqp_0_10
00089 
00090 #endif  

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