blob: 8974b29041a4332aa68b83d43362a0a21763609c [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
17#include <sdbusplus/timer.hpp>
18#include "utils.hpp"
19
20namespace phosphor
21{
22namespace service
23{
24
25static constexpr const char *serviceConfigSrvName =
26 "xyz.openbmc_project.Control.Service.Manager";
27static constexpr const char *serviceConfigIntfName =
28 "xyz.openbmc_project.Control.Service.Attributes";
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053029static constexpr const char *srcCfgMgrBasePath =
30 "/xyz/openbmc_project/control/service";
31static constexpr const char *srvCfgPropPort = "Port";
32static constexpr const char *srvCfgPropMasked = "Masked";
33static constexpr const char *srvCfgPropEnabled = "Enabled";
34static constexpr const char *srvCfgPropRunning = "Running";
AppaRao Puli00840472018-10-03 19:37:46 +053035
36enum class UpdatedProp
37{
38 port = 1,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053039 maskedState,
40 enabledState,
41 runningState
AppaRao Puli00840472018-10-03 19:37:46 +053042};
43
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053044using VariantType =
45 std::variant<std::string, int64_t, uint64_t, double, int32_t, uint32_t,
46 int16_t, uint16_t, uint8_t, bool,
47 std::vector<std::tuple<std::string, std::string>>>;
48
AppaRao Puli00840472018-10-03 19:37:46 +053049class ServiceConfig
50{
51 public:
52 ServiceConfig(sdbusplus::asio::object_server &srv_,
53 std::shared_ptr<sdbusplus::asio::connection> &conn_,
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053054 const std::string &objPath_, const std::string &baseUnitName,
55 const std::string &instanceName,
56 const std::string &serviceObjPath,
57 const std::string &socketObjPath);
AppaRao Puli00840472018-10-03 19:37:46 +053058 ~ServiceConfig() = default;
59
AppaRao Puli00840472018-10-03 19:37:46 +053060 std::shared_ptr<sdbusplus::asio::connection> conn;
61 uint8_t updatedFlag;
62
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053063 void stopAndApplyUnitConfig(boost::asio::yield_context yield);
64 void restartUnitConfig(boost::asio::yield_context yield);
65 void startServiceRestartTimer();
66
AppaRao Puli00840472018-10-03 19:37:46 +053067 private:
68 sdbusplus::asio::object_server &server;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053069 std::shared_ptr<sdbusplus::asio::dbus_interface> iface;
70 bool internalSet = false;
AppaRao Puli00840472018-10-03 19:37:46 +053071 std::string objPath;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053072 std::string instanceName;
73 std::string baseUnitName;
74 std::string instantiatedUnitName;
75 std::string socketObjectPath;
76 std::string serviceObjectPath;
77 std::string overrideConfDir;
AppaRao Puli00840472018-10-03 19:37:46 +053078
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053079 // Properties
80 std::string activeState;
81 std::string subState;
AppaRao Puli00840472018-10-03 19:37:46 +053082 uint16_t portNum;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053083 std::vector<std::string> channelList;
AppaRao Puli00840472018-10-03 19:37:46 +053084 std::string protocol;
85 std::string stateValue;
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053086 bool unitMaskedState = false;
87 bool unitEnabledState = false;
88 bool unitRunningState = false;
89 std::string subStateValue;
AppaRao Puli00840472018-10-03 19:37:46 +053090
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053091 bool isMaskedOut();
AppaRao Puli00840472018-10-03 19:37:46 +053092 void registerProperties();
Richard Marian Thomaiyar90f2da32019-05-23 05:37:50 +053093 void queryAndUpdateProperties();
94 void createSocketOverrideConf();
95 void updateServiceProperties(
96 const boost::container::flat_map<std::string, VariantType>
97 &propertyMap);
98 void updateSocketProperties(
99 const boost::container::flat_map<std::string, VariantType>
100 &propertyMap);
101 std::string getSocketUnitName();
102 std::string getServiceUnitName();
AppaRao Puli00840472018-10-03 19:37:46 +0530103};
104
105} // namespace service
106} // namespace phosphor