-
Notifications
You must be signed in to change notification settings - Fork 3
/
metadata_wrapper.h
132 lines (112 loc) · 3.89 KB
/
metadata_wrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* \file metadata_wrapper.h
* \brief Wrapper singleton around the Read Metadata plugin shared object.
* \copyright
* 2021 Andrew Buettner (ABi)
*
* \section LICENSE
*
* QModbusTool - A QT Based Modbus Client
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* \section DESCRIPTION
*
* The MetadataWrapper class is a singleton class providing access the
* metadata modbus plugin (non-GPL). It also provides safe abstraction so
* functionality isn't lost (aside from the data its self) if the plugin isn't
* present. It also allows for easy replacement with another interface that
* can provide the same information.
*/
#ifndef METADATA_WRAPPER_H
#define METADATA_WRAPPER_H
// c++ includes
#include <QtCore> // QObject
#include <QPair> // QPair
#include <QLibrary> // QLibrary
#include <string_view> // std::string_view
#include <vector> // std::vector
#include <memory> // std::shared_ptr
#include <string> // std::string
// C includes
/* -none- */
// project includes
#include "metadata_structs.h" // Metadata
/**
* \brief State-aware wrapper around the metadata modbus plugin
*/
class MetadataWrapper : protected QObject
{
Q_OBJECT
// friend class Metadata;
public:
/**
* \brief Test if the library has been successfully loaded
* @return ``true`` if loaded, ``false`` otherwise
*/
[[nodiscard]] bool loaded() const;
/**
* \brief Generate request container
* @param reg_number Request metadata for this register number
* @return Metadata container
*/
[[nodiscard]] std::shared_ptr<Metadata> create_request(const quint16 reg_number);
/**
* \brief Generate an outgoing request PDU
* @param request Request container
* @return raw PDU (length and data pointer)
*/
[[nodiscard]] QPair<const quint8*, quint8> encode_request(std::shared_ptr<Metadata> request);
/**
* \brief Decode a response PDU
* @param request Request container (updated)
* @param data response PDU
*/
void decode_response(std::shared_ptr<Metadata> request, const std::vector<quint8> &data);
/**
* \brief This class is a singleton, get the instance.
* @return Singleton instance
*/
static MetadataWrapper* get_instance();
/**
* \brief Dispose metadata during destructor
* \note
* This function is only called by the MetaData object, and only during
* destruction. It is responsible for instructing the plugin to free
* internal resources.
*
* @param m pointer to metadata object
*/
void dispose_metadata(const Metadata *const m);
virtual ~MetadataWrapper();
private:
/**
* \brief constructor
* @param lib_path Path to the shared object
*/
MetadataWrapper(const QString &lib_path);
/**
* \fn decode_labels, decode_defaults, decode_encoding, decode_limits
* \brief Internal decoder functions
* @param request pointer to request instance
*/
void decode_labels(Metadata *const request);
void decode_defaults(Metadata *const request);
void decode_encoding(Metadata *const request);
void decode_limits(Metadata *const request);
QLibrary *const m_dll_reference;
// void *m_dll_reference = nullptr;
};
#endif // METADATA_WRAPPER_H