2016-09-04 09:01:44 -04:00
|
|
|
/*
|
|
|
|
* libresapi local socket client
|
2016-09-15 07:07:13 -04:00
|
|
|
* Copyright (C) 2016 Gioacchino Mazzurco <gio@eigenlab.org>
|
2016-09-04 09:01:44 -04:00
|
|
|
* Copyright (C) 2016 Manu Pineda <manu@cooperativa.cat>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LIBRESAPILOCALCLIENT_H
|
|
|
|
#define LIBRESAPILOCALCLIENT_H
|
|
|
|
|
|
|
|
#include <QLocalSocket>
|
2016-12-08 09:56:23 -05:00
|
|
|
#include <QQueue>
|
|
|
|
#include <QJSValue>
|
2016-09-04 09:01:44 -04:00
|
|
|
|
|
|
|
class LibresapiLocalClient : public QObject
|
|
|
|
{
|
2016-09-15 07:07:13 -04:00
|
|
|
Q_OBJECT
|
2016-09-04 09:01:44 -04:00
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
public:
|
|
|
|
LibresapiLocalClient() : mLocalSocket(this) {}
|
2016-09-04 09:01:44 -04:00
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
Q_INVOKABLE int request( const QString& path, const QString& jsonData = "",
|
|
|
|
QJSValue callback = QJSValue::NullValue);
|
2016-09-15 07:07:13 -04:00
|
|
|
Q_INVOKABLE void openConnection(QString socketPath);
|
2016-09-04 09:01:44 -04:00
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
private:
|
|
|
|
QLocalSocket mLocalSocket;
|
2016-12-08 09:56:23 -05:00
|
|
|
QQueue<QJSValue> callbackQueue;
|
2016-09-04 09:01:44 -04:00
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
private slots:
|
|
|
|
void socketError(QLocalSocket::LocalSocketError error);
|
|
|
|
void read();
|
2016-09-04 09:01:44 -04:00
|
|
|
|
2016-09-15 07:07:13 -04:00
|
|
|
signals:
|
2016-12-08 09:56:23 -05:00
|
|
|
/// @deprecated @see LibresapiLocalClient::responseReceived instead
|
|
|
|
void goodResponseReceived(const QString & msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief responseReceived emitted when a response is received
|
|
|
|
* @param msg
|
|
|
|
*/
|
|
|
|
void responseReceived(const QString & msg);
|
2016-09-04 09:01:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LIBRESAPILOCALCLIENT_H
|