blob: 95cc7a44eeb80e553294906f358c5e69c1e2a3cd [file] [log] [blame]
Patrick Venture33569752018-03-12 18:56:14 -07001/**
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 Ventureb5754fd2018-09-10 13:13:58 -070017#include "lpcsnoop/snoop_listen.hpp"
18
Benjamin Fairf69ad7e2018-07-13 13:41:10 -070019#include <cinttypes>
Patrick Venture33569752018-03-12 18:56:14 -070020#include <cstdio>
21#include <iostream>
22#include <memory>
23
Kun Yiafff5742018-07-10 12:28:05 -070024/* Example PostCode handler which simply prints them */
wukaihua-fii-naf8d0e0b2022-05-11 14:43:09 +080025static void printPostcode(FILE*, postcode_t postcode)
Patrick Venture33569752018-03-12 18:56:14 -070026{
Kun Yiafff5742018-07-10 12:28:05 -070027 /* Print output to verify the example program is receiving values. */
Cosmo Choufe514952024-09-05 01:08:58 +080028 auto code = std::get<0>(postcode);
29 std::string hexCode;
30 hexCode.reserve(2 * code.size());
31 for (const auto& byte : code)
32 {
33 hexCode += std::format("{:02x}", byte);
34 }
35 std::printf("recv: 0x%s\n", hexCode.c_str());
Kun Yiafff5742018-07-10 12:28:05 -070036}
Patrick Venture33569752018-03-12 18:56:14 -070037
Kun Yiafff5742018-07-10 12:28:05 -070038/*
39 * One can also specify custom handler that operates on
Patrick Williamsaebf87c2022-07-22 19:26:54 -050040 * sdbusplus::message_t type and pass them to constructor.
Kun Yiafff5742018-07-10 12:28:05 -070041 * e.g.
42 *
Patrick Williamsaebf87c2022-07-22 19:26:54 -050043 * static void PrintMessageMap(sdbusplus::message_t& m)
Kun Yiafff5742018-07-10 12:28:05 -070044 * {
Kun Yiafff5742018-07-10 12:28:05 -070045 * std::string messageBusName;
Patrick Williams59c5d9f2020-05-13 11:46:38 -050046 * std::map<std::string, std::variant<uint64_t>> messageData;
Kun Yiafff5742018-07-10 12:28:05 -070047 *
48 * m.read(messageBusName, messageData);
49 *
50 * std::cout << "Got message from " << messageBusName << std::endl;
51 * for (const auto& kv : messageData)
52 * {
53 * std::cout << "Key: " << kv.first << std::endl;
54 * std::cout << "Value: " << get<uint64_t>(kv.second) << std::endl;
55 * }
56 * }
57 *
58 * lpcsnoop::SnoopListen snoop(ListenBus, PrintMessageMap);
59 */
Patrick Venture33569752018-03-12 18:56:14 -070060
61/*
62 * This is the entry point for the application.
63 *
64 * This application simply creates an object that registers for incoming value
65 * updates for the POST code dbus object.
66 */
Kun Yicce09622020-04-06 14:01:55 -070067int main()
Patrick Venture33569752018-03-12 18:56:14 -070068{
69 auto ListenBus = sdbusplus::bus::new_default();
Kun Yiafff5742018-07-10 12:28:05 -070070 lpcsnoop::SnoopListen snoop(ListenBus, printPostcode);
Patrick Venture33569752018-03-12 18:56:14 -070071
72 while (true)
73 {
74 ListenBus.process_discard();
75 ListenBus.wait();
76 }
77
78 return 0;
79}