/usr/share/cruisecontrol-bin-2.6.1/projects/qpid-trunk/cpp/src/qpid/client/Message.h

00001 #ifndef _client_Message_h
00002 #define _client_Message_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 #include <string>
00025 #include "qpid/client/Session.h"
00026 #include "qpid/framing/MessageTransferBody.h"
00027 #include "qpid/framing/TransferContent.h"
00028 
00029 namespace qpid {
00030 namespace client {
00031 
00038 class Message : public framing::TransferContent 
00039 {
00040 public:
00041     Message(const std::string& data_=std::string(),
00042             const std::string& routingKey=std::string(),
00043             const std::string& exchange=std::string()
00044     ) : TransferContent(data_, routingKey, exchange) {}
00045 
00046     std::string getDestination() const 
00047     { 
00048         return method.getDestination(); 
00049     }
00050 
00051     bool isRedelivered() const 
00052     { 
00053         return hasDeliveryProperties() && getDeliveryProperties().getRedelivered(); 
00054     }
00055 
00056     void setRedelivered(bool redelivered) 
00057     { 
00058         getDeliveryProperties().setRedelivered(redelivered); 
00059     }
00060 
00061     framing::FieldTable& getHeaders() 
00062     { 
00063         return getMessageProperties().getApplicationHeaders(); 
00064     }
00065 
00066     void acknowledge(Session& session, bool cumulative = true, bool send = true) const
00067     {
00068         session.getExecution().completed(id, cumulative, send);
00069     }
00070 
00071     void acknowledge(bool cumulative = true, bool send = true) const
00072     {
00073         const_cast<Session&>(session).getExecution().completed(id, cumulative, send);
00074     }
00075 
00077     Message(const framing::FrameSet& frameset, Session s) :
00078         method(*frameset.as<framing::MessageTransferBody>()), id(frameset.getId()), session(s)
00079     {
00080         populate(frameset);
00081     }
00082 
00083     const framing::MessageTransferBody& getMethod() const
00084     {
00085         return method;
00086     }
00087 
00088     const framing::SequenceNumber& getId() const
00089     {
00090         return id;
00091     }
00092 
00094     void setSession(Session s) { session=s; }
00095 private:
00096     //method and id are only set for received messages:
00097     framing::MessageTransferBody method;
00098     framing::SequenceNumber id;
00099     Session session;
00100 };
00101 
00102 }}
00103 
00104 #endif  

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