update20140630
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
#include "ResourceValueTimer.h"
|
||||
|
||||
#include "rvd/ResourceValueDistributor.h"
|
||||
#include "rvd/profil/TimerResourceValueProfile.h"
|
||||
#include "ms/PeerResources.h"
|
||||
#include "Dispatcher.h"
|
||||
|
||||
#define DEBUG(msg) MOV_DEBUG << " "<<msg<<endl;
|
||||
|
||||
namespace ubeeme {
|
||||
namespace moversight {
|
||||
|
||||
/**
|
||||
* @brief Default constructor
|
||||
*/
|
||||
ResourceValueTimer::ResourceValueTimer(TimerResourceValueProfile & trvprofile, ResourceValueDistributor & rvd) : MoversightTimer(rvd), trvp(trvprofile) {
|
||||
#if OMNETPP
|
||||
setName("RESOURCE_VALUE_TIMER");
|
||||
#endif
|
||||
setTimeout(RESOURCE_VALUE_TIMEOUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-Constructor
|
||||
*/
|
||||
ResourceValueTimer::~ResourceValueTimer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copy-Constructor
|
||||
* @param source object
|
||||
*/
|
||||
ResourceValueTimer::ResourceValueTimer(const ResourceValueTimer& other) : MoversightTimer(other), trvp(other.trvp) {
|
||||
operator=(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assignment operator
|
||||
* @param other Object to assign from
|
||||
* @return A reference to this
|
||||
*/
|
||||
ResourceValueTimer& ResourceValueTimer::operator=(const ResourceValueTimer& rhs) {
|
||||
|
||||
if (this == &rhs) return *this; // handle self assignment
|
||||
|
||||
MoversightTimer::operator =(rhs);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief method execute timer timeout
|
||||
*/
|
||||
void
|
||||
ResourceValueTimer::timeout() {
|
||||
|
||||
if (service.getLocalState() == JOINED) {
|
||||
|
||||
ResourceValueDistributor & rvd = static_cast<ResourceValueDistributor &> (service);
|
||||
PeerResources currentResources = rvd.getCurrentResourceValue();
|
||||
|
||||
PeerResources newResources(PeerResources::MINIMUM_RESOURCE_VALUE);
|
||||
|
||||
PeerResources deltaResources = getPeerResources();
|
||||
newResources = currentResources - deltaResources;
|
||||
rvd.setAndSendResourceValue(newResources);
|
||||
}
|
||||
|
||||
trvp.signalCurrentTimerTimeout();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief method duplicate this timer
|
||||
* @return ResourceValueProfile
|
||||
*/
|
||||
ResourceValueTimer *
|
||||
ResourceValueTimer::dup() {
|
||||
return new ResourceValueTimer(*this);
|
||||
}
|
||||
|
||||
PeerResources
|
||||
ResourceValueTimer::getPeerResources() {
|
||||
return storage.get<PeerResources>("resources");
|
||||
}
|
||||
|
||||
void
|
||||
ResourceValueTimer::setPeerResources(const PeerResources & resources) {
|
||||
storage.set<PeerResources>("resources" ,resources);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user