My Project
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
uuid::telnet::TelnetService Class Reference

Provides access to a console shell as a telnet server. More...

#include <uuid/telnet.h>

Collaboration diagram for uuid::telnet::TelnetService:
Collaboration graph
[legend]

Classes

class  Connection
 Telnet connection. More...
 

Public Types

using shell_factory_function = std::function< std::shared_ptr< uuid::console::Shell >(Stream &stream, const IPAddress &addr, uint16_t port)>
 Function to handle the creation of a shell. More...
 

Public Member Functions

 TelnetService (std::shared_ptr< uuid::console::Commands > commands, unsigned int context=0, unsigned int flags=0)
 Create a new telnet service listening on the default port. More...
 
 TelnetService (uint16_t port, std::shared_ptr< uuid::console::Commands > commands, unsigned int context=0, unsigned int flags=0)
 Create a new telnet service listening on a specific port. More...
 
 TelnetService (shell_factory_function shell_factory)
 Create a new telnet service listening on the default port. More...
 
 TelnetService (uint16_t port, shell_factory_function shell_factory)
 Create a new telnet service listening on a specific port. More...
 
void start ()
 Start listening for connections on the configured port. More...
 
void close_all ()
 Close all connections. More...
 
void stop ()
 Stop listening for connections. More...
 
size_t maximum_connections () const
 Get the maximum number of concurrent open connections. More...
 
void maximum_connections (size_t count)
 Set the maximum number of concurrent open connections. More...
 
unsigned long initial_idle_timeout () const
 Get the initial idle timeout for new connections. More...
 
void initial_idle_timeout (unsigned long timeout)
 Set the initial idle timeout for new connections. More...
 
unsigned long default_write_timeout () const
 Get the default socket write timeout for new connections. More...
 
void default_write_timeout (unsigned long timeout)
 Set the default socket write timeout for new connections. More...
 
void loop ()
 Accept new connections. More...
 

Static Public Attributes

static constexpr size_t MAX_CONNECTIONS = 3
 
static constexpr uint16_t DEFAULT_PORT = 23
 
static constexpr unsigned long DEFAULT_IDLE_TIMEOUT = 600
 
static constexpr unsigned long DEFAULT_WRITE_TIMEOUT = 0
 

Private Member Functions

 TelnetService (const TelnetService &)=delete
 
TelnetServiceoperator= (const TelnetService &)=delete
 

Private Attributes

WiFiServer server_
 
size_t maximum_connections_ = MAX_CONNECTIONS
 
std::list< Connectionconnections_
 
shell_factory_function shell_factory_
 
unsigned long initial_idle_timeout_ = DEFAULT_IDLE_TIMEOUT
 
unsigned long write_timeout_ = DEFAULT_WRITE_TIMEOUT
 

Static Private Attributes

static uuid::log::Logger logger_ {FPSTR(__pstr__logger_name), uuid::log::Facility::DAEMON}
 

Detailed Description

Provides access to a console shell as a telnet server.

Since
0.1.0

Definition at line 230 of file telnet.h.

Member Typedef Documentation

◆ shell_factory_function

using uuid::telnet::TelnetService::shell_factory_function = std::function<std::shared_ptr<uuid::console::Shell>(Stream &stream, const IPAddress &addr, uint16_t port)>

Function to handle the creation of a shell.

Parameters
[in]streamStream for the telnet connection.
[in]addrRemote IP address.
[in]portRemote port.
Since
0.1.0

Definition at line 245 of file telnet.h.

Constructor & Destructor Documentation

◆ TelnetService() [1/4]

uuid::telnet::TelnetService::TelnetService ( std::shared_ptr< uuid::console::Commands commands,
unsigned int  context = 0,
unsigned int  flags = 0 
)

Create a new telnet service listening on the default port.

Parameters
[in]commandsCommands available for execution in shells.
[in]contextDefault context for shells.
[in]flagsInitial flags for shells.
Since
0.1.0

Definition at line 73 of file telnet.cpp.

◆ TelnetService() [2/4]

uuid::telnet::TelnetService::TelnetService ( uint16_t  port,
std::shared_ptr< uuid::console::Commands commands,
unsigned int  context = 0,
unsigned int  flags = 0 
)

Create a new telnet service listening on a specific port.

Parameters
[in]portTCP listening port.
[in]commandsCommands available for execution in shells.
[in]contextDefault context for shells.
[in]flagsInitial flags for shells.
Since
0.1.0

Definition at line 78 of file telnet.cpp.

◆ TelnetService() [3/4]

uuid::telnet::TelnetService::TelnetService ( shell_factory_function  shell_factory)
explicit

Create a new telnet service listening on the default port.

Parameters
[in]shell_factoryFunction to create a shell for new connections.
Since
0.1.0

Definition at line 86 of file telnet.cpp.

◆ TelnetService() [4/4]

uuid::telnet::TelnetService::TelnetService ( uint16_t  port,
shell_factory_function  shell_factory 
)

Create a new telnet service listening on a specific port.

Parameters
[in]portTCP listening port.
[in]shell_factoryFunction to create a shell for new connections.
Since
0.1.0

Definition at line 91 of file telnet.cpp.

Member Function Documentation

◆ close_all()

void uuid::telnet::TelnetService::close_all ( )

Close all connections.

The listening status is not affected.

