Files
scandocs/uni/masterarbeit/source/moversight/mt/msg/GroupData.cc
2014-06-30 13:58:10 +02:00

151 lines
4.3 KiB
C++

#include "GroupData.h"
#include "Moversight.h"
#include "Dispatcher.h"
#include "app/Application.h"
#include "common/validator/MessageValidator.h"
#include "fd/NetworkFailureDetector.h"
namespace ubeeme {
namespace moversight {
/**
* @brief Constructor.
*/
GroupData::GroupData()
: MulticastMessage( "DT", DT) {
}
/**
* @brief Copy Constructor.
* @param other The instance to copy.
*/
GroupData::GroupData( const GroupData& other)
: MulticastMessage( other) {
operator=( other);
}
/**
* @brief Destructor.
*/
GroupData::~GroupData() {
}
/**
* @brief Duplicates the current instance. A way to copy a message.
* @return The duplicated instance.
*/
GroupData*
GroupData::dup() const {
return new GroupData(*this);
}
/**
* @brief Assignment operator.
* @param other The instance to assign.
* @return A reference to the local instance.
*/
GroupData&
GroupData::operator=( const GroupData& other) {
if( this == &other) return *this;
MulticastMessage::operator=( other);
setData( other.getData());
return *this;
}
/**
* @brief Handles this message. To handle a message, it has first successfully validated.
* @param dis A reference to the dispatcher, used to forward this message to the handling modules.
*/
void
GroupData::handleReceive( Dispatcher & dis) {
//validate the message
if (dis.getMessageValidator()->isValid( *this)) {
//notify the NFD about ongoing traffic
dis.getNetworkFailureDetector().handleMessage( this);
//handle the message
dis.getMessageTransfer().handleMessage( this);
}//End if
}
/**
* @brief Handles the message delivering. To deliver a message, the message to each module which is interested in this message.
* @param dis A reference to the dispatcher, used to forward this message to the handling modules.
* @param missedPeers A list of peers, which have missed this message, as they are pending.
*/
void
GroupData::handleDeliver( Dispatcher& dis, const PeerIDList& /*missedPeers*/) {
//store the message for re-synchronization
dis.getMobilitySupport().storeMessage(*this);
//process the message
#if OMNETPP
// Application
dis.getMoversightCallback().receiveGroupData( *this, getSourceID());
#else
dis.getMoversight().delegateReceive(data, getSourceID());
#endif
}
/**
* @brief Sets the data
* @param data The data to be send along with this message.
*/
void
GroupData::setData( ByteArray&& data) {
this->data = data;
}
/**
* @brief Sets the data
* @param data The data to be send along with this message.
*/
void
GroupData::setData( const ByteArray& data) {
this->data = data;
}
/**
* @brief Retrieve the stored data.
* @return The ByteArray of data
*/
const ByteArray&
GroupData::getData() const {
return data;
}
/**
* @brief Archive method
* @param archive The archive to which the attributes are to add
*/
void
GroupData::set( Archive& archive) {
MulticastMessage::set( archive);
if( archive.isReading()){
ByteArray theData;
size_t dataSize;
archive(dataSize);
for( size_t i = 0 ; i < dataSize; i++) {
byte elem;
archive( (int8&) elem);
theData.push_back(elem);
}
setData( theData);
}
else {
size_t size = getData().size();
archive(size);
for( size_t i = 0; i < size; i++) {
byte elem = getData().at(i);
archive( (int8&) elem);
}
}
}
}
}