blob: cd453b0eeb0655a967957a84818a3f60307becd4 [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";
AppaRao Puliee853eb2020-05-29 00:53:20 +053030static constexpr const char* srcCfgMgrBasePath =
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053031 "/xyz/openbmc_project/control/service";
AppaRao Puliee853eb2020-05-29 00:53:20 +053032static constexpr const char* srvCfgPropPort = "Port";
33static constexpr const char* srvCfgPropMasked = "Masked";
34static constexpr const char* srvCfgPropEnabled = "Enabled";
35static constexpr const char* srvCfgPropRunning = "Running";
AppaRao Puli00840472018-10-03 19:37:46 +053036
37enum class UpdatedProp
38{
39 port = 1,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053040 maskedState,
41 enabledState,
42 runningState
AppaRao Puli00840472018-10-03 19:37:46 +053043};
44
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053045using VariantType =
46 std::variant<std::string, int64_t, uint64_t, double, int32_t, uint32_t,
47 int16_t, uint16_t, uint8_t, bool,
48 std::vector<std::tuple<std::string, std::string>>>;
49
AppaRao Puli00840472018-10-03 19:37:46 +053050class ServiceConfig
51{
52 public:
AppaRao Puliee853eb2020-05-29 00:53:20 +053053 ServiceConfig(sdbusplus::asio::object_server& srv_,
54 std::shared_ptr<sdbusplus::asio::connection>& conn_,
55 const std::string& objPath_, const std::string& baseUnitName,
56 const std::string& instanceName,
57 const std::string& serviceObjPath,
58 const std::string& socketObjPath);
AppaRao Puli00840472018-10-03 19:37:46 +053059 ~ServiceConfig() = default;
60
AppaRao Puli00840472018-10-03 19:37:46 +053061 std::shared_ptr<sdbusplus::asio::connection> conn;
62 uint8_t updatedFlag;
63
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053064 void stopAndApplyUnitConfig(boost::asio::yield_context yield);
65 void restartUnitConfig(boost::asio::yield_context yield);
66 void startServiceRestartTimer();
67
AppaRao Puli00840472018-10-03 19:37:46 +053068 private:
AppaRao Puliee853eb2020-05-29 00:53:20 +053069 sdbusplus::asio::object_server& server;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053070 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
71 bool internalSet = false;
AppaRao Puli00840472018-10-03 19:37:46 +053072 std::string objPath;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053073 std::string instanceName;
74 std::string baseUnitName;
75 std::string instantiatedUnitName;
76 std::string socketObjectPath;
77 std::string serviceObjectPath;
78 std::string overrideConfDir;
AppaRao Puli00840472018-10-03 19:37:46 +053079
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053080 // Properties
81 std::string activeState;
82 std::string subState;
AppaRao Puli00840472018-10-03 19:37:46 +053083 uint16_t portNum;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053084 std::vector<std::string> channelList;
AppaRao Puli00840472018-10-03 19:37:46 +053085 std::string protocol;
86 std::string stateValue;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053087 bool unitMaskedState = false;
88 bool unitEnabledState = false;
89 bool unitRunningState = false;
90 std::string subStateValue;
AppaRao Puli00840472018-10-03 19:37:46 +053091
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053092 bool isMaskedOut();
AppaRao Puli00840472018-10-03 19:37:46 +053093 void registerProperties();
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053094 void queryAndUpdateProperties();
95 void createSocketOverrideConf();
96 void updateServiceProperties(
AppaRao Puliee853eb2020-05-29 00:53:20 +053097 const boost::container::flat_map<std::string, VariantType>&
98 propertyMap);
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053099 void updateSocketProperties(
AppaRao Puliee853eb2020-05-29 00:53:20 +0530100 const boost::container::flat_map<std::string, VariantType>&
101 propertyMap);
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +0530102 std::string getSocketUnitName();
103 std::string getServiceUnitName();
AppaRao Puli00840472018-10-03 19:37:46 +0530104};
105
106} // namespace service
107} // namespace phosphor