blob: 403662344d9ab031d971db7dc68c72f8df9c806f [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
39enum class UpdatedProp
40{
41 port = 1,
42 maskedState,
43 enabledState,
44 runningState
45};
46
47using 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
52class 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
70 private:
71 sdbusplus::asio::object_server& server;
72 std::shared_ptr<sdbusplus::asio::dbus_interface> srvCfgIface;
73 std::shared_ptr<sdbusplus::asio::dbus_interface> sockAttrIface;
74
75 bool internalSet = false;
76 std::string objPath;
77 std::string baseUnitName;
78 std::string instanceName;
79 std::string instantiatedUnitName;
80 std::string serviceObjectPath;
81 std::string socketObjectPath;
82 std::string overrideConfDir;
83
84 // Properties
85 std::string activeState;
86 std::string subState;
87 uint16_t portNum;
88 std::vector<std::string> channelList;
89 std::string protocol;
90 std::string stateValue;
91 bool unitMaskedState = false;
92 bool unitEnabledState = false;
93 bool unitRunningState = false;
George Liua19b5092021-05-24 15:54:02 +080094
95 // dropbear is handled specially because it is a socket-activated service.
96 bool isDropBearService = false;
Vernon Maueryba2c0832020-07-15 10:02:38 -070097 std::string subStateValue;
98
99 bool isMaskedOut();
100 void registerProperties();
101 void queryAndUpdateProperties();
102 void createSocketOverrideConf();
103 void updateServiceProperties(
104 const boost::container::flat_map<std::string, VariantType>&
105 propertyMap);
106 void updateSocketProperties(
107 const boost::container::flat_map<std::string, VariantType>&
108 propertyMap);
109 std::string getSocketUnitName();
110 std::string getServiceUnitName();
111};
112
113} // namespace service
114} // namespace phosphor