Browse Source

Store the response as a string.

cl-refactor
chriseth 10 years ago
parent
commit
0c8f4d4e11
  1. 2
      libjsconsole/JSV8Connector.cpp
  2. 17
      libjsconsole/JSV8Connector.h
  3. 29
      libjsconsole/JSV8RemoteConnector.cpp
  4. 32
      libjsconsole/JSV8RemoteConnector.h
  5. 2
      libjsengine/JSEngine.h
  6. 2
      libjsengine/JSPrinter.h
  7. 2
      libjsengine/JSV8Engine.h
  8. 2
      libjsengine/JSV8Printer.h
  9. 8
      libjsengine/JSV8RPC.cpp
  10. 8
      libjsengine/JSV8RPC.h

2
libjsconsole/JSV8Connector.cpp

@ -39,7 +39,7 @@ bool JSV8Connector::StopListening()
bool JSV8Connector::SendResponse(std::string const& _response, void* _addInfo)
{
(void)_addInfo;
m_lastResponse = _response.c_str();
m_lastResponse = _response;
return true;
}

17
libjsconsole/JSV8Connector.h

@ -22,6 +22,7 @@
#pragma once
#include <string>
#include <jsonrpccpp/server/abstractserverconnector.h>
#include <libjsengine/JSV8RPC.h>
@ -30,20 +31,24 @@ namespace dev
namespace eth
{
class JSV8Connector: public jsonrpc::AbstractServerConnector, public JSV8RPC
class JSV8Connector: public jsonrpc::AbstractServerConnector, private JSV8RPC
{
public:
JSV8Connector(JSV8Engine const& _engine): JSV8RPC(_engine) {}
virtual ~JSV8Connector();
// implement AbstractServerConnector interface
bool StartListening();
bool StopListening();
bool SendResponse(std::string const& _response, void* _addInfo = nullptr);
bool StartListening() override;
bool StopListening() override;
bool SendResponse(std::string const& _response, void* _addInfo = nullptr) override;
private:
// implement JSV8RPC interface
void onSend(char const* _payload);
void onSend(char const* _payload) override;
char const* lastResponse() const override { return m_lastResponse.c_str(); }
std::string m_lastResponse = R"({"id": 1, "jsonrpc": "2.0", "error": "Uninitalized JSV8RPC!"})";
};
}

29
libjsconsole/JSV8RemoteConnector.cpp

@ -1,10 +1,27 @@
//
// Created by Marek Kotewicz on 15/06/15.
//
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file JSV8RemoteConnector.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Connector from the standalone javascript console to a remote RPC node.
*/
#include "JSV8RemoteConnector.h"
using namespace std;
using namespace dev;
using namespace dev::eth;
@ -13,8 +30,6 @@ void JSV8RemoteConnector::onSend(char const* _payload)
m_request.setUrl(m_url);
m_request.setBody(_payload);
long code;
string response;
tie(code, response) = m_request.post();
tie(code, m_lastResponse) = m_request.post();
(void)code;
m_lastResponse = response.c_str();
}

32
libjsconsole/JSV8RemoteConnector.h

@ -1,10 +1,27 @@
//
// Created by Marek Kotewicz on 15/06/15.
//
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file JSV8RemoteConnector.cpp
* @author Marek Kotewicz <marek@ethdev.com>
* @date 2015
* Connector from the standalone javascript console to a remote RPC node.
*/
#pragma once
#include <string>
#include <libjsengine/JSV8RPC.h>
#include "CURLRequest.h"
@ -13,18 +30,21 @@ namespace dev
namespace eth
{
class JSV8RemoteConnector : public JSV8RPC
class JSV8RemoteConnector: private JSV8RPC
{
public:
JSV8RemoteConnector(JSV8Engine const& _engine, std::string _url): JSV8RPC(_engine), m_url(_url) {}
virtual ~JSV8RemoteConnector() {}
private:
// implement JSV8RPC interface
void onSend(char const* _payload);
void onSend(char const* _payload) override;
const char* lastResponse() const override { return m_lastResponse.c_str(); }
private:
std::string m_url;
std::string m_lastResponse = R"({"id": 1, "jsonrpc": "2.0", "error": "Uninitalized JSV8RPC!"})";
CURLRequest m_request;
};

2
libjsengine/JSEngine.h

@ -23,6 +23,8 @@
#pragma once
#include <exception>
/// Do not use libstd headers here, it will break on MacOS.
namespace dev
{
namespace eth

2
libjsengine/JSPrinter.h

@ -24,6 +24,8 @@
#include "JSEngine.h"
/// Do not use libstd headers here, it will break on MacOS.
namespace dev
{
namespace eth

2
libjsengine/JSV8Engine.h

@ -28,6 +28,8 @@
#pragma clang diagnostic pop
#include "JSEngine.h"
/// Do not use libstd headers here, it will break on MacOS.
namespace dev
{
namespace eth

2
libjsengine/JSV8Printer.h

@ -25,6 +25,8 @@
#include "JSPrinter.h"
#include "JSV8Engine.h"
/// Do not use libstd headers here, it will break on MacOS.
namespace dev
{
namespace eth

8
libjsengine/JSV8RPC.cpp

@ -89,12 +89,4 @@ JSV8RPC::JSV8RPC(JSV8Engine const& _engine): m_engine(_engine)
v8::Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(web3object->Get(setProvider));
v8::Local<v8::Value> values[1] = {obj};
func->Call(func, 1, values);
m_lastResponse = R"(
{
"id": 1,
"jsonrpc": "2.0",
"error": "Uninitalized JSV8RPC!"
}
)";
}

8
libjsengine/JSV8RPC.h

@ -24,6 +24,8 @@
#include <libjsengine/JSV8Engine.h>
/// Do not use libstd headers here, it will break on MacOS.
namespace dev
{
namespace eth
@ -33,14 +35,12 @@ class JSV8RPC
{
public:
JSV8RPC(JSV8Engine const& _engine);
virtual ~JSV8RPC() { }
virtual void onSend(char const* _payload) = 0;
char const* lastResponse() const { return m_lastResponse; }
virtual char const* lastResponse() const = 0;
private:
JSV8Engine const& m_engine;
protected:
char const* m_lastResponse;
};
}

Loading…
Cancel
Save