Page MenuHomePhorge

DeluxeSensor.cpp
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

DeluxeSensor.cpp

//===-- deluxe/DeluxeSensor.cpp ---------------------------------*- C++ -*-===//
//
// The RoSA Framework
//
//===----------------------------------------------------------------------===//
///
/// \file deluxe/DeluxeSensor.cpp
///
/// \author David Juhasz (david.juhasz@tuwien.ac.at)
///
/// \date 2017-2019
///
/// \brief Implementation of rosa/deluxe/DeluxeSensor.hpp.
///
//===----------------------------------------------------------------------===//
#include "rosa/deluxe/DeluxeSensor.hpp"
#include "rosa/deluxe/DeluxeSystem.hpp"
namespace rosa {
namespace deluxe {
bool DeluxeSensor::inv(void) const noexcept {
// Check execution policy.
// \note The \c rosa::System the \c rosa::Unit is created with is a
// \c rosa::DeluxeSystem.
const DeluxeSystem &DS = static_cast<DeluxeSystem &>(Unit::system());
if (!ExecutionPolicy || !ExecutionPolicy->canHandle(Self, DS)) {
return false;
}
// Check the index of next expected element from the *master*.
const token_size_t MITL = lengthOfToken(MasterInputType);
if ((MITL != 0 && MasterInputNextPos >= MITL) ||
(MITL == 0 && MasterInputNextPos != 0)) {
return false;
}
// All checks were successful, the invariant is held.
return true;
}
id_t DeluxeSensor::masterId(void) const noexcept {
ASSERT(Master);
return unwrapAgent(*Master).Id;
}
DeluxeSensor::~DeluxeSensor(void) noexcept {
ASSERT(inv());
LOG_TRACE_STREAM << "Destroying DeluxeSensor " << FullName << "..."
<< std::endl;
// Make sure \p this object is not a registered *slave*.
if (Master) {
ASSERT(unwrapAgent(*Master).Kind == atoms::AgentKind); // Sanity check.
DeluxeAgent &M = static_cast<DeluxeAgent&>(unwrapAgent(*Master));
ASSERT(M.positionOfSlave(self()) != M.NumberOfInputs); // Sanity check.
M.registerSlave(M.positionOfSlave(self()), {});
Master = {};
}
}
const DeluxeExecutionPolicy &DeluxeSensor::executionPolicy(void) const
noexcept {
ASSERT(inv());
return *ExecutionPolicy;
}
bool DeluxeSensor::setExecutionPolicy(
std::unique_ptr<DeluxeExecutionPolicy> &&EP) noexcept {
ASSERT(inv());
LOG_TRACE_STREAM << "DeluxeSensor " << FullName
<< " setting execution policy " << *EP << std::endl;
bool Success = false;
// \note The \c rosa::System the \c rosa::Unit is created with is a
// \c rosa::DeluxeSystem.
const DeluxeSystem &DS = static_cast<DeluxeSystem &>(Unit::system());
if (EP && EP->canHandle(self(), DS)) {
ExecutionPolicy.swap(EP);
Success = true;
} else {
LOG_TRACE_STREAM << "Execution policy " << *EP
<< " cannot handle DeluxeSensor " << FullName << std::endl;
}
ASSERT(inv());
return Success;
}
Optional<AgentHandle> DeluxeSensor::master(void) const noexcept {
ASSERT(inv());
return Master;
}
void DeluxeSensor::registerMaster(const Optional<AgentHandle> _Master) noexcept {
ASSERT(inv() && (!_Master || unwrapAgent(*_Master).Kind == atoms::AgentKind));
Master = _Master;
ASSERT(inv());
}
void DeluxeSensor::clearSimulationDataSource(void) noexcept {
ASSERT(inv());
SFP = nullptr;
ASSERT(inv());
}
bool DeluxeSensor::simulationDataSourceIsSet(void) const noexcept {
ASSERT(inv());
return SFP != nullptr;
}
void DeluxeSensor::handleTrigger(atoms::Trigger) noexcept {
ASSERT(inv() && MasterInputNextPos == 0);
// Process master-input.
MFP();
// Obtain the next sensory value.
// \note Execution policy is respected within the data source function.
// Use \c rosa::deluxe::DeluxeSensor::SFP if set, otherwise
// \c rosa::deluxe::DeluxeSensor::FP.
const H &F = SFP ? SFP : FP;
F();
ASSERT(inv());
}
} // End namespace deluxe
} // End namespace rosa

File Metadata

Mime Type
text/x-c++
Expires
Sun, Mar 1, 9:30 PM (1 d, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
281240
Default Alt Text
DeluxeSensor.cpp (3 KB)

Event Timeline