Removed ConfigurationManager changes and replaced with Properties. Not perfect, but can acess from "Global Properties.ResearchKit.Timer._timeout"

This commit is contained in:
Matthew Territo
2017-07-12 19:13:55 -06:00
parent 51d722ca33
commit ec0a90db5c
5 changed files with 28 additions and 54 deletions

View File

@@ -144,14 +144,6 @@ public:
static const std::string PartFilterIdentifierIdentifier;
/// The part of the key storing a list of severities that should be filtered out
static const std::string PartFilterSeverity;
/// The key for Research Kit module values
static const std::string KeyModuleResearchKit;
/// The part of the key that sets the type of Research Kit Timer for the application
static const std::string PartModuleAppTimer;
/// The part of the key that sets the timeout for the applications Research Kit ShutdownTimer
static const std::string PartModuleTimeoutTicks;
/// The part of the key that sets the timeout cycles for the applications Research Kit ShutdownTimer
static const std::string PartModuleTimeoutCycles;
/**
* Iteratively walks the directory structure starting with \p filename to find the

View File

@@ -39,8 +39,11 @@ namespace openspace {
ResearchKitModule::ResearchKitModule()
: OpenSpaceModule("ResearchKit")
, _applicationTimer(nullptr) {
, _applicationTimer(nullptr) {
internalInitialize();
if (_applicationTimer) { addPropertySubOwner(_applicationTimer); };
}
void ResearchKitModule::internalInitialize() {
@@ -48,30 +51,8 @@ void ResearchKitModule::internalInitialize() {
return;
}
rk::timing::ShutdownTimer * appTimer = dynamic_cast<rk::timing::ShutdownTimer*>(_applicationTimer);
const auto conf = OsEng.configurationManager();
// Configure the application timer
const std::string AppTimer = ConfigurationManager::KeyModuleResearchKit
+ '.' + ConfigurationManager::PartModuleAppTimer;
const std::string Timeout = ConfigurationManager::KeyModuleResearchKit
+ '.' + ConfigurationManager::PartModuleTimeoutTicks;
const std::string TimeoutCycles = ConfigurationManager::KeyModuleResearchKit
+ '.' + ConfigurationManager::PartModuleTimeoutCycles;
if (conf.hasKeyAndValue<std::string>(AppTimer)) {
_applicationTimer = new rk::timing::ShutdownTimer;
size_t t = 0, c = 0;
if (conf.hasKeyAndValue<int>(Timeout)) {
conf.getValue(Timeout, t);
}
if (conf.hasKeyAndValue<int>(TimeoutCycles)) {
conf.getValue(Timeout, c);
}
appTimer->setTimeout(t, c);
}
_applicationTimer = new rk::timing::ShutdownTimer;
registerCallbacks();
}
void ResearchKitModule::registerCallbacks() {

View File

@@ -44,11 +44,11 @@ void printFrame() {
}
Timer::Timer()
: _tick(0)
: properties::PropertyOwner("Timer")
,_tick(0)
, _cycles(0) { }
bool Timer::tick() {
LINFO("Tick" << _tick);
// Tick first, so (timeout && rollover == 0) means "No timeout"
_tick++;
if (_tick == std::numeric_limits<std::size_t>::max()) {
@@ -68,26 +68,30 @@ size_t Timer::getCycles() {
TimeoutTimer::TimeoutTimer()
: Timer()
, _timeout(0)
, _timeoutCycles(0) { }
, _timeout("_timeout", "Timeout", 0, 0, std::numeric_limits<unsigned long long>::max())
, _timeoutCycles("_timeoutCycles", "Timeout Cycles", 0, 0, std::numeric_limits<unsigned long long>::max()) {
addProperty(_timeout);
addProperty(_timeoutCycles);
}
bool TimeoutTimer::tick() {
// Tick first, so (timeout && rollover == 0) means "No timeout"
Timer::tick();
// Return whether past timeout
const bool timedOut = (_timeout <= _tick && _timeoutCycles <= _cycles);
const bool timedOut = (_timeout || _timeoutCycles ) && (_timeout <= _tick && _timeoutCycles <= _cycles);
if (timedOut) callback();
return timedOut;
}
void TimeoutTimer::setTimeout(size_t t) {
void TimeoutTimer::setTimeout(unsigned long long t) {
setTimeout(t, 0);
}
void TimeoutTimer::setTimeout(size_t t, size_t r) {
void TimeoutTimer::setTimeout(unsigned long long t, unsigned long long c) {
_timeout = t;
_timeoutCycles = r;
_timeoutCycles = c;
}
void ShutdownTimer::callback() {

View File

@@ -26,6 +26,8 @@
#define __OPENSPACE_MODULE_RESEARCHKIT___TIMING___H__
#include <openspace/properties/propertyowner.h>
#include <openspace/properties/scalarproperty.h>
namespace openspace {
namespace rk {
@@ -41,12 +43,12 @@ public:
// Increments tick counter, returns whether timeout has occured
virtual bool tick();
size_t getTick();
size_t getCycles();
unsigned long long getTick();
unsigned long long getCycles();
protected:
size_t _tick;
size_t _cycles;
unsigned long long _tick;
unsigned long long _cycles;
};
class TimeoutTimer : public Timer {
@@ -54,12 +56,12 @@ public:
TimeoutTimer();
virtual bool tick() override;
// Sets the value for the timeout: will cancel after t ticks
void setTimeout(size_t t);
// Sets the value for the timeout: will cancel after r*size_t::max + t ticks
void setTimeout(size_t t, size_t r);
void setTimeout(unsigned long long t);
// Sets the value for the timeout: will cancel after c*size_t::max + t ticks
void setTimeout(unsigned long long t, unsigned long long c);
protected:
size_t _timeout;
size_t _timeoutCycles;
properties::ULongLongProperty _timeout;
properties::ULongLongProperty _timeoutCycles;
virtual void callback() = 0;

View File

@@ -98,11 +98,6 @@ const string ConfigurationManager::PartFilterIdentifierType = "Type";
const string ConfigurationManager::PartFilterIdentifierIdentifier = "Identifier";
const string ConfigurationManager::PartFilterSeverity = "PartFilterSeverity";
const string ConfigurationManager::KeyModuleResearchKit = "Module_ResearchKit";
const string ConfigurationManager::PartModuleAppTimer = "ApplicationTimer";
const string ConfigurationManager::PartModuleTimeoutTicks = "TimeoutTicks";
const string ConfigurationManager::PartModuleTimeoutCycles = "TimeoutCycles";
string ConfigurationManager::findConfiguration(const string& filename) {
using ghoul::filesystem::Directory;