Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 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 | |
Patrick Venture | b5754fd | 2018-09-10 13:13:58 -0700 | [diff] [blame] | 17 | #include "lpcsnoop/snoop_listen.hpp" |
| 18 | |
Benjamin Fair | f69ad7e | 2018-07-13 13:41:10 -0700 | [diff] [blame] | 19 | #include <cinttypes> |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 20 | #include <cstdio> |
| 21 | #include <iostream> |
| 22 | #include <memory> |
| 23 | |
Kun Yi | afff574 | 2018-07-10 12:28:05 -0700 | [diff] [blame] | 24 | /* Example PostCode handler which simply prints them */ |
wukaihua-fii-na | f8d0e0b | 2022-05-11 14:43:09 +0800 | [diff] [blame] | 25 | static void printPostcode(FILE*, postcode_t postcode) |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 26 | { |
Kun Yi | afff574 | 2018-07-10 12:28:05 -0700 | [diff] [blame] | 27 | /* Print output to verify the example program is receiving values. */ |
Manojkiran Eda | ba5258f | 2021-02-25 13:23:33 +0530 | [diff] [blame] | 28 | std::printf("recv: 0x%" PRIx64 "\n", |
| 29 | std::get<primary_post_code_t>(postcode)); |
Kun Yi | afff574 | 2018-07-10 12:28:05 -0700 | [diff] [blame] | 30 | } |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 31 | |
Kun Yi | afff574 | 2018-07-10 12:28:05 -0700 | [diff] [blame] | 32 | /* |
| 33 | * One can also specify custom handler that operates on |
| 34 | * sdbusplus::message::message type and pass them to constructor. |
| 35 | * e.g. |
| 36 | * |
| 37 | * static void PrintMessageMap(sdbusplus::message::message& m) |
| 38 | * { |
Kun Yi | afff574 | 2018-07-10 12:28:05 -0700 | [diff] [blame] | 39 | * std::string messageBusName; |
Patrick Williams | 59c5d9f | 2020-05-13 11:46:38 -0500 | [diff] [blame] | 40 | * std::map<std::string, std::variant<uint64_t>> messageData; |
Kun Yi | afff574 | 2018-07-10 12:28:05 -0700 | [diff] [blame] | 41 | * |
| 42 | * m.read(messageBusName, messageData); |
| 43 | * |
| 44 | * std::cout << "Got message from " << messageBusName << std::endl; |
| 45 | * for (const auto& kv : messageData) |
| 46 | * { |
| 47 | * std::cout << "Key: " << kv.first << std::endl; |
| 48 | * std::cout << "Value: " << get<uint64_t>(kv.second) << std::endl; |
| 49 | * } |
| 50 | * } |
| 51 | * |
| 52 | * lpcsnoop::SnoopListen snoop(ListenBus, PrintMessageMap); |
| 53 | */ |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 54 | |
| 55 | /* |
| 56 | * This is the entry point for the application. |
| 57 | * |
| 58 | * This application simply creates an object that registers for incoming value |
| 59 | * updates for the POST code dbus object. |
| 60 | */ |
Kun Yi | cce0962 | 2020-04-06 14:01:55 -0700 | [diff] [blame] | 61 | int main() |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 62 | { |
| 63 | auto ListenBus = sdbusplus::bus::new_default(); |
Kun Yi | afff574 | 2018-07-10 12:28:05 -0700 | [diff] [blame] | 64 | lpcsnoop::SnoopListen snoop(ListenBus, printPostcode); |
Patrick Venture | 3356975 | 2018-03-12 18:56:14 -0700 | [diff] [blame] | 65 | |
| 66 | while (true) |
| 67 | { |
| 68 | ListenBus.process_discard(); |
| 69 | ListenBus.wait(); |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |