Instrument Neutral Distributed Interface INDI  1.6.0
indiproperty.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2011 Jasem Mutlaq. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 *******************************************************************************/
18 
19 #include "indiproperty.h"
20 
21 #include <cstdlib>
22 
24 {
25  pPtr = nullptr;
26  pRegistered = false;
27  pDynamic = false;
28  pType = INDI_UNKNOWN;
29 }
30 
32 {
33  // Only delete properties if they were created dynamically via the buildSkeleton
34  // function. Other drivers are responsible for their own memory allocation.
35  if (pDynamic)
36  {
37  switch (pType)
38  {
39  case INDI_NUMBER:
40  {
42  free(p->np);
43  delete p;
44  break;
45  }
46 
47  case INDI_TEXT:
48  {
50  for (int i = 0; i < p->ntp; ++i)
51  {
52  free(p->tp[i].text);
53  }
54  free(p->tp);
55  delete p;
56  break;
57  }
58 
59  case INDI_SWITCH:
60  {
62  free(p->sp);
63  delete p;
64  break;
65  }
66 
67  case INDI_LIGHT:
68  {
70  free(p->lp);
71  delete p;
72  break;
73  }
74 
75  case INDI_BLOB:
76  {
78  for (int i = 0; i < p->nbp; ++i)
79  {
80  free(p->bp[i].blob);
81  }
82  free(p->bp);
83  delete p;
84  break;
85  }
86 
87  case INDI_UNKNOWN:
88  break;
89  }
90  }
91 }
92 
94 {
95  pRegistered = true;
96  pPtr = p;
97 }
98 
100 {
101  pType = t;
102 }
103 
105 {
106  pRegistered = r;
107 }
108 
110 {
111  pDynamic = d;
112 }
113 
115 {
116  dp = idp;
117 }
118 
119 const char *INDI::Property::getName() const
120 {
121  if (pPtr == nullptr)
122  return nullptr;
123 
124  switch (pType)
125  {
126  case INDI_NUMBER:
127  return ((INumberVectorProperty *)pPtr)->name;
128  break;
129 
130  case INDI_TEXT:
131  return ((ITextVectorProperty *)pPtr)->name;
132  break;
133 
134  case INDI_SWITCH:
135  return ((ISwitchVectorProperty *)pPtr)->name;
136  break;
137 
138  case INDI_LIGHT:
139  return ((ILightVectorProperty *)pPtr)->name;
140  break;
141 
142  case INDI_BLOB:
143  return ((IBLOBVectorProperty *)pPtr)->name;
144  break;
145 
146  case INDI_UNKNOWN:
147  break;
148  }
149 
150  return nullptr;
151 }
152 
153 const char *INDI::Property::getLabel() const
154 {
155  if (pPtr == nullptr)
156  return nullptr;
157 
158  switch (pType)
159  {
160  case INDI_NUMBER:
161  return ((INumberVectorProperty *)pPtr)->label;
162  break;
163 
164  case INDI_TEXT:
165  return ((ITextVectorProperty *)pPtr)->label;
166  break;
167 
168  case INDI_SWITCH:
169  return ((ISwitchVectorProperty *)pPtr)->label;
170  break;
171 
172  case INDI_LIGHT:
173  return ((ILightVectorProperty *)pPtr)->label;
174  break;
175 
176  case INDI_BLOB:
177  return ((IBLOBVectorProperty *)pPtr)->label;
178  break;
179 
180  case INDI_UNKNOWN:
181  break;
182  }
183  return nullptr;
184 }
185 
186 const char *INDI::Property::getGroupName() const
187 {
188  if (pPtr == nullptr)
189  return nullptr;
190 
191  switch (pType)
192  {
193  case INDI_NUMBER:
194  return ((INumberVectorProperty *)pPtr)->group;
195  break;
196 
197  case INDI_TEXT:
198  return ((ITextVectorProperty *)pPtr)->group;
199  break;
200 
201  case INDI_SWITCH:
202  return ((ISwitchVectorProperty *)pPtr)->group;
203  break;
204 
205  case INDI_LIGHT:
206  return ((ILightVectorProperty *)pPtr)->group;
207  break;
208 
209  case INDI_BLOB:
210  return ((IBLOBVectorProperty *)pPtr)->group;
211  break;
212 
213  case INDI_UNKNOWN:
214  break;
215  }
216 
217  return nullptr;
218 }
219 
220 const char *INDI::Property::getDeviceName() const
221 {
222  if (pPtr == nullptr)
223  return nullptr;
224 
225  switch (pType)
226  {
227  case INDI_NUMBER:
228  return ((INumberVectorProperty *)pPtr)->device;
229  break;
230 
231  case INDI_TEXT:
232  return ((ITextVectorProperty *)pPtr)->device;
233  break;
234 
235  case INDI_SWITCH:
236  return ((ISwitchVectorProperty *)pPtr)->device;
237  break;
238 
239  case INDI_LIGHT:
240  return ((ILightVectorProperty *)pPtr)->device;
241  break;
242 
243  case INDI_BLOB:
244  return ((IBLOBVectorProperty *)pPtr)->device;
245  break;
246 
247  case INDI_UNKNOWN:
248  break;
249  }
250 
251  return nullptr;
252 }
253 
254 const char *INDI::Property::getTimestamp() const
255 {
256  if (pPtr == nullptr)
257  return nullptr;
258 
259  switch (pType)
260  {
261  case INDI_NUMBER:
262  return ((INumberVectorProperty *)pPtr)->timestamp;
263  break;
264 
265  case INDI_TEXT:
266  return ((ITextVectorProperty *)pPtr)->timestamp;
267  break;
268 
269  case INDI_SWITCH:
270  return ((ISwitchVectorProperty *)pPtr)->timestamp;
271  break;
272 
273  case INDI_LIGHT:
274  return ((ILightVectorProperty *)pPtr)->timestamp;
275  break;
276 
277  case INDI_BLOB:
278  return ((IBLOBVectorProperty *)pPtr)->timestamp;
279  break;
280 
281  case INDI_UNKNOWN:
282  break;
283  }
284 
285  return nullptr;
286 }
287 
289 {
290  switch (pType)
291  {
292  case INDI_NUMBER:
293  return ((INumberVectorProperty *)pPtr)->s;
294  break;
295 
296  case INDI_TEXT:
297  return ((ITextVectorProperty *)pPtr)->s;
298  break;
299 
300  case INDI_SWITCH:
301  return ((ISwitchVectorProperty *)pPtr)->s;
302  break;
303 
304  case INDI_LIGHT:
305  return ((ILightVectorProperty *)pPtr)->s;
306  break;
307 
308  case INDI_BLOB:
309  return ((IBLOBVectorProperty *)pPtr)->s;
310  break;
311 
312  default:
313  break;
314  }
315 
316  return IPS_IDLE;
317 }
318 
320 {
321  switch (pType)
322  {
323  case INDI_NUMBER:
324  return ((INumberVectorProperty *)pPtr)->p;
325  break;
326 
327  case INDI_TEXT:
328  return ((ITextVectorProperty *)pPtr)->p;
329  break;
330 
331  case INDI_SWITCH:
332  return ((ISwitchVectorProperty *)pPtr)->p;
333  break;
334 
335  case INDI_LIGHT:
336  break;
337 
338  case INDI_BLOB:
339  return ((IBLOBVectorProperty *)pPtr)->p;
340  break;
341 
342  default:
343  break;
344  }
345 
346  return IP_RO;
347 }
348 
350 {
351  if (pType == INDI_NUMBER)
352  return ((INumberVectorProperty *)pPtr);
353 
354  return nullptr;
355 }
356 
358 {
359  if (pType == INDI_TEXT)
360  return ((ITextVectorProperty *)pPtr);
361 
362  return nullptr;
363 }
364 
366 {
367  if (pType == INDI_SWITCH)
368  return ((ISwitchVectorProperty *)pPtr);
369 
370  return nullptr;
371 }
372 
374 {
375  if (pType == INDI_LIGHT)
376  return ((ILightVectorProperty *)pPtr);
377 
378  return nullptr;
379 }
380 
382 {
383  if (pType == INDI_BLOB)
384  return ((IBLOBVectorProperty *)pPtr);
385 
386  return nullptr;
387 }
const char * getLabel() const
Light vector property descriptor.
Definition: indiapi.h:397
INDI_PROPERTY_TYPE
Definition: indibasetypes.h:22
char * text
Definition: indiapi.h:213
IPState
Property state.
Definition: indiapi.h:143
void setProperty(void *)
const char * getGroupName() const
ILightVectorProperty * getLight()
IPerm getPermission() const
void setDynamic(bool d)
Definition: indiapi.h:165
const char * getName() const
ISwitchVectorProperty * getSwitch()
Class to provide basic INDI device functionality.
Definition: basedevice.h:44
void setType(INDI_PROPERTY_TYPE t)
Switch vector property descriptor.
Definition: indiapi.h:347
const char * getTimestamp() const
void setBaseDevice(BaseDevice *idp)
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:451
void * blob
Definition: indiapi.h:432
void setRegistered(bool r)
Number vector property descriptor.
Definition: indiapi.h:299
ITextVectorProperty * getText()
IPerm
Permission hint, with respect to client.
Definition: indiapi.h:164
const char * getDeviceName() const
IPState getState() const
Text vector property descriptor.
Definition: indiapi.h:226
INumberVectorProperty * getNumber()
IBLOBVectorProperty * getBLOB()