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 */
printPostcode(FILE *,postcode_t postcode)25f8d0e0bfSwukaihua-fii-na static void printPostcode(FILE*, postcode_t postcode)
2633569758SPatrick Venture {
27afff574eSKun Yi /* Print output to verify the example program is receiving values. */
28ba5258f7SManojkiran Eda std::printf("recv: 0x%" PRIx64 "\n",
29ba5258f7SManojkiran Eda std::get<primary_post_code_t>(postcode));
3033569758SPatrick Venture }
3133569758SPatrick Venture
32afff574eSKun Yi /*
33afff574eSKun Yi * One can also specify custom handler that operates on
34*aebf87ccSPatrick Williams * sdbusplus::message_t type and pass them to constructor.
35afff574eSKun Yi * e.g.
36afff574eSKun Yi *
37*aebf87ccSPatrick Williams * static void PrintMessageMap(sdbusplus::message_t& m)
38afff574eSKun Yi * {
39afff574eSKun Yi * std::string messageBusName;
4059c5d9ffSPatrick Williams * std::map<std::string, std::variant<uint64_t>> messageData;
41afff574eSKun Yi *
42afff574eSKun Yi * m.read(messageBusName, messageData);
43afff574eSKun Yi *
44afff574eSKun Yi * std::cout << "Got message from " << messageBusName << std::endl;
45afff574eSKun Yi * for (const auto& kv : messageData)
46afff574eSKun Yi * {
47afff574eSKun Yi * std::cout << "Key: " << kv.first << std::endl;
48afff574eSKun Yi * std::cout << "Value: " << get<uint64_t>(kv.second) << std::endl;
49afff574eSKun Yi * }
50afff574eSKun Yi * }
51afff574eSKun Yi *
52afff574eSKun Yi * lpcsnoop::SnoopListen snoop(ListenBus, PrintMessageMap);
53afff574eSKun Yi */
5433569758SPatrick Venture
5533569758SPatrick Venture /*
5633569758SPatrick Venture * This is the entry point for the application.
5733569758SPatrick Venture *
5833569758SPatrick Venture * This application simply creates an object that registers for incoming value
5933569758SPatrick Venture * updates for the POST code dbus object.
6033569758SPatrick Venture */
main()61cce09623SKun Yi int main()
6233569758SPatrick Venture {
6333569758SPatrick Venture auto ListenBus = sdbusplus::bus::new_default();
64afff574eSKun Yi lpcsnoop::SnoopListen snoop(ListenBus, printPostcode);
6533569758SPatrick Venture
6633569758SPatrick Venture while (true)
6733569758SPatrick Venture {
6833569758SPatrick Venture ListenBus.process_discard();
6933569758SPatrick Venture ListenBus.wait();
7033569758SPatrick Venture }
7133569758SPatrick Venture
7233569758SPatrick Venture return 0;
7333569758SPatrick Venture }
74