Instrument Neutral Distributed Interface INDI 2.2.5
basedevice.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2011-2025 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
46namespace INDI
47{
48
49class LilXmlElement;
50class BaseDevicePrivate;
52{
53 DECLARE_PRIVATE(BaseDevice)
54 public:
56 // typedef std::vector<INDI::Property*> Properties;
57
66
68 enum
69 {
72 };
73
81
110 public:
111 BaseDevice();
112 virtual ~BaseDevice();
113
114 public: // property
118 void registerProperty(const INDI::Property &property);
119 void registerProperty(const INDI::Property &property,
120 INDI_PROPERTY_TYPE type); // backward compatibility (PentaxCCD, PkTriggerCordCCD)
121
127 int removeProperty(const char *name, char *errmsg);
128
136 void watchProperty(const char *name, const std::function<void (INDI::Property)> &callback, WATCH watch = WATCH_NEW);
137
144 Property getProperty(const char *name, INDI_PROPERTY_TYPE type = INDI_UNKNOWN) const;
145
148 const Properties getProperties() const;
149
150 public:
152 INDI::PropertyNumber getNumber(const char *name) const;
154 INDI::PropertyText getText(const char *name) const;
156 INDI::PropertySwitch getSwitch(const char *name) const;
158 INDI::PropertyLight getLight(const char *name) const;
160 INDI::PropertyBlob getBLOB(const char *name) const;
161
162 public: // deprecated
164 IPState getPropertyState(const char *name) const;
166 IPerm getPropertyPermission(const char *name) const;
167
177 void *getRawProperty(const char *name, INDI_PROPERTY_TYPE type = INDI_UNKNOWN) const;
178
179 public:
183 void addMessage(const std::string &msg);
184 void checkMessage(XMLEle *root);
185 void doMessage(XMLEle *msg);
186
188 const std::string &messageQueue(size_t index) const;
189
191 const std::string &lastMessage() const;
192
193 public:
195 bool isValid() const;
196
201 bool isSameDevice(const BaseDevice &other) const;
202
204 bool isConnected() const;
205
209 void attach();
210
214 void detach();
215
217 void setMediator(INDI::BaseMediator *mediator);
218
221
225 void setDeviceName(const char *dev);
226
228 const char *getDeviceName() const;
229
231 bool isDeviceNameMatch(const char *otherName) const;
232
234 bool isDeviceNameMatch(const std::string &otherName) const;
235
239 const char *getDriverName() const;
240
244 const char *getDriverExec() const;
245
249 const char *getDriverVersion() const;
250
259 uint16_t getDriverInterface() const;
260
261 public:
271 bool buildSkeleton(const char *filename);
272
279 int buildProp(const INDI::LilXmlElement &root, char *errmsg, bool isDynamic = false);
280
282 int setValue(const INDI::LilXmlElement &root, char *errmsg);
283
287 static std::string getSharedFilePath(std::string fileName);
288
289 public:
290 INDI_DEPRECATED("Do not use BaseDevice as pointer.")
291 operator BaseDevice*();
292
293 INDI_DEPRECATED("Do not use BaseDevice as pointer.")
294 BaseDevice* operator->();
295
296 INDI_DEPRECATED("Use comparison to true.")
297 bool operator != (std::nullptr_t) const
298 {
299 return isValid();
300 }
301
302 INDI_DEPRECATED("Use comparison to false.")
303 bool operator == (std::nullptr_t) const
304 {
305 return !isValid();
306 }
307
308 operator bool() const
309 {
310 return isValid();
311 }
312 operator bool()
313 {
314 return isValid();
315 }
316
317 protected:
319 std::shared_ptr<BaseDevicePrivate> d_ptr;
321 BaseDevice(const std::shared_ptr<BaseDevicePrivate> &dd);
322};
323
324}
Class to provide basic INDI device functionality.
Definition basedevice.h:52
bool isConnected() const
INDI::PropertyNumber getNumber(const char *name) const
void * getRawProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
void checkMessage(XMLEle *root)
void addMessage(const std::string &msg)
Add message to the driver's message queue.
bool isSameDevice(const BaseDevice &other) const
bool buildSkeleton(const char *filename)
Build driver properties from a skeleton file.
const std::string & messageQueue(size_t index) const
void attach()
indicates that the device is ready
void watchProperty(const char *name, const std::function< void(INDI::Property)> &callback, WATCH watch=WATCH_NEW)
Call the callback function if property is available.
static std::string getSharedFilePath(std::string fileName)
const char * getDeviceName() const
void detach()
indicates that the device is being removed
INDI::BaseMediator * getMediator() const
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
Property getProperty(const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
Return a property and its type given its name.
INDI::PropertySwitch getSwitch(const char *name) const
virtual ~BaseDevice()
void setMediator(INDI::BaseMediator *mediator)
Set the driver's mediator to receive notification of news devices and updated property values.
int removeProperty(const char *name, char *errmsg)
Remove a property.
void setDeviceName(const char *dev)
Set the device name.
INDI::PropertyBlob getBLOB(const char *name) const
uint16_t getDriverInterface() const
getDriverInterface returns ORed values of DRIVER_INTERFACE. It presents the device classes supported ...
INDI::Properties Properties
Definition basedevice.h:55
INDI::PropertyLight getLight(const char *name) const
void registerProperty(const INDI::Property &property)
Register the property to be able to observe and update.
bool isValid() const
int setValue(const INDI::LilXmlElement &root, char *errmsg)
handle SetXXX commands from client
const char * getDriverVersion() const
const std::string & lastMessage() const
std::shared_ptr< BaseDevicePrivate > d_ptr
Definition basedevice.h:319
void doMessage(XMLEle *msg)
const char * getDriverExec() const
INDI::PropertyText getText(const char *name) const
bool isDeviceNameMatch(const char *otherName) const
Check that the device name matches the argument.
IPerm getPropertyPermission(const char *name) const
IPState getPropertyState(const char *name) const
Properties getProperties()
Return a list of all properties in the device.
int buildProp(const INDI::LilXmlElement &root, char *errmsg, bool isDynamic=false)
Build a property given the supplied XML element (defXXX)
Meditates event notification as generated by driver and passed to clients.
Definition indibase.h:98
Provides generic container for INDI properties.
IPerm
Permission hint, with respect to client.
Definition indiapi.h:181
IPState
Property state.
Definition indiapi.h:158
INDI_PROPERTY_TYPE
@ INDI_UNKNOWN
Definition indidriver.c:62
#define INDI_DEPRECATED(message)
Definition indimacros.h:309
Namespace to encapsulate INDI client, drivers, and mediator classes.
uint16_t type
Definition pwc-ioctl.h:0