TwiceAsNice  2019-02-18
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
INDI::BaseClientQt Class Reference

Class to provide basic client functionality based on Qt5 toolkit and is therefore suitable for cross-platform development. More...

#include <baseclientqt.h>

Inheritance diagram for INDI::BaseClientQt:
Inheritance graph
Collaboration diagram for INDI::BaseClientQt:
Collaboration graph

Classes

struct  BLOBMode
 

Public Member Functions

 BaseClientQt (QObject *parent=Q_NULLPTR)
 
virtual ~BaseClientQt ()
 
void setServer (const char *hostname, unsigned int port)
 Set the server host name and port. More...
 
void watchDevice (const char *deviceName)
 Add a device to the watch list. More...
 
bool connectServer ()
 Connect to INDI server. More...
 
bool disconnectServer ()
 Disconnect from INDI server. More...
 
bool isServerConnected () const
 
void connectDevice (const char *deviceName)
 Connect to INDI driver. More...
 
void disconnectDevice (const char *deviceName)
 Disconnect INDI driver. More...
 
INDI::BaseDevicegetDevice (const char *deviceName)
 
const std::vector< INDI::BaseDevice * > & getDevices () const
 
bool getDevices (std::vector< INDI::BaseDevice *> &deviceList, uint16_t driverInterface)
 
getDevices Returns list of devices that belong to a particular DRIVER_INTERFACE class. More...
 
void setBLOBMode (BLOBHandling blobH, const char *dev, const char *prop=NULL)
 Set Binary Large Object policy mode. More...
 
BLOBHandling getBLOBMode (const char *dev, const char *prop=NULL)
 getBLOBMode Get Binary Large Object policy mode IF set previously by setBLOBMode More...
 
const char * getHost ()
 
int getPort ()
 
void sendNewText (ITextVectorProperty *pp)
 Send new Text command to server. More...
 
void sendNewText (const char *deviceName, const char *propertyName, const char *elementName, const char *text)
 Send new Text command to server. More...
 
void sendNewNumber (INumberVectorProperty *pp)
 Send new Number command to server. More...
 
void sendNewNumber (const char *deviceName, const char *propertyName, const char *elementName, double value)
 Send new Number command to server. More...
 
void sendNewSwitch (ISwitchVectorProperty *pp)
 Send new Switch command to server. More...
 
void sendNewSwitch (const char *deviceName, const char *propertyName, const char *elementName)
 Send new Switch command to server. More...
 
void startBlob (const char *devName, const char *propName, const char *timestamp)
 Send opening tag for BLOB command to server. More...
 
void sendOneBlob (IBLOB *bp)
 Send ONE blob content to server. More...
 
void sendOneBlob (const char *blobName, unsigned int blobSize, const char *blobFormat, void *blobBuffer)
 Send ONE blob content to server. More...
 
void finishBlob ()
 Send closing tag for BLOB command to server. More...
 
void setVerbose (bool enable)
 setVerbose Set verbose mode More...
 
bool isVerbose () const
 isVerbose Is client in verbose mode? More...
 
void setConnectionTimeout (uint32_t seconds, uint32_t microseconds)
 setConnectionTimeout Set connection timeout. More...
 
- Public Member Functions inherited from INDI::BaseMediator
virtual void newDevice (INDI::BaseDevice *dp)=0
 Emmited when a new device is created from INDI server. More...
 
virtual void removeDevice (INDI::BaseDevice *dp)=0
 Emmited when a device is deleted from INDI server. More...
 
virtual void newProperty (INDI::Property *property)=0
 Emmited when a new property is created for an INDI driver. More...
 
virtual void removeProperty (INDI::Property *property)=0
 Emmited when a property is deleted for an INDI driver. More...
 
virtual void newBLOB (IBLOB *bp)=0
 Emmited when a new BLOB value arrives from INDI server. More...
 
virtual void newSwitch (ISwitchVectorProperty *svp)=0
 Emmited when a new switch value arrives from INDI server. More...
 
virtual void newNumber (INumberVectorProperty *nvp)=0
 Emmited when a new number value arrives from INDI server. More...
 
virtual void newText (ITextVectorProperty *tvp)=0
 Emmited when a new text value arrives from INDI server. More...
 
virtual void newLight (ILightVectorProperty *lvp)=0
 Emmited when a new light value arrives from INDI server. More...
 
virtual void newMessage (INDI::BaseDevice *dp, int messageID)=0
 Emmited when a new message arrives from INDI server. More...
 
virtual void serverConnected ()=0
 Emmited when the server is connected. More...
 
virtual void serverDisconnected (int exit_code)=0
 Emmited when the server gets disconnected. More...
 
