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

157 lines
5.9 KiB
C++

/*
* File: MSMessageFactory.cc
* Author: jgaebler
*
* Created on March 10, 2011, 11:56 AM
*/
#include "MSMessageFactory.h"
#include "ms/MembershipService.h"
#include "JoinRequest.h"
#include "JoinConfirm.h"
#include "JoinAbort.h"
#include "RosterMessage.h"
#include "JoinAnnounce.h"
#include "LeaveAnnounce.h"
#include "app/PeerDescription.h"
#include "common/transport/TransportAddress.h"
#include "common/time/VirtualLogicalTime.h"
#include "ms/Invitation.h"
#include "ms/PeerResources.h"
namespace ubeeme {
namespace moversight {
/**
* @brief Creates a join request message.
* @param invitationID The ID of the invitaion, associated with this request. Used at application level to distinguish between two recieved invitations.
* @param pDesc The peer description of the requesting peer.
* @param ms The current membership service instance
* @return The created message.
*/
JoinRequest
MSMessageFactory::createJoinRequestMessage(const MembershipService & ms,
const InvitationID invitationID,
const PeerDescription & pDesc) {
JoinRequest joinReq;
joinReq.setInvitationID(invitationID);
joinReq.setInviterID(ms.getLocalID());
joinReq.setSourceTA(ms.getLocalAddress());
joinReq.setInviterGroupSize(ms.mr.getNumberOfPeers());
joinReq.setPeerDescription(pDesc.getDescription());
return joinReq;
}
/**
* @brief Creates a join confirm message.
* @param inv The inviation to respondes.
* @param message The reason for declining or a welcome message, depends on the intention of the message.
* @param pDesc A short description of the local peer provided by the application, published within the group, is the peer accept the invitation.
* @param ms The current membership service instance
* @param resources The peer resources representation.
* @return The created message.
*/
JoinConfirm
MSMessageFactory::createJoinConfirmMessage(const MembershipService & ms,
const Invitation & inv,
const std::string & message,
const PeerDescription & pDesc,
const PeerResources & resources) {
JoinConfirm joinConf;
joinConf.setJcMessage(message);
joinConf.setInvitationID(inv.getInvitationID());
joinConf.setSourceTA(ms.getLocalAddress());
joinConf.setPeerDescription(pDesc);
joinConf.setResources(resources);
#if !OMNETPP
joinConf.setInviterTa(inv.getInviterAddress());
#endif
return joinConf;
}
/**
* @brief Creates a join abort message.
* @param inv The corresponding invitation.
* @param message The abort reason.
* @param ms The current membership service instance*
* @return The created message.
*/
JoinAbort
MSMessageFactory::createJoinAbortMessage(const MembershipService & ms,
const Invitation & inv,
const std::string & message) {
JoinAbort joinAbort;
joinAbort.setJabMessage(message);
joinAbort.setInvitationID(inv.getInvitationID());
joinAbort.setSourceTA(ms.getLocalAddress());
return joinAbort;
}
/**
* @brief Creates a roster message, to inform a joined peer about the current group composition.
* @param pID The id of the joined peer.
* @param ms The current membership service instance*
* @return The created roster Message.
*/
RosterMessage
MSMessageFactory::createRosterMessage(const MembershipService & ms,
const PeerID pID) {
Roster roster(ms.mr.createRoster());
RosterMessage rosterMsg;
rosterMsg.setViewID(roster.getViewID());
rosterMsg.setNextPeerID(roster.getNextPeerID());
rosterMsg.setJoinedPeerID(pID);
rosterMsg.setMemberDescriptionList(roster.getMemberDescriptionList());
return rosterMsg;
}//End
/**
* @brief Creates a join announce message.
* @param inviteeAddress The transport address of the invited peer
* @param pDesc the peer description of the invited peer.
* @param resources the resources of the invited peer
* @return The created message.
*/
JoinAnnounce
MSMessageFactory::createJoinAnnounceMessage(const TransportAddress & inviteeAddress,
const PeerDescription & pDesc,
const PeerResources & resources) {
JoinAnnounce join;
join.setJoinedPeerTA(inviteeAddress);
join.setPeerDescription(pDesc);
join.setPeerResources(resources);
return join;
}//End
/**
* @brief Creates a leave announce message.
* @param leaveList List which contains the ids of the leaving peers
* @param referenceTime The time of the leave event.
* @return The created message.
*/
LeaveAnnounce
MSMessageFactory::createLeaveAnnounceMessage(const PeerIDList & leaveList,
const VirtualLogicalTime & referenceTime) {
LeaveAnnounce la;
la.setReferenceTime(referenceTime);
la.setLeaveList(leaveList);
return la;
}//End
}
}