IBR-DTNSuite 0.6

daemon/src/routing/epidemic/EpidemicControlMessage.cpp

Go to the documentation of this file.
00001 /*
00002  * EpidemicControlMessage.cpp
00003  *
00004  *  Created on: 24.01.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #include "routing/epidemic/EpidemicControlMessage.h"
00009 
00010 namespace dtn
00011 {
00012         namespace routing
00013         {
00014                 EpidemicControlMessage::EpidemicControlMessage()
00015                  : type(ECM_QUERY_SUMMARY_VECTOR), flags(0)
00016                 {
00017                 }
00018 
00019                 EpidemicControlMessage::~EpidemicControlMessage()
00020                 {
00021                 }
00022 
00023                 void EpidemicControlMessage::setSummaryVector(const SummaryVector &vector)
00024                 {
00025                         flags |= ECM_CONTAINS_SUMMARY_VECTOR;
00026                         _vector = vector;
00027                 }
00028 
00029                 const SummaryVector& EpidemicControlMessage::getSummaryVector() const
00030                 {
00031                         return _vector;
00032                 }
00033 
00034                 void EpidemicControlMessage::setPurgeVector(const SummaryVector &vector)
00035                 {
00036                         flags |= ECM_CONTAINS_PURGE_VECTOR;
00037                         _purge = vector;
00038                 }
00039 
00040                 const SummaryVector& EpidemicControlMessage::getPurgeVector() const
00041                 {
00042                         return _purge;
00043                 }
00044 
00045                 std::ostream& operator<<(std::ostream &stream, const EpidemicControlMessage &ecm)
00046                 {
00047                         // write the message type
00048                         char mt = ecm.type;
00049                         stream.write((char*)&mt, 1);
00050 
00051                         // write the message flags
00052                         char mf = ecm.flags;
00053                         stream.write((char*)&mf, 1);
00054 
00055                         if (ecm.type == EpidemicControlMessage::ECM_RESPONSE)
00056                         {
00057                                 if (ecm.flags == EpidemicControlMessage::ECM_CONTAINS_SUMMARY_VECTOR)
00058                                 {
00059                                         stream << ecm._vector;
00060                                 }
00061 
00062                                 if (ecm.flags == EpidemicControlMessage::ECM_CONTAINS_PURGE_VECTOR)
00063                                 {
00064                                         stream << ecm._purge;
00065                                 }
00066                         }
00067 
00068                         return stream;
00069                 }
00070 
00071                 std::istream& operator>>(std::istream &stream, EpidemicControlMessage &ecm)
00072                 {
00073                         // read the message type
00074                         char mt = 0;
00075                         stream.read((char*)&mt, 1);
00076                         ecm.type = (EpidemicControlMessage::MessageType)mt;
00077 
00078                         // read the message flags
00079                         stream.read((char*)&ecm.flags, 1);
00080 
00081                         if (ecm.type == EpidemicControlMessage::ECM_RESPONSE)
00082                         {
00083                                 if (ecm.flags == EpidemicControlMessage::ECM_CONTAINS_SUMMARY_VECTOR)
00084                                 {
00085                                         stream >> ecm._vector;
00086                                 }
00087 
00088                                 if (ecm.flags == EpidemicControlMessage::ECM_CONTAINS_PURGE_VECTOR)
00089                                 {
00090                                         stream >> ecm._purge;
00091                                 }
00092                         }
00093 
00094                         return stream;
00095                 }
00096         }
00097 }