Aktualizr
C++ SOTA Client
configuration.h
1 #ifndef OPCUABRIDGE_CONFIGURATION_H_
2 #define OPCUABRIDGE_CONFIGURATION_H_
3 
4 #include "common.h"
5 
6 #include "uptane/tuf.h"
7 #include "utilities/types.h"
8 
9 #include <utility>
10 
11 namespace opcuabridge {
13  public:
14  Configuration() = default;
15  virtual ~Configuration() = default;
16 
17  const Uptane::EcuSerial& getSerial() const { return serial_; }
18  void setSerial(const Uptane::EcuSerial& serial) { serial_ = serial; }
19  Uptane::HardwareIdentifier getHwId() const { return hwid_; }
20  void setHwId(const Uptane::HardwareIdentifier& hwid) { hwid_ = hwid; }
21  const KeyType& getPublicKeyType() const { return public_key_type_; }
22  void setPublicKeyType(const KeyType& public_key_type) { public_key_type_ = public_key_type; }
23  const std::string& getPublicKey() const { return public_key_; }
24  void setPublicKey(const std::string& public_key) { public_key_ = public_key; }
25 
26  INITSERVERNODESET_FUNCTION_DEFINITION(Configuration) // InitServerNodeset(UA_Server*)
27  CLIENTREAD_FUNCTION_DEFINITION() // ClientRead(UA_Client*)
28  CLIENTWRITE_FUNCTION_DEFINITION() // ClientWrite(UA_Client*)
29 
30  void setOnBeforeReadCallback(MessageOnBeforeReadCallback<Configuration>::type cb) {
31  on_before_read_cb_ = std::move(cb);
32  }
33  void setOnAfterWriteCallback(MessageOnAfterWriteCallback<Configuration>::type cb) {
34  on_after_write_cb_ = std::move(cb);
35  }
36 
37  protected:
38  KeyType public_key_type_{};
39  Uptane::HardwareIdentifier hwid_{Uptane::HardwareIdentifier::Unknown()};
40  std::string public_key_;
41  Uptane::EcuSerial serial_{Uptane::EcuSerial::Unknown()};
42 
43  MessageOnBeforeReadCallback<Configuration>::type on_before_read_cb_;
44  MessageOnAfterWriteCallback<Configuration>::type on_after_write_cb_;
45 
46  private:
47  static const char* node_id_;
48 
49  Json::Value wrapMessage() const {
50  Json::Value v;
51  v["hwid"] = getHwId().ToString();
52  v["public_key_type"] = static_cast<int>(getPublicKeyType());
53  v["public_key"] = getPublicKey();
54  v["serial"] = getSerial().ToString();
55  return v;
56  }
57  void unwrapMessage(Json::Value v) {
58  setHwId(Uptane::HardwareIdentifier(v["hwid"].asString()));
59  setPublicKeyType(static_cast<KeyType>(v["public_key_type"].asInt()));
60  setPublicKey(v["public_key"].asString());
61  setSerial(Uptane::EcuSerial(v["serial"].asString()));
62  }
63 
64  WRAPMESSAGE_FUCTION_DEFINITION(Configuration)
65  UNWRAPMESSAGE_FUCTION_DEFINITION(Configuration)
66  READ_FUNCTION_FRIEND_DECLARATION(Configuration)
67  WRITE_FUNCTION_FRIEND_DECLARATION(Configuration)
68  INTERNAL_FUNCTIONS_FRIEND_DECLARATION(Configuration)
69 
70 #ifdef OPCUABRIDGE_ENABLE_SERIALIZATION
71  SERIALIZE_FUNCTION_FRIEND_DECLARATION
72 
73  DEFINE_SERIALIZE_METHOD() {
74  SERIALIZE_FIELD(ar, "hwid_", hwid_);
75  SERIALIZE_FIELD(ar, "serial_", serial_);
76  SERIALIZE_FIELD(ar, "public_key_", public_key_);
77  }
78 #endif // OPCUABRIDGE_ENABLE_SERIALIZATION
79 };
80 } // namespace opcuabridge
81 
82 #endif // OPCUABRIDGE_CONFIGURATION_H_