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"; 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"; 35 36 enum class UpdatedProp 37 { 38 port = 1, 39 maskedState, 40 enabledState, 41 runningState 42 }; 43 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 49 class ServiceConfig 50 { 51 public: 52 ServiceConfig(sdbusplus::asio::object_server &srv_, 53 std::shared_ptr<sdbusplus::asio::connection> &conn_, 54 const std::string &objPath_, const std::string &baseUnitName, 55 const std::string &instanceName, 56 const std::string &serviceObjPath, 57 const std::string &socketObjPath); 58 ~ServiceConfig() = default; 59 60 std::shared_ptr<sdbusplus::asio::connection> conn; 61 uint8_t updatedFlag; 62 63 void stopAndApplyUnitConfig(boost::asio::yield_context yield); 64 void restartUnitConfig(boost::asio::yield_context yield); 65 void startServiceRestartTimer(); 66 67 private: 68 sdbusplus::asio::object_server &server; 69 std::shared_ptr<sdbusplus::asio::dbus_interface> iface; 70 bool internalSet = false; 71 std::string objPath; 72 std::string instanceName; 73 std::string baseUnitName; 74 std::string instantiatedUnitName; 75 std::string socketObjectPath; 76 std::string serviceObjectPath; 77 std::string overrideConfDir; 78 79 // Properties 80 std::string activeState; 81 std::string subState; 82 uint16_t portNum; 83 std::vector<std::string> channelList; 84 std::string protocol; 85 std::string stateValue; 86 bool unitMaskedState = false; 87 bool unitEnabledState = false; 88 bool unitRunningState = false; 89 std::string subStateValue; 90 91 bool isMaskedOut(); 92 void registerProperties(); 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(); 103 }; 104 105 } // namespace service 106 } // namespace phosphor 107