blob: d0a3ae1a77b082685a73822a7529e948cdf0b412 [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";
34static constexpr const char* srcCfgMgrIntf =
35 "/xyz/openbmc_project.Control.Service.Manager";
36static constexpr const char* sockAttrPropPort = "Port";
37static constexpr const char* srvCfgPropMasked = "Masked";
38static constexpr const char* srvCfgPropEnabled = "Enabled";
39static constexpr const char* srvCfgPropRunning = "Running";
40
41enum class UpdatedProp
42{
43 port = 1,
44 maskedState,
45 enabledState,
46 runningState
47};
48
49using VariantType =
50 std::variant<std::string, int64_t, uint64_t, double, int32_t, uint32_t,
51 int16_t, uint16_t, uint8_t, bool,
52 std::vector<std::tuple<std::string, std::string>>>;
53
54class ServiceConfig
55{
56 public:
57 ServiceConfig(sdbusplus::asio::object_server& srv_,
58 std::shared_ptr<sdbusplus::asio::connection>& conn_,
59 const std::string& objPath_, const std::string& baseUnitName,
60 const std::string& instanceName,
61 const std::string& serviceObjPath,
62 const std::string& socketObjPath);
63 ~ServiceConfig() = default;
64
65 std::shared_ptr<sdbusplus::asio::connection> conn;
66 uint8_t updatedFlag;
67
68 void stopAndApplyUnitConfig(boost::asio::yield_context yield);
69 void restartUnitConfig(boost::asio::yield_context yield);
70 void startServiceRestartTimer();
71
72 private:
73 sdbusplus::asio::object_server& server;
74 std::shared_ptr<sdbusplus::asio::dbus_interface> srvCfgIface;
75 std::shared_ptr<sdbusplus::asio::dbus_interface> sockAttrIface;
76
77 bool internalSet = false;
78 std::string objPath;
79 std::string baseUnitName;
80 std::string instanceName;
81 std::string instantiatedUnitName;
82 std::string serviceObjectPath;
83 std::string socketObjectPath;
84 std::string overrideConfDir;
85
86 // Properties
87 std::string activeState;
88 std::string subState;
89 uint16_t portNum;
90 std::vector<std::string> channelList;
91 std::string protocol;
92 std::string stateValue;
93 bool unitMaskedState = false;
94 bool unitEnabledState = false;
95 bool unitRunningState = false;
96 std::string subStateValue;
97
98 bool isMaskedOut();
99 void registerProperties();
100 void queryAndUpdateProperties();
101 void createSocketOverrideConf();
102 void updateServiceProperties(
103 const boost::container::flat_map<std::string, VariantType>&
104 propertyMap);
105 void updateSocketProperties(
106 const boost::container::flat_map<std::string, VariantType>&
107 propertyMap);
108 std::string getSocketUnitName();
109 std::string getServiceUnitName();
110};
111
112} // namespace service
113} // namespace phosphor