Instrument Neutral Distributed Interface INDI 2.2.5
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Connection::TCP Class Reference

The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection, reads & writes from and to the device are performed via the returned file descriptor using standard UNIX read/write functions. More...

#include <connectiontcp.h>

Inheritance diagram for Connection::TCP:
Connection::Interface

Public Types

enum  ConnectionType { TYPE_TCP = 0 , TYPE_UDP }
 
- Public Types inherited from Connection::Interface
enum  Type {
  CONNECTION_NONE = 1 << 0 , CONNECTION_SERIAL = 1 << 1 , CONNECTION_TCP = 1 << 2 , CONNECTION_USB = 1 << 3 ,
  CONNECTION_I2C = 1 << 4 , CONNECTION_CUSTOM = 1 << 15
}
 

Public Member Functions

 TCP (INDI::DefaultDevice *dev, IPerm permission=IP_RW)
 
virtual ~TCP ()=default
 
virtual bool Connect () override
 Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
 
virtual bool Disconnect () override
 Disconnect Disconnect from device.
 
virtual void Activated () override
 Activated Function called by the framework when the plugin is activated (i.e. selected by the user). It is usually used to define properties pertaining to the specific plugin functionalities.
 
virtual void Deactivated () override
 Deactivated Function called by the framework when the plugin is deactivated. It is usually used to delete properties by were defined previously since the plugin is no longer active.
 
virtual std::string name () override
 
virtual std::string label () override
 
virtual const char * host () const
 
virtual uint32_t port () const
 
ConnectionType connectionType () const
 
virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) override
 
virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) override
 
virtual bool saveConfigItems (FILE *fp) override
 
int getPortFD () const
 
void setDefaultHost (const char *addressHost)
 
void setDefaultPort (uint32_t addressPort)
 
void setConnectionType (int type)
 TODO should be renamed to setDefaultConnectionType.
 
void setLANSearchEnabled (bool enabled)
 
- Public Member Functions inherited from Connection::Interface
virtual Type type ()
 type Return connection type
 
virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
 
virtual bool ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
 
void registerHandshake (std::function< bool()> callback)
 registerHandshake Register a handshake function to be called once the initial connection to the device is established.
 

Protected Member Functions

bool establishConnection (const std::string &hostname, const std::string &port, int timeout=-1)
 establishConnection Create a socket connection to the host and port. If successful, set the socket variable.
 
- Protected Member Functions inherited from Connection::Interface
 Interface (INDI::DefaultDevice *dev, Type type=CONNECTION_NONE)
 
virtual ~Interface ()
 
const char * getDeviceName ()
 

Protected Attributes

INDI::PropertyText AddressTP {2}
 Properties.
 
INDI::PropertySwitch TcpUdpSP {2}
 
INDI::PropertySwitch LANSearchSP {2}
 
IPerm m_Permission = IP_RW
 
std::string m_ConfigHost
 
std::string m_ConfigPort
 
int m_ConfigConnectionType {-1}
 
int m_SockFD {-1}
 
int PortFD = -1
 
- Protected Attributes inherited from Connection::Interface
std::function< bool()> Handshake
 
INDI::DefaultDevice * m_Device { nullptr }
 
Type m_Type { CONNECTION_NONE }
 

Static Protected Attributes

static constexpr uint8_t SOCKET_TIMEOUT {5}
 

Detailed Description

The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection, reads & writes from and to the device are performed via the returned file descriptor using standard UNIX read/write functions.

Definition at line 39 of file connectiontcp.h.

Member Enumeration Documentation

◆ ConnectionType

Enumerator
TYPE_TCP 
TYPE_UDP 

Definition at line 42 of file connectiontcp.h.

Constructor & Destructor Documentation

◆ TCP()

Connection::TCP::TCP ( INDI::DefaultDevice *  dev,
IPerm  permission = IP_RW 
)

Definition at line 44 of file connectiontcp.cpp.

◆ ~TCP()

virtual Connection::TCP::~TCP ( )
virtualdefault

Member Function Documentation

◆ Activated()

void Connection::TCP::Activated ( )
overridevirtual

Activated Function called by the framework when the plugin is activated (i.e. selected by the user). It is usually used to define properties pertaining to the specific plugin functionalities.

Implements Connection::Interface.

Definition at line 353 of file connectiontcp.cpp.

◆ Connect()

bool Connection::TCP::Connect ( )
overridevirtual

Connect Connect to device via the implemented communication medium. Do not perform any handshakes.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

Definition at line 208 of file connectiontcp.cpp.

◆ connectionType()

ConnectionType Connection::TCP::connectionType ( ) const
inline

Definition at line 77 of file connectiontcp.h.

