Instrument Neutral Distributed Interface INDI  2.0.2
basedevice.h
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 #pragma once
20 
21 #include "indibase.h"
22 #include "indiproperty.h"
23 #include "indiproperties.h"
24 
25 #include <string>
26 #include <vector>
27 #include <cstdint>
28 
29 #include "indipropertytext.h"
30 #include "indipropertynumber.h"
31 #include "indipropertyswitch.h"
32 #include "indipropertylight.h"
33 #include "indipropertyblob.h"
34 
35 // #define MAXRBUF 2048 // #PS: defined in indibase.h
36 
46 namespace INDI
47 {
48 
49 class LilXmlElement;
50 class BaseDevicePrivate;
52 {
53  DECLARE_PRIVATE(BaseDevice)
54  public:
56  // typedef std::vector<INDI::Property*> Properties;
57 
60  {
65  };
66 
68  enum
69  {
72  };
73 
75  enum WATCH
76  {
77  WATCH_NEW = 0,
80  };
81 
84  {
86  TELESCOPE_INTERFACE = (1 << 0),
87  CCD_INTERFACE = (1 << 1),
88  GUIDER_INTERFACE = (1 << 2),
89  FOCUSER_INTERFACE = (1 << 3),
90  FILTER_INTERFACE = (1 << 4),
91  DOME_INTERFACE = (1 << 5),
92  GPS_INTERFACE = (1 << 6),
93  WEATHER_INTERFACE = (1 << 7),
94  AO_INTERFACE = (1 << 8),
95  DUSTCAP_INTERFACE = (1 << 9),
96  LIGHTBOX_INTERFACE = (1 << 10),
97  DETECTOR_INTERFACE = (1 << 11),
98  ROTATOR_INTERFACE = (1 << 12),
99  SPECTROGRAPH_INTERFACE = (1 << 13),
100  CORRELATOR_INTERFACE = (1 << 14),
101  AUX_INTERFACE = (1 << 15),
104  };
105  public:
106  BaseDevice();
107  virtual ~BaseDevice();
108 
109  public: // property
113  void registerProperty(const INDI::Property &property);
114  void registerProperty(const INDI::Property &property,
115  INDI_PROPERTY_TYPE type); // backward compatiblity (PentaxCCD, PkTriggerCordCCD)
116 
122  int removeProperty(const char *name, char *errmsg);
123 
131  void watchProperty(const char *name, const std::function<void (INDI::Property)> &callback, WATCH watch = WATCH_NEW);
132 
139  Property getProperty(const char *name, INDI_PROPERTY_TYPE type = INDI_UNKNOWN) const;
140 
143  const Properties getProperties() const;
144 
145  public:
147  INDI::PropertyNumber getNumber(const char *name) const;
149  INDI::PropertyText getText(const char *name) const;
151  INDI::PropertySwitch getSwitch(const char *name) const;
153  INDI::PropertyLight getLight(const char *name) const;
155  INDI::PropertyBlob getBLOB(const char *name) const;
156 
157  public: // deprecated
159  IPState getPropertyState(const char *name) const;
161  IPerm getPropertyPermission(const char *name) const;
162 
172  void *getRawProperty(const char *name, INDI_PROPERTY_TYPE type = INDI_UNKNOWN) const;
173 
174  public:
178  void addMessage(const std::string &msg);
179  void checkMessage(XMLEle *root);
180  void doMessage(XMLEle *msg);
181 
183  const std::string &messageQueue(size_t index) const;
184 
186  const std::string &lastMessage() const;
187 
188  public:
190  bool isValid() const;
191 
193  bool isConnected() const;
194 
198  void attach();
199 
203  void detach();
204 
206  void setMediator(INDI::BaseMediator *mediator);
207 
210 
214  void setDeviceName(const char *dev);
215 
217  const char *getDeviceName() const;
218 
220  bool isDeviceNameMatch(const char *otherName) const;
221 
223  bool isDeviceNameMatch(const std::string &otherName) const;
224 
228  const char *getDriverName() const;
229 
233  const char *getDriverExec() const;
234 
238  const char *getDriverVersion() const;
239 
248  uint16_t getDriverInterface() const;
249 
250  public:
260  bool buildSkeleton(const char *filename);
261 
268  int buildProp(const INDI::LilXmlElement &root, char *errmsg, bool isDynamic = false);
269 
271  int setValue(const INDI::LilXmlElement &root, char *errmsg);
272 
276  static std::string getSharedFilePath(std::string fileName);
277 
278  public:
279  INDI_DEPRECATED("Do not use BaseDevice as pointer.")
280  operator BaseDevice*();
281 
282  INDI_DEPRECATED("Do not use BaseDevice as pointer.")
283  BaseDevice* operator->();
284 
285  INDI_DEPRECATED("Use comparison to true.")
286  bool operator != (std::nullptr_t) const
287  {
288  return isValid();
289  }
290 
291  INDI_DEPRECATED("Use comparison to false.")
292  bool operator == (std::nullptr_t) const
293  {
294  return !isValid();
295  }
296 
297  operator bool() const
298  {
299  return isValid();
300  }
301  operator bool()
302  {
303  return isValid();
304  }
305 
306  protected:
308  std::shared_ptr<BaseDevicePrivate> d_ptr;
310  BaseDevice(const std::shared_ptr<BaseDevicePrivate> &dd);
311 };
312 
313 }
Class to provide basic INDI device functionality.
Definition: basedevice.h:52
bool isConnected() const
Definition: basedevice.cpp:520
INDI::PropertyNumber getNumber(const char *name) const
Definition: basedevice.cpp:89
void * getRawProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
Definition: basedevice.cpp:132
void checkMessage(XMLEle *root)
Definition: basedevice.cpp:842
void addMessage(const std::string &msg)
Add message to the driver's message queue.
Definition: basedevice.cpp:878
bool buildSkeleton(const char *filename)
Build driver properties from a skeleton file.
Definition: basedevice.cpp:302
const std::string & messageQueue(size_t index) const
Definition: basedevice.cpp:888
void attach()
indicates that the device is ready
Definition: basedevice.cpp:531
void watchProperty(const char *name, const std::function< void(INDI::Property)> &callback, WATCH watch=WATCH_NEW)
Call the callback function if property is available.
Definition: basedevice.cpp:910
static std::string getSharedFilePath(std::string fileName)
Definition: basedevice.cpp:213
const char * getDeviceName() const
Definition: basedevice.cpp:821
void detach()
indicates that the device is being removed
Definition: basedevice.cpp:537
INDI::BaseMediator * getMediator() const
Definition: basedevice.cpp:976
DRIVER_INTERFACE
The DRIVER_INTERFACE enum defines the class of devices the driver implements. A driver may implement ...
Definition: basedevice.h:84
const char * getDriverName() const
Definition: basedevice.cpp:945
Property getProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
Definition: basedevice.cpp:138
INDI::PropertySwitch getSwitch(const char *name) const
Definition: basedevice.cpp:99
virtual ~BaseDevice()
Definition: basedevice.cpp:78
void setMediator(INDI::BaseMediator *mediator)
Set the driver's mediator to receive notification of news devices and updated property values.
Definition: basedevice.cpp:970
int removeProperty(const char *name, char *errmsg)
Remove a property.
Definition: basedevice.cpp:170
void setDeviceName(const char *dev)
Set the device name.
Definition: basedevice.cpp:815
INDI::PropertyBlob getBLOB(const char *name) const
Definition: basedevice.cpp:109
uint16_t getDriverInterface() const
getDriverInterface returns ORed values of DRIVER_INTERFACE. It presents the device classes supported ...
Definition: basedevice.cpp:964
INDI::Properties Properties
Definition: basedevice.h:55
INDI::PropertyLight getLight(const char *name) const
Definition: basedevice.cpp:104
void registerProperty(const INDI::Property &property)
Register the property to be able to observe and update.
Definition: basedevice.cpp:924
bool isValid() const
Definition: basedevice.cpp:904
int setValue(const INDI::LilXmlElement &root, char *errmsg)
handle SetXXX commands from client
Definition: basedevice.cpp:567
const char * getDriverVersion() const
Definition: basedevice.cpp:958
const std::string & lastMessage() const
Definition: basedevice.cpp:896
std::shared_ptr< BaseDevicePrivate > d_ptr
Definition: basedevice.h:308
void doMessage(XMLEle *msg)
Definition: basedevice.cpp:852
const char * getDriverExec() const
Definition: basedevice.cpp:952
INDI::PropertyText getText(const char *name) const
Definition: basedevice.cpp:94
bool isDeviceNameMatch(const char *otherName) const
Check that the device name matches the argument.
Definition: basedevice.cpp:827
IPerm getPropertyPermission(const char *name) const
Definition: basedevice.cpp:123
IPState getPropertyState(const char *name) const
Definition: basedevice.cpp:114
@ INDI_PROPERTY_DUPLICATED
Definition: basedevice.h:63
Properties getProperties()
Return a list of all properties in the device.
Definition: basedevice.cpp:158
int buildProp(const INDI::LilXmlElement &root, char *errmsg, bool isDynamic=false)
Build a property given the supplied XML element (defXXX)
Definition: basedevice.cpp:324
Meditates event notification as generated by driver and passed to clients.
Definition: indibase.h:90
Provides generic container for INDI properties.
Definition: indiproperty.h:48
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
@ INDI_UNKNOWN
Definition: indidriver.c:62
#define INDI_DEPRECATED(message)
Definition: indimacros.h:162
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: json.h:4973
__le16 type
Definition: pwc-ioctl.h:0