Instrument Neutral Distributed Interface INDI  1.9.2
baseclientqt.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2016 Jasem Mutlaq. All rights reserved.
3 
4  INDI Qt Client
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 
21 #pragma once
22 
23 #include "indiapi.h"
24 #include "indidevapi.h"
25 #include "indibase.h"
26 
27 #include <QTcpSocket>
28 
29 #include <vector>
30 #include <string>
31 #include <map>
32 #include <set>
33 
34 #if defined(_MSC_VER)
35 #include <BaseTsd.h>
36 typedef SSIZE_T ssize_t;
37 #endif
38 
39 // #define MAXRBUF 2048 // #PS: defined in indibase.h
40 
57 class INDI::BaseClientQt : public QObject, public INDI::BaseMediator
58 {
59  Q_OBJECT
60 
61  public:
62  BaseClientQt(QObject *parent = Q_NULLPTR);
63  virtual ~BaseClientQt();
64 
69  void setServer(const char *hostname, unsigned int port);
70 
78  void watchDevice(const char *deviceName);
79 
88  void watchProperty(const char *deviceName, const char *propertyName);
89 
95  bool connectServer();
96 
102  bool disconnectServer();
103 
104  bool isServerConnected() const;
105 
109  void connectDevice(const char *deviceName);
110 
114  void disconnectDevice(const char *deviceName);
115 
119  INDI::BaseDevice *getDevice(const char *deviceName);
120 
123  const std::vector<INDI::BaseDevice *> &getDevices() const
124  {
125  return cDevices;
126  }
127 
143  bool getDevices(std::vector<INDI::BaseDevice *> &deviceList, uint16_t driverInterface);
144 
161  void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop = nullptr);
162 
169  BLOBHandling getBLOBMode(const char *dev, const char *prop = nullptr);
170 
171  // Update
172  static void *listenHelper(void *context);
173 
174  const char *getHost()
175  {
176  return cServer.c_str();
177  }
178  int getPort()
179  {
180  return cPort;
181  }
182 
186  void sendNewText(const char *deviceName, const char *propertyName, const char *elementName, const char *text);
190  void sendNewNumber(const char *deviceName, const char *propertyName, const char *elementName, double value);
194  void sendNewSwitch(const char *deviceName, const char *propertyName, const char *elementName);
195 
197  void startBlob(const char *devName, const char *propName, const char *timestamp);
199  void sendOneBlob(IBLOB *bp);
201  void sendOneBlob(const char *blobName, unsigned int blobSize, const char *blobFormat, void *blobBuffer);
203  void finishBlob();
204 
210  void setVerbose(bool enable)
211  {
212  verbose = enable;
213  }
214 
219  bool isVerbose() const
220  {
221  return verbose;
222  }
223 
229  void setConnectionTimeout(uint32_t seconds, uint32_t microseconds)
230  {
231  timeout_sec = seconds;
232  timeout_us = microseconds;
233  }
234 
235  protected:
237  int dispatchCommand(XMLEle *root, char *errmsg);
238 
240  int deleteDevice(const char *devName, char *errmsg);
241 
243  int delPropertyCmd(XMLEle *root, char *errmsg);
244 
246  INDI::BaseDevice *findDev(const char *devName, char *errmsg);
248  INDI::BaseDevice *addDevice(XMLEle *dep, char *errmsg);
250  INDI::BaseDevice *findDev(XMLEle *root, int create, char *errmsg);
251 
253  int messageCmd(XMLEle *root, char *errmsg);
254 
260  virtual void newUniversalMessage(std::string message);
261 
262  private:
263  typedef struct
264  {
265  std::string device;
266  std::string property;
267  BLOBHandling blobMode;
268  } BLOBMode;
269 
270  BLOBMode *findBLOBMode(const std::string &device, const std::string &property);
271 
277  void setDriverConnection(bool status, const char *deviceName);
278 
282  void clear();
283 
284  QTcpSocket client_socket;
285 
286  std::vector<INDI::BaseDevice *> cDevices;
287  std::vector<std::string> cDeviceNames;
288  std::vector<BLOBMode *> blobModes;
289  std::map<std::string, std::set<std::string>> cWatchProperties;
290 
291  std::string cServer;
292  uint32_t cPort;
293  bool sConnected;
294  bool verbose;
295 
296  // Parse & FILE buffers for IO
297 
298  LilXML *lillp; /* XML parser context */
299  uint32_t timeout_sec, timeout_us;
300 
301  private slots:
302 
303  void listenINDI();
304  void processSocketError(QAbstractSocket::SocketError socketError);
305 };
indibase.h
INDI::BaseClientQt::connectServer
bool connectServer()
Connect to INDI server.
Definition: baseclientqt.cpp:119
INDI::BaseClientQt::disconnectDevice
void disconnectDevice(const char *deviceName)
Disconnect INDI driver.
Definition: baseclientqt.cpp:187
INDI::BaseClientQt::~BaseClientQt
virtual ~BaseClientQt()
Definition: baseclientqt.cpp:76
INDI::BaseClientQt::getPort
int getPort()
Definition: baseclientqt.h:178
INDI::BaseClientQt::findDev
INDI::BaseDevice * findDev(const char *devName, char *errmsg)
Find and return a particular device.
Definition: baseclientqt.cpp:426
INDI::BaseClientQt::getDevice
INDI::BaseDevice * getDevice(const char *deviceName)
Definition: baseclientqt.cpp:237
indiapi.h
Constants and Data structure definitions for the interface to the reference INDI C API implementation...
INDI::BaseClientQt::isServerConnected
bool isServerConnected() const
Definition: baseclientqt.cpp:714
INDI::BaseClientQt::watchDevice
void watchDevice(const char *deviceName)
Add a device to the watch list.
Definition: baseclientqt.cpp:103
timestamp
const char * timestamp()
Create an ISO 8601 formatted time stamp. The format is YYYY-MM-DDTHH:MM:SS.
Definition: indicom.c:334
INDI::BaseClientQt::getBLOBMode
BLOBHandling getBLOBMode(const char *dev, const char *prop=nullptr)
getBLOBMode Get Binary Large Object policy mode IF set previously by setBLOBMode
Definition: baseclientqt.cpp:665
INDI::BaseClientQt::watchProperty
void watchProperty(const char *deviceName, const char *propertyName)
watchProperties Add a property to the watch list. When communicating with INDI server....
Definition: baseclientqt.cpp:113
INDI::BaseClientQt::messageCmd
int messageCmd(XMLEle *root, char *errmsg)
Definition: baseclientqt.cpp:507
INDI::BaseClientQt
Class to provide basic client functionality based on Qt5 toolkit and is therefore suitable for cross-...
Definition: baseclientqt.h:57
INDI::BaseClientQt::getDevices
const std::vector< INDI::BaseDevice * > & getDevices() const
Definition: baseclientqt.h:123
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
INDI::BaseClientQt::setConnectionTimeout
void setConnectionTimeout(uint32_t seconds, uint32_t microseconds)
setConnectionTimeout Set connection timeout. By default it is 3 seconds.
Definition: baseclientqt.h:229
device
hid_device * device
Definition: activefocuser_utils.cpp:92
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::BaseClientQt::BaseClientQt
BaseClientQt(QObject *parent=Q_NULLPTR)
Definition: baseclientqt.cpp:48
INDI::BaseClientQt::sendNewText
void sendNewText(ITextVectorProperty *pp)
Send new Text command to server.
Definition: baseclientqt.cpp:522
indidevapi.h
Interface to the reference INDI C API device implementation on the Device Driver side.
INDI::BaseClientQt::addDevice
INDI::BaseDevice * addDevice(XMLEle *dep, char *errmsg)
Add a new device.
Definition: baseclientqt.cpp:441
INDI::BaseMediator
Meditates event notification as generated by driver and passed to clients.
Definition: indibase.h:80
xml_ele_
Definition: lilxml.c:105
BLOBHandling
BLOBHandling
How drivers handle BLOBs incoming from snooping drivers.
Definition: indidevapi.h:268
INDI::BaseClientQt::finishBlob
void finishBlob()
Send closing tag for BLOB command to server.
Definition: baseclientqt.cpp:634
INDI::BaseClientQt::delPropertyCmd
int delPropertyCmd(XMLEle *root, char *errmsg)
Delete property command.
Definition: baseclientqt.cpp:371
INDI::BaseClientQt::sendNewSwitch
void sendNewSwitch(ISwitchVectorProperty *pp)
Send new Switch command to server.
Definition: baseclientqt.cpp:584
INDI::BaseClientQt::newUniversalMessage
virtual void newUniversalMessage(std::string message)
newUniversalMessage Universal messages are sent from INDI server without a specific device....
Definition: baseclientqt.cpp:517
INDI::BaseClientQt::sendOneBlob
void sendOneBlob(IBLOB *bp)
Send ONE blob content to server. The BLOB data in raw binary format and will be converted to base64 a...
Definition: baseclientqt.cpp:617
INDI::BaseClientQt::setServer
void setServer(const char *hostname, unsigned int port)
Set the server host name and port.
Definition: baseclientqt.cpp:97
INDI::BaseClientQt::getHost
const char * getHost()
Definition: baseclientqt.h:174
INDI::BaseClientQt::connectDevice
void connectDevice(const char *deviceName)
Connect to INDI driver.
Definition: baseclientqt.cpp:182
INDI::BaseClientQt::disconnectServer
bool disconnectServer()
Disconnect from INDI server.
Definition: baseclientqt.cpp:159
INDI::BaseClientQt::sendNewNumber
void sendNewNumber(INumberVectorProperty *pp)
Send new Number command to server.
Definition: baseclientqt.cpp:553
LilXML_
Definition: lilxml.c:91
INDI::BaseClientQt::deleteDevice
int deleteDevice(const char *devName, char *errmsg)
Remove device.
Definition: baseclientqt.cpp:405
INDI::BaseClientQt::dispatchCommand
int dispatchCommand(XMLEle *root, char *errmsg)
Dispatch command received from INDI server to respective devices handled by the client.
Definition: baseclientqt.cpp:306
INDI::BaseClientQt::startBlob
void startBlob(const char *devName, const char *propName, const char *timestamp)
Send opening tag for BLOB command to server.
Definition: baseclientqt.cpp:612
INDI::BaseClientQt::isVerbose
bool isVerbose() const
isVerbose Is client in verbose mode?
Definition: baseclientqt.h:219
INDI::BaseDevice
Class to provide basic INDI device functionality.
Definition: basedevice.h:45
INDI::BaseClientQt::setBLOBMode
void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop=nullptr)
Set Binary Large Object policy mode.
Definition: baseclientqt.cpp:639
IBLOB
One Blob (Binary Large Object) descriptor.
INDI::BaseClientQt::setVerbose
void setVerbose(bool enable)
setVerbose Set verbose mode
Definition: baseclientqt.h:210
INDI::BaseClientQt::listenHelper
static void * listenHelper(void *context)
Definition: baseclientqt.cpp:247
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365