| Vernon Mauery | ba2c083 | 2020-07-15 10:02:38 -0700 | [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 "utils.hpp" | 
|  | 18 |  | 
|  | 19 | #include <sdbusplus/timer.hpp> | 
|  | 20 |  | 
|  | 21 | namespace phosphor | 
|  | 22 | { | 
|  | 23 | namespace service | 
|  | 24 | { | 
|  | 25 |  | 
|  | 26 | static constexpr const char* serviceConfigSrvName = | 
|  | 27 | "xyz.openbmc_project.Control.Service.Manager"; | 
|  | 28 | static constexpr const char* serviceConfigIntfName = | 
|  | 29 | "xyz.openbmc_project.Control.Service.Attributes"; | 
|  | 30 | static constexpr const char* sockAttrIntfName = | 
|  | 31 | "xyz.openbmc_project.Control.Service.SocketAttributes"; | 
|  | 32 | static constexpr const char* srcCfgMgrBasePath = | 
|  | 33 | "/xyz/openbmc_project/control/service"; | 
| Vernon Mauery | ba2c083 | 2020-07-15 10:02:38 -0700 | [diff] [blame] | 34 | static constexpr const char* sockAttrPropPort = "Port"; | 
|  | 35 | static constexpr const char* srvCfgPropMasked = "Masked"; | 
|  | 36 | static constexpr const char* srvCfgPropEnabled = "Enabled"; | 
|  | 37 | static constexpr const char* srvCfgPropRunning = "Running"; | 
|  | 38 |  | 
|  | 39 | enum class UpdatedProp | 
|  | 40 | { | 
|  | 41 | port = 1, | 
|  | 42 | maskedState, | 
|  | 43 | enabledState, | 
|  | 44 | runningState | 
|  | 45 | }; | 
|  | 46 |  | 
|  | 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 |  | 
|  | 52 | class ServiceConfig | 
|  | 53 | { | 
|  | 54 | public: | 
|  | 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); | 
|  | 61 | ~ServiceConfig() = default; | 
|  | 62 |  | 
|  | 63 | std::shared_ptr<sdbusplus::asio::connection> conn; | 
|  | 64 | uint8_t updatedFlag; | 
|  | 65 |  | 
|  | 66 | void stopAndApplyUnitConfig(boost::asio::yield_context yield); | 
|  | 67 | void restartUnitConfig(boost::asio::yield_context yield); | 
|  | 68 | void startServiceRestartTimer(); | 
|  | 69 |  | 
| Chicago Duan | 25a0f63 | 2021-11-11 16:32:07 +0800 | [diff] [blame] | 70 | #ifdef USB_CODE_UPDATE | 
|  | 71 | void saveUSBCodeUpdateStateToFile(const bool& maskedState, | 
|  | 72 | const bool& enabledState); | 
|  | 73 | void getUSBCodeUpdateStateFromFile(); | 
|  | 74 | void setUSBCodeUpdateState(const bool& state); | 
|  | 75 | #endif | 
|  | 76 |  | 
| Vernon Mauery | ba2c083 | 2020-07-15 10:02:38 -0700 | [diff] [blame] | 77 | private: | 
|  | 78 | sdbusplus::asio::object_server& server; | 
|  | 79 | std::shared_ptr<sdbusplus::asio::dbus_interface> srvCfgIface; | 
|  | 80 | std::shared_ptr<sdbusplus::asio::dbus_interface> sockAttrIface; | 
|  | 81 |  | 
|  | 82 | bool internalSet = false; | 
|  | 83 | std::string objPath; | 
|  | 84 | std::string baseUnitName; | 
|  | 85 | std::string instanceName; | 
|  | 86 | std::string instantiatedUnitName; | 
|  | 87 | std::string serviceObjectPath; | 
|  | 88 | std::string socketObjectPath; | 
|  | 89 | std::string overrideConfDir; | 
|  | 90 |  | 
|  | 91 | // Properties | 
|  | 92 | std::string activeState; | 
|  | 93 | std::string subState; | 
|  | 94 | uint16_t portNum; | 
|  | 95 | std::vector<std::string> channelList; | 
|  | 96 | std::string protocol; | 
|  | 97 | std::string stateValue; | 
|  | 98 | bool unitMaskedState = false; | 
|  | 99 | bool unitEnabledState = false; | 
|  | 100 | bool unitRunningState = false; | 
| George Liu | a19b509 | 2021-05-24 15:54:02 +0800 | [diff] [blame] | 101 |  | 
| Jiaqing Zhao | f476683 | 2022-02-28 14:28:18 +0800 | [diff] [blame^] | 102 | bool isSocketActivatedService = false; | 
| Vernon Mauery | ba2c083 | 2020-07-15 10:02:38 -0700 | [diff] [blame] | 103 | std::string subStateValue; | 
|  | 104 |  | 
|  | 105 | bool isMaskedOut(); | 
|  | 106 | void registerProperties(); | 
|  | 107 | void queryAndUpdateProperties(); | 
|  | 108 | void createSocketOverrideConf(); | 
|  | 109 | void updateServiceProperties( | 
|  | 110 | const boost::container::flat_map<std::string, VariantType>& | 
|  | 111 | propertyMap); | 
|  | 112 | void updateSocketProperties( | 
|  | 113 | const boost::container::flat_map<std::string, VariantType>& | 
|  | 114 | propertyMap); | 
|  | 115 | std::string getSocketUnitName(); | 
|  | 116 | std::string getServiceUnitName(); | 
|  | 117 | }; | 
|  | 118 |  | 
|  | 119 | } // namespace service | 
|  | 120 | } // namespace phosphor |