diff options
author | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2016-12-19 12:43:36 -0500 |
---|---|---|
committer | Brad Bishop <bradleyb@fuzziesquirrel.com> | 2017-01-13 16:25:51 -0500 |
commit | 9c7b6e0668d91f8a8513ca11495e1e309d373535 (patch) | |
tree | ecdff720bdc49e15b33446fcfa995077a21ab44b | |
parent | b9e2b07eeb324f3cc8cf037986e5a43a09464419 (diff) | |
download | phosphor-hwmon-9c7b6e0668d91f8a8513ca11495e1e309d373535.tar.gz phosphor-hwmon-9c7b6e0668d91f8a8513ca11495e1e309d373535.zip |
Grab DBus connection
Connect to DBus and own a busname.
Create a freedesktop ObjectManager.
Change-Id: I186dadc5a5172f44edf9cfc8d0a338677636de04
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
-rw-r--r-- | mainloop.cpp | 38 | ||||
-rw-r--r-- | mainloop.hpp | 8 | ||||
-rw-r--r-- | readd.cpp | 1 | ||||
-rw-r--r-- | test/test.cpp | 1 |
4 files changed, 40 insertions, 8 deletions
diff --git a/mainloop.cpp b/mainloop.cpp index 8d34b18..746e032 100644 --- a/mainloop.cpp +++ b/mainloop.cpp @@ -15,23 +15,33 @@ */ #include <iostream> #include <memory> -#include <thread> +#include <cstring> +#include <cstdlib> +#include <chrono> #include "sensorset.hpp" #include "sensorcache.hpp" #include "hwmon.hpp" #include "sysfs.hpp" #include "mainloop.hpp" +using namespace std::literals::chrono_literals; + MainLoop::MainLoop( + sdbusplus::bus::bus&& bus, const std::string& path, const char* prefix, const char* root) - : _shutdown(false), + : _bus(std::move(bus)), + _manager(sdbusplus::server::manager::manager(_bus, root)), + _shutdown(false), _path(path), _prefix(prefix), _root(root) { - + if (_path.back() == '/') + { + _path.pop_back(); + } } void MainLoop::shutdown() noexcept @@ -45,6 +55,20 @@ void MainLoop::run() auto sensors = std::make_unique<SensorSet>(_path); auto sensor_cache = std::make_unique<SensorCache>(); + { + struct Free + { + void operator()(char* ptr) const + { + free(ptr); + } + }; + + auto copy = std::unique_ptr<char, Free>(strdup(_path.c_str())); + auto busname = std::string(_prefix) + '.' + basename(copy.get()); + _bus.request_name(busname.c_str()); + } + // TODO: Issue#3 - Need to make calls to the dbus sensor cache here to // ensure the objects all exist? @@ -73,13 +97,13 @@ void MainLoop::run() } } + // Respond to DBus + _bus.process_discard(); + // Sleep until next interval. // TODO: Issue#5 - Make this configurable. // TODO: Issue#6 - Optionally look at polling interval sysfs entry. - { - using namespace std::literals::chrono_literals; - std::this_thread::sleep_for(1s); - } + _bus.wait((1000000us).count()); // TODO: Issue#7 - Should probably periodically check the SensorSet // for new entries. diff --git a/mainloop.hpp b/mainloop.hpp index 2d2cea2..23ee683 100644 --- a/mainloop.hpp +++ b/mainloop.hpp @@ -1,6 +1,7 @@ #pragma once #include <string> +#include <sdbusplus/server.hpp> /** @class MainLoop * @brief hwmon-readd main application loop. @@ -17,6 +18,7 @@ class MainLoop /** @brief Constructor * + * @param[in] bus - sdbusplus bus client connection. * @param[in] path - hwmon sysfs instance to manage * @param[in] prefix - DBus busname prefix. * @param[in] root - DBus sensors namespace root. @@ -28,6 +30,7 @@ class MainLoop * the format <prefix>.hwmon<n>. */ MainLoop( + sdbusplus::bus::bus&& bus, const std::string& path, const char* prefix, const char* root); @@ -42,7 +45,10 @@ class MainLoop void shutdown() noexcept; private: - + /** @brief sdbusplus bus client connection. */ + sdbusplus::bus::bus _bus; + /** @brief sdbusplus freedesktop.ObjectManager storage. */ + sdbusplus::server::manager::manager _manager; /** @brief Shutdown requested. */ volatile bool _shutdown; /** @brief Path to hwmon sysfs instance. */ @@ -43,6 +43,7 @@ int main(int argc, char** argv) options.reset(); MainLoop loop( + sdbusplus::bus::new_default(), path, BUSNAME_PREFIX, SENSOR_ROOT); diff --git a/test/test.cpp b/test/test.cpp index df9ed22..c5c8a1d 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -44,6 +44,7 @@ int main() f << "1234"; auto loop = MainLoop( + sdbusplus::bus::new_default(), dir, "xyz.openbmc_project.Testing", "/testing"); auto t = std::thread(server_thread, &loop); |