1 /** 2 * Copyright 2017 Google Inc. 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 #include "lpcsnoop/snoop_listen.hpp" 18 19 #include <cinttypes> 20 #include <cstdio> 21 #include <iostream> 22 #include <memory> 23 24 /* Example PostCode handler which simply prints them */ 25 static void printPostcode(uint64_t postcode) 26 { 27 /* Print output to verify the example program is receiving values. */ 28 std::printf("recv: 0x%" PRIx64 "\n", postcode); 29 } 30 31 /* 32 * One can also specify custom handler that operates on 33 * sdbusplus::message::message type and pass them to constructor. 34 * e.g. 35 * 36 * static void PrintMessageMap(sdbusplus::message::message& m) 37 * { 38 * std::string messageBusName; 39 * std::map<std::string, std::variant<uint64_t>> messageData; 40 * 41 * m.read(messageBusName, messageData); 42 * 43 * std::cout << "Got message from " << messageBusName << std::endl; 44 * for (const auto& kv : messageData) 45 * { 46 * std::cout << "Key: " << kv.first << std::endl; 47 * std::cout << "Value: " << get<uint64_t>(kv.second) << std::endl; 48 * } 49 * } 50 * 51 * lpcsnoop::SnoopListen snoop(ListenBus, PrintMessageMap); 52 */ 53 54 /* 55 * This is the entry point for the application. 56 * 57 * This application simply creates an object that registers for incoming value 58 * updates for the POST code dbus object. 59 */ 60 int main() 61 { 62 auto ListenBus = sdbusplus::bus::new_default(); 63 lpcsnoop::SnoopListen snoop(ListenBus, printPostcode); 64 65 while (true) 66 { 67 ListenBus.process_discard(); 68 ListenBus.wait(); 69 } 70 71 return 0; 72 } 73