Motorcortex Core  version: 2.7.6
sg_signalid.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2018 VECTIONEER.
4  */
5 
6 #ifndef SG_SIGNALID_H
7 #define SG_SIGNALID_H
8 
9 #include <cstdint>
10 
11 namespace mcx {
12 
13 namespace signal_monitor {
14 
15 constexpr uint64_t encodeKey(uint32_t code, uint32_t subsystem) {
16  return (static_cast<uint64_t> (code) << (sizeof(code) * 8)) + subsystem;
17 };
18 
19 constexpr void decodeKey(const uint64_t& key, uint32_t* code,
20  uint32_t* subsystem) {
21  *code = static_cast<uint32_t>((key >> (sizeof(*code) * 8)) & 0xffffffff);
22  *subsystem = static_cast<uint32_t>(key & 0xffffffff);
23 }
24 
25 class SignalId {
26 public:
27 
28  SignalId();
29 
30  SignalId(uint32_t code);
31 
32  SignalId(uint32_t code, uint32_t subsystem);
33 
34  SignalId(uint32_t code, uint32_t subsystem, const uint32_t* info);
35 
36  uint64_t getKey() const;
37 
38  uint32_t getCode() const;
39 
40  uint32_t getSubsystem() const;
41 
42  bool hasSubsystem() const;
43 
44  uint32_t getInfo() const;
45 
46  const uint32_t* getInfoPtr() const;
47 
48  bool operator()(const SignalId& lhs, const SignalId& rhs) const;
49 
50 private:
51 
52  bool has_subsystem_;
53  uint64_t key_;
54  uint32_t code_;
55  uint32_t subsystem_;
56  const uint32_t* info_;
57 };
58 
59 bool operator==(const SignalId& lhs, const SignalId& rhs);
60 
61 bool operator>=(const SignalId& lhs, const SignalId& rhs);
62 
63 bool operator>(const SignalId& lhs, const SignalId& rhs);
64 
65 bool operator<=(const SignalId& lhs, const SignalId& rhs);
66 
67 bool operator<(const SignalId& lhs, const SignalId& rhs);
68 
69 bool operator!=(const SignalId& lhs, const SignalId& rhs);
70 
71 } // namespace signal_monitor
72 
73 } // namespace mcx
74 
75 #endif /* SG_SIGNALID_H */
76 
mcx::signal_monitor::SignalId
Definition: sg_signalid.h:25