Instrument Neutral Distributed Interface INDI  2.0.2
abstractbaseclient.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2016 Jasem Mutlaq. All rights reserved.
3  Copyright(c) 2022 Pawel Soja <kernel32.pl@gmail.com>
4 
5  INDI Qt Client
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License version 2 as published by the Free Software Foundation.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 *******************************************************************************/
21 
22 #pragma once
23 
24 #include "indibase.h"
25 #include "indimacros.h"
26 #include "indiproperty.h"
27 
28 #include <memory>
29 #include <vector>
30 #include <functional>
31 
32 namespace INDI
33 {
34 
35 class BaseDevice;
36 class AbstractBaseClientPrivate;
38 {
39  DECLARE_PRIVATE_D(d_ptr_indi, AbstractBaseClient)
40 
41  public:
42  AbstractBaseClient() = delete;
43  virtual ~AbstractBaseClient();
44 
45  public:
50  void setServer(const char *hostname, unsigned int port);
51 
53  const char *getHost() const;
54 
56  int getPort() const;
57 
58  public:
63  virtual bool connectServer() = 0;
64 
69  virtual bool disconnectServer(int exit_code = 0) = 0;
70 
72  bool isServerConnected() const;
73 
78  void setConnectionTimeout(uint32_t seconds, uint32_t microseconds);
79 
80  public:
85  void setVerbose(bool enable);
86 
90  bool isVerbose() const;
91 
92  public:
100  void watchDevice(const char *deviceName);
101  void watchDevice(const char *deviceName, const std::function<void (BaseDevice)> &callback);
102 
111  void watchProperty(const char *deviceName, const char *propertyName);
112 
113  public:
117  void connectDevice(const char *deviceName);
118 
122  void disconnectDevice(const char *deviceName);
123 
124  public:
128  INDI::BaseDevice getDevice(const char *deviceName);
129 
131  std::vector<INDI::BaseDevice> getDevices() const;
132 
146  bool getDevices(std::vector<INDI::BaseDevice> &deviceList, uint16_t driverInterface);
147 
148  public:
164  void setBLOBMode(BLOBHandling blobH, const char *dev, const char *prop = nullptr);
165 
171  BLOBHandling getBLOBMode(const char *dev, const char *prop = nullptr);
172 
173  public:
176 
178  void sendNewText(INDI::Property pp);
180  void sendNewText(const char *deviceName, const char *propertyName, const char *elementName, const char *text);
182  void sendNewNumber(INDI::Property pp);
184  void sendNewNumber(const char *deviceName, const char *propertyName, const char *elementName, double value);
186  void sendNewSwitch(INDI::Property pp);
188  void sendNewSwitch(const char *deviceName, const char *propertyName, const char *elementName);
189 
191  void startBlob(const char *devName, const char *propName, const char *timestamp);
193  void sendOneBlob(IBLOB *bp);
194  void sendOneBlob(INDI::WidgetViewBlob *blob);
196  void sendOneBlob(const char *blobName, unsigned int blobSize, const char *blobFormat, void *blobBuffer);
198  void finishBlob();
199 
200  public:
205  void sendPingRequest(const char * uid);
206 
210  void sendPingReply(const char * uid);
211 
212  protected:
215  virtual void newPingReply(std::string uid);
216 
217  protected:
223  virtual void newUniversalMessage(std::string message);
224 
225  protected:
226  friend class BaseClientPrivate;
227  friend class BaseClientQtPrivate;
228 
229  protected:
230  AbstractBaseClient(std::unique_ptr<AbstractBaseClientPrivate> &&dd);
231 
232  protected:
233  std::unique_ptr<AbstractBaseClientPrivate> d_ptr_indi;
234 };
235 
236 }
237 
238 #ifdef SWIG
239 %template(BaseDeviceVectorShared) std::vector<INDI::BaseDevice>;
240 #endif
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.
bool getDevices(std::vector< INDI::BaseDevice > &deviceList, uint16_t driverInterface)
getDevices Returns list of devices that belong to a particular DRIVER_INTERFACE class.
void sendNewProperty(INDI::Property pp)
Send new Property command to server.
virtual bool connectServer()=0
Connect to INDI server.
virtual bool disconnectServer(int exit_code=0)=0
Disconnect from INDI server. Any devices previously created will be deleted and memory cleared.
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.
std::unique_ptr< AbstractBaseClientPrivate > d_ptr_indi
void setVerbose(bool enable)
setVerbose Set verbose mode
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.
Definition: basedevice.h:52
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
BLOBHandling
How drivers handle BLOBs incoming from snooping drivers.
Definition: indidevapi.h:266
Namespace to encapsulate INDI client, drivers, and mediator classes.
One Blob (Binary Large Object) descriptor.