blob: e644f2b7c58d40f7aad96743f073744958064c27 [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 */
25static void printPostcode(uint64_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. */
28 std::printf("recv: 0x%" PRIx64 "\n", postcode);
29}
Patrick Venture33569752018-03-12 18:56:14 -070030
Kun Yiafff5742018-07-10 12:28:05 -070031/*
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 * using sdbusplus::message::variant_ns::get;
39 * std::string messageBusName;
40 * std::map<std::string, sdbusplus::message::variant<uint64_t>>
41 * messageData;
42 *
43 * m.read(messageBusName, messageData);
44 *
45 * std::cout << "Got message from " << messageBusName << std::endl;
46 * for (const auto& kv : messageData)
47 * {
48 * std::cout << "Key: " << kv.first << std::endl;
49 * std::cout << "Value: " << get<uint64_t>(kv.second) << std::endl;
50 * }
51 * }
52 *
53 * lpcsnoop::SnoopListen snoop(ListenBus, PrintMessageMap);
54 */
Patrick Venture33569752018-03-12 18:56:14 -070055
56/*
57 * This is the entry point for the application.
58 *
59 * This application simply creates an object that registers for incoming value
60 * updates for the POST code dbus object.
61 */
62int main(int argc, char* argv[])
63{
64 auto ListenBus = sdbusplus::bus::new_default();
Kun Yiafff5742018-07-10 12:28:05 -070065 lpcsnoop::SnoopListen snoop(ListenBus, printPostcode);
Patrick Venture33569752018-03-12 18:56:14 -070066
67 while (true)
68 {
69 ListenBus.process_discard();
70 ListenBus.wait();
71 }
72
73 return 0;
74}