blob: 978d8b6f293b2bb27e9e04605c008a928490f11c [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))
Matt Spinler743e5822018-03-27 13:44:50 -050038#ifdef USE_POLICY_INTERFACE
39 , policies(POLICY_JSON_PATH)
40#endif
Matt Spinlere0017eb2018-03-27 11:17:38 -050041{
Matt Spinler54bfa7e2018-03-27 11:28:59 -050042 createAll();
43}
44
45void Manager::createAll()
46{
47 auto objects = getManagedObjects(
48 bus, LOGGING_BUSNAME, LOGGING_PATH);
49
50 for (const auto& object : objects)
51 {
52 const auto& interfaces = object.second;
53
54 auto propertyMap = std::find_if(
55 interfaces.begin(),
56 interfaces.end(),
57 [](const auto& i)
58 {
59 return i.first == LOGGING_IFACE;
60 });
61
62 if (propertyMap != interfaces.end())
63 {
64 create(object.first, propertyMap->second);
65 }
66 }
67}
68
69void Manager::create(
70 const std::string& objectPath,
71 const DbusPropertyMap& properties)
72{
73 //TODO
Matt Spinlere0017eb2018-03-27 11:17:38 -050074}
75
76void Manager::interfaceAdded(sdbusplus::message::message& msg)
77{
78 sdbusplus::message::object_path path;
79 DbusInterfaceMap interfaces;
80
81 msg.read(path, interfaces);
82
83 //Find the Logging.Entry interface with all of its properties
84 //to pass to create().
85 auto propertyMap = std::find_if(
86 interfaces.begin(),
87 interfaces.end(),
88 [](const auto& i)
89 {
90 return i.first == LOGGING_IFACE;
91 });
92
93 if (propertyMap != interfaces.end())
94 {
Matt Spinler54bfa7e2018-03-27 11:28:59 -050095 create(path, propertyMap->second);
Matt Spinlere0017eb2018-03-27 11:17:38 -050096 }
97}
98
99void Manager::interfaceRemoved(sdbusplus::message::message& msg)
100{
101 sdbusplus::message::object_path path;
102 DbusInterfaceList interfaces;
103
104 msg.read(path, interfaces);
105
106 //If the Logging.Entry interface was removed, then remove
107 //our object
108
109 auto i = std::find(
110 interfaces.begin(),
111 interfaces.end(),
112 LOGGING_IFACE);
113
114 if (i != interfaces.end())
115 {
116 auto id = getEntryID(path);
117
118 auto entry = entries.find(id);
119 if (entry != entries.end())
120 {
121 entries.erase(entry);
122 }
123 }
124}
125
126}
127}