Since
0.1.0

Definition at line 100 of file telnet.cpp.

◆ default_write_timeout() [1/2]

unsigned long uuid::telnet::TelnetService::default_write_timeout ( ) const

Get the default socket write timeout for new connections.

Returns
The default socket write timeout in seconds (or 0 for platform default).
Since
0.1.0

Definition at line 138 of file telnet.cpp.

◆ default_write_timeout() [2/2]

void uuid::telnet::TelnetService::default_write_timeout ( unsigned long  timeout)

Set the default socket write timeout for new connections.

Defaults to TelnetService::DEFAULT_WRITE_TIMEOUT (platform default).

Parameters
[in]timeoutSocket write timeout in seconds (or 0 for platform default).
Since
0.1.0

Definition at line 142 of file telnet.cpp.

◆ initial_idle_timeout() [1/2]

unsigned long uuid::telnet::TelnetService::initial_idle_timeout ( ) const

Get the initial idle timeout for new connections.

Returns
The initial idle timeout in seconds (or 0 for disabled).
Since
0.1.0

Definition at line 130 of file telnet.cpp.

◆ initial_idle_timeout() [2/2]

void uuid::telnet::TelnetService::initial_idle_timeout ( unsigned long  timeout)

Set the initial idle timeout for new connections.

Defaults to TelnetService::DEFAULT_IDLE_TIMEOUT.

Parameters
[in]timeoutIdle timeout in seconds (or 0 to disable).
Since
0.1.0

Definition at line 134 of file telnet.cpp.

◆ loop()

void uuid::telnet::TelnetService::loop ( )

Accept new connections.

Since
0.1.0

Definition at line 146 of file telnet.cpp.

◆ maximum_connections() [1/2]

size_t uuid::telnet::TelnetService::maximum_connections ( ) const

Get the maximum number of concurrent open connections.

Returns
The maximum number of concurrent open connections.
Since
0.1.0

Definition at line 111 of file telnet.cpp.

◆ maximum_connections() [2/2]

void uuid::telnet::TelnetService::maximum_connections ( size_t  count)

Set the maximum number of concurrent open connections.

Defaults to TelnetService::MAX_CONNECTIONS.

Since
0.1.0

Definition at line 115 of file telnet.cpp.

◆ start()

void uuid::telnet::TelnetService::start ( )

Start listening for connections on the configured port.

Since
0.1.0

Definition at line 96 of file telnet.cpp.

◆ stop()

void uuid::telnet::TelnetService::stop ( )

Stop listening for connections.

Existing connections are not affected.

Since
0.1.0

Definition at line 107 of file telnet.cpp.

Member Data Documentation

◆ connections_

std::list<Connection> uuid::telnet::TelnetService::connections_
private

Open connections.

Since
0.1.0

Definition at line 425 of file telnet.h.

◆ DEFAULT_IDLE_TIMEOUT

constexpr unsigned long uuid::telnet::TelnetService::DEFAULT_IDLE_TIMEOUT = 600
staticconstexpr

Default initial idle timeout (in seconds).

Since
0.1.0

Definition at line 234 of file telnet.h.

◆ DEFAULT_PORT

constexpr uint16_t uuid::telnet::TelnetService::DEFAULT_PORT = 23
staticconstexpr

Default TCP port to listen on.

Since
0.1.0

Definition at line 233 of file telnet.h.

◆ DEFAULT_WRITE_TIMEOUT

constexpr unsigned long uuid::telnet::TelnetService::DEFAULT_WRITE_TIMEOUT = 0
staticconstexpr

Default write timeout (in milliseconds). @ since 0.1.0

Definition at line 235 of file telnet.h.

◆ initial_idle_timeout_

unsigned long uuid::telnet::TelnetService::initial_idle_timeout_ = DEFAULT_IDLE_TIMEOUT
private

Initial idle timeout (in seconds).

Since
0.1.0

Definition at line 427 of file telnet.h.

◆ logger_

uuid::log::Logger uuid::telnet::TelnetService::logger_ {FPSTR(__pstr__logger_name), uuid::log::Facility::DAEMON}
staticprivate

uuid::log::Logger instance for telnet services.

Since
0.1.0

Definition at line 421 of file telnet.h.

◆ MAX_CONNECTIONS

constexpr size_t uuid::telnet::TelnetService::MAX_CONNECTIONS = 3
staticconstexpr

Maximum number of concurrent open connections.

Since
0.1.0

Definition at line 232 of file telnet.h.

◆ maximum_connections_

size_t uuid::telnet::TelnetService::maximum_connections_ = MAX_CONNECTIONS
private

Maximum number of concurrent open connections.

Since
0.1.0

Definition at line 424 of file telnet.h.

◆ server_

WiFiServer uuid::telnet::TelnetService::server_
private

TCP server.

Since
0.1.0

Definition at line 423 of file telnet.h.

◆ shell_factory_

shell_factory_function uuid::telnet::TelnetService::shell_factory_
private

Function to create a shell.

Since
0.1.0

Definition at line 426 of file telnet.h.

◆ write_timeout_

unsigned long uuid::telnet::TelnetService::write_timeout_ = DEFAULT_WRITE_TIMEOUT
private

Write timeout (in milliseconds).

Since
0.1.0

Definition at line 428 of file telnet.h.


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