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