33 #define snprintf _snprintf
36 #pragma warning(disable : 4996)
49 io.
write = [](
void *user,
const void * ptr,
size_t count) -> ssize_t
55 io.
vprintf = [](
void *user,
const char * format, va_list ap) ->
int
59 vsnprintf(message,
MAXRBUF, format, ap);
60 return int(self->sendData(message, strlen(message)));
73 if (root.
tagName().find(
"new") == 0)
78 if (root.
tagName() ==
"pingRequest")
84 if (root.
tagName() ==
"pingReply")
90 if (root.
tagName() ==
"message")
95 if (root.
tagName() ==
"delProperty")
101 if (root.
tagName() ==
"getProperties")
110 root.
tagName() !=
"defBLOBVector" &&
111 root.
tagName() !=
"setBLOBVector"
133 snprintf(errmsg,
MAXRBUF,
"Device %s not found", devName);
155 if (!propertyName.isValid())
165 dp.
d_ptr->mediateRemoveProperty(property);
173 snprintf(errmsg,
MAXRBUF,
"Cannot delete property %s as it is not defined yet. Check driver.", propertyName.toCString());
197 if (!message.isValid())
199 strncpy(errmsg,
"No message content found.",
MAXRBUF);
203 if (timestamp.isValid())
205 snprintf(msgBuffer,
MAXRBUF,
"%s: %s", timestamp.toCString(), message.toCString());
214 strftime(ts,
sizeof(ts),
"%Y-%m-%dT%H:%M:%S", tp);
215 snprintf(msgBuffer,
MAXRBUF,
"%s: %s", ts, message.toCString());
236 if (deviceInfo.second.properties.size() == 0)
244 for (
const auto &oneProperty : deviceInfo.second.properties)
262 IDLog(
"BaseClientQt: Error. Unable to find driver %s\n", deviceName);
268 if (!drv_connection.isValid())
275 if (drv_connection[0].getState() ==
ISS_ON)
278 drv_connection.
reset();
280 drv_connection[0].setState(
ISS_ON);
281 drv_connection[1].setState(
ISS_OFF);
288 if (drv_connection[1].getState() ==
ISS_ON)
291 drv_connection.reset();
293 drv_connection[0].setState(
ISS_OFF);
294 drv_connection[1].setState(
ISS_ON);
304 if (blob.device ==
device && (property.empty() || blob.property == property))
314 : d_ptr_indi(
std::move(d))
323 d->cServer = hostname;
330 return d->cServer.c_str();
342 return d->sConnected;
348 d->timeout_sec = seconds;
349 d->timeout_us = microseconds;
367 d->watchDevice.watchDevice(deviceName);
373 d->watchDevice.watchDevice(deviceName, callback);
379 d->watchDevice.watchProperty(deviceName, propertyName);
385 d->setDriverConnection(
true, deviceName);
391 d->setDriverConnection(
false, deviceName);
397 return d->watchDevice.getDeviceByName(deviceName);
403 return d->watchDevice.getDevices();
409 for (
auto &it : d->watchDevice)
411 if (it.second.device.getDriverInterface() & driverInterface)
412 deviceList.push_back(it.second.device);
415 return (deviceList.size() > 0);
425 auto *bMode = d->findBLOBMode(std::string(dev), prop ? std::string(prop) : std::string());
427 if (bMode ==
nullptr)
430 newMode.
device = std::string(dev);
431 newMode.
property = (prop ? std::string(prop) : std::string());
433 d->blobModes.push_back(std::move(newMode));
438 if (bMode->blobMode == blobH)
441 bMode->blobMode = blobH;
452 auto *bMode = d->findBLOBMode(dev, (prop ? std::string(prop) : std::string()));
455 bHandle = bMode->blobMode;
477 IDLog(
"Light type is not supported to send\n");
483 IDLog(
"Unknown type of property to send\n");
591 blobName, blobSize, blobSize, blobBuffer, blobFormat
615 IDLog(
"Ping reply %s\n", uid.c_str());
627 #if defined(_MSC_VER)
int dispatchCommand(const INDI::LilXmlElement &root, char *errmsg)
Dispatch command received from INDI server to respective devices handled by the client.
int messageCmd(const INDI::LilXmlElement &root, char *errmsg)
AbstractBaseClientPrivate(AbstractBaseClient *parent)
void setDriverConnection(bool status, const char *deviceName)
Connect/Disconnect to INDI driver.
std::atomic_bool sConnected
void userIoGetProperties()
int deleteDevice(const char *devName, char *errmsg)
Remove device.
AbstractBaseClient * parent
WatchDeviceProperty watchDevice
int delPropertyCmd(const INDI::LilXmlElement &root, char *errmsg)
Delete property command.
virtual ssize_t sendData(const void *data, size_t size)=0
BLOBMode * findBLOBMode(const std::string &device, const std::string &property)
std::list< BLOBMode > blobModes
int getPort() const
Get the port number.
void setServer(const char *hostname, unsigned int port)
Set the server host name and port.
bool isVerbose() const
isVerbose Is client in verbose mode?
INDI::BaseDevice getDevice(const char *deviceName)
virtual void newUniversalMessage(std::string message)
newUniversalMessage Universal messages are sent from INDI server without a specific device....
void sendNewSwitch(INDI::Property pp)
Send new Switch command to server.
void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop=nullptr)
Set Binary Large Object policy mode.
void watchProperty(const char *deviceName, const char *propertyName)
watchProperties Add a property to the watch list. When communicating with INDI server.
void sendNewProperty(INDI::Property pp)
Send new Property command to server.
AbstractBaseClient()=delete
void setConnectionTimeout(uint32_t seconds, uint32_t microseconds)
setConnectionTimeout Set connection timeout. By default it is 3 seconds.
void finishBlob()
Send closing tag for BLOB command to server.
void disconnectDevice(const char *deviceName)
Disconnect INDI driver.
void setVerbose(bool enable)
setVerbose Set verbose mode
virtual ~AbstractBaseClient()
void sendPingReply(const char *uid)
Send a ping reply for the given uuid.
void sendOneBlob(IBLOB *bp)
Send ONE blob content to server. The BLOB data in raw binary format and will be converted to base64 a...
virtual void newPingReply(std::string uid)
pingReply are sent by the server on response to pingReply (see above).
bool isServerConnected() const
Get status of the connection.
void sendPingRequest(const char *uid)
Send one ping request, the server will answer back with the same uuid.
void connectDevice(const char *deviceName)
Disconnect INDI driver.
void watchDevice(const char *deviceName)
Add a device to the watch list.
const char * getHost() const
Get the server host name.
std::vector< INDI::BaseDevice > getDevices() const
void sendNewNumber(INDI::Property pp)
Send new Number command to server.
BLOBHandling getBLOBMode(const char *dev, const char *prop=nullptr)
getBLOBMode Get Binary Large Object policy mode IF set previously by setBLOBMode
void sendNewText(INDI::Property pp)
Send new Text command to server.
void startBlob(const char *devName, const char *propName, const char *timestamp)
Send opening tag for BLOB command to server.
Class to provide basic INDI device functionality.
INDI::PropertyNumber getNumber(const char *name) const
void checkMessage(XMLEle *root)
const char * getDeviceName() 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
int removeProperty(const char *name, char *errmsg)
Remove a property.
std::shared_ptr< BaseDevicePrivate > d_ptr
INDI::PropertyText getText(const char *name) const
std::string tagName() const
LilXmlAttribute getAttribute(const char *name) const
std::string toString() const
The class is used to create device instances. Class copying is not allowed. When an object is destroy...
WidgetView< T > * findWidgetByName(const char *name) const
Provides generic container for INDI properties.
INDI::PropertyViewSwitch * getSwitch() const
INDI::PropertyViewBlob * getBLOB() const
INDI::PropertyViewText * getText() const
INDI::PropertyViewNumber * getNumber() const
INDI_PROPERTY_TYPE getType() const
void setState(IPState state)
BaseDevice getDeviceByName(const char *name)
int processXml(const INDI::LilXmlElement &root, char *errmsg, const std::function< ParentDevice()> &constructor=[] { return ParentDevice(ParentDevice::Valid);})
bool deleteDevice(const BaseDevice &device)
@ INDI_PROPERTY_DUPLICATED
void IDLog(const char *fmt,...)
BLOBHandling
How drivers handle BLOBs incoming from snooping drivers.
void IUUserIOBLOBContextOne(const userio *io, void *user, const char *name, unsigned int size, unsigned int bloblen, const void *blob, const char *format)
void IUUserIONewBLOBFinish(const userio *io, void *user)
void IUUserIONewBLOB(const userio *io, void *user, const IBLOBVectorProperty *bvp)
void IUUserIONewBLOBStart(const userio *io, void *user, const char *dev, const char *name, const char *timestamp)
void IUUserIONewText(const userio *io, void *user, const ITextVectorProperty *tvp)
void IUUserIOEnableBLOB(const userio *io, void *user, const char *dev, const char *name, BLOBHandling blobH)
void IUUserIOPingRequest(const userio *io, void *user, const char *pingUid)
void IUUserIONewSwitch(const userio *io, void *user, const ISwitchVectorProperty *svp)
void IUUserIONewNumber(const userio *io, void *user, const INumberVectorProperty *nvp)
void IUUserIOGetProperties(const userio *io, void *user, const char *dev, const char *name)
void IUUserIOPingReply(const userio *io, void *user, const char *pingUid)
const char * CONNECTION
Connect to and disconnect from device.
Namespace to encapsulate INDI client, drivers, and mediator classes.
One Blob (Binary Large Object) descriptor.
static PropertyView< T > * cast(PropertyType *raw)
void setText(const char *text, size_t size)
int(* vprintf)(void *user, const char *format, va_list arg)
ssize_t(* write)(void *user, const void *ptr, size_t count)
const struct userio * userio_file()