blob: f4cbf138d613194f4ad5f1895812f4e8cc460569 [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
Vernon Mauerye08fbff2019-04-03 09:19:34 -070025#include <ipmid/api-types.hpp>
26#include <ipmid/filter.hpp>
27#include <ipmid/handler.hpp>
Vernon Mauerye7329c72018-10-08 12:05:16 -070028#include <ipmid/message/types.hpp>
Vernon Mauerye7329c72018-10-08 12:05:16 -070029#include <sdbusplus/asio/connection.hpp>
30#include <sdbusplus/asio/object_server.hpp>
31
Vernon Mauery20ff3332019-03-01 16:52:25 -080032// any client can interact with the main asio context
33std::shared_ptr<boost::asio::io_context> getIoContext();
Vernon Mauerye7329c72018-10-08 12:05:16 -070034
35// any client can interact with the main sdbus
36std::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 */
47template <typename WorkFn>
48static inline void post_work(WorkFn work)
49{
Vernon Mauery20ff3332019-03-01 16:52:25 -080050 getIoContext()->post(std::forward<WorkFn>(work));
Vernon Mauerye7329c72018-10-08 12:05:16 -070051}
Vernon Mauery3719c2f2019-03-20 13:00:20 -070052
53enum 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 */
85void registerSignalHandler(int priority, int signalNumber,
86 const std::function<SignalResponse(int)>& handler);