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