Browse Source

removed qwebthree inner polling, polling is now frontend only, fixed #780

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
74a191031b
  1. 4
      alethzero/MainWin.cpp
  2. 108
      libqwebthree/QWebThree.cpp
  3. 5
      libqwebthree/QWebThree.h
  4. 4
      third/MainWin.cpp

4
alethzero/MainWin.cpp

@ -182,7 +182,6 @@ Main::Main(QWidget *parent) :
connect(ui->webView, &QWebView::loadFinished, [=]() connect(ui->webView, &QWebView::loadFinished, [=]()
{ {
m_qweb->poll();
}); });
connect(ui->webView, &QWebView::titleChanged, [=]() connect(ui->webView, &QWebView::titleChanged, [=]()
@ -1184,9 +1183,6 @@ void Main::timerEvent(QTimerEvent*)
else else
interval += 100; interval += 100;
if (m_qweb)
m_qweb->poll();
for (auto const& i: m_handlers) for (auto const& i: m_handlers)
{ {
auto ls = ethereum()->checkWatch(i.first); auto ls = ethereum()->checkWatch(i.first);

108
libqwebthree/QWebThree.cpp

@ -36,58 +36,8 @@ QWebThree::~QWebThree()
clientDieing(); clientDieing();
} }
static QString toJsonRpcBatch(std::vector<unsigned> const& _watches, QString _method)
{
QJsonArray batch;
for (int w: _watches)
{
QJsonObject res;
res["jsonrpc"] = QString::fromStdString("2.0");
res["method"] = _method;
QJsonArray params;
params.append(w);
res["params"] = params;
res["id"] = w;
batch.append(res);
}
return QString::fromUtf8(QJsonDocument(batch).toJson());
}
void QWebThree::poll()
{
if (m_watches.size() > 0)
{
QString batch = toJsonRpcBatch(m_watches, "eth_changed");
emit processData(batch, "eth_changed");
}
if (m_shhWatches.size() > 0)
{
QString batch = toJsonRpcBatch(m_shhWatches, "shh_changed");
emit processData(batch, "shh_changed");
}
}
void QWebThree::clearWatches()
{
if (m_watches.size() > 0)
{
QString batch = toJsonRpcBatch(m_watches, "eth_uninstallFilter");
m_watches.clear();
emit processData(batch, "internal");
}
if (m_shhWatches.size() > 0)
{
QString batch = toJsonRpcBatch(m_shhWatches, "shh_uninstallFilter");
m_shhWatches.clear();
emit processData(batch, "internal");
}
}
void QWebThree::clientDieing() void QWebThree::clientDieing()
{ {
clearWatches();
this->disconnect(); this->disconnect();
} }
@ -104,70 +54,14 @@ static QString formatInput(QJsonObject const& _object)
QString QWebThree::callMethod(QString _json) QString QWebThree::callMethod(QString _json)
{ {
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
emit processData(formatInput(f), ""); // it's synchronous
QString method = f["call"].toString();
if (!method.compare("eth_uninstallFilter") && f["args"].isArray() && f["args"].toArray().size())
{
int idToRemove = f["args"].toArray()[0].toInt();
m_watches.erase(std::remove(m_watches.begin(), m_watches.end(), idToRemove), m_watches.end());
}
else if (!method.compare("eth_uninstallFilter") && f["args"].isArray() && f["args"].toArray().size())
{
int idToRemove = f["args"].toArray()[0].toInt();
m_watches.erase(std::remove(m_watches.begin(), m_watches.end(), idToRemove), m_watches.end());
}
emit processData(formatInput(f), method); // it's synchronous
return m_response; return m_response;
} }
//static QString formatOutput(QJsonObject const& _object)
//{
// QJsonObject res;
// res["_id"] = _object["id"];
// res["data"] = _object["result"];
// res["error"] = _object["error"];
// return QString::fromUtf8(QJsonDocument(res).toJson());
//}
void QWebThree::onDataProcessed(QString _json, QString _addInfo) void QWebThree::onDataProcessed(QString _json, QString _addInfo)
{ {
if (!_addInfo.compare("internal"))
return;
if (!_addInfo.compare("shh_changed") || !_addInfo.compare("eth_changed"))
{
QJsonArray resultsArray = QJsonDocument::fromJson(_json.toUtf8()).array();
for (int i = 0; i < resultsArray.size(); i++)
{
QJsonObject elem = resultsArray[i].toObject();
if (elem["result"].isArray() && elem["result"].toArray().size() > 0)
{
QJsonObject res;
res["_event"] = _addInfo;
if (!_addInfo.compare("shh_changed"))
res["_id"] = (int)m_shhWatches[i]; // we can do that couse poll is synchronous
else
res["_id"] = (int)m_watches[i];
res["data"] = elem["result"].toArray();
syncResponse(QString::fromUtf8(QJsonDocument(res).toJson()));
}
}
}
QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object();
if ((!_addInfo.compare("eth_newFilter") || !_addInfo.compare("eth_newFilterString")) && f.contains("result"))
m_watches.push_back(f["result"].toInt());
else if (!_addInfo.compare("shh_newFilter") && f.contains("result"))
m_shhWatches.push_back(f["result"].toInt());
else if (!_addInfo.compare("shh_newIdentity") && f.contains("result"))
emit onNewId(f["result"].toString());
syncResponse(QString::fromUtf8(QJsonDocument(f).toJson())); syncResponse(QString::fromUtf8(QJsonDocument(f).toJson()));
// syncResponse(formatOutput(f));
} }
void QWebThree::syncResponse(QString _json) void QWebThree::syncResponse(QString _json)

5
libqwebthree/QWebThree.h

@ -34,9 +34,6 @@ class QWebThree: public QObject
public: public:
QWebThree(QObject* _p); QWebThree(QObject* _p);
virtual ~QWebThree(); virtual ~QWebThree();
void poll();
void clearWatches();
void clientDieing(); void clientDieing();
Q_INVOKABLE QString callMethod(QString _json); Q_INVOKABLE QString callMethod(QString _json);
@ -51,8 +48,6 @@ signals:
void onNewId(QString _id); void onNewId(QString _id);
private: private:
std::vector<unsigned> m_watches;
std::vector<unsigned> m_shhWatches;
QString m_response; QString m_response;
}; };

4
third/MainWin.cpp

@ -135,7 +135,6 @@ Main::Main(QWidget *parent) :
connect(ui->webView, &QWebView::loadFinished, [=]() connect(ui->webView, &QWebView::loadFinished, [=]()
{ {
m_qweb->poll();
}); });
connect(ui->webView, &QWebView::titleChanged, [=]() connect(ui->webView, &QWebView::titleChanged, [=]()
@ -531,9 +530,6 @@ void Main::timerEvent(QTimerEvent*)
} }
else else
interval += 100; interval += 100;
if (m_qweb)
m_qweb->poll();
for (auto const& i: m_handlers) for (auto const& i: m_handlers)
{ {

Loading…
Cancel
Save