Aktualizr
C++ SOTA Client
filedata.h
1 #ifndef OPCUABRIDGE_FILEDATA_H_
2 #define OPCUABRIDGE_FILEDATA_H_
3 
4 #include "common.h"
5 
6 #include <boost/filesystem.hpp>
7 #include <utility>
8 
9 namespace opcuabridge {
10 class FileData : public MessageFileData {
11  public:
12  FileData() = default;
13  explicit FileData(boost::filesystem::path base_path) : base_path_(std::move(base_path)) {}
14  ~FileData() final = default;
15 
16  const boost::filesystem::path& getBasePath() const { return base_path_; }
17  void setBasePath(const boost::filesystem::path& base_path) { base_path_ = base_path; }
18  const boost::filesystem::path& getFilePath() const { return file_path_; }
19  void setFilePath(const boost::filesystem::path& file_path) { file_path_ = file_path; }
20 
21  std::string getFullFilePath() const override { return (getBasePath() / getFilePath()).native(); }
22 
23  INITSERVERNODESET_FILE_FUNCTION_DEFINITION(FileData) // InitServerNodeset(UA_Server*)
24  CLIENTWRITE_FILE_FUNCTION_DEFINITION() // ClientWrite(UA_Client*)
25 
26  void setOnBeforeReadCallback(MessageOnBeforeReadCallback<FileData>::type cb) { on_before_read_cb_ = std::move(cb); }
27  void setOnAfterWriteCallback(MessageOnAfterWriteCallback<FileData>::type cb) { on_after_write_cb_ = std::move(cb); }
28 
29  protected:
30  boost::filesystem::path base_path_;
31  boost::filesystem::path file_path_;
32 
33  MessageOnBeforeReadCallback<FileData>::type on_before_read_cb_;
34  MessageOnAfterWriteCallback<FileData>::type on_after_write_cb_;
35 
36  private:
37  static const char* node_id_;
38  static const char* bin_node_id_;
39 
40  Json::Value wrapMessage() const {
41  Json::Value v;
42  v["filename"] = getFilePath().native();
43  return v;
44  }
45  void unwrapMessage(Json::Value v) { setFilePath(v["filename"].asString()); }
46 
47  WRAPMESSAGE_FUCTION_DEFINITION(FileData)
48  UNWRAPMESSAGE_FUCTION_DEFINITION(FileData)
49  READ_FUNCTION_FRIEND_DECLARATION(FileData)
50  WRITE_FUNCTION_FRIEND_DECLARATION(FileData)
51  INTERNAL_FUNCTIONS_FRIEND_DECLARATION(FileData)
52 };
53 } // namespace opcuabridge
54 
55 #endif // OPCUABRIDGE_FILEDATA_H_