blob: 234124d85a0c210e48be13e9ac4595d36ee8660b [file] [log] [blame]
Vernon Maueryba2c0832020-07-15 10:02:38 -07001/*
2// Copyright (c) 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#pragma once
17#include <boost/asio.hpp>
18#include <phosphor-logging/elog-errors.hpp>
19#include <sdbusplus/asio/object_server.hpp>
20#include <xyz/openbmc_project/Common/error.hpp>
21
22#include <chrono>
23#include <ctime>
24#include <filesystem>
25#include <string>
26
27static constexpr const char* sysdStartUnit = "StartUnit";
28static constexpr const char* sysdStopUnit = "StopUnit";
29static constexpr const char* sysdRestartUnit = "RestartUnit";
30static constexpr const char* sysdReloadMethod = "Reload";
31static constexpr const char* sysdGetJobMethod = "GetJob";
32static constexpr const char* sysdReplaceMode = "replace";
33static constexpr const char* dBusGetAllMethod = "GetAll";
34static constexpr const char* dBusGetMethod = "Get";
35static constexpr const char* sysdService = "org.freedesktop.systemd1";
36static constexpr const char* sysdObjPath = "/org/freedesktop/systemd1";
37static constexpr const char* sysdMgrIntf = "org.freedesktop.systemd1.Manager";
38static constexpr const char* sysdUnitIntf = "org.freedesktop.systemd1.Unit";
39static constexpr const char* sysdSocketIntf = "org.freedesktop.systemd1.Socket";
40static constexpr const char* dBusPropIntf = "org.freedesktop.DBus.Properties";
41static constexpr const char* stateMasked = "masked";
42static constexpr const char* stateEnabled = "enabled";
43static constexpr const char* stateDisabled = "disabled";
44static constexpr const char* subStateRunning = "running";
George Liua19b5092021-05-24 15:54:02 +080045static constexpr const char* subStateListening = "listening";
46
47using ListUnitsType =
48 std::tuple<std::string, std::string, std::string, std::string, std::string,
49 std::string, sdbusplus::message::object_path, uint32_t,
50 std::string, sdbusplus::message::object_path>;
51
52enum class ListUnitElements
53{
54 name,
55 descriptionString,
56 loadState,
57 activeState,
58 subState,
59 followedUnit,
60 objectPath,
61 queuedJobType,
62 jobType,
63 jobObject
64};
Vernon Maueryba2c0832020-07-15 10:02:38 -070065
66static inline std::string addInstanceName(const std::string& instanceName,
67 const std::string& suffix)
68{
69 return (instanceName.empty() ? "" : suffix + instanceName);
70}
71
George Liua19b5092021-05-24 15:54:02 +080072void checkAndThrowInternalFailure(boost::system::error_code& ec,
73 const std::string& msg);
74
Vernon Maueryba2c0832020-07-15 10:02:38 -070075void systemdDaemonReload(
76 const std::shared_ptr<sdbusplus::asio::connection>& conn,
77 boost::asio::yield_context yield);
78
79void systemdUnitAction(const std::shared_ptr<sdbusplus::asio::connection>& conn,
80 boost::asio::yield_context yield,
81 const std::string& unitName,
82 const std::string& actionMethod);
83
84void systemdUnitFilesStateChange(
85 const std::shared_ptr<sdbusplus::asio::connection>& conn,
86 boost::asio::yield_context yield, const std::vector<std::string>& unitFiles,
87 const std::string& unitState, bool maskedState, bool enabledState);