Skip to content

Commit

Permalink
Merge branch 'release/v0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Spiess-Knafl committed Apr 7, 2015
2 parents b342d6e + 30b3858 commit 0383719
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 77 deletions.
5 changes: 4 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ Kasper Laudrup <laudrup@stacktrace.dk>

Erik Lundin
+ bugfix in cpp-server stubgen
+ bugfix for gcc 4.7 compatibility
+ bugfix for gcc 4.7 compatibility

Michał Górny <mgorny@gentoo.org>
+ bugfixes in the build system
13 changes: 10 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
Changes in v0.4.3 [unreleased]
Changes in v0.5.0
-----------------
- added `--version` option to jsonrpcstub
- added msvc support
- added `--version` option to jsonrpcstub.
- added msvc support.
- added data field support for JsonRpcException.
- added contributions guide: https://github.com/cinemast/libjson-rpc-cpp#contributions
- HttpClient uses Http Keep-Alive, which improves performance drastically.
- Added `LIB_SUFFIX` to CMake to support multilib.
- Fixed building tests with examples disabled.
- Made static library build optional (via `BUILD_STATIC_LIBS`).
- Fixed unnecessary rebuilds of stubs on each `make` call.

Changes in v0.4.2
-----------------
Expand Down
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ if (${CMAKE_MAJOR_VERSION} GREATER 2)
endif()

set(MAJOR_VERSION 0)
set(MINOR_VERSION 4)
set(PATCH_VERSION 2)
set(MINOR_VERSION 5)
set(PATCH_VERSION 0)
set(SO_VERSION 0)

set(BUILD_STATIC_LIBS NO CACHE BOOL "Build static libraries in addition to shared")
set(LIB_SUFFIX "" CACHE STRING "Suffix for library directory (32/64)")

# defaults for modules that can be enabled/disabled
set(HTTP_SERVER YES CACHE BOOL "Include HTTP server using libmicrohttpd")
set(HTTP_CLIENT YES CACHE BOOL "Include HTTP client support using curl")
Expand Down Expand Up @@ -58,7 +61,7 @@ if (COMPILE_STUBGEN)
endif ()

# setup examples
if (COMPILE_EXAMPLES AND HTTP_SERVER AND HTTP_CLIENT)
if (HTTP_SERVER AND HTTP_CLIENT)
add_subdirectory(src/examples)
endif()

Expand Down
2 changes: 1 addition & 1 deletion dev/testcoverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bin/unit_testsuite

echo "Generate HTML report"
mkdir -p reports
gcovr -r .. -d -e "src/test" --html --html-details -o reports/coverage.html
gcovr -r .. -d -e "build" -e "src/test" --html --html-details -o reports/coverage.html
xdg-open reports/coverage.html
cd ../dev

30 changes: 16 additions & 14 deletions doc/manpage.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.\" Manpage for jsonrpcstub.
.\" Contact psk@autistici.org to correct errors or typos.
.TH man 1 "22 November 2014" "@MAJOR_VERSION@.@MINOR_VERSION@.@PATCH_VERSION@" "jsonrpcstub man page"
.TH man 1 "7 April 2015" "@MAJOR_VERSION@.@MINOR_VERSION@.@PATCH_VERSION@" "jsonrpcstub man page"
.SH NAME
jsonrpcstub \- genearate stubs for the libjson\-rpc\-cpp framework.
.SH SYNOPSIS
.B
jsonrpcstub specfile.json [\-\-cpp\-server=namespace::ClassName]
[\-\-cpp\-server\-file=classqname.h] [\-\-cpp\-client=namespace::ClassName]
[\-\-cpp\-client-file=classname.h] [\-\-js\-client=ClassName]
[\-\-js-client-file=classname.js] [\-h] [\-v]
[\-\-js-client-file=classname.js] [\-h] [\-v] [\-\-version]
.PP