◆ Deactivated()

void Connection::TCP::Deactivated ( )
overridevirtual

Deactivated Function called by the framework when the plugin is deactivated. It is usually used to delete properties by were defined previously since the plugin is no longer active.

Implements Connection::Interface.

Definition at line 366 of file connectiontcp.cpp.

◆ Disconnect()

bool Connection::TCP::Disconnect ( )
overridevirtual

Disconnect Disconnect from device.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

Definition at line 339 of file connectiontcp.cpp.

◆ establishConnection()

bool Connection::TCP::establishConnection ( const std::string &  hostname,
const std::string &  port,
int  timeout = -1 
)
protected

establishConnection Create a socket connection to the host and port. If successful, set the socket variable.

Parameters
hostnamefully qualified hostname or IP address to host
portPort
timeouttimeout in seconds. If not sent, use default 5 seconds timeout.
Returns
Success if connection established, false otherwise.
Note
Connection type (TCP vs UDP) is fetched from the TcpUdpSP property.

Definition at line 140 of file connectiontcp.cpp.

◆ getPortFD()

int Connection::TCP::getPortFD ( ) const
inline

Definition at line 86 of file connectiontcp.h.

◆ host()

virtual const char * Connection::TCP::host ( ) const
inlinevirtual

Definition at line 69 of file connectiontcp.h.

◆ ISNewSwitch()

bool Connection::TCP::ISNewSwitch ( const char *  dev,
const char *  name,
ISState *  states,
char *  names[],
int  n 
)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 99 of file connectiontcp.cpp.

◆ ISNewText()

bool Connection::TCP::ISNewText ( const char *  dev,
const char *  name,
char *  texts[],
char *  names[],
int  n 
)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 79 of file connectiontcp.cpp.

◆ label()

virtual std::string Connection::TCP::label ( )
inlineoverridevirtual
Returns
Plugin friendly label presented to the client/user.

Implements Connection::Interface.

Definition at line 64 of file connectiontcp.h.

◆ name()

virtual std::string Connection::TCP::name ( )
inlineoverridevirtual
Returns
Plugin name

Implements Connection::Interface.

Definition at line 59 of file connectiontcp.h.

◆ port()

virtual uint32_t Connection::TCP::port ( ) const
inlinevirtual

Definition at line 73 of file connectiontcp.h.

◆ saveConfigItems()

bool Connection::TCP::saveConfigItems ( FILE *  fp)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 379 of file connectiontcp.cpp.

◆ setConnectionType()

void Connection::TCP::setConnectionType ( int  type)

TODO should be renamed to setDefaultConnectionType.

Definition at line 416 of file connectiontcp.cpp.

◆ setDefaultHost()

void Connection::TCP::setDefaultHost ( const char *  addressHost)

Definition at line 394 of file connectiontcp.cpp.

◆ setDefaultPort()

void Connection::TCP::setDefaultPort ( uint32_t  addressPort)

Definition at line 405 of file connectiontcp.cpp.

◆ setLANSearchEnabled()

void Connection::TCP::setLANSearchEnabled ( bool  enabled)

Definition at line 430 of file connectiontcp.cpp.

Member Data Documentation

◆ AddressTP

INDI::PropertyText Connection::TCP::AddressTP {2}
protected

Properties.

Definition at line 110 of file connectiontcp.h.

◆ LANSearchSP

INDI::PropertySwitch Connection::TCP::LANSearchSP {2}
protected

Definition at line 114 of file connectiontcp.h.

◆ m_ConfigConnectionType

int Connection::TCP::m_ConfigConnectionType {-1}
protected

Definition at line 120 of file connectiontcp.h.

◆ m_ConfigHost

std::string Connection::TCP::m_ConfigHost
protected

Definition at line 118 of file connectiontcp.h.

◆ m_ConfigPort

std::string Connection::TCP::m_ConfigPort
protected

Definition at line 119 of file connectiontcp.h.

◆ m_Permission

IPerm Connection::TCP::m_Permission = IP_RW
protected

Definition at line 117 of file connectiontcp.h.

◆ m_SockFD

int Connection::TCP::m_SockFD {-1}
protected

Definition at line 121 of file connectiontcp.h.

◆ PortFD

int Connection::TCP::PortFD = -1
protected

Definition at line 122 of file connectiontcp.h.

◆ SOCKET_TIMEOUT

constexpr uint8_t Connection::TCP::SOCKET_TIMEOUT {5}
staticconstexprprotected

Definition at line 123 of file connectiontcp.h.

◆ TcpUdpSP

INDI::PropertySwitch Connection::TCP::TcpUdpSP {2}
protected

Definition at line 112 of file connectiontcp.h.


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