Instrument Neutral Distributed Interface INDI  2.0.2
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 successfull 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_CUSTOM = 1 << 15
}
 

Public Member Functions

 TCP (INDI::DefaultDevice *dev)
 
virtual ~TCP ()=default
 
virtual bool Connect () override
 Connect Connect to device via the implemented communication medium. Do not perform any handshakes. More...
 
virtual bool Disconnect () override
 Disconnect Disconnect from device. More...
 
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. More...
 
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. More...
 
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. More...
 
void setLANSearchEnabled (bool enabled)
 
- Public Member Functions inherited from Connection::Interface
virtual Type type ()
 type Return connection type More...
 
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 intial connection to the device is established. More...
 

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. More...
 
- Protected Member Functions inherited from Connection::Interface
 Interface (INDI::DefaultDevice *dev, Type type=CONNECTION_NONE)
 
virtual ~Interface ()
 
const char * getDeviceName ()
 

Protected Attributes

ITextVectorProperty AddressTP
 Properties. More...
 
IText AddressT [2] {}
 
ISwitch TcpUdpS [2]
 
ISwitchVectorProperty TcpUdpSP
 
ISwitch LANSearchS [2]
 
ISwitchVectorProperty LANSearchSP
 
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::DefaultDevicem_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 successfull connection, reads & writes from and to the device are performed via the returned file descriptor using standard UNIX read/write functions.

Definition at line 37 of file connectiontcp.h.

Member Enumeration Documentation

◆ ConnectionType

Enumerator
TYPE_TCP 
TYPE_UDP 

Definition at line 40 of file connectiontcp.h.

Constructor & Destructor Documentation

◆ TCP()

Connection::TCP::TCP ( INDI::DefaultDevice dev)

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 359 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 213 of file connectiontcp.cpp.

◆ connectionType()

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

Definition at line 75 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 369 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 345 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 145 of file connectiontcp.cpp.

◆ getPortFD()

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

Definition at line 84 of file connectiontcp.h.

◆ host()

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

Definition at line 67 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 104 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 84 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 62 of file connectiontcp.h.

◆ name()

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

Implements Connection::Interface.

Definition at line 57 of file connectiontcp.h.

◆ port()

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

Definition at line 71 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 417 of file connectiontcp.cpp.

◆ setDefaultHost()

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

Definition at line 391 of file connectiontcp.cpp.

◆ setDefaultPort()

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

Definition at line 402 of file connectiontcp.cpp.

◆ setLANSearchEnabled()

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

Definition at line 431 of file connectiontcp.cpp.

Member Data Documentation

◆ AddressT

IText Connection::TCP::AddressT[2] {}
protected

Definition at line 109 of file connectiontcp.h.

◆ AddressTP

ITextVectorProperty Connection::TCP::AddressTP
protected

Properties.

Definition at line 108 of file connectiontcp.h.

◆ LANSearchS

ISwitch Connection::TCP::LANSearchS[2]
protected

Definition at line 114 of file connectiontcp.h.

◆ LANSearchSP

ISwitchVectorProperty Connection::TCP::LANSearchSP
protected

Definition at line 115 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_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.

◆ TcpUdpS

ISwitch Connection::TCP::TcpUdpS[2]
protected

Definition at line 111 of file connectiontcp.h.

◆ TcpUdpSP

ISwitchVectorProperty Connection::TCP::TcpUdpSP
protected

Definition at line 112 of file connectiontcp.h.


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