1 #include <libpdbg.h>
2 
3 #include <attn/attention.hpp>
4 #include <attn/attn_config.hpp>
5 #include <attn/attn_handler.hpp>
6 #include <cli.hpp>
7 #include <util/trace.hpp>
8 
9 #include <vector>
10 
11 namespace attn
12 {
13 // these are in the attn_lib but not all exposed via headers
14 int handleSpecial(Attention* i_attention);
15 int handleCheckstop(Attention* i_attention);
16 int handleVital(Attention* i_attention);
17 } // namespace attn
18 
19 /** @brief Attention handler test application */
20 int main(int argc, char* argv[])
21 {
22     int rc = 0; // return code
23 
24     // initialize pdbg targets
25     pdbg_targets_init(nullptr);
26 
27     // create attention handler config object
28     attn::Config attnConfig;
29 
30     // convert cmd line args to config values
31     parseConfig(argv, argv + argc, &attnConfig);
32 
33     // exercise attention gpio event path
34     attn::attnHandler(&attnConfig);
35 
36     // Get first enabled proc for testing
37     pdbg_target* target = nullptr;
38     pdbg_for_each_class_target("proc", target)
39     {
40         trace::inf("proc: %u", pdbg_target_index(target));
41         if (PDBG_TARGET_ENABLED == pdbg_target_probe(target))
42         {
43             trace::inf("target enabled");
44             break;
45         }
46     }
47 
48     // Exercise special, checkstop and vital attention handler paths
49     if ((nullptr != target) &&
50         (PDBG_TARGET_ENABLED == pdbg_target_probe(target)))
51     {
52         std::vector<attn::Attention> attentions;
53 
54         attentions.emplace_back(attn::Attention::AttentionType::Special,
55                                 attn::handleSpecial, target, &attnConfig);
56 
57         attentions.emplace_back(attn::Attention::AttentionType::Checkstop,
58                                 attn::handleCheckstop, target, &attnConfig);
59 
60         attentions.emplace_back(attn::Attention::AttentionType::Vital,
61                                 attn::handleVital, target, &attnConfig);
62 
63         std::for_each(std::begin(attentions), std::end(attentions),
64                       [](attn::Attention attention) {
65             trace::inf("calling handler");
66             attention.handle();
67         });
68     }
69 
70     return rc;
71 }
72