60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
#ifndef BEERSERVICE_H
|
|
#define BEERSERVICE_H
|
|
|
|
#include <QObject>
|
|
#include <QtWebSockets/QWebSocket>
|
|
|
|
#include "services/dumpservice.h"
|
|
|
|
class SettingsService;
|
|
class BeerService : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
|
|
|
|
public:
|
|
static BeerService *instance()
|
|
{
|
|
static BeerService i;
|
|
return &i;
|
|
}
|
|
|
|
enum Action
|
|
{
|
|
ActionUndefined = 0,
|
|
ActionGet,
|
|
ActionAdd,
|
|
ActionDelete,
|
|
ActionModify
|
|
};
|
|
|
|
void sendCommand(const QString &entity, Action action, const QVariantMap &data = QVariantMap());
|
|
void connectListener(QObject *listener);
|
|
void removeListener(QObject *listener);
|
|
|
|
signals:
|
|
void connectedChanged();
|
|
|
|
private:
|
|
BeerService();
|
|
~BeerService();
|
|
|
|
SettingsService *settings() const;
|
|
|
|
void restoreStash();
|
|
|
|
void reconnect();
|
|
void sendCommand(const QVariantMap &command);
|
|
bool connected() const;
|
|
|
|
QMultiMap<QString, QObject *> m_listeners;
|
|
|
|
DumpService m_dumpService;
|
|
QWebSocket m_socket;
|
|
QVariantList m_commandStash;
|
|
QMap<Action, QString> m_actions;
|
|
};
|
|
|
|
#endif // BEERSERVICE_H
|