GWE::GXmlDirectNetwork Class Reference

XML Network implementation, using direct TCP connections. More...

#include <GXmlDirectNetwork.h>

Inheritance diagram for GWE::GXmlDirectNetwork:

Inheritance graph
[legend]
Collaboration diagram for GWE::GXmlDirectNetwork:

Collaboration graph
[legend]
List of all members.

Public Slots

void setNetworkId (const QString &id)
void setMasterServer (const QString &master)
bool initNetwork ()
bool closeNetwork ()
void setPassword (const QString &password)
bool send (QDomElement data, const QString &destination)
bool send (const QString &data)
bool flushOutput ()
void makeDestinationAvailable (const QString &destination)
bool isDestinationAvailable (const QString &destination)

Public Member Functions

 GXmlDirectNetwork (QString networkid, QString master, int port=7471, QObject *parent=NULL)
virtual ~GXmlDirectNetwork ()
bool isConnected ()
QString getNetworkId () const
QString getMasterServer () const

Protected Slots

void socketError (QAbstractSocket::SocketError socketError)
void socketDisconnected ()
void processPendingClientConnection ()
void receiveData ()
void sendQueuedMessages (QString destination)
void socketConnected ()

Protected Member Functions

void removeConnection (const QString &destination)
void connectSocketSignals (QTcpSocket *socket)
QByteArray readSection (QIODevice *datasource, const QByteArray &begin, const QByteArray &ending)

Protected Attributes

QString NetworkID
QString MasterServer
QTcpServer Server
QMap< QString, GXmlDirectNetworkConnection * > Connections
QMap< const QTcpSocket *,
GXmlDirectNetworkConnection * > 
IncomingConnections
QMap< const QTcpSocket *,
QString > 
SocketNameMapping
GNetworkMessageQueue MessageQueue
int Port
QMutex ReceiveMutex

Detailed Description

XML Network implementation, using direct TCP connections.

Author:
Raphael Langerhorst
This type of xml network can be used as a simpler replacement for XMPP networks, or when XMPP networks are not applicable.

GXmlDirectNetwork uses a TCP server socket to allow other world engines to connect to this server and uses a TCP client sockets to connect to other servers.

Please note that server identification is done with strings. These strings are interpreted as FQDN (fully qualified domain name). Names given for peer GWE Servers must be resolvable by the DNS.

This implementation does not use passwords or any kind of authentication! Use GXmppNetwork if you want security.

Note:
It is recommended to use GXmpNetwork instead of this one. Only use GXmlDirectNetwork if using XMPP is not applicable or possible.

It might be possible to even use this class as a gateway between direct connections and the XMPP network by directly connecting to a XMPP/jabber server. This use case is not yet investigated, but it should be possible to tweak this class without too much difficulty.

Do not use the networkConnected signal, a connection to the master server is only established when a message is sent there. Look at the GxmlDataController constructor to see how to work around this.

See also:
GXmppNetwork
Todo:
don't receive data here, but in the connection itself which also can handle message buffers.
Bug:
Potential data loss under high load because messages need to come in one complete TCP frame, fix by implementing buffers for each connection


Constructor & Destructor Documentation

GWE::GXmlDirectNetwork::GXmlDirectNetwork ( QString  networkid,
QString  master,
int  port = 7471,
QObject *  parent = NULL 
)

Constructor.

Parameters:
networkid server name of this server, usually the fqdn.
master server name of the master server, usually the fqdn.
port TCP/IP port for network connections.
parent QObject parent

GWE::GXmlDirectNetwork::~GXmlDirectNetwork (  )  [virtual]

Virtual Destructor.


Member Function Documentation

bool GWE::GXmlDirectNetwork::closeNetwork (  )  [virtual, slot]

Shuts down the network. This should be called when the GWE Server is shutting down, and AFTER all required tasks were performed to allow safe shutdown (moving data to other server, etc.).

Implements GWE::GXmlNetwork.

void GWE::GXmlDirectNetwork::connectSocketSignals ( QTcpSocket *  socket  )  [protected]

Connects various socket signals to slots in GXmlDirectNetwork, required for noticing available data and socket errors.

bool GWE::GXmlDirectNetwork::flushOutput (  )  [virtual, slot]

Send all pending output data. This call blocks until all data was sent.

Implements GWE::GXmlNetwork.

QString GWE::GXmlDirectNetwork::getMasterServer (  )  const [virtual]

Returns:
the network ID of this GWE Server instance.

Implements GWE::GXmlNetwork.

QString GWE::GXmlDirectNetwork::getNetworkId (  )  const [virtual]

Returns:
the network ID of this GWE Server instance.

Implements GWE::GXmlNetwork.

bool GWE::GXmlDirectNetwork::initNetwork (  )  [virtual, slot]

Initialization.

Implements GWE::GXmlNetwork.

bool GWE::GXmlDirectNetwork::isConnected (  )  [virtual]

Returns:
true when the network is connected and usable, otherwise false

Implements GWE::GXmlNetwork.

bool GWE::GXmlDirectNetwork::isDestinationAvailable ( const QString &  destination  )  [slot]

Returns:
true if given destination is connected and available.

void GWE::GXmlDirectNetwork::makeDestinationAvailable ( const QString &  destination  )  [virtual, slot]

