forked from Bs0Dd/Coverett
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoverett.h
218 lines (189 loc) · 5.27 KB
/
coverett.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#ifndef COVERETT_H_
#define COVERETT_H_
#ifdef __cplusplus
extern "C"{
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include "cJSON/cJSON.h"
typedef enum TYPES {
CO_ERROR = -1, //Error status
CO_BOOLEAN, CO_LIST, CO_VOID, // Answer types for result_t
CO_NUMBER, CO_STRING, CO_BYTES, // Answer types for result_t / also data types for uniInvoke
CO_DEVICES, CO_METHODS, CO_SOUNDS, CO_DELETED, // Types for list_t
CO_OK, CO_NOFILE, CO_EMPTY // Types for fileinfo_t / stackinfo_t
} cotypes_t;
typedef FILE* bus_t;
typedef struct{
cotypes_t type;
cJSON* body;
char* errString;
} list_t;
typedef struct{
char* name;
char* description;
char* type;
} param_t;
typedef struct{
char* name;
char* returnType;
char* description;
char* returnValueDescription;
int paramNum;
param_t* parameters;
} method_t;
typedef struct{
int exists;
const char* devType;
const char* devId;
bus_t busPtr;
} device_t;
typedef struct{
cotypes_t type;
size_t retNumber;
char* retString;
cJSON* retList;
char* errString;
} result_t;
typedef struct{
cotypes_t type;
char* filename;
size_t size;
char* errString;
} fileinfo_t;
typedef struct{
cotypes_t type;
char* itemId;
int itemCount;
char* errString;
} stackinfo_t;
/**
* @brief Create a new descriptor for bus.
*
* @param[in] path Path to the bus character special file (default "/dev/hvc0").
*
* @return bus_t descriptor or NULL.
*/
bus_t openBus(char* path);
/**
* @brief Close bus descriptor.
*
* @param[in] bus Bus descriptor.
*
* @return Closing status.
*/
int closeBus(bus_t bus);
/**
* @brief Get devices list.
*
* @param[in] bus Bus descriptor.
*
* @return List of type CO_DEVICES or CO_ERROR.
*/
list_t getList(bus_t bus);
/**
* @brief Delete list (free memory).
*
* @param[in] list List for deleting. After function will be CO_DELETED.
*/
void deleteList(list_t* list);
/**
* @brief Get devices ID by list.
*
* @param[in] list List of the type CO_DEVICES.
* @param totaldevices Pointer to an integer where the total number of devices will be placed.
*
* @return Array of strings with devices ID or NULL.
*/
char** getDevsId(list_t list, int* totaldevices);
/**
* @brief Get device names by position in list.
*
* @param[in] list List of the type CO_DEVICES.
* @param[in] position Device position in list (zero-based).
* @param totalnames Pointer to an integer where the total number of names will be placed.
*
* @return Array of strings with device names or NULL.
*/
char** getDevNamesByPos(list_t list, int position, int* totalnames);
/**
* @brief Get device names by ID.
*
* @param[in] list List of the type CO_DEVICES.
* @param[in] id Device ID.
* @param totalnames Pointer to an integer where the total number of names will be placed.
*
* @return Array of strings with device names or NULL.
*/
char** getDevNamesById(list_t list, char* id, int* totalnames);
/**
* @brief Get device ID by name.
*
* @param[in] list List of type CO_DEVICES.
* @param[in] name Device name.
*
* @return String with device ID or NULL.
*/
char* getDevIdByName(list_t list, char* name);
/**
* @brief Get device proxy by ID.
*
* @param[in] bus Bus descriptor.
* @param[in] id Device ID.
*
* @return device_t structure.
*/
device_t proxyDev(bus_t bus, char* id);
/**
* @brief Get device proxy by name.
*
* @param[in] bus Bus descriptor.
* @param[in] id Device ID.
*
* @return device_t structure.
*/
device_t findDev(bus_t bus, char* name);
/**
* @brief Get methods list.
*
* @param[in] device Pointer to device proxy (device_t structure).
*
* @return List of the type CO_METHODS or CO_ERROR.
*/
list_t getMethods(device_t* device);
/**
* @brief Parse methods list.
*
* @param[in] list List of type CO_METHODS.
* @param[in] meths Pointer to an integer where the total number of methods will be placed.
*
* @return Array of method_t structures or NULL.
*/
method_t* parseMethods(list_t list, int* meths);
/**
* @brief Delete array of method_t structures (free memory).
*
* @param[in] methods Array of method_t structures.
* @param[in] meths Pointer to an integer where the total number of methods will be placed.
*/
void deleteParsedMethods(method_t* methods, int meths);
/**
* @brief Unversal invoker for methods.
*
* @param[in] device Pointer to device proxy (device_t structure).
* @param[in] method Method name.
* @param[in] numvals Number (double) parameters.
* @param[in] strvals String parameters.
* @param[in] total Total number of parameters.
* @param[in] order Parameter insertion order (e.g. {CO_NUMBER, CO_STRING, CO_STRING}).
*
* @return result_t structure with the type of CO_BOOLEAN, CO_LIST, CO_VOID, CO_NUMBER, CO_STRING or CO_BYTES.
*/
result_t uniInvoke(device_t* dev, char* method, double* numvals,
char** strvals, int total, cotypes_t* order);
#ifdef __cplusplus
}
#endif
#endif // COVERETT_H_