Skip to content
Snippets Groups Projects
Unverified Commit 80f50ae4 authored by vargheseg's avatar vargheseg Committed by GitHub
Browse files

Merge pull request #9 from vargheseg/master

Skip logic in PeriodicTrigger mainLoop for TestableMode
parents cc06c8f3 88512a34
No related branches found
No related tags found
No related merge requests found
......@@ -16,26 +16,33 @@ namespace ChimeraTK {
/** Constructor. In addition to the usual arguments of an ApplicationModule, the default timeout value is specified.
* This value is used as a timeout if the timeout value is set to 0. The timeout value is in milliseconds. */
PeriodicTrigger(EntityOwner *owner, const std::string &name, const std::string &description,
const uint32_t defaultTimeout=1000, bool eliminateHierarchy=false, const std::unordered_set<std::string> &tags={})
const uint32_t defaultPeriod=1000, bool eliminateHierarchy=false, const std::unordered_set<std::string> &tags={})
: ApplicationModule(owner, name, description, eliminateHierarchy, tags),
defaultTimeout_(defaultTimeout)
defaultPeriod_(defaultPeriod)
{}
ScalarPollInput<uint32_t> timeout{this, "timeout", "ms", "Timeout in milliseconds. The trigger is sent once per the specified duration."};
ScalarPollInput<uint32_t> period{this, "period", "ms", "period in milliseconds. The trigger is sent once per the specified duration."};
ScalarOutput<uint64_t> tick{this, "tick", "", "Timer tick. Counts the trigger number starting from 0."};
void sendTrigger() {
++tick;
tick.write();
}
void mainLoop() {
if (Application::getInstance().isTestableModeEnabled()) {
return;
}
tick = 0;
std::chrono::time_point<std::chrono::steady_clock> t = std::chrono::steady_clock::now();
while(true) {
timeout.read();
if(timeout == 0){
period.read();
if(period == 0){
// set receiving end of timeout. Will only be overwritten if there is new data.
timeout = defaultTimeout_;
period = defaultPeriod_;
}
t += std::chrono::milliseconds(static_cast<uint32_t>(timeout));
t += std::chrono::milliseconds(static_cast<uint32_t>(period));
boost::this_thread::interruption_point();
std::this_thread::sleep_until(t);
......@@ -46,7 +53,7 @@ namespace ChimeraTK {
private:
uint32_t defaultTimeout_;
uint32_t defaultPeriod_;
};
}
......
......@@ -91,6 +91,12 @@ namespace ChimeraTK {
testableModeLock("enableTestableMode");
}
/**
* Returns true if application is in testable mode else returns
* false.
**/
bool isTestableModeEnabled() { return testableMode; }
/** Resume the application until all application threads are stuck in a blocking read operation. Works only when
* the testable mode was enabled. */
void stepApplication();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment