Implement power control for x86 based platforms
This power control module provides the capability to
power on/off the host via gpio.
And provides some interfaces for system to contorl the system
power like:
setPowerState
getPowerState
Change-Id: Icd6530c42f2bc7c4d84062be786d25710b53f434
Signed-off-by: Kuiying Wang <kuiying.wang@intel.com>
diff --git a/power-control/src/main.cpp b/power-control/src/main.cpp
new file mode 100644
index 0000000..695666e
--- /dev/null
+++ b/power-control/src/main.cpp
@@ -0,0 +1,64 @@
+/*
+// Copyright (c) 2018 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+#include "power_control.hpp"
+
+int main(int argc, char* argv[])
+{
+ int ret = 0;
+
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ "Start Chassis power control service...");
+
+ sd_event* event = nullptr;
+ ret = sd_event_default(&event);
+ if (ret < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error creating a default sd_event handler");
+ return ret;
+ }
+ phosphor::watchdog::EventPtr eventP{event,
+ phosphor::watchdog::EventDeleter()};
+ event = nullptr;
+
+ sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
+ sdbusplus::server::manager_t m{bus, DBUS_OBJECT_NAME};
+
+ bus.request_name(DBUS_INTF_NAME);
+
+ PowerControl powerControl{bus, DBUS_OBJECT_NAME, eventP};
+
+ auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(
+ std::chrono::system_clock::now());
+
+ try
+ {
+ bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
+ ret = sd_event_loop(eventP.get());
+ if (ret < 0)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(
+ "Error occurred during the sd_event_loop",
+ phosphor::logging::entry("RET=%d", ret));
+ }
+ }
+ catch (std::exception& e)
+ {
+ phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
+ return -1;
+ }
+ return 0;
+}