diff options
author | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2016-11-30 14:20:53 +0530 |
---|---|---|
committer | Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com> | 2016-12-19 12:18:08 +0530 |
commit | 75b5510f573390e0725fd424b1799f1fdb3baa1a (patch) | |
tree | 58c4643682ace2334fa01a419d3f175b8bb79d85 /controller.cpp | |
parent | bda97eb107fc60544fb8cde0ec1ada1da2d66f73 (diff) | |
download | phosphor-led-sysfs-75b5510f573390e0725fd424b1799f1fdb3baa1a.tar.gz phosphor-led-sysfs-75b5510f573390e0725fd424b1799f1fdb3baa1a.zip |
Add overriding methods for the base interface definition
Defines the functions that override the default setter for
the led state property.
Change-Id: Ic3a8d43cc783003c43f53df8f7e90d7fc4d6715a
Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'controller.cpp')
-rw-r--r-- | controller.cpp | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/controller.cpp b/controller.cpp index bfc1c74..656c9bf 100644 --- a/controller.cpp +++ b/controller.cpp @@ -15,7 +15,10 @@ */ #include <iostream> +#include <string> #include "argument.hpp" +#include "physical.hpp" +#include "config.h" static void ExitWithError(const char* err, char** argv) { @@ -30,19 +33,46 @@ int main(int argc, char** argv) // Read arguments. auto options = phosphor::led::ArgumentParser(argc, argv); - // Parse out Name argument. - auto name = std::move((options)["name"]); - if (name == phosphor::led::ArgumentParser::empty_string) - { - ExitWithError("Name not specified.", argv); - } - - // Parse out Name argument. + // Parse out Path argument. auto path = std::move((options)["path"]); if (path == phosphor::led::ArgumentParser::empty_string) { ExitWithError("Path not specified.", argv); } + // Extract the name of LED from path. + auto index = path.rfind("/"); + if (index == std::string::npos) + { + throw std::runtime_error("No Led in " + path); + } + + // Remove the leading "/" + auto name = path.substr(index + 1); + + // Unique bus name representing a single LED. + auto busName = std::string(BUSNAME) + '.' + name; + auto objPath = std::string(OBJPATH) + '/' + name; + + // Get a handle to system dbus. + auto bus = std::move(sdbusplus::bus::new_default()); + + // Add systemd object manager. + sdbusplus::server::manager::manager(bus, objPath.c_str()); + + // Create the Physical LED objects for directing actions. + // Need to save this else sdbusplus destructor will wipe this off. + auto obj = phosphor::led::Physical(bus, objPath, path); + + /** @brief Claim the bus */ + bus.request_name(busName.c_str()); + + /** @brief Wait for client requests */ + while(true) + { + // Handle dbus message / signals discarding unhandled + bus.process_discard(); + bus.wait(); + } return 0; } |