Instrument Neutral Distributed Interface INDI 2.2.5
connectiontcp.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2017 Jasem Mutlaq. All rights reserved.
3
4 Connection Plugin Interface
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License version 2 as published by the Free Software Foundation.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*******************************************************************************/
20
21#pragma once
22
23#include "connectioninterface.h"
24#include "indipropertytext.h"
25#include "indipropertyswitch.h"
26
27#include <stdint.h>
28#include <cstdlib>
29#include <string>
30
31namespace Connection
32{
39class TCP : public Interface
40{
41 public:
47
48 TCP(INDI::DefaultDevice *dev, IPerm permission = IP_RW);
49 virtual ~TCP() = default;
50
51 virtual bool Connect() override;
52
53 virtual bool Disconnect() override;
54
55 virtual void Activated() override;
56
57 virtual void Deactivated() override;
58
59 virtual std::string name() override
60 {
61 return "CONNECTION_TCP";
62 }
63
64 virtual std::string label() override
65 {
66 return "Network";
67 }
68
69 virtual const char *host() const
70 {
71 return AddressTP[0].getText();
72 }
73 virtual uint32_t port() const
74 {
75 return atoi(AddressTP[1].getText());
76 }
78 {
79 return static_cast<ConnectionType>(TcpUdpSP.findOnSwitchIndex());
80 }
81
82 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
83 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
84 virtual bool saveConfigItems(FILE *fp) override;
85
86 int getPortFD() const
87 {
88 return PortFD;
89 }
90 void setDefaultHost(const char *addressHost);
91 void setDefaultPort(uint32_t addressPort);
92 void setConnectionType(int type);
93 void setLANSearchEnabled(bool enabled);
94
95 protected:
104 bool establishConnection(const std::string &hostname, const std::string &port, int timeout = -1);
105
109 // IP Address/Port
111 // Connection Type
113 // Auto search
115
116 // Variables
118 std::string m_ConfigHost;
119 std::string m_ConfigPort;
121 int m_SockFD {-1};
122 int PortFD = -1;
123 static constexpr uint8_t SOCKET_TIMEOUT {5};
124};
125}
The Interface class is the base class for all INDI connection plugins.
virtual Type type()
type Return connection type
The TCP class manages connection with devices over the network via TCP/IP. Upon successful connection...
virtual ~TCP()=default
void setDefaultHost(const char *addressHost)
virtual std::string label() override
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
static constexpr uint8_t SOCKET_TIMEOUT
void setLANSearchEnabled(bool enabled)
virtual std::string name() override
virtual bool Disconnect() override
Disconnect Disconnect from device.
void setConnectionType(int type)
TODO should be renamed to setDefaultConnectionType.
virtual void Activated() override
Activated Function called by the framework when the plugin is activated (i.e. selected by the user)....
void setDefaultPort(uint32_t addressPort)
int getPortFD() const
virtual const char * host() const
INDI::PropertyText AddressTP
Properties.
virtual bool Connect() override
Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
INDI::PropertySwitch LANSearchSP
INDI::PropertySwitch TcpUdpSP
std::string m_ConfigHost
std::string m_ConfigPort
virtual uint32_t port() const
virtual bool saveConfigItems(FILE *fp) override
ConnectionType connectionType() const
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,...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
virtual void Deactivated() override
Deactivated Function called by the framework when the plugin is deactivated. It is usually used to de...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
INDI::PropertyViewText * getText() const
ISState
Switch state.
Definition indiapi.h:148
IPerm
Permission hint, with respect to client.
Definition indiapi.h:181
@ IP_RW
Definition indiapi.h:184
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34