diff options
author | Matthew Barth <msbarth@us.ibm.com> | 2017-06-23 14:38:05 -0500 |
---|---|---|
committer | Matthew Barth <msbarth@us.ibm.com> | 2017-07-06 17:25:12 -0500 |
commit | 8600d9a0058071951e0881037deff77fc03d1601 (patch) | |
tree | 6d1b42e94f22db089ed39534555acaacd337bee9 /control/main.cpp | |
parent | 0ce99d8b377e68b5286c37e7e644301051972083 (diff) | |
download | phosphor-fan-presence-8600d9a0058071951e0881037deff77fc03d1601.tar.gz phosphor-fan-presence-8600d9a0058071951e0881037deff77fc03d1601.zip |
Timer to decrease fan speeds
Create a repeating timer for decreasing fan speeds where the fan speeds
in the zone are decreased when the timer expires and a decrease speed
request exists with no increase request present or active.
Change-Id: I419592f6f50c0ed524f8bf3ebf183854ab5ef2ea
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Diffstat (limited to 'control/main.cpp')
-rw-r--r-- | control/main.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/control/main.cpp b/control/main.cpp index 413a419..cde71d0 100644 --- a/control/main.cpp +++ b/control/main.cpp @@ -14,14 +14,18 @@ * limitations under the License. */ #include <sdbusplus/bus.hpp> +#include <phosphor-logging/log.hpp> #include "argument.hpp" #include "manager.hpp" +#include "event.hpp" using namespace phosphor::fan::control; +using namespace phosphor::logging; int main(int argc, char* argv[]) { auto bus = sdbusplus::bus::new_default(); + sd_event* events = nullptr; phosphor::fan::util::ArgumentParser args(argc, argv); if (argc != 2) @@ -46,7 +50,21 @@ int main(int argc, char* argv[]) exit(-1); } - Manager manager(bus, mode); + auto r = sd_event_default(&events); + if (r < 0) + { + log<level::ERR>("Failed call to sd_event_default()", + entry("ERROR=%s", strerror(-r))); + return -1; + } + + phosphor::fan::event::EventPtr eventPtr{events}; + + //Attach the event object to the bus object so we can + //handle both sd_events (for the timers) and dbus signals. + bus.attach_event(eventPtr.get(), SD_EVENT_PRIORITY_NORMAL); + + Manager manager(bus, eventPtr, mode); //Init mode will just set fans to max and delay if (mode == Mode::init) @@ -54,12 +72,15 @@ int main(int argc, char* argv[]) manager.doInit(); return 0; } - - while (true) + else { - bus.process_discard(); - bus.wait(); + r = sd_event_loop(eventPtr.get()); + if (r < 0) + { + log<level::ERR>("Failed call to sd_event_loop", + entry("ERROR=%s", strerror(-r))); + } } - return 0; + return -1; } |