00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef qpid_framing_BasicPublishBody__
00029 #define qpid_framing_BasicPublishBody__
00030
00031 #include <string>
00032 #include <sstream>
00033
00034 #include <amqp_types.h>
00035 #include <AMQMethodBody.h>
00036 #include <Buffer.h>
00037 #include <FieldTable.h>
00038
00039 namespace qpid
00040 {
00041 namespace framing
00042 {
00043
00044
00045 class BasicPublishBody : public AMQMethodBody
00046 {
00047
00048
00049 u_int16_t ticket;
00050 string exchange;
00051 string routingKey;
00052 bool mandatory;
00053 bool immediate;
00054
00055
00056 public:
00057 typedef boost::shared_ptr<BasicPublishBody> shared_ptr;
00058
00059
00060
00061 BasicPublishBody(ProtocolVersion& version,
00062 u_int16_t ticket,
00063 const string& exchange,
00064 const string& routingKey,
00065 bool mandatory,
00066 bool immediate
00067 ) :
00068 AMQMethodBody(version),
00069 ticket(ticket),
00070 exchange(exchange),
00071 routingKey(routingKey),
00072 mandatory(mandatory),
00073 immediate(immediate)
00074 { }
00075
00076
00077 inline BasicPublishBody(u_int8_t major, u_int8_t minor): AMQMethodBody(major, minor) {}
00078 inline BasicPublishBody(ProtocolVersion& version): AMQMethodBody(version) {}
00079 virtual ~BasicPublishBody() {}
00080
00081
00082
00083 inline u_int16_t getTicket() { return ticket; }
00084 inline const string& getExchange() { return exchange; }
00085 inline const string& getRoutingKey() { return routingKey; }
00086 inline bool getMandatory() { return mandatory; }
00087 inline bool getImmediate() { return immediate; }
00088
00089
00090
00091 inline void print(std::ostream& out) const
00092 {
00093 out << "BasicPublish: ";
00094 out << "ticket=" << ticket;
00095 out << "; exchange=" << exchange;
00096 out << "; routingKey=" << routingKey;
00097 out << "; mandatory=" << mandatory;
00098 out << "; immediate=" << immediate;
00099 }
00100
00101 inline u_int16_t amqpClassId() const
00102 {
00103 return 60;
00104 }
00105
00106 inline u_int16_t amqpMethodId() const
00107 {
00108 return 40;
00109 }
00110
00111 inline u_int32_t bodySize() const
00112 {
00113 u_int32_t size = 0;
00114 size += 2;
00115 size += 1 + exchange.length();
00116 size += 1 + routingKey.length();
00117 size += 1;
00118 return size;
00119 }
00120
00121 inline void encodeContent(Buffer& buffer) const
00122 {
00123 buffer.putShort(ticket);
00124 buffer.putShortString(exchange);
00125 buffer.putShortString(routingKey);
00126 u_int8_t flags_4[1] = {0};
00127 flags_4[0] |= mandatory << 0;
00128 flags_4[0] |= immediate << 1;
00129 buffer.putOctet(flags_4[0]);
00130 }
00131
00132 inline void decodeContent(Buffer& buffer)
00133 {
00134 ticket = buffer.getShort();
00135 buffer.getShortString(exchange);
00136 buffer.getShortString(routingKey);
00137 u_int8_t flags_4[1];
00138 flags_4[0] = buffer.getOctet();
00139 mandatory = (1 << 0) & flags_4[0];
00140 immediate = (1 << 1) & flags_4[0];
00141 }
00142
00143 inline void invoke(AMQP_ServerOperations& target, u_int16_t channel)
00144 {
00145 target.getBasicHandler()->publish(channel,
00146 ticket,
00147 exchange,
00148 routingKey,
00149 mandatory,
00150 immediate
00151 );
00152 }
00153
00154
00155 };
00156
00157
00158 }
00159 }
00160
00161 #endif
00162