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