virtual ~BaseMediator ()
 
virtual void newDevice (INDI::BaseDevice *dp)=0
 Emmited when a new device is created from INDI server. More...
 
virtual void removeDevice (INDI::BaseDevice *dp)=0
 Emmited when a device is deleted from INDI server. More...
 
virtual void newProperty (INDI::Property *property)=0
 Emmited when a new property is created for an INDI driver. More...
 
virtual void removeProperty (INDI::Property *property)=0
 Emmited when a property is deleted for an INDI driver. More...
 
virtual void newBLOB (IBLOB *bp)=0
 Emmited when a new BLOB value arrives from INDI server. More...
 
virtual void newSwitch (ISwitchVectorProperty *svp)=0
 Emmited when a new switch value arrives from INDI server. More...
 
virtual void newNumber (INumberVectorProperty *nvp)=0
 Emmited when a new number value arrives from INDI server. More...
 
virtual void newText (ITextVectorProperty *tvp)=0
 Emmited when a new text value arrives from INDI server. More...
 
virtual void newLight (ILightVectorProperty *lvp)=0
 Emmited when a new light value arrives from INDI server. More...
 
virtual void newMessage (INDI::BaseDevice *dp, int messageID)=0
 Emmited when a new message arrives from INDI server. More...
 
virtual void serverConnected ()=0
 Emmited when the server is connected. More...
 
virtual void serverDisconnected (int exit_code)=0
 Emmited when the server gets disconnected. More...
 
virtual ~BaseMediator ()
 

Static Public Member Functions

static void * listenHelper (void *context)
 

Protected Member Functions

int dispatchCommand (XMLEle *root, char *errmsg)
 Dispatch command received from INDI server to respective devices handled by the client. More...
 
int deleteDevice (const char *devName, char *errmsg)
 Remove device. More...
 
int delPropertyCmd (XMLEle *root, char *errmsg)
 Delete property command. More...
 
INDI::BaseDevicefindDev (const char *devName, char *errmsg)
 Find and return a particular device. More...
 
INDI::BaseDeviceaddDevice (XMLEle *dep, char *errmsg)
 Add a new device. More...
 
INDI::BaseDevicefindDev (XMLEle *root, int create, char *errmsg)
 Find a device, and if it doesn't exist, create it if create is set to 1. More...
 
int messageCmd (XMLEle *root, char *errmsg)
 Process messages. More...
 

Private Slots

void listenINDI ()
 
void processSocketError (QAbstractSocket::SocketError socketError)
 

Private Member Functions

BLOBModefindBLOBMode (const std::string &device, const std::string &property)
 
void setDriverConnection (bool status, const char *deviceName)
 Connect/Disconnect to INDI driver. More...
 
void clear ()
 clear Clear devices and blob modes More...
 

Private Attributes

QTcpSocket client_socket
 
std::vector< INDI::BaseDevice * > cDevices
 
std::vector< std::string > cDeviceNames
 
std::vector< BLOBMode * > blobModes
 
std::string cServer
 
unsigned int cPort
 
bool sConnected
 
bool verbose
 
LilXMLlillp
 
uint32_t timeout_sec
 
uint32_t timeout_us
 

Detailed Description

Class to provide basic client functionality based on Qt5 toolkit and is therefore suitable for cross-platform development.

BaseClientQt enables accelerated development of INDI Clients by providing a framework that facilitates communication, device handling, and event notification. By subclassing BaseClientQt, clients can quickly connect to an INDI server, and query for a set of INDI::BaseDevice devices, and read and write properties seamlessly. Event driven programming is possible due to notifications upon reception of new devices or properties.

Attention
All notifications functions defined in INDI::BaseMediator must be implemented in the client class even if they are not used because these are pure virtual functions.
See also
INDI Client Tutorial for more details.
Author
Jasem Mutlaq

Constructor & Destructor Documentation

◆ BaseClientQt()

INDI::BaseClientQt::BaseClientQt ( QObject *  parent = Q_NULLPTR)

◆ ~BaseClientQt()

INDI::BaseClientQt::~BaseClientQt ( )
virtual

Member Function Documentation

◆ addDevice()

INDI::BaseDevice * INDI::BaseClientQt::addDevice ( XMLEle dep,
char *  errmsg 
)
protected

Add a new device.

◆ clear()

void INDI::BaseClientQt::clear ( void  )
private

clear Clear devices and blob modes

◆ connectDevice()

void INDI::BaseClientQt::connectDevice ( const char *  deviceName)

Connect to INDI driver.

Parameters
deviceNameName of the device to connect to.

◆ connectServer()

bool INDI::BaseClientQt::connectServer ( )

Connect to INDI server.

