Instrument Neutral Distributed Interface INDI 2.2.5
indiproperty.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2011 Jasem Mutlaq. All rights reserved.
3 2022 Pawel Soja <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
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 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*******************************************************************************/
19
20#pragma once
21
22#include "indibase.h"
23#include "indiutility.h"
24
25#include "indipropertyview.h"
26
27#include <memory>
28#include <cstdarg>
29#include <functional>
30
31#define INDI_PROPERTY_BACKWARD_COMPATIBILE
32namespace INDI
33{
34class BaseDevice;
35class PropertyNumber;
36class PropertyText;
37class PropertySwitch;
38class PropertyLight;
39class PropertyBlob;
46class PropertyPrivate;
48{
49 DECLARE_PRIVATE(Property)
50 public:
51 Property();
52 ~Property();
53
54 public:
60
61#ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
62 public:
68
69 public:
75
76#endif
77 public:
78 void setProperty(void *);
80 void setRegistered(bool r);
81 void setDynamic(bool d);
82
83 INDI_DEPRECATED("Use setBaseDevice(BaseDevice).")
84 void setBaseDevice(BaseDevice *idp);
85
87
88 public:
89 void *getProperty() const;
91 const char *getTypeAsString() const;
92 bool getRegistered() const;
93 bool isDynamic() const;
95
96 public: // Convenience Functions
97 void setName(const char *name);
98 void setLabel(const char *label);
99 void setGroupName(const char *groupName);
100 void setDeviceName(const char *deviceName);
101 void setTimestamp(const char *timestamp);
102 void setState(IPState state);
103 void setPermission(IPerm permission);
104 void setTimeout(double timeout);
105
106 public: // Convenience Functions
107 const char *getName() const;
108 const char *getLabel() const;
109 const char *getGroupName() const;
110 const char *getDeviceName() const;
111 const char *getTimestamp() const;
112 IPState getState() const;
113 const char *getStateAsString() const;
114 IPerm getPermission() const;
115
116 public:
117 bool isEmpty() const;
118 bool isValid() const;
119
120 bool isNameMatch(const char *otherName) const;
121 bool isNameMatch(const std::string &otherName) const;
122
123 bool isLabelMatch(const char *otherLabel) const;
124 bool isLabelMatch(const std::string &otherLabel) const;
125
126 bool isDeviceNameMatch(const char *otherDeviceName) const;
127 bool isDeviceNameMatch(const std::string &otherDeviceName) const;
128
129 bool isTypeMatch(INDI_PROPERTY_TYPE otherType) const;
130
131 public:
132 void onUpdate(const std::function<void()> &callback);
133
134 public:
135 void emitUpdate();
136 bool hasUpdateCallback() const;
137
138 public:
139 bool load();
140 void save(FILE *fp) const;
141
142 public:
143 void apply(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
144 void define(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
145
146 void apply() const
147 {
148 apply(nullptr);
149 }
150 void define() const
151 {
152 define(nullptr);
153 }
154
155 public:
156#ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
162#endif
163
164 public:
165#ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
166 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
167 INDI::Property* operator->();
168
169 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
170 const INDI::Property* operator->() const;
171
172 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
173 operator INDI::Property *();
174
175 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
176 operator const INDI::Property *() const;
177
178 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
179 operator INDI::PropertyViewNumber *() const
180 {
181 return getNumber();
182 }
183
184 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
185 operator INDI::PropertyViewText *() const
186 {
187 return getText();
188 }
189
190 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
191 operator INDI::PropertyViewSwitch *() const
192 {
193 return getSwitch();
194 }
195
196 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
197 operator INDI::PropertyViewLight *() const
198 {
199 return getLight();
200 }
201
202 INDI_DEPRECATED("Do not use INDI::Property as pointer.")
203 operator INDI::PropertyViewBlob *() const
204 {
205 return getBLOB();
206 }
207
208 INDI_DEPRECATED("Use comparison to true.")
209 bool operator != (std::nullptr_t) const
210 {
211 return isValid();
212 }
213
214 INDI_DEPRECATED("Use comparison to false.")
215 bool operator == (std::nullptr_t) const
216 {
217 return !isValid();
218 }
219
220 operator bool() const
221 {
222 return isValid();
223 }
224 operator bool()
225 {
226 return isValid();
227 }
228#endif
229
230 protected:
231 std::shared_ptr<PropertyPrivate> d_ptr;
232 Property(const std::shared_ptr<PropertyPrivate> &dd);
234 friend class PropertyNumber;
235 friend class PropertyText;
236 friend class PropertySwitch;
237 friend class PropertyLight;
238 friend class PropertyBlob;
239
240 protected:
241 friend class BaseDevicePrivate;
243};
244
245} // namespace INDI
246
247#ifdef QT_CORE_LIB
248#include <QMetaType>
249Q_DECLARE_METATYPE(INDI::Property)
250static int indi_property_metatype_id = QMetaTypeId< INDI::Property >::qt_metatype_id();
251#endif
hid_device * device
Class to provide basic INDI device functionality.
Definition basedevice.h:52
Provides generic container for INDI properties.
bool isDeviceNameMatch(const char *otherDeviceName) const
void onUpdate(const std::function< void()> &callback)
INDI::PropertyViewSwitch * getSwitch() const
const char * getGroupName() const
INDI::PropertyViewBlob * getBLOB() const
INDI::PropertyViewText * getText() const
void void void apply() const
const char * getDeviceName() const
void setTimestamp(const char *timestamp)
bool isValid() const
void setLabel(const char *label)
INDI::Property * self()
void save(FILE *fp) const
void setDynamic(bool d)
bool isEmpty() const
const char * getStateAsString() const
INDI::PropertyViewNumber * getNumber() const
const char * getName() const
INDI::PropertyViewLight * getLight() const
IPerm getPermission() const
void setType(INDI_PROPERTY_TYPE t)
void setGroupName(const char *groupName)
void * getProperty() const
bool hasUpdateCallback() const
bool isDynamic() const
void setTimeout(double timeout)
void setDeviceName(const char *deviceName)
bool isNameMatch(const char *otherName) const
const char * getTypeAsString() const
BaseDevice getBaseDevice() const
std::shared_ptr< PropertyPrivate > d_ptr
const char * getLabel() const
void define() const
IPState getState() const
void setBaseDevice(BaseDevice *idp)
bool getRegistered() const
void setName(const char *name)
INDI_PROPERTY_TYPE getType() const
bool isLabelMatch(const char *otherLabel) const
void setRegistered(bool r)
void setProperty(void *)
const char * getTimestamp() const
bool isTypeMatch(INDI_PROPERTY_TYPE otherType) const
void setState(IPState state)
void setPermission(IPerm permission)
IPerm
Permission hint, with respect to client.
Definition indiapi.h:181
IPState
Property state.
Definition indiapi.h:158
INDI_PROPERTY_TYPE
#define ATTRIBUTE_FORMAT_PRINTF(A, B)
Definition indidevapi.h:140
#define INDI_DEPRECATED(message)
Definition indimacros.h:309
Namespace to encapsulate INDI client, drivers, and mediator classes.
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