133569758SPatrick Venture /** 233569758SPatrick Venture * Copyright 2017 Google Inc. 333569758SPatrick Venture * 433569758SPatrick Venture * Licensed under the Apache License, Version 2.0 (the "License"); 533569758SPatrick Venture * you may not use this file except in compliance with the License. 633569758SPatrick Venture * You may obtain a copy of the License at 733569758SPatrick Venture * 833569758SPatrick Venture * http://www.apache.org/licenses/LICENSE-2.0 933569758SPatrick Venture * 1033569758SPatrick Venture * Unless required by applicable law or agreed to in writing, software 1133569758SPatrick Venture * distributed under the License is distributed on an "AS IS" BASIS, 1233569758SPatrick Venture * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1333569758SPatrick Venture * See the License for the specific language governing permissions and 1433569758SPatrick Venture * limitations under the License. 1533569758SPatrick Venture */ 1633569758SPatrick Venture 17b5754fd4SPatrick Venture #include "lpcsnoop/snoop_listen.hpp" 18b5754fd4SPatrick Venture 19f69ad7e6SBenjamin Fair #include <cinttypes> 2033569758SPatrick Venture #include <cstdio> 2133569758SPatrick Venture #include <iostream> 2233569758SPatrick Venture #include <memory> 2333569758SPatrick Venture 24afff574eSKun Yi /* Example PostCode handler which simply prints them */ 25afff574eSKun Yi static void printPostcode(uint64_t postcode) 2633569758SPatrick Venture { 27afff574eSKun Yi /* Print output to verify the example program is receiving values. */ 28afff574eSKun Yi std::printf("recv: 0x%" PRIx64 "\n", postcode); 2933569758SPatrick Venture } 3033569758SPatrick Venture 31afff574eSKun Yi /* 32afff574eSKun Yi * One can also specify custom handler that operates on 33afff574eSKun Yi * sdbusplus::message::message type and pass them to constructor. 34afff574eSKun Yi * e.g. 35afff574eSKun Yi * 36afff574eSKun Yi * static void PrintMessageMap(sdbusplus::message::message& m) 37afff574eSKun Yi * { 38afff574eSKun Yi * std::string messageBusName; 39*59c5d9ffSPatrick Williams * std::map<std::string, std::variant<uint64_t>> messageData; 40afff574eSKun Yi * 41afff574eSKun Yi * m.read(messageBusName, messageData); 42afff574eSKun Yi * 43afff574eSKun Yi * std::cout << "Got message from " << messageBusName << std::endl; 44afff574eSKun Yi * for (const auto& kv : messageData) 45afff574eSKun Yi * { 46afff574eSKun Yi * std::cout << "Key: " << kv.first << std::endl; 47afff574eSKun Yi * std::cout << "Value: " << get<uint64_t>(kv.second) << std::endl; 48afff574eSKun Yi * } 49afff574eSKun Yi * } 50afff574eSKun Yi * 51afff574eSKun Yi * lpcsnoop::SnoopListen snoop(ListenBus, PrintMessageMap); 52afff574eSKun Yi */ 5333569758SPatrick Venture 5433569758SPatrick Venture /* 5533569758SPatrick Venture * This is the entry point for the application. 5633569758SPatrick Venture * 5733569758SPatrick Venture * This application simply creates an object that registers for incoming value 5833569758SPatrick Venture * updates for the POST code dbus object. 5933569758SPatrick Venture */ 60cce09623SKun Yi int main() 6133569758SPatrick Venture { 6233569758SPatrick Venture auto ListenBus = sdbusplus::bus::new_default(); 63afff574eSKun Yi lpcsnoop::SnoopListen snoop(ListenBus, printPostcode); 6433569758SPatrick Venture 6533569758SPatrick Venture while (true) 6633569758SPatrick Venture { 6733569758SPatrick Venture ListenBus.process_discard(); 6833569758SPatrick Venture ListenBus.wait(); 6933569758SPatrick Venture } 7033569758SPatrick Venture 7133569758SPatrick Venture return 0; 7233569758SPatrick Venture } 73