AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 1 | /*
|
| 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
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 17 | #include <boost/asio.hpp>
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 18 | #include <phosphor-logging/elog-errors.hpp>
|
| 19 | #include <sdbusplus/asio/object_server.hpp>
|
| 20 | #include <xyz/openbmc_project/Common/error.hpp>
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 21 |
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 22 | #include <chrono>
|
| 23 | #include <ctime>
|
Tom Joseph | 82e9557 | 2020-05-07 20:28:05 +0530 | [diff] [blame] | 24 | #include <filesystem>
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 25 | #include <string>
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 26 |
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 27 | static constexpr const char* sysdStartUnit = "StartUnit";
|
| 28 | static constexpr const char* sysdStopUnit = "StopUnit";
|
| 29 | static constexpr const char* sysdRestartUnit = "RestartUnit";
|
| 30 | static constexpr const char* sysdReloadMethod = "Reload";
|
| 31 | static constexpr const char* sysdGetJobMethod = "GetJob";
|
| 32 | static constexpr const char* sysdReplaceMode = "replace";
|
| 33 | static constexpr const char* dBusGetAllMethod = "GetAll";
|
| 34 | static constexpr const char* dBusGetMethod = "Get";
|
| 35 | static constexpr const char* sysdService = "org.freedesktop.systemd1";
|
| 36 | static constexpr const char* sysdObjPath = "/org/freedesktop/systemd1";
|
| 37 | static constexpr const char* sysdMgrIntf = "org.freedesktop.systemd1.Manager";
|
| 38 | static constexpr const char* sysdUnitIntf = "org.freedesktop.systemd1.Unit";
|
| 39 | static constexpr const char* sysdSocketIntf = "org.freedesktop.systemd1.Socket";
|
| 40 | static constexpr const char* dBusPropIntf = "org.freedesktop.DBus.Properties";
|
| 41 | static constexpr const char* stateMasked = "masked";
|
| 42 | static constexpr const char* stateEnabled = "enabled";
|
| 43 | static constexpr const char* stateDisabled = "disabled";
|
| 44 | static constexpr const char* subStateRunning = "running";
|
| 45 |
|
| 46 | static inline std::string addInstanceName(const std::string& instanceName,
|
| 47 | const std::string& suffix)
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 48 | {
|
| 49 | return (instanceName.empty() ? "" : suffix + instanceName);
|
| 50 | }
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 51 |
|
| 52 | void systemdDaemonReload(
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 53 | const std::shared_ptr<sdbusplus::asio::connection>& conn,
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 54 | boost::asio::yield_context yield);
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 55 |
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 56 | void systemdUnitAction(const std::shared_ptr<sdbusplus::asio::connection>& conn,
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 57 | boost::asio::yield_context yield,
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 58 | const std::string& unitName,
|
| 59 | const std::string& actionMethod);
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 60 |
|
AppaRao Puli | e55cfd6 | 2019-02-15 15:35:29 +0530 | [diff] [blame] | 61 | void systemdUnitFilesStateChange(
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 62 | const std::shared_ptr<sdbusplus::asio::connection>& conn,
|
| 63 | boost::asio::yield_context yield, const std::vector<std::string>& unitFiles,
|
| 64 | const std::string& unitState, bool maskedState, bool enabledState);
|