blob: 05dce98bbf1ad670570bbc243e93f17f4358eee9 [file] [log] [blame]
Matt Spinlere73446e2017-04-10 13:55:52 -05001/**
2 * Copyright © 2017 IBM 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 */
Matt Spinleree7f6422017-05-09 11:03:14 -050016#include "argument.hpp"
Matt Spinlere10416e2017-04-10 14:15:53 -050017#include "manager.hpp"
Matt Spinlerba7b5fe2018-04-25 15:26:10 -050018#include "sdbusplus.hpp"
Matt Spinlere73446e2017-04-10 13:55:52 -050019
Matthew Barth3e1bb272020-05-26 11:09:21 -050020#include <phosphor-logging/log.hpp>
21#include <sdbusplus/bus.hpp>
22#include <sdeventplus/event.hpp>
23
Matt Spinleree7f6422017-05-09 11:03:14 -050024using namespace phosphor::fan::control;
Matthew Barth8600d9a2017-06-23 14:38:05 -050025using namespace phosphor::logging;
Matt Spinleree7f6422017-05-09 11:03:14 -050026
Matt Spinlere73446e2017-04-10 13:55:52 -050027int main(int argc, char* argv[])
28{
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070029 auto event = sdeventplus::Event::get_default();
Matt Spinlere73446e2017-04-10 13:55:52 -050030 auto bus = sdbusplus::bus::new_default();
Matt Spinleree7f6422017-05-09 11:03:14 -050031 phosphor::fan::util::ArgumentParser args(argc, argv);
Matt Spinlere73446e2017-04-10 13:55:52 -050032
Matt Spinleree7f6422017-05-09 11:03:14 -050033 if (argc != 2)
34 {
35 args.usage(argv);
William A. Kennington III3e781062018-10-19 17:18:34 -070036 return 1;
Matt Spinleree7f6422017-05-09 11:03:14 -050037 }
38
Matthew Barth14184132017-05-19 14:37:30 -050039 Mode mode;
Matt Spinleree7f6422017-05-09 11:03:14 -050040
41 if (args["init"] == "true")
42 {
Matthew Barth14184132017-05-19 14:37:30 -050043 mode = Mode::init;
Matt Spinleree7f6422017-05-09 11:03:14 -050044 }
45 else if (args["control"] == "true")
46 {
Matthew Barth14184132017-05-19 14:37:30 -050047 mode = Mode::control;
Matt Spinleree7f6422017-05-09 11:03:14 -050048 }
49 else
50 {
51 args.usage(argv);
William A. Kennington III3e781062018-10-19 17:18:34 -070052 return 1;
Matt Spinleree7f6422017-05-09 11:03:14 -050053 }
54
Matthew Barth3e1bb272020-05-26 11:09:21 -050055 // Attach the event object to the bus object so we can
56 // handle both sd_events (for the timers) and dbus signals.
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070057 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Matthew Barth8600d9a2017-06-23 14:38:05 -050058
Matt Spinlerba7b5fe2018-04-25 15:26:10 -050059 try
60 {
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070061 Manager manager(bus, event, mode);
Matt Spinleree7f6422017-05-09 11:03:14 -050062
Matthew Barth3e1bb272020-05-26 11:09:21 -050063 // Init mode will just set fans to max and delay
Matt Spinlerba7b5fe2018-04-25 15:26:10 -050064 if (mode == Mode::init)
Matthew Barth8600d9a2017-06-23 14:38:05 -050065 {
Matt Spinlerba7b5fe2018-04-25 15:26:10 -050066 manager.doInit();
67 return 0;
Matthew Barth8600d9a2017-06-23 14:38:05 -050068 }
William A. Kennington III1cfc2f12018-10-19 17:29:46 -070069
70 return event.loop();
Matt Spinlerba7b5fe2018-04-25 15:26:10 -050071 }
Matthew Barth3e1bb272020-05-26 11:09:21 -050072 // Log the useful metadata on these exceptions and let the app
73 // return 1 so it is restarted without a core dump.
Matt Spinlerba7b5fe2018-04-25 15:26:10 -050074 catch (phosphor::fan::util::DBusServiceError& e)
75 {
76 log<level::ERR>("Uncaught DBus service lookup failure exception",
Matthew Barth3e1bb272020-05-26 11:09:21 -050077 entry("PATH=%s", e.path.c_str()),
78 entry("INTERFACE=%s", e.interface.c_str()));
Matt Spinlerba7b5fe2018-04-25 15:26:10 -050079 }
80 catch (phosphor::fan::util::DBusMethodError& e)
81 {
82 log<level::ERR>("Uncaught DBus method failure exception",
Matthew Barth3e1bb272020-05-26 11:09:21 -050083 entry("BUSNAME=%s", e.busName.c_str()),
84 entry("PATH=%s", e.path.c_str()),
85 entry("INTERFACE=%s", e.interface.c_str()),
86 entry("METHOD=%s", e.method.c_str()));
Matt Spinlere73446e2017-04-10 13:55:52 -050087 }
Matthew Barth88923a02018-05-11 10:14:44 -050088 catch (phosphor::fan::util::DBusPropertyError& e)
89 {
90 log<level::ERR>("Uncaught DBus property access failure exception",
Matthew Barth3e1bb272020-05-26 11:09:21 -050091 entry("BUSNAME=%s", e.busName.c_str()),
92 entry("PATH=%s", e.path.c_str()),
93 entry("INTERFACE=%s", e.interface.c_str()),
94 entry("PROPERTY=%s", e.property.c_str()));
Matthew Barth88923a02018-05-11 10:14:44 -050095 }
Matt Spinlere73446e2017-04-10 13:55:52 -050096
William A. Kennington III3e781062018-10-19 17:18:34 -070097 return 1;
Matt Spinlere73446e2017-04-10 13:55:52 -050098}