.SH DESCRIPTION
Expand All @@ -22,12 +22,12 @@ with their corresponding parameters and return values contained in a top\-level
.nf
[
{
"name": "method_with_positional_params",
"params": [3,4],
"name": "method_with_positional_params",
"params": [3,4],
"returns": 7
},
{
"name": "methid_with_named_params",
"name": "method_with_named_params",
"params": {"param1": 3, "param2": 4},
"returns": 7
},
Expand All @@ -42,25 +42,27 @@ The literal in each \fB"params"\fP and \fB"returns"\fP section defines the corr
If the \fb"params"\fP contains an array, the parameters are accepted by position,
if it contains an object, they are accepted by name.
.SH OPTIONS
.IP -h
.IP \-h
Print usage information.
.IP -v
.IP \-v
Print verbose information during generation.
.IP --cpp-server=ClassName
.IP \-\-version
Print version info and exit.
.IP \-\-cpp\-server=ClassName
Creates a Abstract Server class. Namespaces can be provided using the :: notation
(e.g. ns1::ns2::Classname).
.IP --cpp-server-file=filename.h
.IP \-\-cpp\-server\-file=filename.h
Defines the filename to use when generating the C++ Abstract Server class.
If this is not provided, the lowercase classname is used.
.IP --cpp-client=ClassName
.IP \-\-cpp\-client=ClassName
Creates a C++ client class. Namespaces can be provided using the :: notation
(e.g. ns1::ns2::Classname).
.IP --cpp-client-file=filename.h
.IP \-\-cpp\-client\-file=filename.h
Defines the filename to use when generating the C++ client class.
If this is not provided, the lowercase classname is used.
.IP --js-client=ClassName
.IP \-\-js\-client=ClassName
Creates a JavaScript client class. No namespaces are supported in this option.
.IP --js-client-file=filename.js
.IP \-\-js\-client-file=filename.js
Defines the filename to use when generating the JavaScrip client class.
.SH EXAMPLES
.PP
Expand Down Expand Up @@ -104,4 +106,4 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
OR OTHER DEALINGS IN THE SOFTWARE.

.SH AUTHOR
Peter Spiess\-Knafl (psk@autistici.org)
Peter Spiess\-Knafl (dev@spiessknafl.at)
32 changes: 17 additions & 15 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/gen)

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

add_custom_command(
OUTPUT stubclient.h
OUTPUT ${CMAKE_BINARY_DIR}/gen/stubclient.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/spec.json --cpp-client=StubClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/stubclient.h
MAIN_DEPENDENCY spec.json
DEPENDS jsonrpcstub
COMMENT "Generating Client Stubfile"
VERBATIM
)

add_custom_target(common_stubs
DEPENDS ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h ${CMAKE_BINARY_DIR}/gen/stubclient.h
)

add_custom_command(
OUTPUT xbmcremote.h
OUTPUT ${CMAKE_BINARY_DIR}/gen/xbmcremote.h
COMMAND jsonrpcstub ARGS ${CMAKE_CURRENT_SOURCE_DIR}/xbmc_remote.json --cpp-client=XbmcRemoteClient --cpp-client-file=${CMAKE_BINARY_DIR}/gen/xbmcremote.h
MAIN_DEPENDENCY xbmc_remote.json
DEPENDS jsonrpcstub
Expand All @@ -33,22 +36,21 @@ include_directories(${CMAKE_BINARY_DIR})
include_directories(${JSONCPP_INCLUDE_DIRS})
include_directories(${MHD_INCLUDE_DIRS})

if (HTTP_SERVER AND HTTP_CLIENT)
if (COMPILE_EXAMPLES)
add_executable(simpleserversample simpleserver.cpp)
target_link_libraries(simpleserversample jsonrpcserver)

add_executable(simpleclientsample simpleclient.cpp)
target_link_libraries(simpleclientsample jsonrpcclient)
endif()

if (COMPILE_STUBGEN AND HTTP_SERVER AND HTTP_CLIENT)
add_executable(stubclientsample stubclient.cpp stubclient.h)
target_link_libraries(stubclientsample jsonrpcclient)
if (COMPILE_STUBGEN)
add_executable(stubclientsample stubclient.cpp ${CMAKE_BINARY_DIR}/gen/stubclient.h)
target_link_libraries(stubclientsample jsonrpcclient)

add_executable(stubserversample stubserver.cpp abstractstubserver.h)
target_link_libraries(stubserversample jsonrpcserver)
add_executable(stubserversample stubserver.cpp ${CMAKE_BINARY_DIR}/gen/abstractstubserver.h)
target_link_libraries(stubserversample jsonrpcserver)

add_executable(xbmcremote xbmcremote.cpp xbmcremote.h)
target_link_libraries(xbmcremote jsonrpcclient)
add_executable(xbmcremote xbmcremote.cpp ${CMAKE_BINARY_DIR}/gen/xbmcremote.h)
target_link_libraries(xbmcremote jsonrpcclient)
endif()
endif()

2 changes: 1 addition & 1 deletion src/examples/stubserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
************************************************************************/
#include <iostream>

#include "gen/abstractsubserver.h"
#include "gen/abstractstubserver.h"
#include <jsonrpccpp/server/connectors/httpserver.h>
#include <stdio.h>

Expand Down
42 changes: 27 additions & 15 deletions src/jsonrpccpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,36 +65,48 @@ target_link_libraries(jsonrpccommon ${JSONCPP_LIBRARIES})
set_target_properties(jsonrpccommon PROPERTIES OUTPUT_NAME jsonrpccpp-common)

# setup static common library
add_library(jsonrpccommonStatic STATIC ${jsonrpc_source_common} ${jsonrpc_header} ${jsonrpc_helper_source_common})
target_link_libraries(jsonrpccommonStatic ${JSONCPP_LIBRARIES})
set_target_properties(jsonrpccommonStatic PROPERTIES OUTPUT_NAME jsonrpccpp-common)
if (BUILD_STATIC_LIBS)
add_library(jsonrpccommonStatic STATIC ${jsonrpc_source_common} ${jsonrpc_header} ${jsonrpc_helper_source_common})
target_link_libraries(jsonrpccommonStatic ${JSONCPP_LIBRARIES})
set_target_properties(jsonrpccommonStatic PROPERTIES OUTPUT_NAME jsonrpccpp-common)
endif()

# setup shared client library
add_library(jsonrpcclient SHARED ${jsonrpc_source_client} ${jsonrpc_header} ${jsonrpc_header_client} ${client_connector_source})
add_dependencies(jsonrpcclient jsonrpccommonStatic)
add_dependencies(jsonrpcclient jsonrpccommon)
target_link_libraries(jsonrpcclient jsonrpccommon ${client_connector_libs})
set_target_properties(jsonrpcclient PROPERTIES OUTPUT_NAME jsonrpccpp-client)

# setup static client library
add_library(jsonrpcclientStatic STATIC ${jsonrpc_source_client} ${jsonrpc_header} ${jsonrpc_header_client} ${client_connector_source})
target_link_libraries(jsonrpcclientStatic jsonrpccommonStatic ${client_connector_libs})
set_target_properties(jsonrpcclientStatic PROPERTIES OUTPUT_NAME jsonrpccpp-client)
if (BUILD_STATIC_LIBS)
add_library(jsonrpcclientStatic STATIC ${jsonrpc_source_client} ${jsonrpc_header} ${jsonrpc_header_client} ${client_connector_source})
target_link_libraries(jsonrpcclientStatic jsonrpccommonStatic ${client_connector_libs})
set_target_properties(jsonrpcclientStatic PROPERTIES OUTPUT_NAME jsonrpccpp-client)
endif()

# setup shared server library
add_library(jsonrpcserver SHARED ${jsonrpc_source_server} ${jsonrpc_header} ${jsonrpc_header_server} ${server_connector_source})
add_dependencies(jsonrpcserver jsonrpccommonStatic)
add_dependencies(jsonrpcserver jsonrpccommon)
target_link_libraries(jsonrpcserver jsonrpccommon ${server_connector_libs})
set_target_properties(jsonrpcserver PROPERTIES OUTPUT_NAME jsonrpccpp-server)

# setup static server library
add_library(jsonrpcserverStatic STATIC ${jsonrpc_source_server} ${jsonrpc_header} ${jsonrpc_header_server} ${server_connector_source})
target_link_libraries(jsonrpcserverStatic jsonrpccommonStatic ${server_connector_libs})
set_target_properties(jsonrpcserverStatic PROPERTIES OUTPUT_NAME jsonrpccpp-server)
if (BUILD_STATIC_LIBS)
add_library(jsonrpcserverStatic STATIC ${jsonrpc_source_server} ${jsonrpc_header} ${jsonrpc_header_server} ${server_connector_source})
target_link_libraries(jsonrpcserverStatic jsonrpccommonStatic ${server_connector_libs})
set_target_properties(jsonrpcserverStatic PROPERTIES OUTPUT_NAME jsonrpccpp-server)
endif()

set(ALL_LIBS jsonrpccommon jsonrpcclient jsonrpcserver)

if (BUILD_STATIC_LIBS)
list(APPEND ALL_LIBS jsonrpccommonStatic jsonrpcclientStatic jsonrpcserverStatic)
endif()

# setup version
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
set_target_properties(
jsonrpccommon jsonrpccommonStatic jsonrpcclient jsonrpcclientStatic jsonrpcserver jsonrpcserverStatic
${ALL_LIBS}
PROPERTIES VERSION "${VERSION_STRING}" SOVERSION "${SO_VERSION}"
)

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

install(TARGETS jsonrpccommon jsonrpccommonStatic jsonrpcclient jsonrpcclientStatic jsonrpcserver jsonrpcserverStatic
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
install(TARGETS ${ALL_LIBS}
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX}
RUNTIME DESTINATION bin
)

20 changes: 15 additions & 5 deletions src/jsonrpccpp/client/connectors/httpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@

using namespace jsonrpc;

class curl_initializer {
public:
curl_initializer() {curl_global_init(CURL_GLOBAL_ALL);}
~curl_initializer() {curl_global_cleanup();}
};

// See here: http://curl.haxx.se/libcurl/c/curl_global_init.html
static curl_initializer _curl_init = curl_initializer();

/**
* taken from http://stackoverflow.com/questions/2329571/c-libcurl-get-output-into-a-string
*/
Expand Down Expand Up @@ -48,11 +57,16 @@ HttpClient::HttpClient(const std::string& url) throw(JsonRpcException)
: url(url)
{
this->timeout = 10000;
curl = curl_easy_init();
}

HttpClient::~HttpClient()
{
curl_easy_cleanup(curl);
}

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

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

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

if (http_code != 200)
{
curl_easy_cleanup(curl);
throw JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR, result);
}

curl_easy_cleanup(curl);
}

void HttpClient::SetUrl(const std::string& url)
Expand Down
4 changes: 3 additions & 1 deletion src/jsonrpccpp/client/connectors/httpclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "../iclientconnector.h"
#include <jsonrpccpp/common/exception.h>
#include <curl/curl.h>
#include <map>

namespace jsonrpc
Expand All @@ -20,7 +21,7 @@ namespace jsonrpc
{
public:
HttpClient(const std::string& url) throw (JsonRpcException);

virtual ~HttpClient();
virtual void SendRPCMessage(const std::string& message, std::string& result) throw (JsonRpcException);

void SetUrl(const std::string& url);
Expand All @@ -37,6 +38,7 @@ namespace jsonrpc
* @brief timeout for http request in milliseconds
*/
long timeout;
CURL* curl;
};

} /* namespace jsonrpc */
Expand Down
Loading

0 comments on commit 0383719

Please sign in to comment.