Refactor RPC module:

* Move JsonPropertyStream to ripple_json
* Remove unused RPC service manager
* Recreate RPC module in app code area
* Add RPC::Manager
* Add DoPrint handler
This commit is contained in:
Vinnie Falco
2014-02-04 07:55:45 -08:00
parent 9bc6e83f8a
commit 9b657ba224
34 changed files with 404 additions and 445 deletions

View File

@@ -71,7 +71,6 @@ SOURCES += \
../../src/ripple/peerfinder/ripple_peerfinder.cpp \
../../src/ripple/radmap/ripple_radmap.cpp \
../../src/ripple/resource/ripple_resource.cpp \
../../src/ripple/rpc/ripple_rpc.cpp \
../../src/ripple/sitefiles/ripple_sitefiles.cpp \
../../src/ripple/sslutil/ripple_sslutil.cpp \
../../src/ripple/testoverlay/ripple_testoverlay.cpp \
@@ -96,6 +95,7 @@ SOURCES += \
../../src/ripple_data/ripple_data.cpp \
../../src/ripple_hyperleveldb/ripple_hyperleveldb.cpp \
../../src/ripple_leveldb/ripple_leveldb.cpp \
../../src/ripple_rpc/ripple_rpc.cpp \
../../src/ripple_net/ripple_net.cpp \
../../src/ripple_websocket/ripple_websocket.cpp

View File

@@ -72,6 +72,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\http\ripple_http.cpp" />
<ClCompile Include="..\..\src\ripple\json\impl\JsonPropertyStream.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\json\impl\json_reader.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -623,31 +629,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\ErrorCodes.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\Handler.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\Manager.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\Service.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\ripple_rpc.cpp" />
<ClCompile Include="..\..\src\ripple\sitefiles\impl\Manager.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -705,12 +686,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\types\impl\JsonPropertyStream.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\types\impl\RandomNumbers.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -1850,6 +1825,25 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\impl\DoPrint.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\impl\ErrorCodes.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\impl\Manager.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\ripple_rpc.cpp" />
<ClCompile Include="..\..\src\ripple_websocket\autosocket\AutoSocket.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -2227,6 +2221,7 @@
<ClInclude Include="..\..\src\ripple\http\impl\ServerImpl.h" />
<ClInclude Include="..\..\src\ripple\http\impl\Types.h" />
<ClInclude Include="..\..\src\ripple\http\ripple_http.h" />
<ClInclude Include="..\..\src\ripple\json\api\JsonPropertyStream.h" />
<ClInclude Include="..\..\src\ripple\json\api\json_config.h" />
<ClInclude Include="..\..\src\ripple\json\api\json_features.h" />
<ClInclude Include="..\..\src\ripple\json\api\json_forwards.h" />
@@ -2379,12 +2374,6 @@
<ClInclude Include="..\..\src\ripple\rocksdb\rocksdb\util\string_util.h" />
<ClInclude Include="..\..\src\ripple\rocksdb\rocksdb\util\testharness.h" />
<ClInclude Include="..\..\src\ripple\rocksdb\rocksdb\util\testutil.h" />
<ClInclude Include="..\..\src\ripple\rpc\api\ErrorCodes.h" />
<ClInclude Include="..\..\src\ripple\rpc\api\Handler.h" />
<ClInclude Include="..\..\src\ripple\rpc\api\Manager.h" />
<ClInclude Include="..\..\src\ripple\rpc\api\Service.h" />
<ClInclude Include="..\..\src\ripple\rpc\impl\ManagerImpl.h" />
<ClInclude Include="..\..\src\ripple\rpc\ripple_rpc.h" />
<ClInclude Include="..\..\src\ripple\sitefiles\api\Listener.h" />
<ClInclude Include="..\..\src\ripple\sitefiles\api\Manager.h" />
<ClInclude Include="..\..\src\ripple\sitefiles\api\Section.h" />
@@ -2417,7 +2406,6 @@
<ClInclude Include="..\..\src\ripple\types\api\IdentifierStorage.h" />
<ClInclude Include="..\..\src\ripple\types\api\IdentifierType.h" />
<ClInclude Include="..\..\src\ripple\types\api\HashMaps.h" />
<ClInclude Include="..\..\src\ripple\types\api\JsonPropertyStream.h" />
<ClInclude Include="..\..\src\ripple\types\api\RandomNumbers.h" />
<ClInclude Include="..\..\src\ripple\types\api\RippleAccountID.h" />
<ClInclude Include="..\..\src\ripple\types\api\RippleAccountPrivateKey.h" />
@@ -2641,6 +2629,11 @@
<ClInclude Include="..\..\src\ripple_net\rpc\RPCErr.h" />
<ClInclude Include="..\..\src\ripple_net\rpc\RPCSub.h" />
<ClInclude Include="..\..\src\ripple_net\rpc\RPCUtil.h" />
<ClInclude Include="..\..\src\ripple_rpc\api\ErrorCodes.h" />
<ClInclude Include="..\..\src\ripple_rpc\api\Manager.h" />
<ClInclude Include="..\..\src\ripple_rpc\api\Request.h" />
<ClInclude Include="..\..\src\ripple_rpc\impl\Command.h" />
<ClInclude Include="..\..\src\ripple_rpc\ripple_rpc.h" />
<ClInclude Include="..\..\src\ripple_websocket\autosocket\AutoSocket.h" />
<ClInclude Include="..\..\src\ripple_websocket\ripple_websocket.h" />
<ClInclude Include="..\..\src\BeastConfig.h" />
@@ -2757,8 +2750,6 @@
<None Include="..\..\src\ripple\radmap\TODO.md" />
<None Include="..\..\src\ripple\resource\README.md" />
<None Include="..\..\src\ripple\resource\TODO.md" />
<None Include="..\..\src\ripple\rpc\README.md" />
<None Include="..\..\src\ripple\rpc\TODO.md" />
<None Include="..\..\src\ripple\sitefiles\README.md" />
<None Include="..\..\src\ripple\sitefiles\TODO.md" />
<None Include="..\..\src\ripple\sslutil\README.md" />
@@ -2771,6 +2762,8 @@
<None Include="..\..\src\ripple\validators\README.md" />
<None Include="..\..\src\ripple_app\ledger\TODO.md" />
<None Include="..\..\src\ripple_app\TODO.md" />
<None Include="..\..\src\ripple_rpc\README.md" />
<None Include="..\..\src\ripple_rpc\TODO.md" />
<None Include="..\QtCreator\rippled.pro" />
</ItemGroup>
<ItemGroup>

View File

@@ -187,12 +187,6 @@
<Filter Include="[2] Old Ripple\ripple_core\nodestore\tests">
<UniqueIdentifier>{071582fa-cf16-4e41-8791-613cfe00eef8}</UniqueIdentifier>
</Filter>
<Filter Include="[1] Ripple\rpc">
<UniqueIdentifier>{7abb5fcf-8793-45d0-95db-0cf448198765}</UniqueIdentifier>
</Filter>
<Filter Include="[1] Ripple\rpc\api">
<UniqueIdentifier>{005e1f40-38ac-4904-af7c-4a018c5662f4}</UniqueIdentifier>
</Filter>
<Filter Include="[1] Ripple\http">
<UniqueIdentifier>{98e572a2-c89a-4ab7-b1d5-7687786e48dd}</UniqueIdentifier>
</Filter>
@@ -202,9 +196,6 @@
<Filter Include="[1] Ripple\http\impl">
<UniqueIdentifier>{386ebc1c-0cbe-43a6-b48e-ac3c503da0ee}</UniqueIdentifier>
</Filter>
<Filter Include="[1] Ripple\rpc\impl">
<UniqueIdentifier>{95c93134-7e8d-47ec-9649-4a8d5d97ce12}</UniqueIdentifier>
</Filter>
<Filter Include="[1] Ripple\types">
<UniqueIdentifier>{a3a2d1ec-d731-42df-9397-40a561c6809a}</UniqueIdentifier>
</Filter>
@@ -307,6 +298,15 @@
<Filter Include="[1] Ripple\peerfinder\sim">
<UniqueIdentifier>{c429638b-4572-44e4-a48a-c18fdd094ae1}</UniqueIdentifier>
</Filter>
<Filter Include="[2] Old Ripple\ripple_rpc">
<UniqueIdentifier>{21125570-1733-47a2-8f20-1d4c1f2bf2d1}</UniqueIdentifier>
</Filter>
<Filter Include="[2] Old Ripple\ripple_rpc\api">
<UniqueIdentifier>{acdb25ae-4985-483b-ad85-94e06aec7eab}</UniqueIdentifier>
</Filter>
<Filter Include="[2] Old Ripple\ripple_rpc\impl">
<UniqueIdentifier>{b86f01de-f924-4584-bb22-d70280b224f3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\ripple_basics\containers\RangeSet.cpp">
@@ -1029,9 +1029,6 @@
<ClCompile Include="..\..\src\ripple_app\main\RPCHTTPServer.cpp">
<Filter>[2] Old Ripple\ripple_app\main</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\ripple_rpc.cpp">
<Filter>[1] Ripple\rpc</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\http\ripple_http.cpp">
<Filter>[1] Ripple\http</Filter>
</ClCompile>
@@ -1044,15 +1041,6 @@
<ClCompile Include="..\..\src\ripple\http\impl\ScopedStream.cpp">
<Filter>[1] Ripple\http\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\Handler.cpp">
<Filter>[1] Ripple\rpc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\Service.cpp">
<Filter>[1] Ripple\rpc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\Manager.cpp">
<Filter>[1] Ripple\rpc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\http\impl\ServerImpl.cpp">
<Filter>[1] Ripple\http\impl</Filter>
</ClCompile>
@@ -1113,6 +1101,12 @@
<ClCompile Include="..\..\src\ripple\types\impl\JsonPropertyStream.cpp">
<Filter>[1] Ripple\types\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Checker.cpp">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\peerfinder\impl\Cache.cpp">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\resource\ripple_resource.cpp">
<Filter>[1] Ripple\resource</Filter>
</ClCompile>
@@ -1410,9 +1404,6 @@
<ClCompile Include="..\..\src\ripple_data\protocol\STParsedJSON.cpp">
<Filter>[2] Old Ripple\ripple_data\protocol</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\impl\ErrorCodes.cpp">
<Filter>[1] Ripple\rpc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_app\paths\PathRequests.cpp">
<Filter>[2] Old Ripple\ripple_app\paths</Filter>
</ClCompile>
@@ -1464,6 +1455,21 @@
<ClCompile Include="..\..\src\ripple\peerfinder\sim\Tests.cpp">
<Filter>[1] Ripple\peerfinder\sim</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\ripple_rpc.cpp">
<Filter>[2] Old Ripple\ripple_rpc</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\impl\ErrorCodes.cpp">
<Filter>[2] Old Ripple\ripple_rpc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\impl\Manager.cpp">
<Filter>[2] Old Ripple\ripple_rpc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple_rpc\impl\DoPrint.h">
<Filter>[2] Old Ripple\ripple_rpc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\json\impl\JsonPropertyStream.cpp">
<Filter>[1] Ripple\json\impl</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ripple_basics\containers\RangeSet.h">
@@ -2328,9 +2334,6 @@
<ClInclude Include="..\..\src\ripple_app\main\RPCHTTPServer.h">
<Filter>[2] Old Ripple\ripple_app\main</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\rpc\ripple_rpc.h">
<Filter>[1] Ripple\rpc</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\http\ripple_http.h">
<Filter>[1] Ripple\http</Filter>
</ClInclude>
@@ -2361,18 +2364,6 @@
<ClInclude Include="..\..\src\ripple\http\impl\Door.h">
<Filter>[1] Ripple\http\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\rpc\api\Handler.h">
<Filter>[1] Ripple\rpc\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\rpc\api\Manager.h">
<Filter>[1] Ripple\rpc\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\rpc\api\Service.h">
<Filter>[1] Ripple\rpc\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\rpc\impl\ManagerImpl.h">
<Filter>[1] Ripple\rpc\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\types\ripple_types.h">
<Filter>[1] Ripple\types</Filter>
</ClInclude>
@@ -2487,6 +2478,27 @@
<ClInclude Include="..\..\src\ripple\types\api\JsonPropertyStream.h">
<Filter>[1] Ripple\types\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Checker.h">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Tuning.h">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\LegacyEndpoint.h">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\LegacyEndpointCache.h">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\CheckerAdapter.h">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\Cache.h">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\impl\CachedEndpoint.h">
<Filter>[1] Ripple\peerfinder\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\resource\ripple_resource.h">
<Filter>[1] Ripple\resource</Filter>
</ClInclude>
@@ -2877,9 +2889,6 @@
<ClInclude Include="..\..\src\ripple_data\protocol\STParsedJSON.h">
<Filter>[2] Old Ripple\ripple_data\protocol</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\rpc\api\ErrorCodes.h">
<Filter>[1] Ripple\rpc\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_app\paths\PathRequests.h">
<Filter>[2] Old Ripple\ripple_app\paths</Filter>
</ClInclude>
@@ -3021,6 +3030,24 @@
<ClInclude Include="..\..\src\ripple\peerfinder\sim\WrappedSink.h">
<Filter>[1] Ripple\peerfinder\sim</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_rpc\ripple_rpc.h">
<Filter>[2] Old Ripple\ripple_rpc</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_rpc\api\ErrorCodes.h">
<Filter>[2] Old Ripple\ripple_rpc\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_rpc\api\Manager.h">
<Filter>[2] Old Ripple\ripple_rpc\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_rpc\api\Request.h">
<Filter>[2] Old Ripple\ripple_rpc\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple_rpc\impl\Command.h">
<Filter>[2] Old Ripple\ripple_rpc\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\json\api\JsonPropertyStream.h">
<Filter>[1] Ripple\json\api</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto">
@@ -3109,12 +3136,6 @@
<None Include="..\..\src\ripple\json\TODO.md">
<Filter>[1] Ripple\json</Filter>
</None>
<None Include="..\..\src\ripple\rpc\README.md">
<Filter>[1] Ripple\rpc</Filter>
</None>
<None Include="..\..\src\ripple\rpc\TODO.md">
<Filter>[1] Ripple\rpc</Filter>
</None>
<None Include="..\..\src\ripple\sitefiles\README.md">
<Filter>[1] Ripple\sitefiles</Filter>
</None>
@@ -3142,6 +3163,12 @@
<None Include="..\..\src\ripple\radmap\TODO.md">
<Filter>[1] Ripple\radmap</Filter>
</None>
<None Include="..\..\src\ripple_rpc\README.md">
<Filter>[2] Old Ripple\ripple_rpc</Filter>
</None>
<None Include="..\..\src\ripple_rpc\TODO.md">
<Filter>[2] Old Ripple\ripple_rpc</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\doc\todo\NIKB_TODO.txt">

View File

@@ -169,7 +169,6 @@ COMPILED_FILES.extend([
'src/ripple/radmap/ripple_radmap.cpp',
'src/ripple/resource/ripple_resource.cpp',
'src/ripple/rocksdb/ripple_rocksdb.cpp',
'src/ripple/rpc/ripple_rpc.cpp',
'src/ripple/sitefiles/ripple_sitefiles.cpp',
'src/ripple/sslutil/ripple_sslutil.cpp',
'src/ripple/testoverlay/ripple_testoverlay.cpp',
@@ -197,6 +196,7 @@ COMPILED_FILES.extend([
'src/ripple_hyperleveldb/ripple_hyperleveldb.cpp',
'src/ripple_leveldb/ripple_leveldb.cpp',
'src/ripple_net/ripple_net.cpp',
'src/ripple_rpc/ripple_rpc.cpp',
'src/ripple_websocket/ripple_websocket.cpp'
])

View File

@@ -192,11 +192,4 @@
#define RIPPLE_USE_PEERFINDER 0
#endif
// Here temporarily
// Controls whether or not the new RPC::Manager logic will be
// used to invoke RPC commands before they pass to the original code.
#ifndef RIPPLE_USE_RPC_SERVICE_MANAGER
#define RIPPLE_USE_RPC_SERVICE_MANAGER 0
#endif
#endif

View File

@@ -20,10 +20,12 @@
#ifndef RIPPLE_JSONPROPERTYSTREAM_H_INCLUDED
#define RIPPLE_JSONPROPERTYSTREAM_H_INCLUDED
#include "../beast/beast/utility/PropertyStream.h"
namespace ripple {
/** A PropertyStream::Sink which produces a Json::Value. */
class JsonPropertyStream : public PropertyStream
class JsonPropertyStream : public beast::PropertyStream
{
public:
Json::Value m_top;
@@ -38,15 +40,25 @@ protected:
void map_begin ();
void map_begin (std::string const& key);
void map_end ();
void add (std::string const& key, int32 v);
void add (std::string const& key, uint32 v);
void add (std::string const& key, short value);
void add (std::string const& key, unsigned short value);
void add (std::string const& key, int value);
void add (std::string const& key, unsigned int value);
void add (std::string const& key, long value);
void add (std::string const& key, float v);
void add (std::string const& key, double v);
void add (std::string const& key, std::string const& v);
void array_begin ();
void array_begin (std::string const& key);
void array_end ();
void add (int32 v);
void add (uint32 v);
void add (short value);
void add (unsigned short value);
void add (int value);
void add (unsigned int value);
void add (long value);
void add (float v);
void add (double v);
void add (std::string const& v);
};

View File

@@ -52,12 +52,32 @@ void JsonPropertyStream::map_end ()
m_stack.pop_back ();
}
void JsonPropertyStream::add (std::string const& key, int32 v)
void JsonPropertyStream::add (std::string const& key, short v)
{
(*m_stack.back())[key] = v;
}
void JsonPropertyStream::add (std::string const& key, uint32 v)
void JsonPropertyStream::add (std::string const& key, unsigned short v)
{
(*m_stack.back())[key] = v;
}
void JsonPropertyStream::add (std::string const& key, int v)
{
(*m_stack.back())[key] = v;
}
void JsonPropertyStream::add (std::string const& key, unsigned int v)
{
(*m_stack.back())[key] = v;
}
void JsonPropertyStream::add (std::string const& key, long v)
{
(*m_stack.back())[key] = int(v);
}
void JsonPropertyStream::add (std::string const& key, float v)
{
(*m_stack.back())[key] = v;
}
@@ -93,12 +113,37 @@ void JsonPropertyStream::array_end ()
m_stack.pop_back ();
}
void JsonPropertyStream::add (int32 v)
void JsonPropertyStream::add (short v)
{
m_stack.back()->append (v);
}
void JsonPropertyStream::add (uint32 v)
void JsonPropertyStream::add (unsigned short v)
{
m_stack.back()->append (v);
}
void JsonPropertyStream::add (int v)
{
m_stack.back()->append (v);
}
void JsonPropertyStream::add (unsigned int v)
{
m_stack.back()->append (v);
}
void JsonPropertyStream::add (long v)
{
m_stack.back()->append (int (v));
}
void JsonPropertyStream::add (float v)
{
m_stack.back()->append (v);
}
void JsonPropertyStream::add (double v)
{
m_stack.back()->append (v);
}

View File

@@ -47,3 +47,5 @@
#include "impl/json_writer.cpp"
#include "impl/Tests.cpp"
#include "impl/JsonPropertyStream.cpp"

View File

@@ -48,4 +48,6 @@
#include "api/json_reader.h"
#include "api/json_writer.h"
#include "api/JsonPropertyStream.h"
#endif

View File

@@ -21,6 +21,7 @@
#define RIPPLE_RESOURCE_CHARGE_H_INCLUDED
#include <ios>
#include <string>
namespace ripple {
namespace Resource {

View File

@@ -1,78 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_MANAGER_H_INCLUDED
#define RIPPLE_RPC_MANAGER_H_INCLUDED
#include "../../../beast/beast/utility/Journal.h"
#include "Handler.h"
#include "Service.h"
namespace ripple {
using namespace beast;
namespace RPC {
/** Manages a collection of Service interface objects. */
class Manager
{
public:
static Manager* New (Journal journal);
virtual ~Manager() { }
/** Add a service.
The list of commands that the service handles is enumerated and
added to the manager's dispatch table.
Thread safety:
Safe to call from any thread.
May only be called once for a given service.
*/
virtual void add (Service& service) = 0;
/** Add a subclass of Service and return the original pointer.
This is provided as a convenient so that RPCService objects may
be added from ctor-initializer lists.
*/
template <class Derived>
Derived* add (Derived* derived)
{
add (*(static_cast <Service*>(derived)));
return derived;
}
/** Execute an RPC command synchronously.
On return, if result.first == `true` then result.second will
have the Json return value from the call of the handler.
*/
virtual std::pair <bool, Json::Value> call (
std::string const& method, Json::Value const& args) = 0;
/** Returns the Handler for the specified method, or nullptr.
Thread safety:
Safe to call from any threads.
*/
virtual Handler const* find (std::string const& method) = 0;
};
}
}
#endif

View File

@@ -1,98 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_RPC_MANAGERIMPL_H_INCLUDED
#define RIPPLE_RPC_MANAGERIMPL_H_INCLUDED
namespace ripple {
namespace RPC {
class ManagerImpl : public Manager
{
public:
// The type of map we use to look up by function name.
//
typedef boost::unordered_map <std::string, Handler> MapType;
//--------------------------------------------------------------------------
explicit ManagerImpl (Journal journal)
: m_journal (journal)
{
}
~ManagerImpl()
{
}
void add (Service& service)
{
Handlers const& handlers (service.handlers());
SharedState::Access state (m_state);
for (Handlers::const_iterator iter (handlers.begin());
iter != handlers.end(); ++iter)
{
Handler const& handler (*iter);
std::pair <MapType::const_iterator, bool> result (
state->table.emplace (handler.method(), handler));
if (!result.second)
m_journal.error << "duplicate method '" << handler.method() << "'";
}
}
std::pair <bool, Json::Value> call (
std::string const& method, Json::Value const& args)
{
Handler const* handler (find (method));
if (! handler)
return std::make_pair (false, Json::Value());
return std::make_pair (true, (*handler)(args));
}
Handler const* find (std::string const& method)
{
Handler const* handler (nullptr);
// Peform lookup on the method to retrieve handler
SharedState::Access state (m_state);
MapType::iterator iter (state->table.find (method));
if (iter != state->table.end())
handler = &iter->second;
else
m_journal.debug << "method '" << method << "' not found.";
return handler;
}
private:
struct State
{
MapType table;
};
typedef SharedData <State> SharedState;
Journal m_journal;
SharedState m_state;
};
}
}
#endif

View File

@@ -46,6 +46,5 @@
#include "impl/UInt256.cpp"
#include "impl/RippleIdentifierTests.cpp"
#include "impl/RippleAssets.cpp"
#include "impl/JsonPropertyStream.cpp"

View File

@@ -68,6 +68,5 @@ using namespace beast;
# include "api/SimpleIdentifier.h"
#include "api/RippleLedgerHash.h"
#include "api/RipplePublicKeyHash.h"
#include "api/JsonPropertyStream.h"
#endif

View File

@@ -24,7 +24,6 @@
#include "beast/beast/http/URL.h"
#include "../ripple/rpc/ripple_rpc.h"
#include "../ripple/types/ripple_types.h"
# include "api/Types.h"

View File

@@ -18,6 +18,8 @@
//==============================================================================
#include "../ripple/common/seconds_clock.h"
#include "../ripple_rpc/api/Manager.h"
#include "Tuning.h"
namespace ripple {
@@ -52,6 +54,8 @@ class ResourceManagerLog;
template <> char const* LogPartition::getPartitionName <ResourceManagerLog> () { return "ResourceManager"; }
class PathRequestLog;
template <> char const* LogPartition::getPartitionName <PathRequestLog> () { return "PathRequest"; }
class RPCManagerLog;
template <> char const* LogPartition::getPartitionName <RPCManagerLog> () { return "RPCManager"; }
template <> char const* LogPartition::getPartitionName <CollectorManager> () { return "Collector"; }
@@ -111,7 +115,6 @@ public:
std::unique_ptr <CollectorManager> m_collectorManager;
std::unique_ptr <Resource::Manager> m_resourceManager;
std::unique_ptr <RPC::Manager> m_rpcServiceManager;
std::unique_ptr <FullBelowCache> m_fullBelowCache;
// These are Stoppable-related
@@ -119,6 +122,7 @@ public:
std::unique_ptr <JobQueue> m_jobQueue;
IoServicePool m_mainIoPool;
std::unique_ptr <SiteFiles::Manager> m_siteFiles;
std::unique_ptr <RPC::Manager> m_rpcManager;
// VFALCO TODO Make OrderBookDB abstract
OrderBookDB m_orderBookDB;
std::unique_ptr <PathRequests> m_pathRequests;
@@ -126,9 +130,7 @@ public:
std::unique_ptr <NetworkOPs> m_networkOPs;
std::unique_ptr <UniqueNodeList> m_deprecatedUNL;
std::unique_ptr <RPCHTTPServer> m_rpcHTTPServer;
#if ! RIPPLE_USE_RPC_SERVICE_MANAGER
RPCServerHandler m_rpcServerHandler;
#endif
std::unique_ptr <NodeStore::Database> m_nodeStore;
std::unique_ptr <SNTPClient> m_sntpClient;
std::unique_ptr <InboundLedgers> m_inboundLedgers;
@@ -224,9 +226,6 @@ public:
m_collectorManager->collector(),
LogPartition::getJournal <ResourceManagerLog> ()))
, m_rpcServiceManager (RPC::Manager::New (
LogPartition::getJournal <RPCServiceManagerLog> ()))
, m_fullBelowCache (std::make_unique <FullBelowCache> (
"full_below", get_seconds_clock (), m_collectorManager->collector (),
fullBelowTargetSize, fullBelowExpirationSeconds))
@@ -252,6 +251,8 @@ public:
, m_siteFiles (SiteFiles::Manager::New (
*this, LogPartition::getJournal <SiteFilesLog> ()))
, m_rpcManager (RPC::make_Manager (LogPartition::getJournal <RPCManagerLog> ()))
, m_orderBookDB (*m_jobQueue)
, m_pathRequests ( new PathRequests (
@@ -270,9 +271,8 @@ public:
, m_rpcHTTPServer (RPCHTTPServer::New (*m_networkOPs,
LogPartition::getJournal <HTTPServerLog> (), *m_jobQueue, *m_networkOPs, *m_resourceManager))
#if ! RIPPLE_USE_RPC_SERVICE_MANAGER
, m_rpcServerHandler (*m_networkOPs, *m_resourceManager) // passive object, not a Service
#endif
, m_nodeStore (m_nodeStoreManager->make_Database ("NodeStore.main", m_nodeStoreScheduler,
LogPartition::getJournal <NodeObject> (),
getConfig ().nodeDatabase, getConfig ().ephemeralNodeDatabase))
@@ -341,11 +341,6 @@ public:
return *m_collectorManager;
}
RPC::Manager& getRPCServiceManager()
{
return *m_rpcServiceManager;
}
FullBelowCache& getFullBelowCache ()
{
return *m_fullBelowCache;
@@ -356,6 +351,11 @@ public:
return *m_jobQueue;
}
RPC::Manager& getRPCManager ()
{
return *m_rpcManager;
}
SiteFiles::Manager& getSiteFiles()
{
return *m_siteFiles;
@@ -757,10 +757,6 @@ public:
//
// Allow RPC connections.
//
#if RIPPLE_USE_RPC_SERVICE_MANAGER
m_rpcHTTPServer->setup (m_journal);
#else
if (! getConfig ().getRpcIP().empty () && getConfig ().getRpcPort() != 0)
{
try
@@ -780,7 +776,6 @@ public:
{
m_journal.info << "RPC interface: disabled";
}
#endif
//
// Begin connecting to network.

View File

@@ -82,9 +82,9 @@ public:
virtual boost::asio::io_service& getIOService () = 0;
virtual CollectorManager& getCollectorManager () = 0;
virtual RPC::Manager& getRPCServiceManager() = 0;
virtual FullBelowCache& getFullBelowCache () = 0;
virtual JobQueue& getJobQueue () = 0;
virtual RPC::Manager& getRPCManager () = 0;
virtual SiteFiles::Manager& getSiteFiles () = 0;
virtual NodeCache& getTempNodeCache () = 0;
virtual SLECache& getSLECache () = 0;

View File

@@ -29,6 +29,7 @@
#include "ripple_app.h"
#include "../ripple_net/ripple_net.h"
#include "../ripple_rpc/ripple_rpc.h"
#include "../ripple_websocket/ripple_websocket.h"
// This .cpp will end up including all of the public header
@@ -37,7 +38,6 @@
#include "../ripple/common/seconds_clock.h"
#include "../ripple/http/ripple_http.h"
#include "../ripple/resource/ripple_resource.h"
#include "../ripple/rpc/ripple_rpc.h"
#include "../ripple/sitefiles/ripple_sitefiles.h"
#include "../ripple/validators/ripple_validators.h"

View File

@@ -26,7 +26,7 @@
#pragma warning (disable: 4309) // truncation of constant value
#endif
#include "../ripple/rpc/api/ErrorCodes.h"
#include "../ripple_rpc/api/ErrorCodes.h"
namespace ripple
{

View File

@@ -4110,16 +4110,7 @@ Json::Value RPCHandler::doRpcCommand (const std::string& strMethod, Json::Value
// Provide the JSON-RPC method as the field "command" in the request.
params["command"] = strMethod;
Json::Value jvResult;
#if RIPPLE_USE_RPC_SERVICE_MANAGER
std::pair <bool, Json::Value> result (getApp().
getRPCServiceManager().call (strMethod, params));
if (result.first)
jvResult = result.second;
else
#endif
jvResult = doCommand (params, iRole, loadType);
Json::Value jvResult = doCommand (params, iRole, loadType);
// Always report "status". On an error report the request as received.
if (jvResult.isMember ("error"))

View File

@@ -38,20 +38,20 @@ bool RPCServerHandler::isAuthorized (
std::string RPCServerHandler::processRequest (std::string const& request, IPAddress const& remoteIPAddress)
{
Json::Value jvRequest;
Json::Value jsonRequest;
{
Json::Reader reader;
if ((request.size() > 1000000) ||
! reader.parse (request, jvRequest) ||
jvRequest.isNull () ||
! jvRequest.isObject ())
! reader.parse (request, jsonRequest) ||
jsonRequest.isNull () ||
! jsonRequest.isObject ())
{
return createResponse (400, "Unable to parse request");
}
}
Config::Role const role (getConfig ().getAdminRole (jvRequest, remoteIPAddress));
Config::Role const role (getConfig ().getAdminRole (jsonRequest, remoteIPAddress));
Resource::Consumer usage;
@@ -67,9 +67,9 @@ std::string RPCServerHandler::processRequest (std::string const& request, IPAddr
//
// VFALCO NOTE Except that "id" isn't included in the following errors...
//
Json::Value const id = jvRequest ["id"];
Json::Value const& id = jsonRequest ["id"];
Json::Value const method = jvRequest ["method"];
Json::Value const& method = jsonRequest ["method"];
if (method.isNull ())
{
@@ -82,17 +82,14 @@ std::string RPCServerHandler::processRequest (std::string const& request, IPAddr
std::string strMethod = method.asString ();
// Parse params
Json::Value params = jvRequest ["params"];
if (jsonRequest["params"].isNull())
jsonRequest["params"] = Json::Value (Json::arrayValue);
if (params.isNull ())
{
params = Json::Value (Json::arrayValue);
}
else if (!params.isArray ())
{
// Parse params
Json::Value& params = jsonRequest ["params"];
if (!params.isArray ())
return HTTPReply (400, "params unparseable");
}
// VFALCO TODO Shouldn't we handle this earlier?
//
@@ -116,13 +113,25 @@ std::string RPCServerHandler::processRequest (std::string const& request, IPAddr
WriteLog (lsDEBUG, RPCServer) << "Query: " << strMethod << params;
RPC::Request req (LogPartition::getJournal <RPCServer> (),
strMethod, params, getApp ());
// VFALCO Try processing the command using the new code
if (getApp().getRPCManager().dispatch (req))
{
usage.charge (req.fee);
WriteLog (lsDEBUG, RPCServer) << "Reply: " << req.result;
return createResponse (200,
JSONRPCReply (req.result, Json::Value (), id));
}
// legacy dispatcher
RPCHandler rpcHandler (&m_networkOPs);
Json::Value const result = rpcHandler.doRpcCommand (
strMethod, params, role, req.fee);
Resource::Charge loadType = Resource::feeReferenceRPC;
Json::Value const result = rpcHandler.doRpcCommand (strMethod, params, role, loadType);
usage.charge (loadType);
usage.charge (req.fee);
WriteLog (lsDEBUG, RPCServer) << "Reply: " << result;

View File

@@ -44,7 +44,7 @@
#include <openssl/err.h>
#include "../ripple/sslutil/ripple_sslutil.h"
#include "../ripple/rpc/api/ErrorCodes.h"
#include "../ripple_rpc/api/ErrorCodes.h"
// VFALCO TODO fix these warnings!
#if BEAST_MSVC

View File

@@ -46,7 +46,7 @@
// directly (instead of th emodule header). The corresponding .cpp
// still uses the unity style inclusion.
//
#include "../ripple/rpc/api/ErrorCodes.h"
#include "../ripple_rpc/api/ErrorCodes.h"
namespace ripple
{

View File

@@ -20,6 +20,8 @@
#ifndef RIPPLE_RPC_ERRORCODES_H_INCLUDED
#define RIPPLE_RPC_ERRORCODES_H_INCLUDED
#include "../../ripple/json/ripple_json.h"
namespace ripple {
// VFALCO NOTE These are outside the RPC namespace

View File

@@ -17,13 +17,47 @@
*/
//==============================================================================
#ifndef RIPPLE_RPC_MANAGER_H_INCLUDED
#define RIPPLE_RPC_MANAGER_H_INCLUDED
#include "Request.h"
namespace ripple {
namespace RPC {
Manager* Manager::New (Journal journal)
/** Processes RPC commands. */
class Manager
{
return new ManagerImpl (journal);
}
public:
typedef std::function <void (Request&)> handler_type;
virtual ~Manager () = 0;
/** Add a handler for the specified JSON-RPC command. */
/** @{ */
template <class Handler>
void add (std::string const& method)
{
add (method, handler_type (
[](Request& req)
{
Handler h;
h (req);
}));
}
virtual void add (std::string const& method, handler_type&& handler) = 0;
/** @} */
/** Dispatch the JSON-RPC request.
@return `true` If the command was found.
*/
virtual bool dispatch (Request& req) = 0;
};
std::unique_ptr <Manager> make_Manager (Journal journal);
}
}
#endif

View File

@@ -17,43 +17,52 @@
*/
//==============================================================================
#ifndef RIPPLE_RPC_SERVCE_H_INCLUDED
#define RIPPLE_RPC_SERVCE_H_INCLUDED
#ifndef RIPPLE_RPC_REQUEST_H_INCLUDED
#define RIPPLE_RPC_REQUEST_H_INCLUDED
#include "../ripple/json/ripple_json.h"
#include "../ripple/resource/ripple_resource.h"
#include "Handler.h"
namespace ripple {
class Application; // forward declare
namespace RPC {
/** Interface for abstacting RPC commands processing. */
class Service : public Uncopyable
struct Request
{
public:
/** Create the service.
Derived classes will usually call add() repeatedly from their
constructor to fill in the list of handlers prior to Manager::add.
*/
Service ();
virtual ~Service ();
/** Returns the handlers associated with this service. */
Handlers const& handlers() const;
/** Add a handler for the specified method.
Adding a handler after the service is already associated with a
Manager results in undefined behavior.
Thread safety:
May not be called concurrently.
*/
template <typename Function>
void addRPCHandler (std::string const& method, Function function)
explicit Request (Journal journal_,
std::string const& method_, Json::Value& params_,
Application& app_)
: journal (journal_)
, method (method_)
, params (params_)
, fee (Resource::feeReferenceRPC)
, app (app_)
{
m_handlers.push_back (Handler (method, function));
}
// [in] The Journal for logging
Journal journal;
// [in] The JSON-RPC method
std::string method;
// [in] The complete JSON-RPC request
Json::Value params;
// [in, out] The resource cost for the command
Resource::Charge fee;
// [out] The JSON-RPC response
Json::Value result;
// [in] The Application instance
Application& app;
private:
Handlers m_handlers;
Request& operator= (Request const&);
};
}

View File

@@ -17,21 +17,19 @@
*/
//==============================================================================
#ifndef RIPPLE_RPC_COMMAND_H_INCLUDED
#define RIPPLE_RPC_COMMAND_H_INCLUDED
namespace ripple {
namespace RPC {
Service::Service ()
/** Base class common to all RPC commands. */
class Command
{
}
Service::~Service ()
{
}
Handlers const& Service::handlers() const
{
return m_handlers;
}
public:
};
}
}
#endif

View File

@@ -20,28 +20,27 @@
namespace ripple {
namespace RPC {
Handler::Handler (Handler const& other)
: m_method (other.m_method)
, m_function (other.m_function)
class DoPrint
{
}
public:
void operator() (Request& req)
{
JsonPropertyStream stream;
Handler& Handler::operator= (Handler const& other)
{
m_method = other.m_method;
m_function = other.m_function;
return *this;
}
if (req.params.isObject() &&
req.params["params"].isArray() &&
req.params["params"][0u].isString ())
{
req.app.write (stream, req.params["params"][0u].asString());
}
else
{
req.app.write (stream);
}
std::string const& Handler::method() const
{
return m_method;
}
Json::Value Handler::operator() (Json::Value const& args) const
{
return m_function (args);
}
req.result = stream.top();
}
};
}
}

View File

@@ -17,6 +17,23 @@
*/
//==============================================================================
#include <unordered_map>
#include <utility>
#include "../api/ErrorCodes.h"
namespace std {
template <>
struct hash <ripple::error_code_i>
{
std::size_t operator() (ripple::error_code_i value) const
{
return value;
}
};
}
namespace ripple {
namespace RPC {
@@ -25,7 +42,7 @@ namespace detail {
class ErrorCategory
{
public:
typedef boost::unordered_map <error_code_i, ErrorInfo> Map;
typedef std::unordered_map <error_code_i, ErrorInfo> Map;
ErrorCategory ()
: m_unknown (rpcUNKNOWN, "unknown", "An unknown error code.")
@@ -108,10 +125,11 @@ private:
std::string const& message)
{
std::pair <Map::iterator, bool> result (
m_map.emplace (boost::unordered::piecewise_construct,
boost::make_tuple (code), boost::make_tuple (
m_map.emplace (std::piecewise_construct,
std::make_tuple (code), std::make_tuple (
code, token, message)));
check_postcondition (result.second);
if (! result.second)
throw std::invalid_argument ("duplicate error code");
}
private:

View File

@@ -17,49 +17,59 @@
*/
//==============================================================================
#ifndef RIPPLE_RPC_HANDLER_H_INCLUDED
#define RIPPLE_RPC_HANDLER_H_INCLUDED
#include "beast/beast/make_unique.h"
#include <vector>
#include "../api/Manager.h"
#include "DoPrint.h"
namespace ripple {
using namespace beast;
namespace RPC {
/** An invokable handler for a particular RPC method. */
class Handler
class ManagerImp : public Manager
{
public:
/** Create a handler with the specified method and function. */
template <typename Function> // allocator
Handler (std::string const& method_, Function function)
: m_method (method_)
, m_function (function)
typedef std::unordered_map <std::string, handler_type> Map;
Journal m_journal;
Map m_map;
ManagerImp (Journal journal)
: m_journal (journal)
{
}
Handler (Handler const& other);
Handler& operator= (Handler const& other);
void add (std::string const& method, handler_type&& handler)
{
std::pair <Map::iterator, bool> result (m_map.emplace (
std::piecewise_construct, std::make_tuple (method),
std::make_tuple (std::move (handler))));
}
/** Returns the method called when this handler is invoked. */
std::string const& method() const;
/** Synchronously invoke the method on the associated service.
Thread safety:
Determined by the owner.
*/
Json::Value operator() (Json::Value const& args) const;
private:
std::string m_method;
SharedFunction <Json::Value (Json::Value const&)> m_function;
bool dispatch (Request& req)
{
Map::const_iterator const iter (m_map.find (req.method));
if (iter == m_map.end())
return false;
iter->second (req);
return true;
}
};
/** The type of container that holds a set of Handler objects. */
typedef std::vector <Handler> Handlers;
//------------------------------------------------------------------------------
Manager::~Manager ()
{
}
std::unique_ptr <Manager> make_Manager (Journal journal)
{
std::unique_ptr <Manager> m (std::make_unique <ManagerImp> (journal));
m->add <DoPrint> ("print");
return m;
}
}
}
#endif

View File

@@ -21,11 +21,12 @@
#include "ripple_rpc.h"
#include "beast/modules/beast_core/system/BeforeBoost.h"
#include <boost/unordered_map.hpp>
#include "beast/modules/beast_core/beast_core.h" // for UnitTest
// Unfortunate but necessary since RPC handlers can literally do anything
#include "../ripple_app/ripple_app.h"
#include "impl/ErrorCodes.cpp"
# include "impl/ManagerImpl.h"
#include "impl/Manager.cpp"
#include "impl/Handler.cpp"
#include "impl/Service.cpp"

View File

@@ -20,13 +20,10 @@
#ifndef RIPPLE_RPC_H_INCLUDED
#define RIPPLE_RPC_H_INCLUDED
#include "beast/modules/beast_core/beast_core.h"
//#include "beast/modules/beast_core/beast_core.h"
#include "../json/ripple_json.h"
# include "api/Handler.h"
# include "api/Service.h"
#include "api/Manager.h"
#include "api/ErrorCodes.h"
#include "api/Manager.h"
#include "api/Request.h"
#endif