blob: 68e24ea1c642deef0121a91cbb6b99e7dd407121 [file] [log] [blame]
Vernon Mauerye7329c72018-10-08 12:05:16 -07001/*
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 Mauerye08fbff2019-04-03 09:19:34 -070020// make it possible to ONLY include api.hpp during the transition
21#ifdef ALLOW_DEPRECATED_API
22#include <ipmid/api.h>
23#endif
Vernon Mauerye7329c72018-10-08 12:05:16 -070024
Ed Tanous778418d2020-08-17 23:20:21 -070025#include <boost/asio/io_context.hpp>
Vernon Mauerye08fbff2019-04-03 09:19:34 -070026#include <ipmid/api-types.hpp>
27#include <ipmid/filter.hpp>
28#include <ipmid/handler.hpp>
Vernon Mauerye7329c72018-10-08 12:05:16 -070029#include <ipmid/message/types.hpp>
Vernon Mauerye7329c72018-10-08 12:05:16 -070030#include <sdbusplus/asio/connection.hpp>
31#include <sdbusplus/asio/object_server.hpp>
32
Vernon Mauery20ff3332019-03-01 16:52:25 -080033// any client can interact with the main asio context
34std::shared_ptr<boost::asio::io_context> getIoContext();
Vernon Mauerye7329c72018-10-08 12:05:16 -070035
36// any client can interact with the main sdbus
37std::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 */
48template <typename WorkFn>
49static inline void post_work(WorkFn work)
50{
Vernon Mauery23d06442019-03-13 09:16:04 -070051 boost::asio::post(*getIoContext(), std::forward<WorkFn>(work));
Vernon Mauerye7329c72018-10-08 12:05:16 -070052}
Vernon Mauery3719c2f2019-03-20 13:00:20 -070053
54enum 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 */
86void registerSignalHandler(int priority, int signalNumber,
87 const std::function<SignalResponse(int)>& handler);