blob: b0e345c80174853610bb96f456413d95c2577b60 [file] [log] [blame]
Vernon Maueryba2c0832020-07-15 10:02:38 -07001/*
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
Patrick Williamsa1292a62022-09-20 12:12:34 -050019#include <boost/container/flat_map.hpp>
Vernon Maueryba2c0832020-07-15 10:02:38 -070020#include <sdbusplus/timer.hpp>
21
22namespace phosphor
23{
24namespace service
25{
26
27static constexpr const char* serviceConfigSrvName =
28 "xyz.openbmc_project.Control.Service.Manager";
29static constexpr const char* serviceConfigIntfName =
30 "xyz.openbmc_project.Control.Service.Attributes";
31static constexpr const char* sockAttrIntfName =
32 "xyz.openbmc_project.Control.Service.SocketAttributes";
33static constexpr const char* srcCfgMgrBasePath =
34 "/xyz/openbmc_project/control/service";
Vernon Maueryba2c0832020-07-15 10:02:38 -070035static constexpr const char* sockAttrPropPort = "Port";
36static constexpr const char* srvCfgPropMasked = "Masked";
37static constexpr const char* srvCfgPropEnabled = "Enabled";
38static constexpr const char* srvCfgPropRunning = "Running";
39
Jiaqing Zhao430d7ea2022-04-01 23:23:25 +080040#ifdef USB_CODE_UPDATE
41static constexpr const char* usbCodeUpdateUnitName = "phosphor_usb_code_update";
42#endif
43
Vernon Maueryba2c0832020-07-15 10:02:38 -070044enum class UpdatedProp
45{
46 port = 1,
47 maskedState,
48 enabledState,
49 runningState
50};
51
52using VariantType =
53 std::variant<std::string, int64_t, uint64_t, double, int32_t, uint32_t,
54 int16_t, uint16_t, uint8_t, bool,
55 std::vector<std::tuple<std::string, std::string>>>;
56
57class ServiceConfig
58{
59 public:
60 ServiceConfig(sdbusplus::asio::object_server& srv_,
61 std::shared_ptr<sdbusplus::asio::connection>& conn_,
62 const std::string& objPath_, const std::string& baseUnitName,
63 const std::string& instanceName,
64 const std::string& serviceObjPath,
65 const std::string& socketObjPath);
66 ~ServiceConfig() = default;
67
68 std::shared_ptr<sdbusplus::asio::connection> conn;
69 uint8_t updatedFlag;
70
71 void stopAndApplyUnitConfig(boost::asio::yield_context yield);
72 void restartUnitConfig(boost::asio::yield_context yield);
73 void startServiceRestartTimer();
74
Chicago Duan25a0f632021-11-11 16:32:07 +080075#ifdef USB_CODE_UPDATE
76 void saveUSBCodeUpdateStateToFile(const bool& maskedState,
77 const bool& enabledState);
78 void getUSBCodeUpdateStateFromFile();
79 void setUSBCodeUpdateState(const bool& state);
80#endif
81
Vernon Maueryba2c0832020-07-15 10:02:38 -070082 private:
83 sdbusplus::asio::object_server& server;
84 std::shared_ptr<sdbusplus::asio::dbus_interface> srvCfgIface;
85 std::shared_ptr<sdbusplus::asio::dbus_interface> sockAttrIface;
86
87 bool internalSet = false;
88 std::string objPath;
89 std::string baseUnitName;
90 std::string instanceName;
91 std::string instantiatedUnitName;
92 std::string serviceObjectPath;
93 std::string socketObjectPath;
94 std::string overrideConfDir;
95
96 // Properties
97 std::string activeState;
98 std::string subState;
99 uint16_t portNum;
100 std::vector<std::string> channelList;
101 std::string protocol;
102 std::string stateValue;
103 bool unitMaskedState = false;
104 bool unitEnabledState = false;
105 bool unitRunningState = false;
George Liua19b5092021-05-24 15:54:02 +0800106
Jiaqing Zhaof4766832022-02-28 14:28:18 +0800107 bool isSocketActivatedService = false;
Vernon Maueryba2c0832020-07-15 10:02:38 -0700108 std::string subStateValue;
109
110 bool isMaskedOut();
111 void registerProperties();
112 void queryAndUpdateProperties();
113 void createSocketOverrideConf();
114 void updateServiceProperties(
115 const boost::container::flat_map<std::string, VariantType>&
116 propertyMap);
117 void updateSocketProperties(
118 const boost::container::flat_map<std::string, VariantType>&
119 propertyMap);
120 std::string getSocketUnitName();
121 std::string getServiceUnitName();
122};
123
124} // namespace service
125} // namespace phosphor