2019-10-14 20:47:18 +02:00
|
|
|
#ifndef __LOKI_LOKINET_API_CLIENT_HPP__
|
|
|
|
#define __LOKI_LOKINET_API_CLIENT_HPP__
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QJSValue>
|
|
|
|
|
|
|
|
#include "HttpClient.hpp"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A client that implements convenience wrappers around making specific
|
|
|
|
* JSON-RPC requests to a lokinet daemon.
|
|
|
|
*
|
|
|
|
* These are meant to be invoked from QML; as such, they each take a `QJSValue`
|
|
|
|
* object which should be a Javascript callback function. This function should
|
|
|
|
* take two parameters: the message payload and an error, e.g.:
|
|
|
|
*
|
|
|
|
* ```javascript
|
|
|
|
* apiClient.llarpAdminStart(function(response, err) {
|
|
|
|
* if (err) {
|
|
|
|
* console.log("Received error when trying to start lokinet daemon: ", err);
|
|
|
|
* }
|
|
|
|
* });
|
|
|
|
* ```
|
2019-10-21 05:21:37 +02:00
|
|
|
*
|
|
|
|
* TODO: abstract this and just take a string as the endpoint. let QML/Javascript
|
|
|
|
* do the JSON-y things.
|
2019-10-14 20:47:18 +02:00
|
|
|
*/
|
|
|
|
class LokinetApiClient : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2019-10-16 17:11:29 +02:00
|
|
|
* Invoke the `llarp.admin.wakeup` endpoint.
|
2019-10-14 20:47:18 +02:00
|
|
|
*
|
|
|
|
* @param callback is an optional JS function to invoke on success
|
|
|
|
* @return true if the asynchronous request could be made, false otherwise
|
|
|
|
*/
|
2019-10-16 17:11:29 +02:00
|
|
|
Q_INVOKABLE bool llarpAdminWakeup(QJSValue callback);
|
2019-10-21 03:35:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke the `llarp.version` endpoint.
|
|
|
|
*
|
|
|
|
* @param callback is an optional JS function to invoke on success
|
|
|
|
* @return true if the asynchronous request could be made, false otherwise
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE bool llarpVersion(QJSValue callback);
|
2019-10-21 05:21:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke the `llarp.admin.status` endpoint.
|
|
|
|
*
|
|
|
|
* @param callback is an optional JS function to invoke on success
|
|
|
|
* @return true if the asynchronous request could be made, false otherwise
|
|
|
|
*/
|
|
|
|
Q_INVOKABLE bool llarpAdminStatus(QJSValue callback);
|
2019-10-14 20:47:18 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
HttpClient m_httpClient;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __LOKI_LOKINET_API_CLIENT_HPP__
|