From 01fda4c30e5fdcab231ab97a6e48b0dfabca922c Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 31 Aug 2013 21:35:30 -0700 Subject: [PATCH] Refactor RPCSub to remove Application dependency --- modules/ripple_app/main/ripple_Application.cpp | 3 ++- modules/ripple_app/rpc/RPCHandler.cpp | 3 ++- modules/ripple_app/rpc/RPCSub.cpp | 15 +++++++++++---- modules/ripple_app/rpc/RPCSub.h | 7 ++++++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/modules/ripple_app/main/ripple_Application.cpp b/modules/ripple_app/main/ripple_Application.cpp index 411acb27e0..2547944ae0 100644 --- a/modules/ripple_app/main/ripple_Application.cpp +++ b/modules/ripple_app/main/ripple_Application.cpp @@ -631,7 +631,8 @@ public: catch (const std::exception& e) { // Must run as directed or exit. - WriteLog (lsFATAL, Application) << boost::str (boost::format ("Can not open RPC service: %s") % e.what ()); + WriteLog (lsFATAL, Application) << + "Can not open RPC service: " << e.what (); exit (3); } diff --git a/modules/ripple_app/rpc/RPCHandler.cpp b/modules/ripple_app/rpc/RPCHandler.cpp index 64f841e186..ce1842f870 100644 --- a/modules/ripple_app/rpc/RPCHandler.cpp +++ b/modules/ripple_app/rpc/RPCHandler.cpp @@ -3233,7 +3233,8 @@ Json::Value RPCHandler::doSubscribe (Json::Value params, LoadType* loadType, App { WriteLog (lsDEBUG, RPCHandler) << boost::str (boost::format ("doSubscribe: building: %s") % strUrl); - RPCSub::pointer rspSub = boost::make_shared (strUrl, strUsername, strPassword); + RPCSub::pointer rspSub = boost::make_shared (getApp ().getIOService (), + getApp ().getJobQueue (), strUrl, strUsername, strPassword); ispSub = mNetOps->addRpcSub (strUrl, boost::dynamic_pointer_cast (rspSub)); } else diff --git a/modules/ripple_app/rpc/RPCSub.cpp b/modules/ripple_app/rpc/RPCSub.cpp index ed972f917d..b322af0d92 100644 --- a/modules/ripple_app/rpc/RPCSub.cpp +++ b/modules/ripple_app/rpc/RPCSub.cpp @@ -6,8 +6,15 @@ SETUP_LOG (RPCSub) -RPCSub::RPCSub (const std::string& strUrl, const std::string& strUsername, const std::string& strPassword) - : mUrl (strUrl), mSSL (false), mUsername (strUsername), mPassword (strPassword), mSending (false) +RPCSub::RPCSub (boost::asio::io_service& io_service, JobQueue& jobQueue, + const std::string& strUrl, const std::string& strUsername, const std::string& strPassword) + : m_io_service (io_service) + , m_jobQueue (jobQueue) + , mUrl (strUrl) + , mSSL (false) + , mUsername (strUsername) + , mPassword (strPassword) + , mSending (false) { std::string strScheme; @@ -75,7 +82,7 @@ void RPCSub::sendThread () WriteLog (lsINFO, RPCSub) << boost::str (boost::format ("callRPC calling: %s") % mIp); callRPC ( - getApp().getIOService (), + m_io_service, mIp, mPort, mUsername, mPassword, mPath, "event", @@ -113,7 +120,7 @@ void RPCSub::send (const Json::Value& jvObj, bool broadcast) WriteLog (lsINFO, RPCSub) << boost::str (boost::format ("callRPC start")); - getApp().getJobQueue ().addJob ( + m_jobQueue.addJob ( jtCLIENT, "RPCSub::sendThread", BIND_TYPE (&RPCSub::sendThread, this)); } } diff --git a/modules/ripple_app/rpc/RPCSub.h b/modules/ripple_app/rpc/RPCSub.h index b0414e4c75..539999187a 100644 --- a/modules/ripple_app/rpc/RPCSub.h +++ b/modules/ripple_app/rpc/RPCSub.h @@ -18,7 +18,9 @@ public: typedef boost::shared_ptr pointer; typedef const pointer& ref; - RPCSub (const std::string& strUrl, const std::string& strUsername, const std::string& strPassword); + RPCSub (boost::asio::io_service& io_service, + JobQueue& jobQueue, const std::string& strUrl, + const std::string& strUsername, const std::string& strPassword); virtual ~RPCSub () { @@ -46,6 +48,9 @@ protected: void sendThread (); private: + boost::asio::io_service& m_io_service; + JobQueue& m_jobQueue; + std::string mUrl; std::string mIp; int mPort;