35#ifndef _UTILS_CLIENTCONNECTION_HXX_
36#define _UTILS_CLIENTCONNECTION_HXX_
57 virtual int fd() {
return -1; }
169 template<
typename HubType>
171 const string &name, HubType *hub,
const string &dev)
185 int fd = ::open(
dev_.c_str(), O_RDWR);
213 template<
typename HubType>
215 const string &name, HubType *hub,
const string &host,
int port)
240 port_, errno, strerror(errno));
Abstract base class for the Hub's connections.
virtual bool ping()=0
Test the connection whether it is alive; establish the connection if it is dead.
Notification implementation that sets an external variable to -1 when notified.
int * fd_
pointer to file descriptor variable.
void notify() override
Callback from the application when an error is encountered.
DeviceClosedNotify(int *fd, string name)
Constructor.
string name_
info to print to stderr upon error.
Connection client that opens a character device (such as an usb-serial) and sets the termios attribut...
DeviceConnectionClient(const string &name, HubType *hub, const string &dev)
Constructor.
string dev_
filename of device to open
void try_connect() OVERRIDE
Attempts to open the device.
Base class for FD-based GridConnect connection clients.
ByteDirectHubInterface * directHub_
DirectHub to read/write data to.
GCFdConnectionClient(const string &name, ByteDirectHubInterface *direct_hub)
Constructor.
DeviceClosedNotify closedNotify_
Will be called when the descriptor experiences an error (typivcally upon device closed or connection ...
int fd_
File descriptor of the currently open device/socket.
void connection_complete(int fd)
Callback from try_connect to donate the file descriptor.
bool ping() OVERRIDE
Tests if the device is alive or encountered an error.
virtual void try_connect()=0
Abstrct base function to attempt to connect (or open device) to the destination.
CanHubFlow * hub_
CAN hub to read-write data to.
GCFdConnectionClient(const string &name, CanHubFlow *hub)
Constructor.
An object that can schedule itself on an executor to run.
Connection client that connects to an upstream GridConnect-TCP hub via TCP client socket.
void try_connect() OVERRIDE
Implementation of connection method.
string host_
where to connect to (host name)
UpstreamConnectionClient(const string &name, HubType *hub, const string &host, int port)
Constructor.
int port_
where to connect to (TCP port number)
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int INFO
Loglevel that is printed by default, reporting some status information.
#define LOG_ERROR(message...)
Shorthand for LOG(LEVEL_ERROR, message...). See LOG.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
int ConnectSocket(const char *host, int port)
Connects a tcp socket to the specified remote host:port.
static void optimize_tty_fd(int fd)
Sets the kernel settings like queuing and terminal settings for an fd that is an outgoing tty.