blob: 73d77ed89207ba51ec0b95f4d74232c09769dbe3 [file] [log] [blame]
Matt Spinlere0017eb2018-03-27 11:17:38 -05001/**
2 * Copyright © 2018 IBM 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#include "config.h"
17#include "manager.hpp"
18
19namespace ibm
20{
21namespace logging
22{
23
24Manager::Manager(sdbusplus::bus::bus& bus) :
25 bus(bus),
26 addMatch(
27 bus,
28 sdbusplus::bus::match::rules::interfacesAdded() +
29 sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
30 std::bind(std::mem_fn(&Manager::interfaceAdded),
31 this, std::placeholders::_1)),
32 removeMatch(
33 bus,
34 sdbusplus::bus::match::rules::interfacesRemoved() +
35 sdbusplus::bus::match::rules::path_namespace(LOGGING_PATH),
36 std::bind(std::mem_fn(&Manager::interfaceRemoved),
37 this, std::placeholders::_1))
38{
39 //TODO: createAll();
40}
41
42void Manager::interfaceAdded(sdbusplus::message::message& msg)
43{
44 sdbusplus::message::object_path path;
45 DbusInterfaceMap interfaces;
46
47 msg.read(path, interfaces);
48
49 //Find the Logging.Entry interface with all of its properties
50 //to pass to create().
51 auto propertyMap = std::find_if(
52 interfaces.begin(),
53 interfaces.end(),
54 [](const auto& i)
55 {
56 return i.first == LOGGING_IFACE;
57 });
58
59 if (propertyMap != interfaces.end())
60 {
61 //TODO: create(path, propertyMap->second);
62 }
63}
64
65void Manager::interfaceRemoved(sdbusplus::message::message& msg)
66{
67 sdbusplus::message::object_path path;
68 DbusInterfaceList interfaces;
69
70 msg.read(path, interfaces);
71
72 //If the Logging.Entry interface was removed, then remove
73 //our object
74
75 auto i = std::find(
76 interfaces.begin(),
77 interfaces.end(),
78 LOGGING_IFACE);
79
80 if (i != interfaces.end())
81 {
82 auto id = getEntryID(path);
83
84 auto entry = entries.find(id);
85 if (entry != entries.end())
86 {
87 entries.erase(entry);
88 }
89 }
90}
91
92}
93}