Vernon Mauery | e7329c7 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 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 | */ |
| 17 | #pragma once |
| 18 | |
| 19 | #define ALLOW_DEPRECATED_API 1 |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 20 | // make it possible to ONLY include api.hpp during the transition |
| 21 | #ifdef ALLOW_DEPRECATED_API |
| 22 | #include <ipmid/api.h> |
| 23 | #endif |
Vernon Mauery | e7329c7 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 24 | |
Ed Tanous | 778418d | 2020-08-17 23:20:21 -0700 | [diff] [blame] | 25 | #include <boost/asio/io_context.hpp> |
Vernon Mauery | e08fbff | 2019-04-03 09:19:34 -0700 | [diff] [blame] | 26 | #include <ipmid/api-types.hpp> |
| 27 | #include <ipmid/filter.hpp> |
| 28 | #include <ipmid/handler.hpp> |
Vernon Mauery | e7329c7 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 29 | #include <ipmid/message/types.hpp> |
Vernon Mauery | e7329c7 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 30 | #include <sdbusplus/asio/connection.hpp> |
| 31 | #include <sdbusplus/asio/object_server.hpp> |
| 32 | |
Vernon Mauery | 20ff333 | 2019-03-01 16:52:25 -0800 | [diff] [blame] | 33 | // any client can interact with the main asio context |
| 34 | std::shared_ptr<boost::asio::io_context> getIoContext(); |
Vernon Mauery | e7329c7 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 35 | |
| 36 | // any client can interact with the main sdbus |
| 37 | std::shared_ptr<sdbusplus::asio::connection> getSdBus(); |
| 38 | |
| 39 | /** |
| 40 | * @brief post some work to the async exection queue |
| 41 | * |
| 42 | * The IPMI daemon runs an async exection queue; this allows any function to |
| 43 | * pass in work to be executed in that context |
| 44 | * |
| 45 | * @tparam WorkFn - a function of type void(void) |
| 46 | * @param work - the callback function to be executed |
| 47 | */ |
| 48 | template <typename WorkFn> |
| 49 | static inline void post_work(WorkFn work) |
| 50 | { |
Vernon Mauery | 23d0644 | 2019-03-13 09:16:04 -0700 | [diff] [blame] | 51 | boost::asio::post(*getIoContext(), std::forward<WorkFn>(work)); |
Vernon Mauery | e7329c7 | 2018-10-08 12:05:16 -0700 | [diff] [blame] | 52 | } |
Vernon Mauery | 3719c2f | 2019-03-20 13:00:20 -0700 | [diff] [blame] | 53 | |
| 54 | enum class SignalResponse : int |
| 55 | { |
| 56 | breakExecution, |
| 57 | continueExecution, |
| 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * @brief add a signal handler |
| 62 | * |
| 63 | * This registers a handler to be called asynchronously via the execution |
| 64 | * queue when the specified signal is received. |
| 65 | * |
| 66 | * Priority allows a signal handler to specify what order in the handler |
| 67 | * chain it gets called. Lower priority numbers will cause the handler to |
| 68 | * be executed later in the chain, while the highest priority numbers will cause |
| 69 | * the handler to be executed first. |
| 70 | * |
| 71 | * In order to facilitate a chain of handlers, each handler in the chain will be |
| 72 | * able to return breakExecution or continueExecution. Returning breakExecution |
| 73 | * will break the chain and no further handlers will execute for that signal. |
| 74 | * Returning continueExecution will allow lower-priority handlers to execute. |
| 75 | * |
| 76 | * By default, the main asio execution loop will register a low priority |
| 77 | * (prioOpenBmcBase) handler for SIGINT and SIGTERM to cause the process to stop |
| 78 | * on either of those signals. To prevent one of those signals from causing the |
| 79 | * process to stop, simply register a higher priority handler that returns |
| 80 | * breakExecution. |
| 81 | * |
| 82 | * @param int - priority of handler |
| 83 | * @param int - signal number to wait for |
| 84 | * @param handler - the callback function to be executed |
| 85 | */ |
| 86 | void registerSignalHandler(int priority, int signalNumber, |
| 87 | const std::function<SignalResponse(int)>& handler); |