diff options
author | Tom Joseph <tomjoseph@in.ibm.com> | 2017-03-14 17:04:58 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-04-24 11:22:15 -0500 |
commit | 0a0d8f65a27fb3465b9c6fc35df63c3e053fae20 (patch) | |
tree | b7c3daead218775fd80bac879afb47208a8a45e2 | |
parent | cfbd43fd472761d0bd886e5e64de9ef0b299b7f4 (diff) | |
download | phosphor-net-ipmid-0a0d8f65a27fb3465b9c6fc35df63c3e053fae20.tar.gz phosphor-net-ipmid-0a0d8f65a27fb3465b9c6fc35df63c3e053fae20.zip |
Defintion of switchTimer
switchTimer is used to enable or disable the character accumulate
timer or the retry timer.
Change-Id: Ica311650f9c4e723bccdcaeb952d9ec080c06d9a
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
-rw-r--r-- | sd_event_loop.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sd_event_loop.cpp b/sd_event_loop.cpp index d30aafe..14078ea 100644 --- a/sd_event_loop.cpp +++ b/sd_event_loop.cpp @@ -217,4 +217,58 @@ void EventLoop::stopHostConsole() } } +void EventLoop::switchTimer(uint8_t payloadInst, + Timers type, + bool status) +{ + auto iter = payloadInfo.find(payloadInst); + if (iter == payloadInfo.end()) + { + log<level::ERR>("SOL Payload instance not found", + entry("payloadInst=%d", payloadInst)); + throw std::runtime_error("SOL Payload instance not found"); + } + + int rc = 0; + auto source = (std::get<0>(iter->second.at(type))).get(); + auto interval = std::get<1>(iter->second.at(type)); + + // Turn OFF the timer + if (!status) + { + rc = sd_event_source_set_enabled(source, SD_EVENT_OFF); + if (rc < 0) + { + log<level::ERR>("Failed to disable the timer", entry("RC=%d", rc)); + throw std::runtime_error("Failed to disable timer"); + } + return; + } + + // Turn ON the timer + uint64_t currentTime = 0; + rc = sd_event_now(event, CLOCK_MONOTONIC, ¤tTime); + if (rc < 0) + { + log<level::ERR>("Failed to get the current timestamp", + entry("RC=%d", rc)); + throw std::runtime_error("Failed to get current timestamp"); + } + + rc = sd_event_source_set_time(source, currentTime + interval.count()); + if (rc < 0) + { + log<level::ERR>("sd_event_source_set_time function failed", + entry("RC=%d", rc)); + throw std::runtime_error("sd_event_source_set_time function failed"); + } + + rc = sd_event_source_set_enabled(source, SD_EVENT_ONESHOT); + if (rc < 0) + { + log<level::ERR>("Failed to enable the timer", entry("RC=%d",rc)); + throw std::runtime_error("Failed to enable timer"); + } +} + } // namespace eventloop |