xref: /openbmc/entity-manager/src/entity_manager/perform_probe.hpp (revision cfc7f4f423c8163c394fbd777afcaf10a835206f)
1 #pragma once
2 
3 #include "perform_scan.hpp"
4 
5 #include <boost/container/flat_map.hpp>
6 
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace probe
12 {
13 struct CmpStr
14 {
15     bool operator()(const char* a, const char* b) const
16     {
17         return std::strcmp(a, b) < 0;
18     }
19 };
20 
21 // underscore T for collison with dbus c api
22 enum class probe_type_codes
23 {
24     FALSE_T,
25     TRUE_T,
26     AND,
27     OR,
28     FOUND,
29     MATCH_ONE
30 };
31 
32 using FoundProbeTypeT = std::optional<boost::container::flat_map<
33     const char*, probe_type_codes, CmpStr>::const_iterator>;
34 
35 FoundProbeTypeT findProbeType(const std::string& probe);
36 
37 // this class finds the needed dbus fields and on destruction runs the probe
38 struct PerformProbe : std::enable_shared_from_this<PerformProbe>
39 {
40     PerformProbe(nlohmann::json& recordRef,
41                  const std::vector<std::string>& probeCommand,
42                  std::string probeName,
43                  std::shared_ptr<scan::PerformScan>& scanPtr);
44     virtual ~PerformProbe();
45 
46     nlohmann::json& recordRef;
47     std::vector<std::string> _probeCommand;
48     std::string probeName;
49     std::shared_ptr<scan::PerformScan> scan;
50 };
51 
52 } // namespace probe
53