blob: 6f05e82d620197704ef14423e10a3765f58d9f7d [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{
25 auto pulseEventMatcherCallback = [](sdbusplus::message::message &msg) {
26 std::string thresholdInterface;
27 boost::container::flat_map<std::string,
28 sdbusplus::message::variant<std::string>>
29 propertiesChanged;
30 msg.read(thresholdInterface, propertiesChanged);
31
32 if (propertiesChanged.empty())
33 {
34 return;
35 }
36
37 std::string event = propertiesChanged.begin()->first;
38
39 auto variant = sdbusplus::message::variant_ns::get_if<std::string>(
40 &propertiesChanged.begin()->second);
41
42 if (event.empty() || nullptr == variant)
43 {
44 return;
45 }
46
47 if (event == "CurrentHostState")
48 {
49 if (*variant == "xyz.openbmc_project.State.Host.HostState.Off")
50 {
51 std::string message("Host system DC power is off");
Jason M. Bills3d300fc2019-06-25 10:58:11 -070052 std::string redfishMsgId("OpenBMC.0.1.DCPowerOff");
Nikhil Potadeafbaa092019-03-06 16:18:13 -080053
54 sd_journal_send("MESSAGE=%s", message.c_str(),
55 "REDFISH_MESSAGE_ID=%s", redfishMsgId.c_str(),
56 NULL);
57 }
58 else if (*variant ==
59 "xyz.openbmc_project.State.Host.HostState.Running")
60 {
61 std::string message("Host system DC power is on");
Jason M. Bills3d300fc2019-06-25 10:58:11 -070062 std::string redfishMsgId("OpenBMC.0.1.DCPowerOn");
Nikhil Potadeafbaa092019-03-06 16:18:13 -080063
64 sd_journal_send("MESSAGE=%s", message.c_str(),
65 "REDFISH_MESSAGE_ID=%s", redfishMsgId.c_str(),
66 NULL);
67 }
68 }
69 };
70
71 sdbusplus::bus::match::match pulseEventMatcher(
72 static_cast<sdbusplus::bus::bus &>(*conn),
73 "type='signal',interface='org.freedesktop.DBus.Properties',member='"
74 "PropertiesChanged',arg0namespace='xyz.openbmc_project.State.Host'",
75 std::move(pulseEventMatcherCallback));
76
77 return pulseEventMatcher;
78}