xref: /openbmc/phosphor-power/phosphor-power-supply/main.cpp (revision b3028762bafd9e0ef4666c2fa423c3c582e07ce8)
12ad76bd3SBrandon Wyman /**
22ad76bd3SBrandon Wyman  * Copyright © 2019 IBM Corporation
32ad76bd3SBrandon Wyman  *
42ad76bd3SBrandon Wyman  * Licensed under the Apache License, Version 2.0 (the "License");
52ad76bd3SBrandon Wyman  * you may not use this file except in compliance with the License.
62ad76bd3SBrandon Wyman  * You may obtain a copy of the License at
72ad76bd3SBrandon Wyman  *
82ad76bd3SBrandon Wyman  *     http://www.apache.org/licenses/LICENSE-2.0
92ad76bd3SBrandon Wyman  *
102ad76bd3SBrandon Wyman  * Unless required by applicable law or agreed to in writing, software
112ad76bd3SBrandon Wyman  * distributed under the License is distributed on an "AS IS" BASIS,
122ad76bd3SBrandon Wyman  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
132ad76bd3SBrandon Wyman  * See the License for the specific language governing permissions and
142ad76bd3SBrandon Wyman  * limitations under the License.
152ad76bd3SBrandon Wyman  */
162bac8609SBrandon Wyman #include "psu_manager.hpp"
172bac8609SBrandon Wyman 
182ad76bd3SBrandon Wyman #include <CLI/CLI.hpp>
1957939e84SBrandon Wyman #include <phosphor-logging/log.hpp>
202bac8609SBrandon Wyman #include <sdbusplus/bus.hpp>
212bac8609SBrandon Wyman #include <sdeventplus/event.hpp>
2257939e84SBrandon Wyman 
2357939e84SBrandon Wyman #include <filesystem>
242ad76bd3SBrandon Wyman 
252fe5186eSBrandon Wyman using namespace phosphor::power;
26a0f33ce3SBrandon Wyman 
main(void)27*b3028762SBrandon Wyman int main(void)
282ad76bd3SBrandon Wyman {
29a0f33ce3SBrandon Wyman     try
30a0f33ce3SBrandon Wyman     {
3157939e84SBrandon Wyman         using namespace phosphor::logging;
322ad76bd3SBrandon Wyman 
332ad76bd3SBrandon Wyman         CLI::App app{"OpenBMC Power Supply Unit Monitor"};
3457939e84SBrandon Wyman 
352bac8609SBrandon Wyman         auto bus = sdbusplus::bus::new_default();
362bac8609SBrandon Wyman         auto event = sdeventplus::Event::get_default();
372bac8609SBrandon Wyman 
382bac8609SBrandon Wyman         // Attach the event object to the bus object so we can
392bac8609SBrandon Wyman         // handle both sd_events (for the timers) and dbus signals.
402bac8609SBrandon Wyman         bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
412bac8609SBrandon Wyman 
42*b3028762SBrandon Wyman         manager::PSUManager manager(bus, event);
432bac8609SBrandon Wyman 
44a0f33ce3SBrandon Wyman         return manager.run();
45a0f33ce3SBrandon Wyman     }
46a0f33ce3SBrandon Wyman     catch (const std::exception& e)
47a0f33ce3SBrandon Wyman     {
48a0f33ce3SBrandon Wyman         log<level::ERR>(e.what());
49a0f33ce3SBrandon Wyman         return -2;
50a0f33ce3SBrandon Wyman     }
51a0f33ce3SBrandon Wyman     catch (...)
52a0f33ce3SBrandon Wyman     {
53a0f33ce3SBrandon Wyman         log<level::ERR>("Caught unexpected exception type");
54a0f33ce3SBrandon Wyman         return -3;
55a0f33ce3SBrandon Wyman     }
562ad76bd3SBrandon Wyman }
57