Returns
True if the connection is successful, false otherwise.
Note
This function blocks until connection is either successull or unsuccessful.

◆ deleteDevice()

int INDI::BaseClientQt::deleteDevice ( const char *  devName,
char *  errmsg 
)
protected

Remove device.

◆ delPropertyCmd()

int INDI::BaseClientQt::delPropertyCmd ( XMLEle root,
char *  errmsg 
)
protected

Delete property command.

◆ disconnectDevice()

void INDI::BaseClientQt::disconnectDevice ( const char *  deviceName)

Disconnect INDI driver.

Parameters
deviceNameName of the device to disconnect.

◆ disconnectServer()

bool INDI::BaseClientQt::disconnectServer ( )

Disconnect from INDI server.

Disconnects from INDI servers. Any devices previously created will be deleted and memory cleared.

Returns
True if disconnection is successful, false otherwise.

◆ dispatchCommand()

int INDI::BaseClientQt::dispatchCommand ( XMLEle root,
char *  errmsg 
)
protected

Dispatch command received from INDI server to respective devices handled by the client.

◆ findBLOBMode()

INDI::BaseClientQt::BLOBMode * INDI::BaseClientQt::findBLOBMode ( const std::string &  device,
const std::string &  property 
)
private

◆ findDev() [1/2]

INDI::BaseDevice * INDI::BaseClientQt::findDev ( const char *  devName,
char *  errmsg 
)
protected

Find and return a particular device.

◆ findDev() [2/2]

INDI::BaseDevice * INDI::BaseClientQt::findDev ( XMLEle root,
int  create,
char *  errmsg 
)
protected

Find a device, and if it doesn't exist, create it if create is set to 1.

◆ finishBlob()

void INDI::BaseClientQt::finishBlob ( )

Send closing tag for BLOB command to server.

◆ getBLOBMode()

BLOBHandling INDI::BaseClientQt::getBLOBMode ( const char *  dev,
const char *  prop = NULL 
)

getBLOBMode Get Binary Large Object policy mode IF set previously by setBLOBMode

Parameters
devname of device.
propproperty name, can be NULL to return overall device policy if it exists.
Returns
BLOB Policy, if not found, it always returns B_ALSO

◆ getDevice()

INDI::BaseDevice * INDI::BaseClientQt::getDevice ( const char *  deviceName)
Parameters
deviceNameName of device to search for in the list of devices owned by INDI server,
Returns
If deviceName exists, it returns an instance of the device. Otherwise, it returns NULL.

◆ getDevices() [1/2]

const std::vector<INDI::BaseDevice *>& INDI::BaseClientQt::getDevices ( ) const
inline
Returns
Returns a vector of all devices created in the client.

◆ getDevices() [2/2]

bool INDI::BaseClientQt::getDevices ( std::vector< INDI::BaseDevice *> &  deviceList,
uint16_t  driverInterface 
)


getDevices Returns list of devices that belong to a particular DRIVER_INTERFACE class.

For example, to get a list of guide cameras:

std::vector<INDI::BaseDevice *> guideCameras;
getDevices(guideCameras, CCD_INTERFACE | GUIDE_INTERFACE);
for (INDI::BaseDevice *device : guideCameras)
cout << "Guide Camera Name: " << device->getDeviceName();
Parameters
deviceListSupply device list to be filled by the function.
driverInterfaceORed DRIVER_INTERFACE values to select the desired class of devices.
Returns
True if one or more devices are found for the supplied driverInterface, false if no matching devices found.

◆ getHost()

const char* INDI::BaseClientQt::getHost ( )
inline

◆ getPort()

int INDI::BaseClientQt::getPort ( )
inline

◆ isServerConnected()

bool INDI::BaseClientQt::isServerConnected ( ) const

◆ isVerbose()

bool INDI::BaseClientQt::isVerbose ( ) const
inline

isVerbose Is client in verbose mode?

Returns
Is client in verbose mode?

◆ listenHelper()

void * INDI::BaseClientQt::listenHelper ( void *  context)
static

◆ listenINDI

void INDI::BaseClientQt::listenINDI ( )
privateslot

◆ messageCmd()

int INDI::BaseClientQt::messageCmd ( XMLEle root,
char *  errmsg 
)
protected

Process messages.

◆ processSocketError

void INDI::BaseClientQt::processSocketError ( QAbstractSocket::SocketError  socketError)
privateslot

◆ sendNewNumber() [1/2]

void INDI::BaseClientQt::sendNewNumber ( INumberVectorProperty pp)

Send new Number command to server.

◆ sendNewNumber() [2/2]

void INDI::BaseClientQt::sendNewNumber ( const char *  deviceName,
const char *  propertyName,
const char *  elementName,
double  value 
)