Try to establish a connection to given destination.

Implements GWE::GXmlNetwork.

void GWE::GXmlDirectNetwork::processPendingClientConnection (  )  [protected, slot]

Checks the Server for pending client connections and inserts them into the Connection map. Please note that this behaviour means that there is practically no difference between connections established from this host or incoming connections.

QByteArray GWE::GXmlDirectNetwork::readSection ( QIODevice *  datasource,
const QByteArray &  begin,
const QByteArray &  ending 
) [protected]

Reads from datasource from begin up to and including ending pattern. Please note that all data before the begin pattern is silently skipped!

Parameters:
datasource the IO Device from which data should be read
begin the patterm (clear text, no regexp) from which reading begins
ending the pattern (clear text, no regexp) after which reading is stopped
Returns:
all bytes read from first occurance of begin up to and including the first occurance of ending, or until no more data is available.

void GWE::GXmlDirectNetwork::receiveData (  )  [protected, slot]

When a connection has data available for reading, receiveData() is called. The correct socket is determined by QObject::sender() The read data is make available through the dataAvailable() signal.

Todo:
this is a hack to avoid high traffic on incoming connections

void GWE::GXmlDirectNetwork::removeConnection ( const QString &  destination  )  [protected]

Removes socket with given destination from Connections and deletes the socket (with deleteLater).

bool GWE::GXmlDirectNetwork::send ( const QString &  data  )  [virtual, slot]

Given string is directly sent, it's the responsibility of the application to make it XML compliant.

Implements GWE::GXmlNetwork.

bool GWE::GXmlDirectNetwork::send ( QDomElement  data,
const QString &  destination 
) [virtual, slot]

Add data for transportation. It is up to the network implementation when the data is actually sent.

If given destination is not yet available, the message is added to the message queue for given destination and establishing a connection to the destination is attempted. As soon as the destination gets available, all queued messages are sent.

Parameters:
data The data that will be sent to the given network destination.
destination The GWE Server to which the data should be sent to.
See also:
flushOutput(), makeDestinationAvailable()

Implements GWE::GXmlNetwork.

void GWE::GXmlDirectNetwork::sendQueuedMessages ( QString  destination  )  [protected, slot]

Checks if any messages are queued for given destination and sends all queued messages.

void GWE::GXmlDirectNetwork::setMasterServer ( const QString &  master  )  [virtual, slot]

Sets the ID of the master server.

Implements GWE::GXmlNetwork.

void GWE::GXmlDirectNetwork::setNetworkId ( const QString &  id  )  [virtual, slot]

Sets the ID of this server.

Implements GWE::GXmlNetwork.

void GWE::GXmlDirectNetwork::setPassword ( const QString &  password  )  [virtual, slot]

Sets the password to be used

Implements GWE::GXmlNetwork.

void GWE::GXmlDirectNetwork::socketConnected (  )  [protected, slot]

Called when a connection was successfully established. This will also check for queued messages by calling sendQueuedMessages().

void GWE::GXmlDirectNetwork::socketDisconnected (  )  [protected, slot]

Listens for disconnecting signals from connections and removes such connections.

void GWE::GXmlDirectNetwork::socketError ( QAbstractSocket::SocketError  socketError  )  [protected, slot]

Listens for socket errors and removes these sockets.


Member Data Documentation

QMap<QString,GXmlDirectNetworkConnection*> GWE::GXmlDirectNetwork::Connections [protected]

Map with direct TCP connections to other servers.

QMap<const QTcpSocket*,GXmlDirectNetworkConnection*> GWE::GXmlDirectNetwork::IncomingConnections [protected]

Connections that still need to be identified. They are not made available to the GWE before they have successfully identified.

QString GWE::GXmlDirectNetwork::MasterServer [protected]

The identification of the master server. This server is always a client to the master server, in other words, this server is a child of the master server.

The master GWE Server is one level higher in the network hierarchy. If it is an empty string it means that THIS server is the highest in the hierarchy.

If a master server is given on initialization, then it is contacted after a successfull network initialization. This is usually done by the data controller and not by GXmlDirectNetwork itself.

See also:
NetworkID

GNetworkMessageQueue GWE::GXmlDirectNetwork::MessageQueue [protected]

Message queue that can store messages until a connection to a server is established.

QString GWE::GXmlDirectNetwork::NetworkID [protected]

Name of this server. Usually the FQDN.

int GWE::GXmlDirectNetwork::Port [protected]

The port on which the Server should listen and on which client connections are established.

QMutex GWE::GXmlDirectNetwork::ReceiveMutex [protected]

Used to serialize incoming messages and avoid parallel message processing.

Note:
this might not be necessary and may be removed when receiving is really thread-safe

QTcpServer GWE::GXmlDirectNetwork::Server [protected]

The server socket, this can be used by other GWE servers to connect to this server.

QMap<const QTcpSocket*,QString> GWE::GXmlDirectNetwork::SocketNameMapping [protected]

Can be used to get the connection name from the socket pointer. Important for slots connected to QTcpSocket signals to be able to get the actual connection object.


The documentation for this class was generated from the following files:
Generated on Thu Nov 16 07:49:40 2006 for G System by  doxygen 1.4.7