Instrument Neutral Distributed Interface INDI  1.5.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
INDI::BaseClient Class Reference

Class to provide basic client functionality. More...

#include <baseclient.h>

Inheritance diagram for INDI::BaseClient:
INDI::BaseMediator Imager LoaderClient MathPluginManagerClient MyClient SkySafariClient WatchDogClient

Public Member Functions

 BaseClient ()
 
virtual ~BaseClient ()
 
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...
 
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. The BLOB data in raw binary format and will be converted to base64 and sent to server. More...
 
void 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. 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. By default it is 3 seconds. 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 ()
 

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)
 
virtual void newUniversalMessage (std::string message)
 newUniversalMessage Universal messages are sent from INDI server without a specific device. It is addressed to the client overall. More...
 

Detailed Description

Class to provide basic client functionality.

BaseClient enables accelerated development of INDI Clients by providing a framework that facilitates communication, device handling, and event notification. By subclassing BaseClient, 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.

Upon connecting to an INDI server, it creates a dedicated thread to handle all incoming traffic. The thread is terminated when disconnectServer() is called or when a communication error occurs.

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
Examples:
tutorial_client.h.

Definition at line 54 of file baseclient.h.

Constructor & Destructor Documentation

INDI::BaseClient::BaseClient ( )

Definition at line 57 of file baseclient.cpp.

INDI::BaseClient::~BaseClient ( )
virtual

Definition at line 68 of file baseclient.cpp.

Member Function Documentation

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

Add a new device.

Definition at line 593 of file baseclient.cpp.

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

Connect to INDI driver.

Parameters
deviceNameName of the device to connect to.
Examples:
tutorial_client.cpp.

Definition at line 282 of file baseclient.cpp.

bool INDI::BaseClient::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.

Definition at line 94 of file baseclient.cpp.

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

Remove device.

Definition at line 557 of file baseclient.cpp.

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

Delete property command.

Definition at line 529 of file baseclient.cpp.

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

Disconnect INDI driver.

Parameters
deviceNameName of the device to disconnect.

Definition at line 287 of file baseclient.cpp.

bool INDI::BaseClient::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.

Definition at line 254 of file baseclient.cpp.

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

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

Definition at line 488 of file baseclient.cpp.

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

Find and return a particular device.

Definition at line 578 of file baseclient.cpp.

INDI::BaseDevice * INDI::BaseClient::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.

Definition at line 621 of file baseclient.cpp.

void INDI::BaseClient::finishBlob ( )

Send closing tag for BLOB command to server.

Definition at line 928 of file baseclient.cpp.

BLOBHandling INDI::BaseClient::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

Definition at line 978 of file baseclient.cpp.

INDI::BaseDevice * INDI::BaseClient::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.

Definition at line 337 of file baseclient.cpp.

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

Definition at line 106 of file baseclient.h.

bool INDI::BaseClient::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.

Definition at line 1001 of file baseclient.cpp.

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

Definition at line 154 of file baseclient.h.

int INDI::BaseClient::getPort ( )
inline

Definition at line 155 of file baseclient.h.

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

isVerbose Is client in verbose mode?

Returns
Is client in verbose mode?

Definition at line 190 of file baseclient.h.

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

Definition at line 347 of file baseclient.cpp.

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

Process messages

Definition at line 659 of file baseclient.cpp.

void INDI::BaseClient::newUniversalMessage ( std::string  message)
protectedvirtual

newUniversalMessage Universal messages are sent from INDI server without a specific device. It is addressed to the client overall.

Parameters
messagecontent of message.
Note
The default implementation simply logs the message to stderr. Override to handle the message.

Definition at line 704 of file baseclient.cpp.

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

Send new Number command to server.

Examples:
tutorial_client.cpp.

Definition at line 751 of file baseclient.cpp.

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

Send new Number command to server.

Definition at line 771 of file baseclient.cpp.

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

Send new Switch command to server.

Definition at line 794 of file baseclient.cpp.

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

Send new Switch command to server.

Definition at line 825 of file baseclient.cpp.

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

Send new Text command to server.

Definition at line 709 of file baseclient.cpp.

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

Send new Text command to server.

Definition at line 728 of file baseclient.cpp.

void INDI::BaseClient::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.

Definition at line 855 of file baseclient.cpp.

void INDI::BaseClient::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.

Definition at line 891 of file baseclient.cpp.

void INDI::BaseClient::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.

Definition at line 933 of file baseclient.cpp.

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

setConnectionTimeout Set connection timeout. By default it is 3 seconds.

Parameters
secondsseconds
microsecondsmicroseconds

Definition at line 197 of file baseclient.h.

void INDI::BaseClient::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.

Definition at line 83 of file baseclient.cpp.

void INDI::BaseClient::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.

Definition at line 184 of file baseclient.h.

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

Send opening tag for BLOB command to server.

Definition at line 847 of file baseclient.cpp.

void INDI::BaseClient::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.

Definition at line 89 of file baseclient.cpp.


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