2017-10-29 14:47:36 +03:00
|
|
|
#ifndef SYNC_H
|
|
|
|
#define SYNC_H
|
2017-11-12 13:26:37 +03:00
|
|
|
#include "song.h"
|
2017-11-20 00:37:12 +03:00
|
|
|
#include "node.h"
|
2017-11-22 22:34:55 +03:00
|
|
|
#include "LocalScanner.h"
|
2017-11-12 13:26:37 +03:00
|
|
|
#include <chrono>
|
2017-11-09 23:09:59 +03:00
|
|
|
class QSqlDatabase;
|
|
|
|
class QMediaPlayer;
|
|
|
|
class QSqlQuery;
|
2017-10-29 14:47:36 +03:00
|
|
|
namespace syncLib {
|
2017-11-09 23:09:59 +03:00
|
|
|
|
2017-11-12 13:26:37 +03:00
|
|
|
typedef std::chrono::time_point<std::chrono::high_resolution_clock> Clock;
|
|
|
|
|
2017-11-09 23:09:59 +03:00
|
|
|
class Node;
|
2017-11-11 20:35:30 +03:00
|
|
|
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief The Sync class is main class of this library.
|
|
|
|
* the 'sync' has supported synced playning media files on network and saving media data into local database.
|
|
|
|
*/
|
2017-11-22 20:05:53 +03:00
|
|
|
class Sync : public QObject
|
2017-10-29 14:47:36 +03:00
|
|
|
{
|
2017-11-22 20:05:53 +03:00
|
|
|
Q_OBJECT
|
2017-10-29 14:47:36 +03:00
|
|
|
private:
|
2017-11-09 23:09:59 +03:00
|
|
|
Node *node;
|
|
|
|
QSqlDatabase *db;
|
|
|
|
QMediaPlayer *player;
|
2017-11-20 00:37:12 +03:00
|
|
|
QList<SongHeader>* playList;
|
2017-11-09 23:09:59 +03:00
|
|
|
QSqlQuery *qyery;
|
2017-11-22 20:05:53 +03:00
|
|
|
QList<ETcpSocket*> servers;
|
2017-11-20 00:37:12 +03:00
|
|
|
bool fbroadcaster;
|
2017-11-22 22:34:55 +03:00
|
|
|
LocalScanner deepScaner;
|
2017-11-22 20:05:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief rescan - search for existing servers
|
|
|
|
* result saved in servers
|
|
|
|
*/
|
2017-11-22 22:34:55 +03:00
|
|
|
void rescan(bool deep = false);
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief initDB initialize local database of song
|
|
|
|
*/
|
2017-11-09 23:09:59 +03:00
|
|
|
void initDB();
|
2017-11-20 00:37:12 +03:00
|
|
|
/**
|
|
|
|
* @brief load song of database;
|
|
|
|
* @brief song -
|
|
|
|
* @brief result - the resulting value;
|
|
|
|
* @return true if everything's done
|
|
|
|
*/
|
|
|
|
bool load(const SongHeader &song, Song &result);
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
2017-11-11 20:35:30 +03:00
|
|
|
* @brief save media data into local database.
|
2017-11-11 14:03:14 +03:00
|
|
|
* @param song savining media data.
|
2017-11-11 20:35:30 +03:00
|
|
|
* @return id of song saved on local database.
|
|
|
|
*/
|
|
|
|
int save(const Song &song);
|
|
|
|
/**
|
|
|
|
* @brief fromDataBase return a song from local database by id.
|
|
|
|
* @param id of song saved in local database.
|
|
|
|
* @return song drom local database.
|
2017-11-11 14:03:14 +03:00
|
|
|
*/
|
2017-11-11 20:35:30 +03:00
|
|
|
Song fromDataBase(const int id);
|
2017-11-12 13:26:37 +03:00
|
|
|
/**
|
|
|
|
* @brief now - get now time on microsecunds
|
|
|
|
* @return - count of microsecunds
|
|
|
|
*/
|
2017-11-20 00:37:12 +03:00
|
|
|
milliseconds now();
|
2017-11-12 13:26:37 +03:00
|
|
|
/**
|
|
|
|
* @brief from cast to chrono secunds
|
|
|
|
* @param mcrs microseconds of uint_64
|
|
|
|
* @return microseconds of chrono
|
|
|
|
*/
|
2017-11-20 00:37:12 +03:00
|
|
|
Clock from(const milliseconds &mcrs);
|
|
|
|
/**
|
|
|
|
* @brief createPackage - Create a package that shows current state of the node
|
|
|
|
* @param type - Type of an answer
|
|
|
|
* @param pac - the resulting value
|
|
|
|
* @return true if everything's done
|
|
|
|
*/
|
|
|
|
bool createPackage(TypePackage type ,package& pac);
|
2017-11-22 20:05:53 +03:00
|
|
|
private slots:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief packageRender - the handler of all messages received.
|
|
|
|
* @param socket
|
|
|
|
*/
|
|
|
|
void packageRender(ETcpSocket* socket);
|
2017-11-22 22:34:55 +03:00
|
|
|
/**
|
|
|
|
* @brief deepScaned scaning in local network
|
|
|
|
*/
|
|
|
|
void deepScaned(QList<ETcpSocket *> *);
|
2017-11-22 20:05:53 +03:00
|
|
|
|
2017-10-29 14:47:36 +03:00
|
|
|
public:
|
2017-11-20 00:37:12 +03:00
|
|
|
/**
|
|
|
|
* @brief Play song in this device, if device has not supported playning media data this method throw MediaExcrption.
|
|
|
|
* @param header of song
|
|
|
|
* @param syncdata data of synbced playning of media data.
|
|
|
|
* @return true if all done else false.
|
|
|
|
*/
|
|
|
|
bool Play(SongHeader &header, Syncer* syncdata = nullptr);
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Play song in this device, if device has not supported playning media data this method throw MediaExcrption.
|
|
|
|
* @param song playning media data.
|
|
|
|
* @param syncdata data of synbced playning of media data.
|
|
|
|
* @return true if all done else false.
|
|
|
|
*/
|
2017-11-12 13:26:37 +03:00
|
|
|
bool Play(Song &song, Syncer* syncdata = nullptr);
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Play song from local media file.
|
|
|
|
* @param url of local media file.
|
|
|
|
* @return true if all done else false.
|
|
|
|
*/
|
2017-11-11 20:35:30 +03:00
|
|
|
bool Play(QString url);
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Play song from local database by id.
|
|
|
|
* @param id_song of song.
|
|
|
|
* @return true if all done else false.
|
|
|
|
*/
|
2017-11-20 00:37:12 +03:00
|
|
|
bool Play(int id_song, Syncer* syncdata = nullptr);
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief Pause playning song.
|
|
|
|
*/
|
2017-11-11 20:35:30 +03:00
|
|
|
void Pause();
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief stop playning song.
|
|
|
|
*/
|
2017-11-11 20:35:30 +03:00
|
|
|
void stop();
|
2017-11-11 14:03:14 +03:00
|
|
|
/**
|
|
|
|
* @brief jump - jump to new position of playning media data.
|
|
|
|
* @param seek - a new position of media data.
|
|
|
|
*/
|
2017-11-11 20:35:30 +03:00
|
|
|
void jump(const int seek);
|
2017-11-20 00:37:12 +03:00
|
|
|
/**
|
|
|
|
* @brief sync with server
|
|
|
|
* @param sync - data of sync
|
|
|
|
*/
|
|
|
|
bool sync(const Syncer& sync);
|
2017-10-29 14:47:36 +03:00
|
|
|
Sync();
|
|
|
|
~Sync();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // SYNC_H
|