This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
service_monitor.cpp
69 lines (57 loc) · 2.16 KB
/
service_monitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
// Copyright (c) 2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#include "service_monitor.hpp"
#include "mctp_impl.hpp"
#include <boost/asio.hpp>
#include <boost/container/flat_map.hpp>
#include <phosphor-logging/log.hpp>
#include <sdbusplus/asio/connection.hpp>
#include <sdbusplus/bus/match.hpp>
using mctpw::internal::DeleteServiceCallback;
using mctpw::internal::NewServiceCallback;
template <typename T1, typename T2>
using DictType = boost::container::flat_map<T1, T2>;
using MctpPropertiesVariantType =
std::variant<uint16_t, int16_t, int32_t, uint32_t, bool, std::string,
uint8_t, std::vector<uint8_t>>;
NewServiceCallback::NewServiceCallback(MCTPImpl& mctpImpl) : parent(mctpImpl)
{
}
void NewServiceCallback::operator()(sdbusplus::message::message& msg)
{
DictType<std::string, DictType<std::string, MctpPropertiesVariantType>>
values;
sdbusplus::message::object_path object_path;
msg.read(object_path, values);
if (values.end() == values.find(mctpw::MCTPWrapper::bindingToInterface.at(
parent.config.bindingType)))
{
return;
}
phosphor::logging::log<phosphor::logging::level::INFO>(
(std::string("New service ") + msg.get_sender()).c_str());
parent.registerListeners(msg.get_sender());
}
DeleteServiceCallback::DeleteServiceCallback(MCTPImpl& mctpImpl) :
parent(mctpImpl)
{
}
void DeleteServiceCallback::operator()(sdbusplus::message::message& msg)
{
phosphor::logging::log<phosphor::logging::level::INFO>(
(std::string("Deleting device ") + msg.get_sender()).c_str());
parent.unRegisterListeners(msg.get_sender());
}