86 lines
2.8 KiB
C++
86 lines
2.8 KiB
C++
#include "RoleSwitchAnounce.h"
|
|
|
|
#include "Dispatcher.h"
|
|
#include "common/validator/MessageValidator.h"
|
|
#include "fd/NetworkFailureDetector.h"
|
|
|
|
#define DEBUG(msg) MOV_DEBUG << " "<<msg<<endl;
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
/**
|
|
* @brief Constructor
|
|
* @param PeerID : peerSwitchId - Id of the peer which has to been switch his role
|
|
*/
|
|
RoleSwitchAnounce::RoleSwitchAnounce(PeerID peerSwitchId) : MulticastMessage("RSA", RSA) {
|
|
this->roleSwitchId = peerSwitchId;
|
|
}
|
|
|
|
/**
|
|
* @brief Deconstructor
|
|
*/
|
|
RoleSwitchAnounce::~RoleSwitchAnounce() {
|
|
//dtor
|
|
}
|
|
|
|
/**
|
|
* @brief Copy constructor
|
|
* @param other Object to copy from
|
|
*/
|
|
RoleSwitchAnounce::RoleSwitchAnounce(const RoleSwitchAnounce& other) : MulticastMessage(other) {
|
|
operator =(other);
|
|
}
|
|
|
|
/**
|
|
* @brief Assignment operator
|
|
* @param other Object to assign from
|
|
* @return A reference to this
|
|
*/
|
|
RoleSwitchAnounce&
|
|
RoleSwitchAnounce::operator=(const RoleSwitchAnounce& rhs) {
|
|
if (this == &rhs) {
|
|
// handle self assignment
|
|
return *this;
|
|
}
|
|
|
|
this->roleSwitchId = rhs.roleSwitchId;
|
|
//assignment operator
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* @brief method duplicate this messages
|
|
* @return RoleSwitchAnounce
|
|
*/
|
|
RoleSwitchAnounce *
|
|
RoleSwitchAnounce::dup() const {
|
|
return new RoleSwitchAnounce(*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
|
|
RoleSwitchAnounce::handleReceive(Dispatcher& dis) {
|
|
if (dis.getMessageValidator()->isValid(*this)) {
|
|
//notify the NFD about ongoing traffic
|
|
dis.getNetworkFailureDetector().handleMessage(this);
|
|
//handle the message
|
|
dis.getMessageTransfer().handleMessage(this);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
RoleSwitchAnounce::handleDeliver(Dispatcher& dis, const PeerIDList& /* missedPeers */) {
|
|
dis.getMaintenanceRoleService().forceRoleSwitch(this->roleSwitchId);
|
|
}
|
|
}
|
|
}
|