creating thread/basic linking
This commit is contained in:
parent
1d50dcd17b
commit
ef76b3daab
3 changed files with 58 additions and 6 deletions
|
|
@ -16,6 +16,6 @@ file(GLOB QML qml/*)
|
||||||
qt5_add_resources(QML_QRC qml/qml.qrc)
|
qt5_add_resources(QML_QRC qml/qml.qrc)
|
||||||
|
|
||||||
add_executable(light_client ClientDataModel.cpp ClientDataModel.hpp main.cpp ${QML_QRC})
|
add_executable(light_client ClientDataModel.cpp ClientDataModel.hpp main.cpp ${QML_QRC})
|
||||||
add_dependencies(light_client gen_qrc)
|
add_dependencies(light_client gen_qrc )
|
||||||
|
|
||||||
target_link_libraries(light_client PRIVATE Qt5::Core Qt5::Widgets Qt5::Quick graphene_chain graphene_utilities fc)
|
target_link_libraries(light_client PRIVATE Qt5::Core Qt5::Widgets Qt5::Quick graphene_chain graphene_utilities fc graphene_app )
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
#include "ClientDataModel.hpp"
|
#include "ClientDataModel.hpp"
|
||||||
|
|
||||||
|
#include <graphene/app/api.hpp>
|
||||||
|
#include <graphene/chain/protocol/protocol.hpp>
|
||||||
|
|
||||||
|
#include <fc/rpc/websocket_api.hpp>
|
||||||
|
|
||||||
|
ChainDataModel::ChainDataModel( fc::thread& t, QObject* parent )
|
||||||
|
:QObject(parent),m_thread(&t){}
|
||||||
|
|
||||||
Account* ChainDataModel::getAccount(quint64 id) const
|
Account* ChainDataModel::getAccount(quint64 id) const
|
||||||
{
|
{
|
||||||
|
|
@ -24,6 +31,31 @@ QQmlListProperty<Balance> Account::balances()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GrapheneApplication::initialize( QString datadir, QString apiurl )
|
GrapheneApplication::GrapheneApplication( QObject* parent )
|
||||||
|
:QObject( parent ),m_thread("app")
|
||||||
|
{
|
||||||
|
m_model = new ChainDataModel( m_thread, this );
|
||||||
|
}
|
||||||
|
GrapheneApplication::~GrapheneApplication()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GrapheneApplication::start( QString datadir, QString apiurl )
|
||||||
|
{
|
||||||
|
if( !m_thread.is_current() )
|
||||||
|
{
|
||||||
|
m_done = m_thread.async( [=](){ return start( datadir, apiurl ); } );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
auto con = m_client.connect( apiurl.toStdString() );
|
||||||
|
auto apic = std::make_shared<fc::rpc::websocket_api_connection>(*con);
|
||||||
|
|
||||||
|
|
||||||
|
} catch ( const fc::exception& e )
|
||||||
|
{
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||||
|
#include <fc/network/http/websocket.hpp>
|
||||||
|
#include <fc/thread/thread.hpp>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QQmlListProperty>
|
#include <QQmlListProperty>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Asset : public QObject {
|
class Asset : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
@ -51,6 +57,13 @@ class ChainDataModel : public QObject {
|
||||||
public:
|
public:
|
||||||
Q_INVOKABLE Account* getAccount(quint64 id)const;
|
Q_INVOKABLE Account* getAccount(quint64 id)const;
|
||||||
Q_INVOKABLE Account* getAccount(QString name)const;
|
Q_INVOKABLE Account* getAccount(QString name)const;
|
||||||
|
|
||||||
|
ChainDataModel(){}
|
||||||
|
ChainDataModel( fc::thread& t, QObject* parent = nullptr );
|
||||||
|
|
||||||
|
private:
|
||||||
|
fc::thread* m_thread = nullptr;
|
||||||
|
std::string m_api_url;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GrapheneApplication : public QObject {
|
class GrapheneApplication : public QObject {
|
||||||
|
|
@ -59,16 +72,23 @@ class GrapheneApplication : public QObject {
|
||||||
Q_PROPERTY(ChainDataModel* model READ model CONSTANT)
|
Q_PROPERTY(ChainDataModel* model READ model CONSTANT)
|
||||||
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
|
Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
|
||||||
|
|
||||||
ChainDataModel* m_model;
|
|
||||||
bool m_isConnected;
|
|
||||||
|
|
||||||
|
fc::thread m_thread;
|
||||||
|
ChainDataModel* m_model = nullptr;
|
||||||
|
bool m_isConnected = false;
|
||||||
|
|
||||||
|
fc::http::websocket_client m_client;
|
||||||
|
fc::future<bool> m_done;
|
||||||
public:
|
public:
|
||||||
|
GrapheneApplication( QObject* parent = nullptr );
|
||||||
|
~GrapheneApplication();
|
||||||
|
|
||||||
ChainDataModel* model() const
|
ChainDataModel* model() const
|
||||||
{
|
{
|
||||||
return m_model;
|
return m_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE void initialize(QString dataDirectory, QString apiUrl);
|
Q_INVOKABLE bool start(QString dataDirectory, QString apiUrl);
|
||||||
|
|
||||||
bool isConnected() const
|
bool isConnected() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue