Changeset 12060 for source/ariba/utility/messages
- Timestamp:
- Jun 19, 2013, 11:05:49 AM (12 years ago)
- Location:
- source/ariba/utility/messages
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/messages/Message.cpp
r8620 r12060 41 41 #include "ariba/utility/serialization/DataStream.hpp" 42 42 43 #include "ariba/utility/logging/Logging.h" 44 43 45 NAMESPACE_BEGIN 44 46 … … 80 82 } 81 83 84 85 reboost::message_t Message::wrap_up_for_sending() 86 { 87 assert( ! wrapped_up ); 88 wrapped_up = true; 89 90 //// Adapt to new message system //// 91 Data data = data_serialize(this, DEFAULT_V); 92 reboost::shared_buffer_t buf(data.getBuffer(), data.getLength() / 8); 93 94 newstyle_payload.push_front(buf); 95 96 return newstyle_payload; 97 } 98 99 reboost::shared_buffer_t Message::serialize_into_shared_buffer() 100 { 101 assert ( newstyle_payload.length() == 0 ); 102 103 //// Adapt to new message system //// 104 Data data = data_serialize(this, DEFAULT_V); 105 reboost::shared_buffer_t buf(data.getBuffer(), data.getLength() / 8); 106 107 return buf; 108 } 109 110 111 reboost::shared_buffer_t Message::deserialize_from_shared_buffer(reboost::shared_buffer_t buff) 112 { 113 // NOTE: legacy payload is not allowed when using shared buffers 114 this->legacy_payload_disabled = true; 115 116 assert( buff.size() > 0 ); 117 118 // const_cast is necessary here, but without legacy payload we should be save here (more or less) 119 Data dat(const_cast<uint8_t*>(buff.data()), buff.size() * 8); 120 121 size_t len = this->SERIALIZATION_METHOD_NAME(DESERIALIZE, dat) / 8; 122 123 // return remaining sub-buffer 124 return buff(len); 125 } 126 127 128 82 129 NAMESPACE_END 83 130 84 131 std::ostream& operator<<(std::ostream& stream, const ariba::utility::Message& msg ) { 85 132 using_serialization; 86 stream << "msg(type=" << typeid(msg).name() ;133 stream << "msg(type=" << typeid(msg).name() << ","; 87 134 stream << "len=" << (data_length(&msg)/8) << ","; 88 135 Data data = data_serialize(&msg); 89 stream << " ,data=" << data;136 stream << "data=" << data; 90 137 data.release(); 91 138 stream << ")"; 92 139 return stream; 93 140 } 94 -
source/ariba/utility/messages/Message.h
r6919 r12060 62 62 #include "ariba/utility/serialization.h" 63 63 64 // reboost messages 65 #include "ariba/utility/transport/messages/message.hpp" 66 67 64 68 std::ostream& operator<<(std::ostream& stream, const ariba::utility::Message& msg ); 65 69 … … 82 86 friend std::ostream& ::operator<<(std::ostream& stream, const ariba::utility::Message& msg ); 83 87 84 // root binary data85 shared_array<uint8_t> root;86 87 88 // payload 89 bool legacy_payload_disabled; 88 90 bool releasePayload; 89 91 Data payload; //< messages binary data 92 93 // XXX testing... 94 reboost::message_t newstyle_payload; 95 bool wrapped_up; 90 96 91 97 // addresses and control info … … 98 104 */ 99 105 inline Message() : 100 root(), releasePayload(true), payload(), srcAddr(NULL),destAddr(NULL) { 106 legacy_payload_disabled(false), releasePayload(true), payload(), 107 newstyle_payload(), wrapped_up(false), srcAddr(NULL),destAddr(NULL) { 101 108 } 102 109 … … 106 113 */ 107 114 explicit inline Message( const Data& data ) : 108 releasePayload(true), srcAddr(NULL),destAddr(NULL) { 115 legacy_payload_disabled(false), releasePayload(true), 116 newstyle_payload(), wrapped_up(false), srcAddr(NULL),destAddr(NULL) { // FIXME newstyle_payload..? 109 117 this->payload = data.clone(); 110 118 // this->root = shared_array<uint8_t>((uint8_t*)data.getBuffer()); … … 225 233 return decapsulate<T>(); 226 234 } 235 236 237 // XXX testing 238 void set_payload_message(reboost::message_t msg) 239 { 240 newstyle_payload = msg; 241 } 242 243 void append_buffer(reboost::shared_buffer_t buff) 244 { 245 newstyle_payload.push_back(buff); 246 } 247 248 249 // XXX testing... packs this message into the payload message (do not use twice!!) 250 virtual reboost::message_t wrap_up_for_sending(); 251 252 253 /** 254 * Uses the old serialization system to serialize itself into a (new style) shared buffer. 255 */ 256 virtual reboost::shared_buffer_t serialize_into_shared_buffer(); 257 258 /* 259 * XXX experimental 260 * 261 * Uses the old serialization system to deserialize itself out of a (new style) shared buffer. 262 * @return remaining sub-buffer (the "payload") 263 * 264 * Note: This is some kind of a hack! handle with care. 265 */ 266 virtual reboost::shared_buffer_t deserialize_from_shared_buffer(reboost::shared_buffer_t buff); 267 227 268 228 269 protected: … … 262 303 * @return A explicit payload serializer 263 304 */ 264 finline PayloadSerializer Payload( size_t length = ~0 ) { 305 finline PayloadSerializer Payload( size_t length = ~0 ) 306 { 307 // assert( ! legacy_payload_disabled ); // FIXME aktuell 308 265 309 return PayloadSerializer( this, length ); 266 310 } -
source/ariba/utility/messages/MessageProvider.cpp
r6919 r12060 37 37 // [License] 38 38 39 #include "MessageProvider.h"40 41 NAMESPACE_BEGIN42 43 MessageProvider::MessageProvider() {44 }45 46 MessageProvider::~MessageProvider() {47 }48 49 bool MessageProvider::sendMessageToReceivers( const Message* message ) {50 bool sent = false;51 for (size_t i=0; i<receivers.size(); i++)52 if (receivers[i]->receiveMessage(message, LinkID::UNSPECIFIED, NodeID::UNSPECIFIED)) sent = true;53 return sent;54 }55 56 void MessageProvider::addMessageReceiver( MessageReceiver* receiver ) {57 receivers.push_back(receiver);58 }59 60 void MessageProvider::removeMessageReceiver( MessageReceiver* receiver ) {61 for (size_t i=0; i<receivers.size(); i++)62 if (receivers[i]==receiver) {63 receivers.erase( receivers.begin()+i );64 break;65 }66 }67 68 NAMESPACE_END39 //#include "MessageProvider.h" 40 // 41 //NAMESPACE_BEGIN 42 // 43 //MessageProvider::MessageProvider() { 44 //} 45 // 46 //MessageProvider::~MessageProvider() { 47 //} 48 // 49 //bool MessageProvider::sendMessageToReceivers( const Message* message ) { 50 // bool sent = false; 51 // for (size_t i=0; i<receivers.size(); i++) 52 // if (receivers[i]->receiveMessage(message, LinkID::UNSPECIFIED, NodeID::UNSPECIFIED)) sent = true; 53 // return sent; 54 //} 55 // 56 //void MessageProvider::addMessageReceiver( MessageReceiver* receiver ) { 57 // receivers.push_back(receiver); 58 //} 59 // 60 //void MessageProvider::removeMessageReceiver( MessageReceiver* receiver ) { 61 // for (size_t i=0; i<receivers.size(); i++) 62 // if (receivers[i]==receiver) { 63 // receivers.erase( receivers.begin()+i ); 64 // break; 65 // } 66 //} 67 // 68 //NAMESPACE_END -
source/ariba/utility/messages/MessageProvider.h
r3690 r12060 1 // XXX DEPRECATED 2 1 3 // [License] 2 4 // The Ariba-Underlay Copyright … … 37 39 // [License] 38 40 41 // XXX DEPRECATED 42 39 43 #ifndef MESSAGEPROVIDER_H_ 40 44 #define MESSAGEPROVIDER_H_ 41 45 42 #include "_namespace.h"43 #include "MessageReceiver.h"44 #include "ariba/utility/types/LinkID.h"45 #include "ariba/utility/types/NodeID.h"46 #include <vector>47 48 using std::vector;49 using ariba::utility::LinkID;50 using ariba::utility::NodeID;51 52 NAMESPACE_BEGIN53 54 55 / **56 * This class defines an interface for message providers.57 * Implementing classes must allow receivers to register themselves.58 *59 * @author Sebastian Mies60 */61 class MessageProvider {62 private:63 vector<MessageReceiver*> receivers;64 65 protected:66 bool sendMessageToReceivers( const Message* message );67 68 public:69 /**70 * Constructor.71 */72 MessageProvider();73 74 /**75 * Destructor.76 */77 ~MessageProvider();78 79 /**80 * Adds a message receiver.81 *82 * @param receiver The receiver.83 */84 void addMessageReceiver( MessageReceiver* receiver );85 86 /**87 * Removes a message receiver.88 *89 * @param receiver The receiver.90 */91 void removeMessageReceiver( MessageReceiver* receiver );92 };93 94 NAMESPACE_END46 //#include "_namespace.h" 47 //#include "MessageReceiver.h" 48 //#include "ariba/utility/types/LinkID.h" 49 //#include "ariba/utility/types/NodeID.h" 50 //#include <vector> 51 // 52 //using std::vector; 53 //using ariba::utility::LinkID; 54 //using ariba::utility::NodeID; 55 // 56 //NAMESPACE_BEGIN 57 // 58 // 59 ///** 60 // * This class defines an interface for message providers. 61 // * Implementing classes must allow receivers to register themselves. 62 // * 63 // * @author Sebastian Mies 64 // */ 65 //class MessageProvider { 66 //private: 67 // vector<MessageReceiver*> receivers; 68 // 69 //protected: 70 // bool sendMessageToReceivers( const Message* message ); 71 // 72 //public: 73 // /** 74 // * Constructor. 75 // */ 76 // MessageProvider(); 77 // 78 // /** 79 // * Destructor. 80 // */ 81 // ~MessageProvider(); 82 // 83 // /** 84 // * Adds a message receiver. 85 // * 86 // * @param receiver The receiver. 87 // */ 88 // void addMessageReceiver( MessageReceiver* receiver ); 89 // 90 // /** 91 // * Removes a message receiver. 92 // * 93 // * @param receiver The receiver. 94 // */ 95 // void removeMessageReceiver( MessageReceiver* receiver ); 96 //}; 97 // 98 //NAMESPACE_END 95 99 96 100 #endif /* MESSAGEPROVIDER_H_ */ -
source/ariba/utility/messages/MessageReceiver.cpp
r3690 r12060 49 49 } 50 50 51 bool MessageReceiver::receiveMessage( const Message*message, const LinkID& link, const NodeID& node ) {52 //std::cout << "UNIMPLEMENTED MessageReceiver got Message:" << (Message*)message << std::endl;53 return false;54 }51 //bool MessageReceiver::receiveMessage( reboost::shared_buffer_t message, const LinkID& link, const NodeID& node ) { 52 // //std::cout << "UNIMPLEMENTED MessageReceiver got Message:" << (Message*)message << std::endl; 53 // return false; 54 //} 55 55 56 56 NAMESPACE_END -
source/ariba/utility/messages/MessageReceiver.h
r3690 r12060 40 40 #define MESSAGERECEIVER_H__ 41 41 42 #include "ariba/utility/messages/Message.h" 42 //#include "ariba/utility/messages/Message.h" 43 // reboost messages 44 #include "ariba/utility/transport/messages/message.hpp" 43 45 #include "ariba/utility/types/LinkID.h" 44 46 #include "ariba/utility/types/NodeID.h" … … 73 75 * @return True, when the message has been accepted. 74 76 */ 75 virtual bool receiveMessage( const Message* message, const LinkID& link, const NodeID& node ); 77 virtual bool receiveMessage( reboost::shared_buffer_t message, 78 const LinkID& link, 79 const NodeID& node, 80 bool bypass_overlay ) = 0; 76 81 }; 77 82
Note:
See TracChangeset
for help on using the changeset viewer.