defuze.me
Client
|
00001 /************************************************************************** 00002 ** defuze.me Epitech Innovative Project 00003 ** 00004 ** Copyright 2010-2011 00005 ** Athena Calmettes - Jocelyn De La Rosa - Francois Gaillard 00006 ** Adrien Jarthon - Alexandre Moore - Luc Peres - Arnaud Sellier 00007 ** 00008 ** All rights reserved. 00009 **************************************************************************/ 00010 00011 namespace WebService { 00012 class ServiceSync; 00013 } 00014 00015 #ifndef SERVICESYNC_HPP 00016 #define SERVICESYNC_HPP 00017 00018 #include <QLinkedList> 00019 #include <QBuffer> 00020 #include <QMutex> 00021 #include "staticplugin.hpp" 00022 #include "playqueue.hpp" 00023 #include "parameterizable.hpp" 00024 #include "servicerequest.hpp" 00025 #include "playqueue.hpp" 00026 #include "websocket.hpp" 00027 00028 namespace WebService 00029 { 00033 class ServiceSync : public Params::Parameterizable, public StaticPlugin 00034 { 00035 Q_OBJECT 00036 friend class ServiceRequest; 00037 00038 public: 00039 ServiceSync(); 00040 ~ServiceSync(); 00041 void init(); 00042 bool hasRequests() const; 00043 bool isRequesting() const; 00044 ServiceRequest* newRequest(const QString& verb, const QString& url); 00045 00046 private slots: 00047 void sendNextRequest(); 00048 void receiveResponse(); 00049 // Play queue sync slots 00050 void sendPlayQueue(); 00051 void sendRemoveQueueElem(Queue::Queueable*); 00052 void sendAddQueueElem(Queue::Queueable*); 00053 // WebSockets slots 00054 void wsConnect(); 00055 void onMessage(const QByteArray& data); 00056 void onOpen(); 00057 void onClose(const QString& error); 00058 00059 private: 00060 void wsMove(const QVariantMap& data); 00061 void defineParams(); 00062 00063 QLinkedList<ServiceRequest*> requests; 00064 QNetworkReply *reply; 00065 QBuffer buffer; 00066 Queue::PlayQueue* queue; 00067 Network::WebSocket* ws; 00068 int ws_tries, ws_delay; 00069 QMutex sync_mutex; 00070 }; 00071 } 00072 00073 #endif // SERVICESYNC_HPP