trikRuntime
trikNetwork::MailboxInterface Class Referenceabstract

Allows communication between robots. More...

#include <mailboxInterface.h>

Inheritance diagram for trikNetwork::MailboxInterface:
Collaboration diagram for trikNetwork::MailboxInterface:

Public Slots

virtual void connect (const QString &ip, int port)=0
 Connects to robot by IP and port. More...
 
virtual void connect (const QString &ip)=0
 Connects to robot by IP and uses port of local mailbox server as a port on remote robot. More...
 
virtual void send (int hullNumber, const QString &message)=0
 Sends message to a robot with given hull number. More...
 
virtual void send (const QString &message)=0
 Sends message to all known robots. More...
 
virtual bool hasMessages ()=0
 Returns true if there are incoming messages. Returns immediately. More...
 
virtual void renewIp ()=0
 Tries to get renewed IP address. More...
 
virtual QString receive (bool wait=true)=0
 Receives and returns one incoming message. More...
 
virtual int myHullNumber () const =0
 Returns hull number of this robot. More...
 

Signals

void newMessage (int sender, const QString &message)
 Emitted when new message is received from a robot with given hull number. More...
 
void connectionStatusChanged (bool connected)
 Emitted when a mailbox either receives the first connection (connected == true) or loses the last one. More...
 

Public Member Functions

virtual bool isConnected () const =0
 Returns true if at least one opened mailbox connection presents at the moment. More...
 
virtual void setHullNumber (int myHullNumber)=0
 Sets hull number of this robot and sends a message to update hull number to all known robots. More...
 
virtual QHostAddress serverIp () const =0
 Returns IP of a leader robot, or empty QHostAddress if we are not connected. More...
 
virtual QHostAddress myIp () const =0
 Returns our IP address, or empty QHostAddress if we are not connected. More...
 
virtual void clearQueue ()=0
 Clears message queue. More...
 
virtual void stopWaiting ()=0
 Stops waiting for messages. More...
 
virtual bool isEnabled ()=0
 Returns true if mailbox is enabled in current configuration. More...
 

Detailed Description

Allows communication between robots.

Each robot has its hull number (assigned in "Settings->Comm settings" in GUI), and can connect to other robot (called "leader") by IP, if they are in the same subnet (it is also can be done in "Settings->Comm settings", or from script by connect() method). Then robot can send messages to every robot that is connected to a leader (or to a robot that is connected to a robot that is connected to a leader, and so on). Recipients are identified by their hull numbers, if two or more robots in a network have the same hull number, they will all receive a message.

Member Function Documentation

virtual void trikNetwork::MailboxInterface::clearQueue ( )
pure virtual

Clears message queue.

Implemented in trikNetwork::Mailbox.

virtual void trikNetwork::MailboxInterface::connect ( const QString &  ip,
int  port 
)
pure virtualslot

Connects to robot by IP and port.

virtual void trikNetwork::MailboxInterface::connect ( const QString &  ip)
pure virtualslot

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

void trikNetwork::MailboxInterface::connectionStatusChanged ( bool  connected)
signal

Emitted when a mailbox either receives the first connection (connected == true) or loses the last one.

virtual bool trikNetwork::MailboxInterface::hasMessages ( )
pure virtualslot

Returns true if there are incoming messages. Returns immediately.

virtual bool trikNetwork::MailboxInterface::isConnected ( ) const
pure virtual

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

Implemented in trikNetwork::Mailbox.

virtual bool trikNetwork::MailboxInterface::isEnabled ( )
pure virtual

Returns true if mailbox is enabled in current configuration.

Implemented in trikNetwork::Mailbox.

virtual int trikNetwork::MailboxInterface::myHullNumber ( ) const
pure virtualslot

Returns hull number of this robot.

virtual QHostAddress trikNetwork::MailboxInterface::myIp ( ) const
pure virtual

Returns our IP address, or empty QHostAddress if we are not connected.

Implemented in trikNetwork::Mailbox.

void trikNetwork::MailboxInterface::newMessage ( int  sender,
const QString &  message 
)
signal

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

Note that if receive() and handler for newMessage() is used simultaneously, message will be delivered twice — first for receive(), then to handler (or handlers).

virtual QString trikNetwork::MailboxInterface::receive ( bool  wait = true)
pure virtualslot

Receives and returns one incoming message.

If there is already a message in a queue, returns immediately, otherwise blocks until a message is received. Note that if receive() and handler for newMessage() is used simultaneously, message will be delivered twice — first for receive(), then to handler (or handlers).

Parameters
wait- if false, doesn't wait for new messages and returns empty string if message queue is empty
virtual void trikNetwork::MailboxInterface::renewIp ( )
pure virtualslot

Tries to get renewed IP address.

virtual void trikNetwork::MailboxInterface::send ( int  hullNumber,
const QString &  message 
)
pure virtualslot

Sends message to a robot with given hull number.

virtual void trikNetwork::MailboxInterface::send ( const QString &  message)
pure virtualslot

Sends message to all known robots.

virtual QHostAddress trikNetwork::MailboxInterface::serverIp ( ) const
pure virtual

Returns IP of a leader robot, or empty QHostAddress if we are not connected.

Implemented in trikNetwork::Mailbox.

virtual void trikNetwork::MailboxInterface::setHullNumber ( int  myHullNumber)
pure virtual

Sets hull number of this robot and sends a message to update hull number to all known robots.

Implemented in trikNetwork::Mailbox.

virtual void trikNetwork::MailboxInterface::stopWaiting ( )
pure virtual

Stops waiting for messages.

Implemented in trikNetwork::Mailbox.


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