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* srcCfgMgrBasePath = 31 "/xyz/openbmc_project/control/service"; 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"; 36 37 enum class UpdatedProp 38 { 39 port = 1, 40 maskedState, 41 enabledState, 42 runningState 43 }; 44 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 50 class ServiceConfig 51 { 52 public: 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); 59 ~ServiceConfig() = default; 60 61 std::shared_ptr<sdbusplus::asio::connection> conn; 62 uint8_t updatedFlag; 63 64 void stopAndApplyUnitConfig(boost::asio::yield_context yield); 65 void restartUnitConfig(boost::asio::yield_context yield); 66 void startServiceRestartTimer(); 67 68 private: 69 sdbusplus::asio::object_server& server; 70 std::shared_ptr<sdbusplus::asio::dbus_interface> iface; 71 bool internalSet = false; 72 std::string objPath; 73 std::string baseUnitName; 74 std::string instanceName; 75 std::string instantiatedUnitName; 76 std::string serviceObjectPath; 77 std::string socketObjectPath; 78 std::string overrideConfDir; 79 80 // Properties 81 std::string activeState; 82 std::string subState; 83 uint16_t portNum; 84 std::vector<std::string> channelList; 85 std::string protocol; 86 std::string stateValue; 87 bool unitMaskedState = false; 88 bool unitEnabledState = false; 89 bool unitRunningState = false; 90 std::string subStateValue; 91 92 bool isMaskedOut(); 93 void registerProperties(); 94 void queryAndUpdateProperties(); 95 void createSocketOverrideConf(); 96 void updateServiceProperties( 97 const boost::container::flat_map<std::string, VariantType>& 98 propertyMap); 99 void updateSocketProperties( 100 const boost::container::flat_map<std::string, VariantType>& 101 propertyMap); 102 std::string getSocketUnitName(); 103 std::string getServiceUnitName(); 104 }; 105 106 } // namespace service 107 } // namespace phosphor 108