summaryrefslogtreecommitdiffstats
path: root/controller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'controller.cpp')
-rw-r--r--controller.cpp46
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;
}
OpenPOWER on IntegriCloud