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