Instrument Neutral Distributed Interface INDI  1.9.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 #include "indiutility.h"
25 
26 #include <string>
27 #include <vector>
28 #include <cstdint>
29 
30 // #define MAXRBUF 2048 // #PS: defined in indibase.h
31 
41 namespace INDI
42 {
43 
44 class BaseDevicePrivate;
46 {
47  DECLARE_PRIVATE(BaseDevice)
48 public:
50  // typedef std::vector<INDI::Property*> Properties;
51 
54  {
59  };
60 
62  enum
63  {
66  };
67 
70  {
72  TELESCOPE_INTERFACE = (1 << 0),
73  CCD_INTERFACE = (1 << 1),
74  GUIDER_INTERFACE = (1 << 2),
75  FOCUSER_INTERFACE = (1 << 3),
76  FILTER_INTERFACE = (1 << 4),
77  DOME_INTERFACE = (1 << 5),
78  GPS_INTERFACE = (1 << 6),
79  WEATHER_INTERFACE = (1 << 7),
80  AO_INTERFACE = (1 << 8),
81  DUSTCAP_INTERFACE = (1 << 9),
82  LIGHTBOX_INTERFACE = (1 << 10),
83  DETECTOR_INTERFACE = (1 << 11),
84  ROTATOR_INTERFACE = (1 << 12),
85  SPECTROGRAPH_INTERFACE = (1 << 13),
86  CORRELATOR_INTERFACE = (1 << 14),
87  AUX_INTERFACE = (1 << 15),
90  };
91 public:
92  BaseDevice();
93  virtual ~BaseDevice();
94 
95 public:
97  INDI::PropertyView<INumber> *getNumber(const char *name) const;
99  INDI::PropertyView<IText> *getText(const char *name) const;
101  INDI::PropertyView<ISwitch> *getSwitch(const char *name) const;
103  INDI::PropertyView<ILight> *getLight(const char *name) const;
105  INDI::PropertyView<IBLOB> *getBLOB(const char *name) const;
106 
107 public:
109  IPState getPropertyState(const char *name) const;
111  IPerm getPropertyPermission(const char *name) const;
112 
113 public:
115 
116  // #PS: will be deprecated / backward compatibility
117  void registerProperty(ITextVectorProperty *property);
118  void registerProperty(INumberVectorProperty *property);
119  void registerProperty(ISwitchVectorProperty *property);
120  void registerProperty(ILightVectorProperty *property);
121  void registerProperty(IBLOBVectorProperty *property);
122 
128 
129  void registerProperty(INDI::Property &property);
130 
136  int removeProperty(const char *name, char *errmsg);
137 
147  void *getRawProperty(const char *name, INDI_PROPERTY_TYPE type = INDI_UNKNOWN) const;
148 
155  Property getProperty(const char *name, INDI_PROPERTY_TYPE type = INDI_UNKNOWN) const;
156 
159  const Properties getProperties() const;
160 
161 public:
165  void addMessage(const std::string &msg);
166  void checkMessage(XMLEle *root);
167  void doMessage(XMLEle *msg);
168 
170  const std::string &messageQueue(size_t index) const;
171 
173  const std::string &lastMessage() const;
174 
175 public:
177  bool isConnected() const;
178 
180  void setMediator(INDI::BaseMediator *mediator);
181 
184 
188  void setDeviceName(const char *dev);
189 
191  const char *getDeviceName() const;
192 
194  bool isDeviceNameMatch(const char *otherName) const;
195 
197  bool isDeviceNameMatch(const std::string &otherName) const;
198 
202  const char *getDriverName() const;
203 
207  const char *getDriverExec() const;
208 
212  const char *getDriverVersion() const;
213 
222  virtual uint16_t getDriverInterface();
223 
224 public:
234  bool buildSkeleton(const char *filename);
235 
241  int buildProp(XMLEle *root, char *errmsg);
242 
244  int setValue(XMLEle *root, char *errmsg);
245 
247  int setBLOB(IBLOBVectorProperty *pp, XMLEle *root, char *errmsg);
248 
249 protected:
250  std::shared_ptr<BaseDevicePrivate> d_ptr;
252 };
253 
254 }
INDI_UNKNOWN
@ INDI_UNKNOWN
Definition: indidriver.c:62
INDI::BaseDevice::addMessage
void addMessage(const std::string &msg)
Add message to the driver's message queue.
Definition: basedevice.cpp:856
INDI::BaseDevice::getProperties
Properties getProperties()
Return a list of all properties in the device.
Definition: basedevice.cpp:168
INDI::BaseDevice::ROTATOR_INTERFACE
@ ROTATOR_INTERFACE
Definition: basedevice.h:84
indiutility.h
INDI::BaseDevice::getText
INDI::PropertyView< IText > * getText(const char *name) const
Definition: basedevice.cpp:104
INDI::BaseDevice::getDriverInterface
virtual uint16_t getDriverInterface()
getDriverInterface returns ORed values of DRIVER_INTERFACE. It presents the device classes supported ...
Definition: basedevice.cpp:1007
indibase.h
INDI::BaseDevice::getDriverExec
const char * getDriverExec() const
Definition: basedevice.cpp:983
INDI::BaseDevice::SPECTROGRAPH_INTERFACE
@ SPECTROGRAPH_INTERFACE
Definition: basedevice.h:85
IPState
IPState
Property state.
Definition: indiapi.h:158
INDI::BaseDevice::buildProp
int buildProp(XMLEle *root, char *errmsg)
Build a property given the supplied XML element (defXXX)
Definition: basedevice.cpp:299
INDI::BaseDevice::LIGHTBOX_INTERFACE
@ LIGHTBOX_INTERFACE
Definition: basedevice.h:82
INDI::BaseDevice::getDriverName
const char * getDriverName() const
Definition: basedevice.cpp:920
_ILightVectorProperty
Light vector property descriptor.
Definition: indiapi.h:415
INDI::BaseDevice::FILTER_INTERFACE
@ FILTER_INTERFACE
Definition: basedevice.h:76
INDI::BaseDevice::GUIDER_INTERFACE
@ GUIDER_INTERFACE
Definition: basedevice.h:74
INDI::BaseDevicePrivate
Definition: basedevice_p.h:48
INDI::BaseDevice::CORRELATOR_INTERFACE
@ CORRELATOR_INTERFACE
Definition: basedevice.h:86
INDI::BaseDevice::BaseDevice
BaseDevice()
Definition: basedevice.cpp:88
_IBLOBVectorProperty
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:469
INDI::BaseDevice::getBLOB
INDI::PropertyView< IBLOB > * getBLOB(const char *name) const
Definition: basedevice.cpp:119
INDI::BaseDevice::getNumber
INDI::PropertyView< INumber > * getNumber(const char *name) const
Definition: basedevice.cpp:99
INDI::BaseDevice::buildSkeleton
bool buildSkeleton(const char *filename)
Build driver properties from a skeleton file.
Definition: basedevice.cpp:223
INDI::BaseDevice::setBLOB
int setBLOB(IBLOBVectorProperty *pp, XMLEle *root, char *errmsg)
Parse and store BLOB in the respective vector.
Definition: basedevice.cpp:718
INDI::BaseDevice::messageQueue
const std::string & messageQueue(size_t index) const
Definition: basedevice.cpp:867
INDI::BaseDevice::getDeviceName
const char * getDeviceName() const
Definition: basedevice.cpp:799
INDI::Properties
Definition: indiproperties.h:31
INDI_PROPERTY_TYPE
INDI_PROPERTY_TYPE
Definition: indibasetypes.h:22
INDI::BaseDevice::~BaseDevice
virtual ~BaseDevice()
Definition: basedevice.cpp:92
INDI::BaseDevice::setMediator
void setMediator(INDI::BaseMediator *mediator)
Set the driver's mediator to receive notification of news devices and updated property values.
Definition: basedevice.cpp:1019
INDI::BaseDevice::getSwitch
INDI::PropertyView< ISwitch > * getSwitch(const char *name) const
Definition: basedevice.cpp:109
INDI::BaseDevice::GENERAL_INTERFACE
@ GENERAL_INTERFACE
Definition: basedevice.h:71
INDI::BaseDevice::DUSTCAP_INTERFACE
@ DUSTCAP_INTERFACE
Definition: basedevice.h:81
INDI::BaseDevice::doMessage
void doMessage(XMLEle *msg)
Definition: basedevice.cpp:830
INDI::Property
Provides generic container for INDI properties.
Definition: indiproperty.h:43
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
INDI::BaseDevice::getProperty
Property getProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
Definition: basedevice.cpp:148
type
__le16 type
Definition: pwc-ioctl.h:2
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::BaseDevice::setDeviceName
void setDeviceName(const char *dev)
Set the device name.
Definition: basedevice.cpp:793
indiproperties.h
INDI::BaseDevice::FOCUSER_INTERFACE
@ FOCUSER_INTERFACE
Definition: basedevice.h:75
INDI::BaseDevice::DETECTOR_INTERFACE
@ DETECTOR_INTERFACE
Definition: basedevice.h:83
INDI::BaseDevice::DOME_INTERFACE
@ DOME_INTERFACE
Definition: basedevice.h:77
INDI::BaseDevice::GPS_INTERFACE
@ GPS_INTERFACE
Definition: basedevice.h:78
INDI::BaseMediator
Meditates event notification as generated by driver and passed to clients.
Definition: indibase.h:80
xml_ele_
Definition: lilxml.c:105
INDI::BaseDevice::checkMessage
void checkMessage(XMLEle *root)
Definition: basedevice.cpp:820
INDI::BaseDevice::lastMessage
const std::string & lastMessage() const
Definition: basedevice.cpp:875
INDI::BaseDevice::isConnected
bool isConnected() const
Definition: basedevice.cpp:518
IPerm
IPerm
Permission hint, with respect to client.
Definition: indiapi.h:181
INDI::PropertyView< INumber >
INDI::BaseDevice::getMediator
INDI::BaseMediator * getMediator() const
Definition: basedevice.cpp:1025
INDI::BaseDevice::getDriverVersion
const char * getDriverVersion() const
Definition: basedevice.cpp:995
INDI::BaseDevice::INDI_PROPERTY_INVALID
@ INDI_PROPERTY_INVALID
Definition: basedevice.h:56
INDI::BaseDevice::AO_INTERFACE
@ AO_INTERFACE
Definition: basedevice.h:80
INDI::BaseDevice::setValue
int setValue(XMLEle *root, char *errmsg)
handle SetXXX commands from client
Definition: basedevice.cpp:532
INDI::BaseDevice::removeProperty
int removeProperty(const char *name, char *errmsg)
Remove a property.
Definition: basedevice.cpp:180
INDI::BaseDevice::INDI_ENABLED
@ INDI_ENABLED
Definition: basedevice.h:64
INDI::BaseDevice::getRawProperty
void * getRawProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
Definition: basedevice.cpp:142
indiproperty.h
INDI::BaseDevice::DRIVER_INTERFACE
DRIVER_INTERFACE
The DRIVER_INTERFACE enum defines the class of devices the driver implements. A driver may implement ...
Definition: basedevice.h:69
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::BaseDevice::getPropertyPermission
IPerm getPropertyPermission(const char *name) const
Definition: basedevice.cpp:133
INDI::BaseDevice::isDeviceNameMatch
bool isDeviceNameMatch(const char *otherName) const
Check that the device name matches the argument.
Definition: basedevice.cpp:805
INDI::BaseDevice::INDI_DISABLED
@ INDI_DISABLED
Definition: basedevice.h:65
INDI::BaseDevice::d_ptr
std::shared_ptr< BaseDevicePrivate > d_ptr
Definition: basedevice.h:250
INDI::BaseDevice::INDI_ERROR
INDI_ERROR
Definition: basedevice.h:53
INDI::BaseDevice::getPropertyState
IPState getPropertyState(const char *name) const
Definition: basedevice.cpp:124
INDI::BaseDevice::AUX_INTERFACE
@ AUX_INTERFACE
Definition: basedevice.h:87
INDI::BaseDevice::registerProperty
void registerProperty(void *p, INDI_PROPERTY_TYPE type)
Definition: basedevice.cpp:883
INDI::BaseDevice::CCD_INTERFACE
@ CCD_INTERFACE
Definition: basedevice.h:73
INDI::BaseDevice::INDI_DEVICE_NOT_FOUND
@ INDI_DEVICE_NOT_FOUND
Definition: basedevice.h:55
INDI::BaseDevice::Properties
INDI::Properties Properties
Definition: basedevice.h:49
INDI::BaseDevice::INDI_DISPATCH_ERROR
@ INDI_DISPATCH_ERROR
Definition: basedevice.h:58
INDI::BaseDevice
Class to provide basic INDI device functionality.
Definition: basedevice.h:45
INDI::BaseDevice::INDI_PROPERTY_DUPLICATED
@ INDI_PROPERTY_DUPLICATED
Definition: basedevice.h:57
INDI::BaseDevice::getLight
INDI::PropertyView< ILight > * getLight(const char *name) const
Definition: basedevice.cpp:114
INDI::BaseDevice::SENSOR_INTERFACE
@ SENSOR_INTERFACE
Definition: basedevice.h:89
INDI::BaseDevice::WEATHER_INTERFACE
@ WEATHER_INTERFACE
Definition: basedevice.h:79
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
INDI::BaseDevice::TELESCOPE_INTERFACE
@ TELESCOPE_INTERFACE
Definition: basedevice.h:72