SoundBand/Sync/node.h

104 lines
2.1 KiB
C
Raw Normal View History

2017-11-06 01:33:16 +03:00
#ifndef NODE_H
#define NODE_H
#include <QTcpServer>
2017-11-18 01:29:14 +03:00
#include "ETcpSocket.h"
2018-08-16 09:13:18 +03:00
#include <QTimer>
#include "basepackage.h"
#include "syncpackage.h"
#include "sync_global.h"
2017-11-24 21:17:41 +03:00
2017-11-20 00:37:12 +03:00
/**
2018-08-16 09:13:18 +03:00
* @brief The Node class is tcp server class
2017-11-11 14:03:14 +03:00
*/
class SYNCSHARED_EXPORT Node:public QTcpServer{
2017-11-06 01:33:16 +03:00
Q_OBJECT
2018-08-16 09:13:18 +03:00
private:
QTimer *timer;
int index;
2017-11-06 01:33:16 +03:00
protected:
2017-11-18 01:29:14 +03:00
QList<ETcpSocket*> clients;
2018-08-16 09:13:18 +03:00
bool fBroadcaster;
int step;
2017-11-06 01:33:16 +03:00
private slots:
2018-08-16 09:13:18 +03:00
void synced();
2017-11-18 01:29:14 +03:00
void acceptError_(ETcpSocket*);
2017-11-06 01:33:16 +03:00
void newConnection_();
2017-11-18 01:29:14 +03:00
void readData(ETcpSocket*_client);
2017-11-06 01:33:16 +03:00
public:
Node(const QString &addres = DEFAULT_ADRESS, int port = DEFAULT_PORT);
2018-08-16 09:13:18 +03:00
/**
* @brief isBroadcaster
* @return true if this node is server
*/
bool isBroadcaster()const;
/**
* @brief setBroadcaster set new state for this node
*/
void setBroadcaster(bool newValue);
/**
* @brief WriteAll send package to all connected clients
*/
2017-11-06 01:33:16 +03:00
void WriteAll(const QByteArray&);
2018-08-16 09:13:18 +03:00
/**
* @brief disconnectClient disconet a client
*/
2017-11-18 01:29:14 +03:00
void disconnectClient(ETcpSocket*);
2018-08-16 09:13:18 +03:00
/**
* @brief getClients
* @return list of all connected clients
*/
2017-11-18 01:29:14 +03:00
QList<ETcpSocket*>* getClients();
2018-08-16 09:13:18 +03:00
/**
* @brief addNode add new client for network
* @param node if of node
* @param port port of node
* @return true if all done
*/
2017-11-27 19:43:11 +03:00
bool addNode(const QString &node, int port);
2018-08-16 09:13:18 +03:00
/**
* @brief addNode a connected node
* @param node tcp socket
* @return true if all done
*/
2017-11-18 01:29:14 +03:00
bool addNode(ETcpSocket* node);
2018-08-16 09:13:18 +03:00
2017-11-11 20:35:30 +03:00
~Node();
2017-11-06 01:33:16 +03:00
signals:
2018-08-16 09:13:18 +03:00
/**
* @brief Error signal when a error detected
*/
2017-11-06 01:33:16 +03:00
void Error(QString);
2018-08-16 09:13:18 +03:00
/**
* @brief Message signal when accepted a mewssage from other node
*/
2017-11-22 20:05:53 +03:00
void Message(ETcpSocket*);
2018-08-16 09:13:18 +03:00
/**
* @brief ClientDisconnected - signal when node disconected from this node
*/
2017-11-18 01:29:14 +03:00
void ClientDisconnected(ETcpSocket*);
2018-08-16 09:13:18 +03:00
/**
* @brief ClientConnected signal when connected a new node
*/
2017-11-18 01:29:14 +03:00
void ClientConnected(ETcpSocket*);
2018-08-16 09:13:18 +03:00
/**
* @brief NodeSynced emited when socket synced
*/
void NodeSynced(ETcpSocket*);
2017-11-06 01:33:16 +03:00
};
#endif // NODE_H