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 "utils.hpp"
|
| 18 |
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 19 | #include <sdbusplus/timer.hpp>
|
| 20 |
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 21 | namespace phosphor
|
| 22 | {
|
| 23 | namespace service
|
| 24 | {
|
| 25 |
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 26 | static constexpr const char* serviceConfigSrvName =
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 27 | "xyz.openbmc_project.Control.Service.Manager";
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 28 | static constexpr const char* serviceConfigIntfName =
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 29 | "xyz.openbmc_project.Control.Service.Attributes";
|
Tom Joseph | 83241c0 | 2020-05-30 11:30:20 +0530 | [diff] [blame] | 30 | static constexpr const char* sockAttrIntfName =
|
| 31 | "xyz.openbmc_project.Control.Service.SocketAttributes";
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 32 | static constexpr const char* srcCfgMgrBasePath =
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 33 | "/xyz/openbmc_project/control/service";
|
Tom Joseph | 83241c0 | 2020-05-30 11:30:20 +0530 | [diff] [blame] | 34 | static constexpr const char* sockAttrPropPort = "Port";
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 35 | static constexpr const char* srvCfgPropMasked = "Masked";
|
| 36 | static constexpr const char* srvCfgPropEnabled = "Enabled";
|
| 37 | static constexpr const char* srvCfgPropRunning = "Running";
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 38 |
|
| 39 | enum class UpdatedProp
|
| 40 | {
|
| 41 | port = 1,
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 42 | maskedState,
|
| 43 | enabledState,
|
| 44 | runningState
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 45 | };
|
| 46 |
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 47 | using VariantType =
|
| 48 | std::variant<std::string, int64_t, uint64_t, double, int32_t, uint32_t,
|
| 49 | int16_t, uint16_t, uint8_t, bool,
|
| 50 | std::vector<std::tuple<std::string, std::string>>>;
|
| 51 |
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 52 | class ServiceConfig
|
| 53 | {
|
| 54 | public:
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 55 | ServiceConfig(sdbusplus::asio::object_server& srv_,
|
| 56 | std::shared_ptr<sdbusplus::asio::connection>& conn_,
|
| 57 | const std::string& objPath_, const std::string& baseUnitName,
|
| 58 | const std::string& instanceName,
|
| 59 | const std::string& serviceObjPath,
|
| 60 | const std::string& socketObjPath);
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 61 | ~ServiceConfig() = default;
|
| 62 |
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 63 | std::shared_ptr<sdbusplus::asio::connection> conn;
|
| 64 | uint8_t updatedFlag;
|
| 65 |
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 66 | void stopAndApplyUnitConfig(boost::asio::yield_context yield);
|
| 67 | void restartUnitConfig(boost::asio::yield_context yield);
|
| 68 | void startServiceRestartTimer();
|
| 69 |
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 70 | private:
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 71 | sdbusplus::asio::object_server& server;
|
Tom Joseph | 83241c0 | 2020-05-30 11:30:20 +0530 | [diff] [blame] | 72 | std::shared_ptr<sdbusplus::asio::dbus_interface> srvCfgIface;
|
| 73 | std::shared_ptr<sdbusplus::asio::dbus_interface> sockAttrIface;
|
| 74 |
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 75 | bool internalSet = false;
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 76 | std::string objPath;
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 77 | std::string baseUnitName;
|
Tom Joseph | 82e9557 | 2020-05-07 20:28:05 +0530 | [diff] [blame] | 78 | std::string instanceName;
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 79 | std::string instantiatedUnitName;
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 80 | std::string serviceObjectPath;
|
Tom Joseph | 82e9557 | 2020-05-07 20:28:05 +0530 | [diff] [blame] | 81 | std::string socketObjectPath;
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 82 | std::string overrideConfDir;
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 83 |
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 84 | // Properties
|
| 85 | std::string activeState;
|
| 86 | std::string subState;
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 87 | uint16_t portNum;
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 88 | std::vector<std::string> channelList;
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 89 | std::string protocol;
|
| 90 | std::string stateValue;
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 91 | bool unitMaskedState = false;
|
| 92 | bool unitEnabledState = false;
|
| 93 | bool unitRunningState = false;
|
| 94 | std::string subStateValue;
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 95 |
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 96 | bool isMaskedOut();
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 97 | void registerProperties();
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 98 | void queryAndUpdateProperties();
|
| 99 | void createSocketOverrideConf();
|
| 100 | void updateServiceProperties(
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 101 | const boost::container::flat_map<std::string, VariantType>&
|
| 102 | propertyMap);
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 103 | void updateSocketProperties(
|
AppaRao Puli | ee853eb | 2020-05-29 00:53:20 +0530 | [diff] [blame] | 104 | const boost::container::flat_map<std::string, VariantType>&
|
| 105 | propertyMap);
|
Richard Marian Thomaiyar | 90f2da3 | 2019-05-23 05:37:50 +0530 | [diff] [blame] | 106 | std::string getSocketUnitName();
|
| 107 | std::string getServiceUnitName();
|
AppaRao Puli | 0084047 | 2018-10-03 19:37:46 +0530 | [diff] [blame] | 108 | };
|
| 109 |
|
| 110 | } // namespace service
|
| 111 | } // namespace phosphor
|