Instrument Neutral Distributed Interface INDI  2.0.2
indipropertyview.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2021 by Pawel Soja <kernel32.pl@gmail.com>
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 
21 void (*WeakIDSetTextVA)(const ITextVectorProperty *, const char *, va_list) = nullptr;
22 void (*WeakIDDefTextVA)(const ITextVectorProperty *, const char *, va_list) = nullptr;
23 void (*WeakIDSetNumberVA)(const INumberVectorProperty *, const char *, va_list) = nullptr;
24 void (*WeakIDDefNumberVA)(const INumberVectorProperty *, const char *, va_list) = nullptr;
25 void (*WeakIDSetSwitchVA)(const ISwitchVectorProperty *, const char *, va_list) = nullptr;
26 void (*WeakIDDefSwitchVA)(const ISwitchVectorProperty *, const char *, va_list) = nullptr;
27 void (*WeakIDSetLightVA)(const ILightVectorProperty *, const char *, va_list) = nullptr;
28 void (*WeakIDDefLightVA)(const ILightVectorProperty *, const char *, va_list) = nullptr;
29 void (*WeakIDSetBLOBVA)(const IBLOBVectorProperty *, const char *, va_list) = nullptr;
30 void (*WeakIDDefBLOBVA)(const IBLOBVectorProperty *, const char *, va_list) = nullptr;
31 int (*WeakIUUpdateText)(ITextVectorProperty *, char *[], char *[], int) = nullptr;
32 int (*WeakIUUpdateNumber)(INumberVectorProperty *, double[], char *[], int n) = nullptr;
33 int (*WeakIUUpdateSwitch)(ISwitchVectorProperty *, ISState *, char *[], int n) = nullptr;
34 int (*WeakIUUpdateBLOB)(IBLOBVectorProperty *, int [], int [], char *[], char *[], char *[], int n) = nullptr;
35 void (*WeakIUUpdateMinMax)(const INumberVectorProperty *) = nullptr;
36 
37 namespace INDI
38 {
39 
40 static void errorUnavailable(const char *function)
41 {
42  fprintf(stderr, "%s method available only on driver side\n", function);
43 }
44 
45 template <>
46 void PropertyView<IText>::vapply(const char *format, va_list arg) const
47 {
48  if (WeakIDSetTextVA)
49  WeakIDSetTextVA(this, format, arg);
50  else
51  errorUnavailable(__FUNCTION__);
52 }
53 
54 template <>
55 void PropertyView<IText>::vdefine(const char *format, va_list arg) const
56 {
57  if (WeakIDDefTextVA)
58  WeakIDDefTextVA(this, format, arg);
59  else
60  errorUnavailable(__FUNCTION__);
61 }
62 
63 template <>
64 void PropertyView<INumber>::vapply(const char *format, va_list arg) const
65 {
67  WeakIDSetNumberVA(this, format, arg);
68  else
69  errorUnavailable(__FUNCTION__);
70 }
71 
72 template <>
73 void PropertyView<INumber>::vdefine(const char *format, va_list arg) const
74 {
76  WeakIDDefNumberVA(this, format, arg);
77  else
78  errorUnavailable(__FUNCTION__);
79 }
80 
81 template <>
82 void PropertyView<ISwitch>::vapply(const char *format, va_list arg) const
83 {
85  WeakIDSetSwitchVA(this, format, arg);
86  else
87  errorUnavailable(__FUNCTION__);
88 }
89 
90 template <>
91 void PropertyView<ISwitch>::vdefine(const char *format, va_list arg) const
92 {
94  WeakIDDefSwitchVA(this, format, arg);
95  else
96  errorUnavailable(__FUNCTION__);
97 }
98 
99 template <>
100 void PropertyView<ILight>::vapply(const char *format, va_list arg) const
101 {
102  if (WeakIDSetLightVA)
103  WeakIDSetLightVA(this, format, arg);
104  else
105  errorUnavailable(__FUNCTION__);
106 }
107 
108 template <>
109 void PropertyView<ILight>::vdefine(const char *format, va_list arg) const
110 {
111  if (WeakIDDefLightVA)
112  WeakIDDefLightVA(this, format, arg);
113  else
114  errorUnavailable(__FUNCTION__);
115 }
116 
117 template <>
118 void 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 
126 template <>
127 void 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 
135 template <typename T>
136 void 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 
144 template <typename T>
145 void 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 
153 template <> 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 
165 template <> 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 
177 template <> 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 
189 template <> 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 
201 template <> 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 
213 template <> template<>
214 bool PropertyView<IText>::update(const char * const texts[], const char * const names[], int n)
215 {
216  if (WeakIUUpdateText)
217  return WeakIUUpdateText(this, const_cast<char**>(texts), const_cast<char**>(names), n) == 0;
218 
219  errorUnavailable(__FUNCTION__);
220  return false;
221 }
222 
223 template <> template<>
224 bool PropertyView<INumber>::update(const double values[], const char * const names[], int n)
225 {
226  if (WeakIUUpdateNumber)
227  return WeakIUUpdateNumber(this, const_cast<double*>(values), const_cast<char**>(names), n) == 0;
228 
229  errorUnavailable(__FUNCTION__);
230  return false;
231 }
232 
233 template <> template<>
234 bool PropertyView<ISwitch>::update(const ISState states[], const char * const names[], int n)
235 {
236  if (WeakIUUpdateSwitch)
237  return WeakIUUpdateSwitch(this, const_cast<ISState*>(states), const_cast<char**>(names), n) == 0;
238 
239  errorUnavailable(__FUNCTION__);
240  return false;
241 }
242 
243 template <> 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 {
249  if (WeakIUUpdateBLOB)
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 }
260 
261 template <> template<>
263 {
264  if (WeakIUUpdateMinMax)
265  WeakIUUpdateMinMax(this);
266 }
267 
268 void WidgetView<IText>::fill(const char *name, const char *label, const char *initialText)
269 {
270  IUFillText(this, name, label, initialText);
271 }
272 
273 
274 void WidgetView<ISwitch>::fill(const char *name, const char *label, ISState state)
275 {
276  IUFillSwitch(this, name, label, state);
277 }
278 
279 
280 void WidgetView<ILight>::fill(const char *name, const char *label, IPState state)
281 {
282  IUFillLight(this, name, label, state);
283 }
284 
285 void WidgetView<INumber>::fill(const char *name, const char *label, const char *format,
286  double min, double max, double step, double value)
287 {
288  IUFillNumber(this, name, label, format, min, max, step, value);
289 }
290 
291 void WidgetView<IBLOB>::fill(const char *name, const char *label, const char *format)
292 {
293  IUFillBLOB(this, name, label, format);
294 }
295 
296 template struct PropertyView<INumber>;
297 template struct PropertyView<IText>;
298 template struct PropertyView<ISwitch>;
299 template struct PropertyView<ILight>;
300 template struct PropertyView<IBLOB>;
301 
302 }
hid_device * device
double max(void)
double min(void)
ISState
Switch state.
Definition: indiapi.h:150
IPerm
Permission hint, with respect to client.
Definition: indiapi.h:183
IPState
Property state.
Definition: indiapi.h:160
ISRule
Switch vector rule hint.
Definition: indiapi.h:172
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:169
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:272
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:255
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:291
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:158
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:198
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:180
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:235
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:310
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:216
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
void vapply(const char *format, va_list args) const
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:471
Light vector property descriptor.
Definition: indiapi.h:417
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246