blob: 695666eb11abc90b611c14deae15b0b34bc330ba [file] [log] [blame]
Kuiying Wang64ff7ce2018-08-15 11:17:06 +08001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#include "power_control.hpp"
17
18int main(int argc, char* argv[])
19{
20 int ret = 0;
21
22 phosphor::logging::log<phosphor::logging::level::INFO>(
23 "Start Chassis power control service...");
24
25 sd_event* event = nullptr;
26 ret = sd_event_default(&event);
27 if (ret < 0)
28 {
29 phosphor::logging::log<phosphor::logging::level::ERR>(
30 "Error creating a default sd_event handler");
31 return ret;
32 }
33 phosphor::watchdog::EventPtr eventP{event,
34 phosphor::watchdog::EventDeleter()};
35 event = nullptr;
36
37 sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
38 sdbusplus::server::manager_t m{bus, DBUS_OBJECT_NAME};
39
40 bus.request_name(DBUS_INTF_NAME);
41
42 PowerControl powerControl{bus, DBUS_OBJECT_NAME, eventP};
43
44 auto now_ms = std::chrono::time_point_cast<std::chrono::milliseconds>(
45 std::chrono::system_clock::now());
46
47 try
48 {
49 bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
50 ret = sd_event_loop(eventP.get());
51 if (ret < 0)
52 {
53 phosphor::logging::log<phosphor::logging::level::ERR>(
54 "Error occurred during the sd_event_loop",
55 phosphor::logging::entry("RET=%d", ret));
56 }
57 }
58 catch (std::exception& e)
59 {
60 phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
61 return -1;
62 }
63 return 0;
64}