#include <GXmlDirectNetwork.h>
Inheritance diagram for GWE::GXmlDirectNetwork:


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 |
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.
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.
| GWE::GXmlDirectNetwork::GXmlDirectNetwork | ( | QString | networkid, | |
| QString | master, | |||
| int | port = 7471, |
|||
| QObject * | parent = NULL | |||
| ) |
Constructor.
| 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.
| 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] |
| QString GWE::GXmlDirectNetwork::getNetworkId | ( | ) | const [virtual] |
| bool GWE::GXmlDirectNetwork::initNetwork | ( | ) | [virtual, slot] |
Initialization.
Implements GWE::GXmlNetwork.
| bool GWE::GXmlDirectNetwork::isConnected | ( | ) | [virtual] |
| bool GWE::GXmlDirectNetwork::isDestinationAvailable | ( | const QString & | destination | ) | [slot] |
| 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!
| 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 |
| 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.
| 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.
| data | The data that will be sent to the given network destination. | |
| destination | The GWE Server to which the data should be sent to. |
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.
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.
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.
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.
1.4.7