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 
17*b5754fd4SPatrick Venture #include "lpcsnoop/snoop_listen.hpp"
18*b5754fd4SPatrick 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  *     using sdbusplus::message::variant_ns::get;
39afff574eSKun Yi  *     std::string messageBusName;
40afff574eSKun Yi  *     std::map<std::string, sdbusplus::message::variant<uint64_t>>
41afff574eSKun Yi  *         messageData;
42afff574eSKun Yi  *
43afff574eSKun Yi  *     m.read(messageBusName, messageData);
44afff574eSKun Yi  *
45afff574eSKun Yi  *     std::cout << "Got message from " << messageBusName << std::endl;
46afff574eSKun Yi  *     for (const auto& kv : messageData)
47afff574eSKun Yi  *     {
48afff574eSKun Yi  *         std::cout << "Key: " << kv.first << std::endl;
49afff574eSKun Yi  *         std::cout << "Value: " << get<uint64_t>(kv.second) << std::endl;
50afff574eSKun Yi  *     }
51afff574eSKun Yi  * }
52afff574eSKun Yi  *
53afff574eSKun Yi  * lpcsnoop::SnoopListen snoop(ListenBus, PrintMessageMap);
54afff574eSKun Yi  */
5533569758SPatrick Venture 
5633569758SPatrick Venture /*
5733569758SPatrick Venture  * This is the entry point for the application.
5833569758SPatrick Venture  *
5933569758SPatrick Venture  * This application simply creates an object that registers for incoming value
6033569758SPatrick Venture  * updates for the POST code dbus object.
6133569758SPatrick Venture  */
6233569758SPatrick Venture int main(int argc, char* argv[])
6333569758SPatrick Venture {
6433569758SPatrick Venture     auto ListenBus = sdbusplus::bus::new_default();
65afff574eSKun Yi     lpcsnoop::SnoopListen snoop(ListenBus, printPostcode);
6633569758SPatrick Venture 
6733569758SPatrick Venture     while (true)
6833569758SPatrick Venture     {
6933569758SPatrick Venture         ListenBus.process_discard();
7033569758SPatrick Venture         ListenBus.wait();
7133569758SPatrick Venture     }
7233569758SPatrick Venture 
7333569758SPatrick Venture     return 0;
7433569758SPatrick Venture }
75