SoundBand/sync/node.h

92 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-13 23:05:59 +03:00
#include <song.h>
2017-11-11 14:03:14 +03:00
class Syncer;
2017-11-06 01:33:16 +03:00
namespace syncLib {
2017-11-11 14:03:14 +03:00
/**
* @brief The package class. Package for translite media data on network
*
* parse map:
* 1 byle - type
* 4 byte - size of data of package (it avelable if type is t_sync or t_song)
* data
*/
2017-11-06 01:33:16 +03:00
class package
{
2017-11-06 13:20:52 +03:00
/*parse map */
/*
* 1 byle - type
* 4 byte - size of data of package (it avelable if type is t_sync or t_song)
* data
*/
2017-11-11 14:03:14 +03:00
/**
* @brief The TypePackage enum
* t_void - this package empty and not valid.
* t_close - the information about close channel.
* t_sync - the infomation about sync playning media file on network.
* t_song - the package with this type is necessary for translite media data on network.
* t_stop - the package with type 'stop' necessary for stoping playning media files.
*/
2017-11-06 01:33:16 +03:00
enum TypePackage{
t_void = 0x0,
t_close = 0x1,
t_sync = 0x2,
t_song = 0x4,
t_stop = 0x8
};
private:
TypePackage type;
2017-11-06 13:20:52 +03:00
unsigned int size;
2017-11-06 01:33:16 +03:00
Song source;
2017-11-11 14:03:14 +03:00
Syncer playdata;
2017-11-06 01:33:16 +03:00
public:
package();
package(const QByteArray& array);
~package();
2017-11-11 14:03:14 +03:00
/**
* @brief getSong
* @return Song
*/
2017-11-06 01:33:16 +03:00
const Song& getSong() const;
2017-11-11 14:03:14 +03:00
/**
* @brief getPlayTime
* @return time of playning media data
*/
Syncer getPlayData() const;
2017-11-13 23:05:59 +03:00
TypePackage getType() const;
2017-11-06 01:33:16 +03:00
bool isValid() const;
2017-11-13 23:05:59 +03:00
QByteArray parseTo();
2017-11-06 01:33:16 +03:00
bool parseFrom(const QByteArray& array);
};
class Node:public QTcpServer{
Q_OBJECT
protected:
QList<QTcpSocket*> clients;
private slots:
void acceptError_(QTcpSocket*);
void newConnection_();
void readData(QTcpSocket*_client);
public:
2017-11-11 20:35:30 +03:00
Node();
2017-11-06 01:33:16 +03:00
void WriteAll(const QByteArray&);
void disconnectClient(QTcpSocket*);
QList<QTcpSocket*>* getClients();
2017-11-09 23:09:59 +03:00
bool addNode(const QString &node, int port = DEDAULT_PORT);
bool addNode(QTcpSocket* node);
2017-11-11 20:35:30 +03:00
~Node();
2017-11-06 01:33:16 +03:00
signals:
void Error(QString);
void Message(QTcpSocket*);
void ClientDisconnected(QTcpSocket*);
void ClientConnected(QTcpSocket*);
};
}
#endif // NODE_H