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