blob: bdd1ee4384a0c7486cbc702d1ac9c31285431efd [file] [log] [blame]
Nikhil Potadeafbaa092019-03-06 16:18:13 -08001/*
2// Copyright (c) 2019 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
17#pragma once
18#include <sdbusplus/asio/object_server.hpp>
19#include <sel_logger.hpp>
20#include <sensorutils.hpp>
21
22inline static sdbusplus::bus::match::match
23 startPulseEventMonitor(std::shared_ptr<sdbusplus::asio::connection> conn)
24{
Zhikui Ren672bdfc2020-07-14 11:37:01 -070025 auto pulseEventMatcherCallback = [](sdbusplus::message::message& msg) {
Nikhil Potadeafbaa092019-03-06 16:18:13 -080026 std::string thresholdInterface;
Patrick Williams761bf202020-05-13 18:00:24 -050027 boost::container::flat_map<std::string, std::variant<std::string>>
Nikhil Potadeafbaa092019-03-06 16:18:13 -080028 propertiesChanged;
29 msg.read(thresholdInterface, propertiesChanged);
30
31 if (propertiesChanged.empty())
32 {
33 return;
34 }
35
36 std::string event = propertiesChanged.begin()->first;
37
Patrick Williams16afcb92020-05-13 11:39:46 -050038 auto variant =
39 std::get_if<std::string>(&propertiesChanged.begin()->second);
Nikhil Potadeafbaa092019-03-06 16:18:13 -080040
41 if (event.empty() || nullptr == variant)
42 {
43 return;
44 }
45
46 if (event == "CurrentHostState")
47 {
48 if (*variant == "xyz.openbmc_project.State.Host.HostState.Off")
49 {
50 std::string message("Host system DC power is off");
Jason M. Bills3d300fc2019-06-25 10:58:11 -070051 std::string redfishMsgId("OpenBMC.0.1.DCPowerOff");
Nikhil Potadeafbaa092019-03-06 16:18:13 -080052
53 sd_journal_send("MESSAGE=%s", message.c_str(),
54 "REDFISH_MESSAGE_ID=%s", redfishMsgId.c_str(),
55 NULL);
56 }
57 else if (*variant ==
58 "xyz.openbmc_project.State.Host.HostState.Running")
59 {
60 std::string message("Host system DC power is on");
Jason M. Bills3d300fc2019-06-25 10:58:11 -070061 std::string redfishMsgId("OpenBMC.0.1.DCPowerOn");
Nikhil Potadeafbaa092019-03-06 16:18:13 -080062
63 sd_journal_send("MESSAGE=%s", message.c_str(),
64 "REDFISH_MESSAGE_ID=%s", redfishMsgId.c_str(),
65 NULL);
66 }
67 }
68 };
69
70 sdbusplus::bus::match::match pulseEventMatcher(
Zhikui Ren672bdfc2020-07-14 11:37:01 -070071 static_cast<sdbusplus::bus::bus&>(*conn),
Nikhil Potadeafbaa092019-03-06 16:18:13 -080072 "type='signal',interface='org.freedesktop.DBus.Properties',member='"
73 "PropertiesChanged',arg0namespace='xyz.openbmc_project.State.Host'",
74 std::move(pulseEventMatcherCallback));
75
76 return pulseEventMatcher;
77}