157 lines
3.9 KiB
C++
157 lines
3.9 KiB
C++
/*
|
|
* File: StreamTransfer.cc
|
|
* Author: jgaebler
|
|
*
|
|
* Created on February 17, 2012, 3:45 PM
|
|
*/
|
|
|
|
#include "StreamTransfer.h"
|
|
|
|
#include "Dispatcher.h"
|
|
#include "Moversight.h"
|
|
|
|
#include "st/msg/StreamMessage.h"
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
#undef DEBUG
|
|
#define DEBUG(msg) if (module.isPrintDebugST()) MOV_DEBUG << "ST@" << getLocalID()<< " "<<msg<<endl;
|
|
|
|
/**
|
|
* @brief Constructor
|
|
* @param d A reference to the moversight dispatcher.
|
|
*/
|
|
StreamTransfer::StreamTransfer(Dispatcher & d) : MoversightService(d, "StreamTransfer") {
|
|
}
|
|
|
|
/**
|
|
* @brief Initialize service.
|
|
*/
|
|
void
|
|
StreamTransfer::initialise() {
|
|
|
|
sequ = 0;
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Finish the operation of the service.
|
|
*/
|
|
void
|
|
StreamTransfer::finalise() {
|
|
}
|
|
|
|
/**
|
|
* @brief Destructor
|
|
*/
|
|
StreamTransfer::~StreamTransfer() {
|
|
}
|
|
|
|
/**
|
|
* @brief Sends a message unreliable to the group
|
|
* @param msg The message to send.
|
|
*/
|
|
void
|
|
StreamTransfer::send( StreamMessage& msg) {
|
|
|
|
//set the source of the message
|
|
msg.setSourceID(getLocalID());
|
|
|
|
//only one member within the group?
|
|
if (dispatcher.getMembershipService().getNumberOfPeers() == 1) {
|
|
|
|
DEBUG("send - send message successfully");
|
|
deliverMessage(msg);
|
|
|
|
}//End if
|
|
else {
|
|
|
|
//we have to send the message to the group
|
|
//slave
|
|
if (!isLocalPeerMaster()) {
|
|
|
|
std::stringstream buf;
|
|
buf << "send - send message to master";
|
|
DEBUG(buf.str().c_str());
|
|
sendToMaster(msg);
|
|
|
|
}//End if
|
|
//master
|
|
else {
|
|
|
|
DEBUG("send - send message to other masters");
|
|
sendToAllMasters(msg);
|
|
DEBUG("send - send message to slaves");
|
|
sendToCluster(msg);
|
|
|
|
}//End else
|
|
}//End else
|
|
|
|
//generate the next sequ
|
|
sequ++;
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief This method handles a incoming unreliable multicast message.
|
|
* @param pdu The received unreliable multicast message.
|
|
*/
|
|
void
|
|
StreamTransfer::handleMessage(StreamMessage * pdu) {
|
|
|
|
//master
|
|
if (isLocalPeerMaster()) {
|
|
|
|
DEBUG("handleMessage - send message to slaves");
|
|
PeerID lastHop(pdu->getLastHop());
|
|
PeerIDList recList = createReceiverList(lastHop);
|
|
|
|
StreamMessage * pack = pdu->dup();
|
|
pack->setLastHop(getLocalID());
|
|
|
|
#if OMNETPP
|
|
pack->setByteLength(sizeof *pack);
|
|
#endif
|
|
sendTo( *pack, recList);
|
|
delete pack;
|
|
|
|
}//end if
|
|
//slave && not sender
|
|
else {
|
|
|
|
DEBUG("handleMessage - message received");
|
|
deliverMessage(*pdu);
|
|
|
|
}//End else
|
|
}
|
|
|
|
/**
|
|
* @brief Assignment operator.
|
|
* @param other The instance to assign.
|
|
* @return A reference of the current object.
|
|
*/
|
|
StreamTransfer & StreamTransfer::operator=(const StreamTransfer & other) {
|
|
|
|
if (this == &other) {
|
|
return *this;
|
|
}
|
|
this->dispatcher = other.dispatcher;
|
|
this->module = other.module;
|
|
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* @brief Delivers a message to the higher layer.
|
|
* @param msg The message to deliver.
|
|
*/
|
|
void
|
|
StreamTransfer::deliverMessage(StreamMessage & msg) {
|
|
|
|
//deliver the message
|
|
msg.handleDeliver(dispatcher);
|
|
}
|
|
}
|
|
}
|