blob: 023b1d8f881821ec91ed53eb9c09d22cb03ed5c5 [file] [log] [blame]
AppaRao Puli00840472018-10-03 19:37:46 +05301/*
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
AppaRao Puli00840472018-10-03 19:37:46 +053017#include "utils.hpp"
18
AppaRao Puliee853eb2020-05-29 00:53:20 +053019#include <sdbusplus/timer.hpp>
20
AppaRao Puli00840472018-10-03 19:37:46 +053021namespace phosphor
22{
23namespace service
24{
25
AppaRao Puliee853eb2020-05-29 00:53:20 +053026static constexpr const char* serviceConfigSrvName =
AppaRao Puli00840472018-10-03 19:37:46 +053027 "xyz.openbmc_project.Control.Service.Manager";
AppaRao Puliee853eb2020-05-29 00:53:20 +053028static constexpr const char* serviceConfigIntfName =
AppaRao Puli00840472018-10-03 19:37:46 +053029 "xyz.openbmc_project.Control.Service.Attributes";
Tom Joseph83241c02020-05-30 11:30:20 +053030static constexpr const char* sockAttrIntfName =
31 "xyz.openbmc_project.Control.Service.SocketAttributes";
AppaRao Puliee853eb2020-05-29 00:53:20 +053032static constexpr const char* srcCfgMgrBasePath =
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053033 "/xyz/openbmc_project/control/service";
Tom Joseph83241c02020-05-30 11:30:20 +053034static constexpr const char* sockAttrPropPort = "Port";
AppaRao Puliee853eb2020-05-29 00:53:20 +053035static constexpr const char* srvCfgPropMasked = "Masked";
36static constexpr const char* srvCfgPropEnabled = "Enabled";
37static constexpr const char* srvCfgPropRunning = "Running";
AppaRao Puli00840472018-10-03 19:37:46 +053038
39enum class UpdatedProp
40{
41 port = 1,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053042 maskedState,
43 enabledState,
44 runningState
AppaRao Puli00840472018-10-03 19:37:46 +053045};
46
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053047using 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
AppaRao Puli00840472018-10-03 19:37:46 +053052class ServiceConfig
53{
54 public:
AppaRao Puliee853eb2020-05-29 00:53:20 +053055 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);
AppaRao Puli00840472018-10-03 19:37:46 +053061 ~ServiceConfig() = default;
62
AppaRao Puli00840472018-10-03 19:37:46 +053063 std::shared_ptr<sdbusplus::asio::connection> conn;
64 uint8_t updatedFlag;
65
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053066 void stopAndApplyUnitConfig(boost::asio::yield_context yield);
67 void restartUnitConfig(boost::asio::yield_context yield);
68 void startServiceRestartTimer();
69
AppaRao Puli00840472018-10-03 19:37:46 +053070 private:
AppaRao Puliee853eb2020-05-29 00:53:20 +053071 sdbusplus::asio::object_server& server;
Tom Joseph83241c02020-05-30 11:30:20 +053072 std::shared_ptr<sdbusplus::asio::dbus_interface> srvCfgIface;
73 std::shared_ptr<sdbusplus::asio::dbus_interface> sockAttrIface;
74
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053075 bool internalSet = false;
AppaRao Puli00840472018-10-03 19:37:46 +053076 std::string objPath;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053077 std::string baseUnitName;
Tom Joseph82e95572020-05-07 20:28:05 +053078 std::string instanceName;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053079 std::string instantiatedUnitName;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053080 std::string serviceObjectPath;
Tom Joseph82e95572020-05-07 20:28:05 +053081 std::string socketObjectPath;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053082 std::string overrideConfDir;
AppaRao Puli00840472018-10-03 19:37:46 +053083
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053084 // Properties
85 std::string activeState;
86 std::string subState;
AppaRao Puli00840472018-10-03 19:37:46 +053087 uint16_t portNum;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053088 std::vector<std::string> channelList;
AppaRao Puli00840472018-10-03 19:37:46 +053089 std::string protocol;
90 std::string stateValue;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053091 bool unitMaskedState = false;
92 bool unitEnabledState = false;
93 bool unitRunningState = false;
94 std::string subStateValue;
AppaRao Puli00840472018-10-03 19:37:46 +053095
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053096 bool isMaskedOut();
AppaRao Puli00840472018-10-03 19:37:46 +053097 void registerProperties();
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053098 void queryAndUpdateProperties();
99 void createSocketOverrideConf();
100 void updateServiceProperties(
AppaRao Puliee853eb2020-05-29 00:53:20 +0530101 const boost::container::flat_map<std::string, VariantType>&
102 propertyMap);
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +0530103 void updateSocketProperties(
AppaRao Puliee853eb2020-05-29 00:53:20 +0530104 const boost::container::flat_map<std::string, VariantType>&
105 propertyMap);
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +0530106 std::string getSocketUnitName();
107 std::string getServiceUnitName();
AppaRao Puli00840472018-10-03 19:37:46 +0530108};
109
110} // namespace service
111} // namespace phosphor