Send new Number command to server.

◆ sendNewSwitch() [1/2]

void INDI::BaseClientQt::sendNewSwitch ( ISwitchVectorProperty pp)

Send new Switch command to server.

◆ sendNewSwitch() [2/2]

void INDI::BaseClientQt::sendNewSwitch ( const char *  deviceName,
const char *  propertyName,
const char *  elementName 
)

Send new Switch command to server.

◆ sendNewText() [1/2]

void INDI::BaseClientQt::sendNewText ( ITextVectorProperty pp)

Send new Text command to server.

◆ sendNewText() [2/2]

void INDI::BaseClientQt::sendNewText ( const char *  deviceName,
const char *  propertyName,
const char *  elementName,
const char *  text 
)

Send new Text command to server.

◆ sendOneBlob() [1/2]

void INDI::BaseClientQt::sendOneBlob ( IBLOB bp)

Send ONE blob content to server.

The BLOB data in raw binary format and will be converted to base64 and sent to server

◆ sendOneBlob() [2/2]

void INDI::BaseClientQt::sendOneBlob ( const char *  blobName,
unsigned int  blobSize,
const char *  blobFormat,
void *  blobBuffer 
)

Send ONE blob content to server.

The BLOB data in raw binary format and will be converted to base64 and sent to server

◆ setBLOBMode()

void INDI::BaseClientQt::setBLOBMode ( BLOBHandling  blobH,
const char *  dev,
const char *  prop = NULL 
)

Set Binary Large Object policy mode.

Set the BLOB handling mode for the client. The client may either receive:

  • Only BLOBS
  • BLOBs mixed with normal messages
  • Normal messages only, no BLOBs

If dev and prop are supplied, then the BLOB handling policy is set for this particular device and property. if prop is NULL, then the BLOB policy applies to the whole device.

Parameters
blobHBLOB handling policy
devname of device, required.
propname of property, optional.

◆ setConnectionTimeout()

void INDI::BaseClientQt::setConnectionTimeout ( uint32_t  seconds,
uint32_t  microseconds 
)
inline

setConnectionTimeout Set connection timeout.

By default it is 3 seconds.

Parameters
secondsseconds
microsecondsmicroseconds

◆ setDriverConnection()

void INDI::BaseClientQt::setDriverConnection ( bool  status,
const char *  deviceName 
)
private

Connect/Disconnect to INDI driver.

Parameters
statusIf true, the client will attempt to turn on CONNECTION property within the driver (i.e. turn on the device). Otherwise, CONNECTION will be turned off.
deviceNameName of the device to connect to.

◆ setServer()

void INDI::BaseClientQt::setServer ( const char *  hostname,
unsigned int  port 
)

Set the server host name and port.

Parameters
hostnameINDI server host name or IP address.
portINDI server port.

◆ setVerbose()

void INDI::BaseClientQt::setVerbose ( bool  enable)
inline

setVerbose Set verbose mode

Parameters
enableIf true, enable FULL verbose output. Any XML message received, including BLOBs, are printed on standard output. Only use this for debugging purposes.

◆ startBlob()

void INDI::BaseClientQt::startBlob ( const char *  devName,
const char *  propName,
const char *  timestamp 
)

Send opening tag for BLOB command to server.

◆ watchDevice()

void INDI::BaseClientQt::watchDevice ( const char *  deviceName)

Add a device to the watch list.

A client may select to receive notifications of only a specific device or a set of devices. If the client encounters any of the devices set via this function, it will create a corresponding INDI::BaseDevice object to handle them. If no devices are watched, then all devices owned by INDI server will be created and handled.

Member Data Documentation

◆ blobModes

std::vector<BLOBMode *> INDI::BaseClientQt::blobModes
private

◆ cDeviceNames

std::vector<std::string> INDI::BaseClientQt::cDeviceNames
private

◆ cDevices

std::vector<INDI::BaseDevice *> INDI::BaseClientQt::cDevices
private

◆ client_socket

QTcpSocket INDI::BaseClientQt::client_socket
private

◆ cPort

unsigned int INDI::BaseClientQt::cPort
private

◆ cServer

std::string INDI::BaseClientQt::cServer
private

◆ lillp

LilXML* INDI::BaseClientQt::lillp
private

◆ sConnected

bool INDI::BaseClientQt::sConnected
private

◆ timeout_sec

uint32_t INDI::BaseClientQt::timeout_sec
private

◆ timeout_us

uint32_t INDI::BaseClientQt::timeout_us
private

◆ verbose

bool INDI::BaseClientQt::verbose
private

The documentation for this class was generated from the following files: