8000 Merge branch 'release/v0.5.0' · cinemast/libjson-rpc-cpp@0383719 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 0383719

Browse files
author
Peter Spiess-Knafl
committed
Merge branch 'release/v0.5.0'
2 parents b342d6e + 30b3858 commit 0383719

25 files changed

+170
-77
lines changed

AUTHORS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@ Kasper Laudrup <laudrup@stacktrace.dk>
5454

5555
Erik Lundin
5656
+ bugfix in cpp-server stubgen
57-
+ bugfix for gcc 4.7 compatibility
57+
+ bugfix for gcc 4.7 compatibility
58+
59+
Michał Górny <mgorny@gentoo.org>
60+
+ bugfixes in the build system

CHANGELOG.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
Changes in v0.4.3 [unreleased]
1+
Changes in v0.5.0
22
-----------------
3-
- added `--version` option to jsonrpcstub
4-
- added msvc support
3+
- added `--version` option to jsonrpcstub.
4+
- added msvc support.
5+
- added data field support for JsonRpcException.
6+
- added contributions guide: https://github.com/cinemast/libjson-rpc-cpp#contributions
7+
- HttpClient uses Http Keep-Alive, which improves performance drastically.
8+
- Added `LIB_SUFFIX` to CMake to support multilib.
9+
- Fixed building tests with examples disabled.
10+
- Made static library build optional (via `BUILD_STATIC_LIBS`).
11+
- Fixed unnecessary rebuilds of stubs on each `make` call.
512

613
Changes in v0.4.2
714
-----------------

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ if (${CMAKE_MAJOR_VERSION} GREATER 2)
1111
endif()
1212

1313
set(MAJOR_VERSION 0)
14-
set(MINOR_VERSION 4)
15-
set(PATCH_VERSION 2)
14+
set(MINOR_VERSION 5)
15+
set(PATCH_VERSION 0)
1616
set(SO_VERSION 0)
1717

18+
set(BUILD_STATIC_LIBS NO CACHE BOOL "Build static libraries in addition to shared")
19+
set(LIB_SUFFIX "" CACHE STRING "Suffix for library directory (32/64)")
20+
1821
# defaults for modules that can be enabled/disabled
1922
set(HTTP_SERVER YES CACHE BOOL "Include HTTP server using libmicrohttpd")
2023
set(HTTP_CLIENT YES CACHE BOOL "Include HTTP client support using curl")
@@ -58,7 +61,7 @@ if (COMPILE_STUBGEN)
5861
endif ()
5962

6063
# setup examples
61-
if (COMPILE_EXAMPLES AND HTTP_SERVER AND HTTP_CLIENT)
64+
if (HTTP_SERVER AND HTTP_CLIENT)
6265
add_subdirectory(src/examples)
6366
endif()
6467

dev/testcoverage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bin/unit_testsuite
1010

1111
echo "Generate HTML report"
1212
mkdir -p reports
13-
gcovr -r .. -d -e "src/test" --html --html-details -o reports/coverage.html
13+
gcovr -r .. -d -e "build" -e "src/test" --html --html-details -o reports/coverage.html
1414
xdg-open reports/coverage.html
1515
cd ../dev
1616

doc/manpage.in

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.\" Manpage for jsonrpcstub.
22
.\" Contact psk@autistici.org to correct errors or typos.
3-
.TH man 1 "22 November 2014" "@MAJOR_VERSION@.@MINOR_VERSION@.@PATCH_VERSION@" "jsonrpcstub man page"
3+
.TH man 1 "7 April 2015" "@MAJOR_VERSION@.@MINOR_VERSION@.@PATCH_VERSION@" "jsonrpcstub man page"
44
.SH NAME
55
jsonrpcstub \- genearate stubs for the libjson\-rpc\-cpp framework.
66
.SH SYNOPSIS
77
.B
88
jsonrpcstub specfile.json [\-\-cpp\-server=namespace::ClassName]
99
[\-\-cpp\-server\-file=classqname.h] [\-\-cpp\-client=namespace::ClassName]
1010
[\-\-cpp\-client-file=classname.h] [\-\-js\-client=ClassName]
11-
[\-\-js-client-file=classname.js] [\-h] [\-v]
11+
[\-\-js-client-file=classname.js] [\-h] [\-v] [\-\-version]
1212
.PP
1313

1414
.SH DESCRIPTION
@@ -22,12 +22,12 @@ with their corresponding parameters and return values contained in a top\-level
2222
.nf
2323
[
2424
{
25-
"name": "method_with_positional_params",
26-
"params": [3,4],
25+
"name": "method_with_positional_params",
26+
"params": [3,4],
2727
"returns": 7
2828
},
2929
{
30-
"name": "methid_with_named_params",
30+
"name": "method_with_named_params",
3131
"params": {"param1": 3, "param2": 4},
3232
"returns": 7
3333
},
@@ -42,25 +42,27 @@ The literal in each \fB"params"\fP and \fB"returns"\fP section defines the corr
4242
If the \fb"params"\fP contains an array, the parameters are accepted by position,
4343
if it contains an object, they are accepted by name.
4444
.SH OPTIONS
45-
.IP -h
45+
.IP \-h
4646
Print usage information.
47-
.IP -v
47+
.IP \-v
4848
Print verbose information during generation.
49-
.IP --cpp-server=ClassName
49+
.IP \-\-version
50+
Print version info and exit.
51+
.IP \-\-cpp\-server=ClassName
5052
Creates a Abstract Server class. Namespaces can be provided using the :: notation
5153
(e.g. ns1::ns2::Classname).
52-
.IP --cpp-server-file=filename.h
54+
.IP \-\-cpp\-server\-file=filename.h
5355
Defines the filename to use when generating the C++ Abstract Server class.
5456
If this is not provided, the lowercase classname is used.
55-
.IP --cpp-client=ClassName
57+
.IP \-\-cpp\-client=ClassName
5658
Creates a C++ client class. Namespaces can be provided using the :: notation
5759
(e.g. ns1::ns2::Classname).
58-
.IP --cpp-client-file=filename.h
60+
.IP \-\-cpp\-client\-file=filename.h
5961
Defines the filename to use when generating the C++ client class.
6062
If this is not provided, the lowercase classname is used.
61-
.IP --js-client=ClassName
63+
.IP \-\-js\-client=ClassName
6264
Creates a JavaScript client class. No namespaces are supported in this option.
63-
.IP --js-client-file=filename.js
65+
.IP \-\-js\-client-file=filename.js
6466
Defines the filename to use when generating the JavaScrip client class.
6567
.SH EXAMPLES
6668
.PP
@@ -104,4 +106,4 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
104106
OR OTHER DEALINGS IN THE SOFTWARE.
105107

106108
.SH AUTHOR
107-
Peter Spiess\-Knafl (psk@autistici.org)
109+
Peter Spiess\-Knafl (dev@spiessknafl.at)

src/examples/CMakeLists.txt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/gen)
22

3-
# TODO optimize these scripts, so we will not have to recompile examples every time
43
add_custom_command(
5-
OUTPUT abstractstubserver.h
6-
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-server=AbstractStubServer --cpp-server-file=${CMAKE_BINARY_DIR}/gen/abstractsubserver.h
4+
OUTPUT ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
5+
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-server=AbstractStubServer --cpp-server-file=${CMAKE_BINARY_DIR}/gen/abstractstubserver.h
76
MAIN_DEPENDENCY spec.json
87
DEPENDS jsonrpcstub
98
COMMENT "Generating Server Stubfiles"
109
VERBATIM
1110
)
1211

1312
add_custom_command(
14-
OUTPUT stubclient.h
13+
OUTPUT ${CMAKE_BINARY_DIR}/gen/stubclient.h
1514
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-client=StubClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/stubclient.h
1615
MAIN_DEPENDENCY spec.json
1716
DEPENDS jsonrpcstub
1817
COMMENT "Generating Client Stubfile"
1918
VERBATIM
2019
)
2120

21+
add_custom_target(common_stubs
22+
DEPENDS ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h ${CMAKE_BINARY_DIR}/gen/stubclient.h
23+
)
24+
2225
add_custom_command(
23-
OUTPUT xbmcremote.h
26+
OUTPUT ${CMAKE_BINARY_DIR}/gen/xbmcremote.h
2427
COMMAND jsonrpcstub ARGS 10000 ${CMAKE_CURRENT_SOURCE_DIR}/xbmc_remote.json --cpp-client=XbmcRemoteClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/xbmcremote.h
2528
MAIN_DEPENDENCY xbmc_remote.json
2629
DEPENDS jsonrpcstub
@@ -33,22 +36,21 @@ include_directories(${CMAKE_BINARY_DIR})
3336
include_directories(${JSONCPP_INCLUDE_DIRS})
3437
include_directories(${MHD_INCLUDE_DIRS})
3538

36-
if (HTTP_SERVER AND HTTP_CLIENT)
39+
if (COMPILE_EXAMPLES)
3740
add_executable(simpleserversample simpleserver.cpp)
3841
target_link_libraries(simpleserversample jsonrpcserver)
3942

4043
add_executable(simpleclientsample simpleclient.cpp)
4144
target_link_libraries(simpleclientsample jsonrpcclient)
42-
endif()
4345

44-
if (COMPILE_STUBGEN AND HTTP_SERVER AND HTTP_CLIENT)
45-
add_executable(stubclientsample stubclient.cpp stubclient.h)
46-
target_link_libraries(stubclientsample jsonrpcclient)
46+
if (COMPILE_STUBGEN)
47+
add_executable(stubclientsample stubclient.cpp ${CMAKE_BINARY_DIR}/gen/stubclient.h)
48+
target_link_libraries(stubclientsample jsonrpcclient)
4749

48-
add_executable(stubserversample stubserver.cpp abstractstubserver.h)
49-
target_link_libraries(stubserversample jsonrpcserver)
50+
add_executable(stubserversample stubserver.cpp ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h)
51+
target_link_libraries(stubserversample jsonrpcserver)
5052

51-
add_executable(xbmcremote xbmcremote.cpp xbmcremote.h)
52-
target_link_libraries(xbmcremote jsonrpcclient)
53+
add_executable(xbmcremote xbmcremote.cpp ${CMAKE_BINARY_DIR}/gen/xbmcremote.h)
54+
target_link_libraries(xbmcremote jsonrpcclient)
55+
endif()
5356
endif()
54-

src/examples/stubserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
************************************************************************/
99
#include <iostream>
1010

11-
#include "gen/abstractsubserver.h"
11+
#include "gen/abstractstubserver.h"
1212
#include <jsonrpccpp/server/connectors/httpserver.h>
1313
#include <stdio.h>
1414

src/jsonrpccpp/CMakeLists.txt

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,36 +65,48 @@ target_link_libraries(jsonrpccommon ${JSONCPP_LIBRARIES})
6565
set_target_properties(jsonrpccommon PROPERTIES OUTPUT_NAME jsonrpccpp-common)
6666

6767
# setup static common library
68-
add_library(jsonrpccommonStatic STATIC ${jsonrpc_source_common} ${jsonrpc_header} ${jsonrpc_helper_source_common})
69-
target_link_libraries(jsonrpccommonStatic ${JSONCPP_LIBRARIES})
70-
set_target_properties(jsonrpccommonStatic PROPERTIES OUTPUT_NAME jsonrpccpp-common)
68+
if (BUILD_STATIC_LIBS)
69+
add_library(jsonrpccommonStatic STATIC ${jsonrpc_source_common} ${jsonrpc_header} ${jsonrpc_helper_source_common})
70+
target_link_libraries(jsonrpccommonStatic ${JSONCPP_LIBRARIES})
71+
set_target_properties(jsonrpccommonStatic PROPERTIES OUTPUT_NAME jsonrpccpp-common)
72+
endif()
7173

7274
# setup shared client library
7375
add_library(jsonrpcclient SHARED ${jsonrpc_source_client} ${jsonrpc_header} ${jsonrpc_header_client} ${client_connector_source})
74-
add_dependencies(jsonrpcclient jsonrpccommonStatic)
76+
add_dependencies(jsonrpcclient jsonrpccommon)
7577
target_link_libraries(jsonrpcclient jsonrpccommon ${client_connector_libs})
7678
set_target_properties(jsonrpcclient PROPERTIES OUTPUT_NAME jsonrpccpp-client)
7779

7880
# setup static client library
79-
add_library(jsonrpcclientStatic STATIC ${jsonrpc_source_client} ${jsonrpc_header} ${jsonrpc_header_client} ${client_connector_source})
80-
target_link_libraries(jsonrpcclientStatic jsonrpccommonStatic ${client_connector_libs})
81-
set_target_properties(jsonrpcclientStatic PROPERTIES OUTPUT_NAME jsonrpccpp-client)
81+
if (BUILD_STATIC_LIBS)
82+
add_library(jsonrpcclientStatic STATIC ${jsonrpc_source_client} ${jsonrpc_header} ${jsonrpc_header_client} ${client_connector_source})
83+
target_link_libraries(jsonrpcclientStatic jsonrpccommonStatic ${client_connector_libs})
84+
set_target_properties(jsonrpcclientStatic PROPERTIES OUTPUT_NAME jsonrpccpp-client)
85+
endif()
8286

8387
# setup shared server library
8488
add_library(jsonrpcserver SHARED ${jsonrpc_source_server} ${jsonrpc_header} ${jsonrpc_header_server} ${server_connector_source})
85-
add_dependencies(jsonrpcserver jsonrpccommonStatic)
89+
add_dependencies(jsonrpcserver jsonrpccommon)
8690
target_link_libraries(jsonrpcserver jsonrpccommon ${server_connector_libs})
8791
set_target_properties(jsonrpcserver PROPERTIES OUTPUT_NAME jsonrpccpp-server)
8892

8993
# setup static server library
90-
add_library(jsonrpcserverStatic STATIC ${jsonrpc_source_server} ${jsonrpc_header} ${jsonrpc_header_server} ${server_connector_source})
91-
target_link_libraries(jsonrpcserverStatic jsonrpccommonStatic ${server_connector_libs})
92-
set_target_properties(jsonrpcserverStatic PROPERTIES OUTPUT_NAME jsonrpccpp-server)
94+
if (BUILD_STATIC_LIBS)
95+
add_library(jsonrpcserverStatic STATIC ${jsonrpc_source_server} ${jsonrpc_header} ${jsonrpc_header_server} ${server_connector_source})
96+
target_link_libraries(jsonrpcserverStatic jsonrpccommonStatic ${server_connector_libs})
97+
set_target_properties(jsonrpcserverStatic PROPERTIES OUTPUT_NAME jsonrpccpp-server)
98+
endif()
99+
100+
set(ALL_LIBS jsonrpccommon jsonrpcclient jsonrpcserver)
101+
102+
if (BUILD_STATIC_LIBS)
103+
list(APPEND ALL_LIBS jsonrpccommonStatic jsonrpcclientStatic jsonrpcserverStatic)
104+
endif()
93105

94106
# setup version
95107
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
96108
set_target_properties(
97-
jsonrpccommon jsonrpccommonStatic jsonrpcclient jsonrpcclientStatic jsonrpcserver jsonrpcserverStatic
109+
${ALL_LIBS}
98110
PROPERTIES VERSION "${VERSION_STRING}" SOVERSION "${SO_VERSION}"
99111
)
100112

@@ -114,9 +126,9 @@ if (WIN32)
114126
install(DIRECTORY ${CMAKE_SOURCE_DIR}/win32-deps/include DESTINATION .)
115127
endif()
116128

117-
install(TARGETS jsonrpccommon jsonrpccommonStatic jsonrpcclient jsonrpcclientStatic jsonrpcserver jsonrpcserverStatic
118-
LIBRARY DESTINATION lib
119-
ARCHIVE DESTINATION lib
129+
install(TARGETS ${ALL_LIBS}
130+
LIBRARY DESTINATION lib${LIB_SUFFIX}
131+
ARCHIVE DESTINATION lib${LIB_SUFFIX}
120132
RUNTIME DESTINATION bin
121133
)
122134

src/jsonrpccpp/client/connectors/httpclient.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717

1818
using namespace jsonrpc;
1919

20+
class curl_initializer {
21+
public:
22+
curl_initializer() {curl_global_init(CURL_GLOBAL_ALL);}
23+
~curl_initializer() {curl_global_cleanup();}
24+
};
25+
26+
// See here: http://curl.haxx.se/libcurl/c/curl_global_init.html
27+
static curl_initializer _curl_init = curl_initializer();
28+
2029
/**
2130
* taken from http://stackoverflow.com/questions/2329571/c-libcurl-get-output-into-a-string
2231
*/
@@ -48,11 +57,16 @@ HttpClient::HttpClient(const std::string& url) throw(JsonRpcException)
4857
: url(url)
4958
{
5059
this->timeout = 10000;
60+
curl = curl_easy_init();
61+
}
62+
63+
HttpClient::~HttpClient()
64+
{
65+
curl_easy_cleanup(curl);
5166
}
5267

5368
void HttpClient::SendRPCMessage(const std::string& message, std::string& result) throw (JsonRpcException)
5469
{
55-
CURL* curl = curl_easy_init();
5670
curl_easy_setopt(curl, CURLOPT_URL, this->url.c_str());
5771
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
5872

@@ -89,7 +103,6 @@ void HttpClient::SendRPCMessage(const std::string& message, std::string& result)
89103
str << " -> Could not connect to " << this->url;
90104
else if(res == 28)
91105
str << " -> Operation timed out";
92-
curl_easy_cleanup(curl);
93106
throw JsonRpcException(Errors::ERROR_CLIENT_CONNECTOR, str.str());
94107
}
95108

@@ -98,11 +111,8 @@ void HttpClient::SendRPCMessage(const std::string& message, std::string& result)
98111

99112
if (http_code != 200)
100113
{
101-
curl_easy_cleanup(curl);
102114
throw JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR, result);
103115
}
104-
105-
curl_easy_cleanup(curl);
106116
}
107117

108118
void HttpClient::SetUrl(const std::string& url)

src/jsonrpccpp/client/connectors/httpclient.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "../iclientconnector.h"
1414
#include <jsonrpccpp/common/exception.h>
15+
#include <curl/curl.h>
1516
#include <map>
1617

1718
namespace jsonrpc
@@ -20,7 +21,7 @@ namespace jsonrpc
2021
{
2122
public:
2223
HttpClient(const std::string& url) throw (JsonRpcException);
23-
24+
virtual ~HttpClient();
2425
virtual void SendRPCMessage(const std::string& message, std::string& result) throw (JsonRpcException);
2526

2627
void SetUrl(const std::string& url);
@@ -37,6 +38,7 @@ namespace jsonrpc
3738
* @brief timeout for http request in milliseconds
3839
*/
3940
long timeout;
41+
CURL* curl;
4042
};
4143

4244
} /* namespace jsonrpc */

0 commit comments

Comments
 (0)
0