Instrument Neutral Distributed Interface INDI  2.0.2
indiproperty.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2011 Jasem Mutlaq. All rights reserved.
3  2022 Pawel Soja <kernel32.pl@gmail.com>
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
32 namespace INDI
33 {
34 class BaseDevice;
35 class PropertyNumber;
36 class PropertyText;
37 class PropertySwitch;
38 class PropertyLight;
39 class PropertyBlob;
46 class PropertyPrivate;
47 class Property
48 {
49  DECLARE_PRIVATE(Property)
50  public:
51  Property();
52  ~Property();
53 
54  public:
56  Property(INDI::PropertyText property);
58  Property(INDI::PropertyLight property);
59  Property(INDI::PropertyBlob property);
60 
61 #ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
62  public:
64  Property(ITextVectorProperty *property);
66  Property(ILightVectorProperty *property);
67  Property(IBLOBVectorProperty *property);
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;
94  BaseDevice getBaseDevice() 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  void save(FILE *fp) const;
140 
141  public:
142  void apply(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
143  void define(const char *format, ...) const ATTRIBUTE_FORMAT_PRINTF(2, 3);
144 
145  void apply() const
146  {
147  apply(nullptr);
148  }
149  void define() const
150  {
151  define(nullptr);
152  }
153 
154  public:
155 #ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
161 #endif
162 
163  public:
164 #ifdef INDI_PROPERTY_BACKWARD_COMPATIBILE
165  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
166  INDI::Property* operator->();
167 
168  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
169  const INDI::Property* operator->() const;
170 
171  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
172  operator INDI::Property *();
173 
174  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
175  operator const INDI::Property *() const;
176 
177  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
178  operator INDI::PropertyViewNumber *() const { return getNumber(); }
179 
180  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
181  operator INDI::PropertyViewText *() const { return getText(); }
182 
183  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
184  operator INDI::PropertyViewSwitch *() const { return getSwitch(); }
185 
186  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
187  operator INDI::PropertyViewLight *() const { return getLight(); }
188 
189  INDI_DEPRECATED("Do not use INDI::Property as pointer.")
190  operator INDI::PropertyViewBlob *() const { return getBLOB(); }
191 
192  INDI_DEPRECATED("Use comparison to true.")
193  bool operator != (std::nullptr_t) const { return isValid(); }
194 
195  INDI_DEPRECATED("Use comparison to false.")
196  bool operator == (std::nullptr_t) const { return !isValid(); }
197 
198  operator bool() const { return isValid(); }
199  operator bool() { return isValid(); }
200 #endif
201 
202  protected:
203  std::shared_ptr<PropertyPrivate> d_ptr;
204  Property(const std::shared_ptr<PropertyPrivate> &dd);
206  friend class PropertyNumber;
207  friend class PropertyText;
208  friend class PropertySwitch;
209  friend class PropertyLight;
210  friend class PropertyBlob;
211 
212  protected:
213  friend class BaseDevicePrivate;
214  INDI::Property *self();
215 };
216 
217 } // namespace INDI
218 
219 #ifdef QT_CORE_LIB
220 #include <QMetaType>
221 Q_DECLARE_METATYPE(INDI::Property)
222 static int indi_property_metatype_id = QMetaTypeId< INDI::Property >::qt_metatype_id();
223 #endif
hid_device * device
Class to provide basic INDI device functionality.
Definition: basedevice.h:52
Provides generic container for INDI properties.
Definition: indiproperty.h:48
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
Definition: indiproperty.h:145
const char * getDeviceName() const
void setTimestamp(const char *timestamp)
bool isValid() const
void setLabel(const char *label)
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
Definition: indiproperty.h:203
const char * getLabel() const
void define() const
Definition: indiproperty.h:149
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:183
IPState
Property state.
Definition: indiapi.h:160
INDI_PROPERTY_TYPE
Definition: indibasetypes.h:23
#define ATTRIBUTE_FORMAT_PRINTF(A, B)
Definition: indidevapi.h:139
#define INDI_DEPRECATED(message)
Definition: indimacros.h:162
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: json.h:4973
Provides decorator for Low-Level IXXXVectorProperty/IXXX.
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