1 /** 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 19 namespace ibm 20 { 21 namespace logging 22 { 23 24 Manager::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 createAll(); 40 } 41 42 void Manager::createAll() 43 { 44 auto objects = getManagedObjects( 45 bus, LOGGING_BUSNAME, LOGGING_PATH); 46 47 for (const auto& object : objects) 48 { 49 const auto& interfaces = object.second; 50 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 create(object.first, propertyMap->second); 62 } 63 } 64 } 65 66 void Manager::create( 67 const std::string& objectPath, 68 const DbusPropertyMap& properties) 69 { 70 //TODO 71 } 72 73 void Manager::interfaceAdded(sdbusplus::message::message& msg) 74 { 75 sdbusplus::message::object_path path; 76 DbusInterfaceMap interfaces; 77 78 msg.read(path, interfaces); 79 80 //Find the Logging.Entry interface with all of its properties 81 //to pass to create(). 82 auto propertyMap = std::find_if( 83 interfaces.begin(), 84 interfaces.end(), 85 [](const auto& i) 86 { 87 return i.first == LOGGING_IFACE; 88 }); 89 90 if (propertyMap != interfaces.end()) 91 { 92 create(path, propertyMap->second); 93 } 94 } 95 96 void Manager::interfaceRemoved(sdbusplus::message::message& msg) 97 { 98 sdbusplus::message::object_path path; 99 DbusInterfaceList interfaces; 100 101 msg.read(path, interfaces); 102 103 //If the Logging.Entry interface was removed, then remove 104 //our object 105 106 auto i = std::find( 107 interfaces.begin(), 108 interfaces.end(), 109 LOGGING_IFACE); 110 111 if (i != interfaces.end()) 112 { 113 auto id = getEntryID(path); 114 115 auto entry = entries.find(id); 116 if (entry != entries.end()) 117 { 118 entries.erase(entry); 119 } 120 } 121 } 122 123 } 124 } 125