trikRuntime
trikNetwork::MailboxServer Class Reference

Worker object for mailbox functionality. More...

#include <mailboxServer.h>

Inheritance diagram for trikNetwork::MailboxServer:
Collaboration diagram for trikNetwork::MailboxServer:

Signals

void newMessage (int senderHullNumber, const QString &message)
 Emitted when new message was received from a robot with given hull number. More...
 
- Signals inherited from trikNetwork::TrikServer
void connected ()
 Emitted when we get the first connection established. More...
 
void disconnected ()
 Emitted when the last connection closes. More...
 

Public Member Functions

 MailboxServer (int port)
 Constructor. More...
 
bool isConnected ()
 Returns true if at least one opened mailbox connection presents at the moment. More...
 
int hullNumber () const
 Returns hull number of this robot. More...
 
QHostAddress serverIp ()
 Returns IP of leader robot to which we connected last. More...
 
QHostAddress myIp () const
 Returns our own IP address or empty QHostAddress if we have none. More...
 
void renewIp ()
 Tries to update our own IP address. More...
 
Q_INVOKABLE void start ()
 Launches server, supposed to be called when mailbox server is already in a separate thread. More...
 
Q_INVOKABLE void setHullNumber (int hullNumber)
 Sets hull number for this robot and notifies all known robots about change. More...
 
Q_INVOKABLE void connect (const QString &ip, int port)
 Connects to robot by IP and port. More...
 
Q_INVOKABLE void connect (const QString &ip)
 Connects to robot by IP and uses port of local mailbox server as a port on remote robot. More...
 
Q_INVOKABLE void send (int hullNumber, const QString &message)
 Sends message to a robot with given hull number. More...
 
Q_INVOKABLE void send (const QString &message)
 Sends message to all known robots. More...
 
Q_INVOKABLE bool hasMessages ()
 Returns true if there are incoming messages. More...
 
Q_INVOKABLE QString receive ()
 Returns one incoming message or empty string if there are none. More...
 
- Public Member Functions inherited from trikNetwork::TrikServer
 TrikServer (const std::function< Connection *()> &connectionFactory)
 Constructor. More...
 
 ~TrikServer () override
 
int activeConnections () const
 Returns number of connections currently opened. More...
 
Q_INVOKABLE void startServer (quint16 port)
 Starts listening given port on all network interfaces. More...
 

Friends

bool operator== (const MailboxServer::Endpoint &left, const MailboxServer::Endpoint &right)
 
QDebug operator<< (QDebug dbg, const Endpoint &endpoint)
 

Additional Inherited Members

- Public Slots inherited from trikNetwork::TrikServer
void sendMessage (const QString &message)
 Broadcasts message across all opened connections. More...
 
- Protected Member Functions inherited from trikNetwork::TrikServer
void incomingConnection (qintptr socketDescriptor) override
 
void startConnection (Connection *connectionWorker)
 Launches given connection in a separate thread. Takes ownership over connectionWorker object. More...
 
Connectionconnection (const QHostAddress &ip, int port) const
 Searches connection to given IP and port in a list of all open connections. More...
 
Connectionconnection (const QHostAddress &ip) const
 Searches connection to given IP and any port in a list of all open connections. More...
 

Detailed Description

Worker object for mailbox functionality.

It is a server that is supposed to be run in a separate thread and it allows to handle a number of connections, keeping them open if possible or attempting to reestablish them if they errored.

Uses localSettings.ini settings file, keys: hullNumber - hull number of this robot. server - IP of a robot we last connected to. serverPort - mailbox port of a robot we last connected to.

Constructor & Destructor Documentation

MailboxServer::MailboxServer ( int  port)

Constructor.

Parameters
port- a port for mailbox server.

Member Function Documentation

void MailboxServer::connect ( const QString &  ip,
int  port 
)

Connects to robot by IP and port.

void MailboxServer::connect ( const QString &  ip)

Connects to robot by IP and uses port of local mailbox server as a port on remote robot.

bool MailboxServer::hasMessages ( )

Returns true if there are incoming messages.

int MailboxServer::hullNumber ( ) const

Returns hull number of this robot.

bool MailboxServer::isConnected ( )

Returns true if at least one opened mailbox connection presents at the moment.

QHostAddress MailboxServer::myIp ( ) const

Returns our own IP address or empty QHostAddress if we have none.

void trikNetwork::MailboxServer::newMessage ( int  senderHullNumber,
const QString &  message 
)
signal

Emitted when new message was received from a robot with given hull number.

QString MailboxServer::receive ( )

Returns one incoming message or empty string if there are none.

void MailboxServer::renewIp ( )

Tries to update our own IP address.

void MailboxServer::send ( int  hullNumber,
const QString &  message 
)

Sends message to a robot with given hull number.

void MailboxServer::send ( const QString &  message)

Sends message to all known robots.

QHostAddress MailboxServer::serverIp ( )

Returns IP of leader robot to which we connected last.

void MailboxServer::setHullNumber ( int  hullNumber)

Sets hull number for this robot and notifies all known robots about change.

void MailboxServer::start ( )

Launches server, supposed to be called when mailbox server is already in a separate thread.

Friends And Related Function Documentation

QDebug operator<< ( QDebug  dbg,
const Endpoint &  endpoint 
)
friend
bool operator== ( const MailboxServer::Endpoint &  left,
const MailboxServer::Endpoint &  right 
)
friend

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