Instrument Neutral Distributed Interface INDI 2.2.5
indipropertyview.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2021 by Pawel Soja <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#include "indipropertyview.h"
20
21void (*WeakIDSetTextVA)(const ITextVectorProperty *, const char *, va_list) = nullptr;
22void (*WeakIDDefTextVA)(const ITextVectorProperty *, const char *, va_list) = nullptr;
23void (*WeakIDSetNumberVA)(const INumberVectorProperty *, const char *, va_list) = nullptr;
24void (*WeakIDDefNumberVA)(const INumberVectorProperty *, const char *, va_list) = nullptr;
25void (*WeakIDSetSwitchVA)(const ISwitchVectorProperty *, const char *, va_list) = nullptr;
26void (*WeakIDDefSwitchVA)(const ISwitchVectorProperty *, const char *, va_list) = nullptr;
27void (*WeakIDSetLightVA)(const ILightVectorProperty *, const char *, va_list) = nullptr;
28void (*WeakIDDefLightVA)(const ILightVectorProperty *, const char *, va_list) = nullptr;
29void (*WeakIDSetBLOBVA)(const IBLOBVectorProperty *, const char *, va_list) = nullptr;
30void (*WeakIDDefBLOBVA)(const IBLOBVectorProperty *, const char *, va_list) = nullptr;
31int (*WeakIUUpdateText)(ITextVectorProperty *, char *[], char *[], int) = nullptr;
32int (*WeakIUUpdateNumber)(INumberVectorProperty *, double[], char *[], int n) = nullptr;
33int (*WeakIUUpdateSwitch)(ISwitchVectorProperty *, ISState *, char *[], int n) = nullptr;
34int (*WeakIUUpdateBLOB)(IBLOBVectorProperty *, int [], int [], char *[], char *[], char *[], int n) = nullptr;
35void (*WeakIUUpdateMinMax)(const INumberVectorProperty *) = nullptr;
36
37namespace INDI
38{
39
40static void errorUnavailable(const char *function)
41{
42 fprintf(stderr, "%s method available only on driver side\n", function);
43}
44
45template <>
46void PropertyView<IText>::vapply(const char *format, va_list arg) const
47{
49 WeakIDSetTextVA(this, format, arg);
50 else
51 errorUnavailable(__FUNCTION__);
52}
53
54template <>
55void PropertyView<IText>::vdefine(const char *format, va_list arg) const
56{
58 WeakIDDefTextVA(this, format, arg);
59 else
60 errorUnavailable(__FUNCTION__);
61}
62
63template <>
64void PropertyView<INumber>::vapply(const char *format, va_list arg) const
65{
67 WeakIDSetNumberVA(this, format, arg);
68 else
69 errorUnavailable(__FUNCTION__);
70}
71
72template <>
73void PropertyView<INumber>::vdefine(const char *format, va_list arg) const
74{
76 WeakIDDefNumberVA(this, format, arg);
77 else
78 errorUnavailable(__FUNCTION__);
79}
80
81template <>
82void PropertyView<ISwitch>::vapply(const char *format, va_list arg) const
83{
85 WeakIDSetSwitchVA(this, format, arg);
86 else
87 errorUnavailable(__FUNCTION__);
88}
89
90template <>
91void PropertyView<ISwitch>::vdefine(const char *format, va_list arg) const
92{
94 WeakIDDefSwitchVA(this, format, arg);
95 else
96 errorUnavailable(__FUNCTION__);
97}
98
99template <>
100void PropertyView<ILight>::vapply(const char *format, va_list arg) const
101{
103 WeakIDSetLightVA(this, format, arg);
104 else
105 errorUnavailable(__FUNCTION__);
106}
107
108template <>
109void PropertyView<ILight>::vdefine(const char *format, va_list arg) const
110{
112 WeakIDDefLightVA(this, format, arg);
113 else
114 errorUnavailable(__FUNCTION__);
115}
116
117template <>
118void PropertyView<IBLOB>::vapply(const char *format, va_list arg) const
119{
120 if (WeakIDSetBLOBVA)
121 WeakIDSetBLOBVA(this, format, arg);
122 else
123 errorUnavailable(__FUNCTION__);
124}
125
126template <>
127void PropertyView<IBLOB>::vdefine(const char *format, va_list arg) const
128{
129 if (WeakIDDefBLOBVA)
130 WeakIDDefBLOBVA(this, format, arg);
131 else
132 errorUnavailable(__FUNCTION__);
133}
134
135template <typename T>
136void PropertyView<T>::apply(const char *format, ...) const
137{
138 va_list ap;
139 va_start(ap, format);
140 this->vapply(format, ap);
141 va_end(ap);
142}
143
144template <typename T>
145void PropertyView<T>::define(const char *format, ...) const
146{
147 va_list ap;
148 va_start(ap, format);
149 this->vdefine(format, ap);
150 va_end(ap);
151}
152
153template <> template <>
155 const char *device, const char *name, const char *label, const char *group,
156 IPerm permission, double timeout, IPState state
157)
158{
160 this, begin(), count(), device, name, label, group,
161 permission, timeout, state
162 );
163}
164
165template <> template <>
167 const char *device, const char *name, const char *label, const char *group,
168 IPerm permission, double timeout, IPState state
169)
170{
172 this, begin(), count(), device, name, label, group,
173 permission, timeout, state
174 );
175}
176
177template <> template <>
179 const char *device, const char *name, const char *label, const char *group,
180 IPerm permission, ISRule rule, double timeout, IPState state
181)
182{
184 this, begin(), count(), device, name, label, group,
185 permission, rule, timeout, state
186 );
187}
188
189template <> template <>
191 const char *device, const char *name, const char *label, const char *group,
192 IPState state
193)
194{
196 this, begin(), count(), device, name, label, group,
197 state
198 );
199}
200
201template <> template <>
203 const char *device, const char *name, const char *label, const char *group,
204 IPerm permission, double timeout, IPState state
205)
206{
208 this, begin(), count(), device, name, label, group,
209 permission, timeout, state
210 );
211}
212
213template <> template<>
214bool PropertyView<IText>::update(const char * const texts[], const char * const names[], int n)
215{
217 return WeakIUUpdateText(this, const_cast<char**>(texts), const_cast<char**>(names), n) == 0;
218
219 errorUnavailable(__FUNCTION__);
220 return false;
221}
222
223template <> template<>
224bool PropertyView<INumber>::update(const double values[], const char * const names[], int n)
225{
227 return WeakIUUpdateNumber(this, const_cast<double*>(values), const_cast<char**>(names), n) == 0;
228
229 errorUnavailable(__FUNCTION__);
230 return false;
231}
232
233template <> template<>
234bool PropertyView<ISwitch>::update(const ISState states[], const char * const names[], int n)
235{
237 return WeakIUUpdateSwitch(this, const_cast<ISState*>(states), const_cast<char**>(names), n) == 0;
238
239 errorUnavailable(__FUNCTION__);
240 return false;
241}
242
243template <> template<>
245 const int sizes[], const int blobsizes[], const char *const blobs[], const char *const formats[],
246 const char * const names[], int n
247)
248{
250 return WeakIUUpdateBLOB(
251 this,
252 const_cast<int *>(sizes), const_cast<int *>(blobsizes),
253 const_cast<char **>(blobs), const_cast<char **>(formats),
254 const_cast<char **>(names), n
255 ) == 0;
256
257 errorUnavailable(__FUNCTION__);
258 return false;
259}
261template <> template<>
263{
265 WeakIUUpdateMinMax(this);
266}
267
268template <> template<>
269bool PropertyView<IText>::isUpdated(const char * const texts[], const char * const names[], int n) const
270{
271 for (int i = 0; i < n; i++)
272 {
273 auto widget = findWidgetByName(names[i]);
274 if (widget && strcmp(widget->getText(), texts[i]) != 0)
275 return true;
276 }
277 return false;
278}
279
280template <> template<>
281bool PropertyView<INumber>::isUpdated(const double values[], const char * const names[], int n) const
282{
283 for (int i = 0; i < n; i++)
284 {
285 auto widget = findWidgetByName(names[i]);
286 if (widget && widget->getValue() != values[i])
287 return true;
288 }
289 return false;
290}
291
292template <> template<>
293bool PropertyView<ISwitch>::isUpdated(const ISState states[], const char * const names[], int n) const
294{
295 for (int i = 0; i < n; i++)
296 {
297 auto widget = findWidgetByName(names[i]);
298 if (widget && widget->getState() != states[i])
299 return true;
300 }
301 return false;
302}
303
304void WidgetView<IText>::fill(const char *name, const char *label, const char *initialText)
305{
306 IUFillText(this, name, label, initialText);
307}
308
309
310void WidgetView<ISwitch>::fill(const char *name, const char *label, ISState state)
311{
312 IUFillSwitch(this, name, label, state);
313}
314
315
316void WidgetView<ILight>::fill(const char *name, const char *label, IPState state)
317{
318 IUFillLight(this, name, label, state);
319}
320
321void WidgetView<INumber>::fill(const char *name, const char *label, const char *format,
322 double min, double max, double step, double value)
323{
324 IUFillNumber(this, name, label, format, min, max, step, value);
325}
326
327void WidgetView<IBLOB>::fill(const char *name, const char *label, const char *format)
328{
329 IUFillBLOB(this, name, label, format);
330}
331
332template struct PropertyView<INumber>;
333template struct PropertyView<IText>;
334template struct PropertyView<ISwitch>;
335template struct PropertyView<ILight>;
336template struct PropertyView<IBLOB>;
337
338}
hid_device * device
void(* WeakIDSetBLOBVA)(const IBLOBVectorProperty *, const char *, va_list)
int(* WeakIUUpdateText)(ITextVectorProperty *, char *[], char *[], int)
int(* WeakIUUpdateNumber)(INumberVectorProperty *, double[], char *[], int n)
int(* WeakIUUpdateBLOB)(IBLOBVectorProperty *, int[], int[], char *[], char *[], char *[], int n)
void(* WeakIDSetLightVA)(const ILightVectorProperty *, const char *, va_list)
void(* WeakIDDefSwitchVA)(const ISwitchVectorProperty *, const char *, va_list)
void(* WeakIDDefTextVA)(const ITextVectorProperty *, const char *, va_list)
void(* WeakIDSetTextVA)(const ITextVectorProperty *, const char *, va_list)
void(* WeakIDDefBLOBVA)(const IBLOBVectorProperty *, const char *, va_list)
void(* WeakIDDefNumberVA)(const INumberVectorProperty *, const char *, va_list)
void(* WeakIDDefLightVA)(const ILightVectorProperty *, const char *, va_list)
int(* WeakIUUpdateSwitch)(ISwitchVectorProperty *, ISState *, char *[], int n)
void(* WeakIDSetNumberVA)(const INumberVectorProperty *, const char *, va_list)
void(* WeakIDSetSwitchVA)(const ISwitchVectorProperty *, const char *, va_list)
void(* WeakIUUpdateMinMax)(const INumberVectorProperty *)
double max(void)
#define min(a, b)
ISState
Switch state.
Definition indiapi.h:148
IPerm
Permission hint, with respect to client.
Definition indiapi.h:181
IPState
Property state.
Definition indiapi.h:158
ISRule
Switch vector rule hint.
Definition indiapi.h:170
void IUFillLight(ILight *lp, const char *name, const char *label, IPState s)
Assign attributes for a light property. The light's auxiliary elements will be set to NULL.
Definition indidevapi.c:387
void IUFillNumberVector(INumberVectorProperty *nvp, INumber *np, int nnp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a number vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:490
void IUFillLightVector(ILightVectorProperty *lvp, ILight *lp, int nlp, const char *dev, const char *name, const char *label, const char *group, IPState s)
Assign attributes for a light vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:473
void IUFillTextVector(ITextVectorProperty *tvp, IText *tp, int ntp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a text vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:509
void IUFillSwitch(ISwitch *sp, const char *name, const char *label, ISState s)
Assign attributes for a switch property. The switch's auxiliary elements will be set to NULL.
Definition indidevapi.c:376
void IUFillText(IText *tp, const char *name, const char *label, const char *initialText)
Assign attributes for a text property. The text's auxiliary elements will be set to NULL.
Definition indidevapi.c:416
void IUFillNumber(INumber *np, const char *name, const char *label, const char *format, double min, double max, double step, double value)
Assign attributes for a number property. The number's auxiliary elements will be set to NULL.
Definition indidevapi.c:398
void IUFillSwitchVector(ISwitchVectorProperty *svp, ISwitch *sp, int nsp, const char *dev, const char *name, const char *label, const char *group, IPerm p, ISRule r, double timeout, IPState s)
Assign attributes for a switch vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:453
void IUFillBLOBVector(IBLOBVectorProperty *bvp, IBLOB *bp, int nbp, const char *dev, const char *name, const char *label, const char *group, IPerm p, double timeout, IPState s)
Assign attributes for a BLOB vector property. The vector's auxiliary elements will be set to NULL.
Definition indidevapi.c:528
void IUFillBLOB(IBLOB *bp, const char *name, const char *label, const char *format)
Assign attributes for a BLOB property. The BLOB's data and auxiliary elements will be set to NULL.
Definition indidevapi.c:434
void(* WeakIDSetBLOBVA)(const IBLOBVectorProperty *, const char *, va_list)
int(* WeakIUUpdateText)(ITextVectorProperty *, char *[], char *[], int)
int(* WeakIUUpdateNumber)(INumberVectorProperty *, double[], char *[], int n)
int(* WeakIUUpdateBLOB)(IBLOBVectorProperty *, int[], int[], char *[], char *[], char *[], int n)
void(* WeakIDSetLightVA)(const ILightVectorProperty *, const char *, va_list)
void(* WeakIDDefSwitchVA)(const ISwitchVectorProperty *, const char *, va_list)
void(* WeakIDDefTextVA)(const ITextVectorProperty *, const char *, va_list)
void(* WeakIDSetTextVA)(const ITextVectorProperty *, const char *, va_list)
void(* WeakIDDefBLOBVA)(const IBLOBVectorProperty *, const char *, va_list)
void(* WeakIDDefNumberVA)(const INumberVectorProperty *, const char *, va_list)
void(* WeakIDDefLightVA)(const ILightVectorProperty *, const char *, va_list)
int(* WeakIUUpdateSwitch)(ISwitchVectorProperty *, ISState *, char *[], int n)
void(* WeakIDSetNumberVA)(const INumberVectorProperty *, const char *, va_list)
void(* WeakIDSetSwitchVA)(const ISwitchVectorProperty *, const char *, va_list)
void(* WeakIUUpdateMinMax)(const INumberVectorProperty *)
Namespace to encapsulate INDI client, drivers, and mediator classes.
Provides decorator for Low-Level IXXXVectorProperty/IXXX.
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
void void void apply() const
bool update(const char *const texts[], const char *const names[], int n)
void vdefine(const char *format, va_list args) const
bool isUpdated(const char *const texts[], const char *const names[], int n) const
void vapply(const char *format, va_list args) const
BLOB (Binary Large Object) vector property descriptor.
Definition indiapi.h:469
Light vector property descriptor.
Definition indiapi.h:415
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244