Skip to content

Commit 6c5e353

Browse files
committed
Made further refinements to the API.
- The library now depends on Boost 1.58, which now includes Boost.Endian. This removes the dependency on the "standalone" Boost.Endian (closes #5). - Revamped subscriptions and registrations to more closely model Boost.Signals2 connection management. Users are no longer forced to keep `Subscription`/`Registration` objects alive. `ScopedSubscription` and `ScopedRegistraton` have been added to permit automatic lifetime management, if desired (closes #45). - RPC handlers are now required to return an `Outcome` object. This makes it harder to forget returning a result from within an RPC handler (closes #46). - Statically-typed call/event handlers are now handled by `EventUnpacker` and `InvocationUnpacker` wrappers. This eliminates the need for `Session::subscribe` and `Session::enroll` overloads, and greatly simplifies subscription/registration management (closes #51). - Unpacking of positional arguments for statically-typed call/event slots now uses a simpler technique inspired by `std::integer_sequence` (closes #52) - Updated examples and tests to use raw socket handshaking, which is now supported on Crossbar (closes #54).
1 parent 05e76be commit 6c5e353

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2732
-2342
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
v0.3.0
2+
======
3+
Made further refinements to the API. The minimal Boost library version required is now 1.58.0.
4+
5+
### Details
6+
- The library now depends on Boost 1.58, which now includes Boost.Endian. This removes the dependency on the "standalone" Boost.Endian (closes #5).
7+
- Revamped subscriptions and registrations to more closely model Boost.Signals2 connection management. Users are no longer forced to keep `Subscription`/`Registration` objects alive. `ScopedSubscription` and `ScopedRegistraton` have been added to permit automatic lifetime management, if desired (closes #45).
8+
- RPC handlers are now required to return an `Outcome` object. This makes it harder to forget returning a result from within an RPC handler (closes #46).
9+
- Statically-typed call/event handlers are now handled by `EventUnpacker` and `InvocationUnpacker` wrappers. This eliminates the need for `Session::subscribe` and `Session::enroll` overloads, and greatly simplifies subscription/registration management (closes #51).
10+
- Unpacking of positional arguments for statically-typed call/event slots now uses a simpler technique inspired by `std::integer_sequence` (closes #52)
11+
- Updated examples and tests to use raw socket handshaking, which is now supported on Crossbar (closes #54).
12+
113
v0.2.0
214
======
315
Overhauled API to make use of fluent API techniques. Some Advanced WAMP Profile features are now supported.

CMakeLists.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ cmake_minimum_required (VERSION 2.8)
99
project (cppwamp)
1010

1111
# First attempt to find Boost library directories
12-
set(BOOST_MIN_VERSION 1.56.0)
13-
#set(BOOST_COMPONENTS coroutine context thread system)
14-
set(BOOST_COMPONENTS coroutine context system)
12+
set(BOOST_MIN_VERSION 1.58.0)
13+
set(BOOST_COMPONENTS coroutine context thread system)
1514
set(BOOST_ROOT ./ext/boost)
1615
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS ${BOOST_COMPONENTS})
1716
if(Boost_FOUND)
@@ -31,15 +30,19 @@ set(PATH_LIB_BOOST ${SUGGESTED_BOOST_LIBRARY_PATH} CACHE PATH
3130

3231
# Add GUI variables that let the user specify the include path for other
3332
# third-party libraries.
34-
set(PATH_INCLUDE_ENDIAN ${PROJECT_SOURCE_DIR}/ext/endian/include CACHE PATH
35-
"Boost.Endian include path")
3633
set(PATH_INCLUDE_RAPIDJSON ${PROJECT_SOURCE_DIR}/ext/rapidjson/include CACHE PATH
3734
"RapidJson include path")
3835
set(PATH_INCLUDE_MSGPACK ${PROJECT_SOURCE_DIR}/ext/msgpack-c/include CACHE PATH
3936
"Msgpack-c include path")
4037
set(PATH_INCLUDE_CATCH ${PROJECT_SOURCE_DIR}/ext/Catch/include CACHE PATH
4138
"Catch include path")
4239

40+
# Add GUI variables that let the user specify that legacy connectors should be
41+
# used for tests and examples.
42+
option(CPPWAMP_USE_NON_HANDSHAKING_TRANSPORTS
43+
"Use non-handshaking raw socket transports in tests and examples"
44+
OFF)
45+
4346
# Confirm that the user's choices for the Boost library paths are valid.
4447
unset(BOOST_ROOT)
4548
set(BOOST_INCLUDEDIR ${PATH_INCLUDE_BOOST})
@@ -59,7 +62,6 @@ endif()
5962
# Add the include paths to third-party libraries
6063
include_directories(
6164
${PATH_INCLUDE_BOOST}
62-
${PATH_INCLUDE_ENDIAN}
6365
${PATH_INCLUDE_RAPIDJSON}
6466
${PATH_INCLUDE_MSGPACK}
6567
)
@@ -77,6 +79,12 @@ if(CMAKE_USE_PTHREADS_INIT)
7779
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
7880
endif()
7981

82+
# Add the appropriate preprocessor macro define if the user specified
83+
# non-handshaking transports.
84+
if(CPPWAMP_USE_NON_HANDSHAKING_TRANSPORTS)
85+
add_definitions(-DCPPWAMP_USE_LEGACY_CONNECTORS)
86+
endif()
87+
8088
# Add targets for the cppwamp library itself, units tests, and examples.
8189
add_subdirectory(cppwamp)
8290
add_subdirectory(test)

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ C++11 client library for the [WAMP][wamp] protocol.
2020
**Dependencies**:
2121

2222
- [Boost.Asio][boost-asio] for raw socket transport
23-
- [Boost.Endian][boost-endian] (requires [Boost][boost] 1.57.0 or greater)
23+
- [Boost.Endian][boost-endian] (requires [Boost][boost] 1.58.0 or greater)
2424
- [RapidJSON][rapidjson]
2525
- [msgpack-c][msgpack-c]
2626
- (optional) [Boost.Coroutine][boost-coroutine] and
@@ -68,6 +68,8 @@ This library has been tested with:
6868
Usage Examples (using coroutines)
6969
---------------------------------
7070

71+
_For a more comprehensive overview, check out the [Tutorials](https://github.com/ecorm/cppwamp/wiki/Tutorial) in the wiki._
72+
7173
### Establishing a WAMP session
7274
```c++
7375
wamp::AsioService iosvc;
@@ -90,25 +92,20 @@ iosvc.run();
9092
9193
### Registering a remote procedure
9294
```c++
93-
void add(wamp::Invocation inv, int n, int m)
94-
{
95-
inv.yield({n + m});
96-
}
97-
9895
boost::asio::spawn(iosvc, [&](boost::asio::yield_context yield)
9996
{
10097
:::
101-
auto reg = session->enroll<int, int>(Procedure("add"), &add, yield);
98+
session->enroll(Procedure("add"), unpackedRpc<int, int>(
99+
[](wamp::Invocation inv, int n, int m) {return {n+m};}),
100+
yield);
102101
:::
103102
});
104103
```
105104

106105
### Calling a remote procedure
107106
```c++
108107
auto result = session->call(Rpc("add").withArgs({2, 2}), yield);
109-
int sum = 0;
110-
result.convertTo(sum);
111-
std::cout << "2 + 2 is " << sum << "\n";
108+
std::cout << "2 + 2 is " << result[0].to<int>() << "\n";
112109
```
113110
114111
### Subscribing to a topic
@@ -122,8 +119,9 @@ void sensorSampled(wamp::Event event, float value)
122119
boost::asio::spawn(iosvc, [&](boost::asio::yield_context yield)
123120
{
124121
:::
125-
auto sub = session->subscribe<float>(Topic("sensorSampled"),
126-
&sensorSampled, yield);
122+
session->subscribe(Topic("sensorSampled"),
123+
unpackedEvent<float>(&sensorSampled),
124+
yield);
127125
:::
128126
});
129127
```
@@ -146,7 +144,7 @@ session->publish(Pub("sensorSampled").withArgs({value}));
146144
Questions, Discussions, and Issues
147145
----------------------------------
148146
149-
For general questions and discussion regarding CppWAMP, please use the
147+
For general questions and discussions regarding CppWAMP, please use the
150148
[CppWAMP Google Group][googlegroup] (membership required).
151149
152150
For reporting bugs or for suggesting enhancements, please use the GitHub

cppwamp.pro

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,5 @@ OTHER_FILES += \
2323
Doxyfile.in \
2424
doc/concepts.dox \
2525
doc/cppwamp.dox \
26-
doc/args.md \
27-
doc/async.md \
28-
doc/connectors.md \
29-
doc/errors.md \
30-
doc/pubsub.md \
31-
doc/rpc.md \
32-
doc/sessions.md \
33-
doc/tutorial.md \
34-
doc/variant.md
26+
doc/registrations.dox \
27+
doc/subscriptions.dox

cppwamp/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(HEADERS
2929
include/cppwamp/subscription.hpp
3030
include/cppwamp/tcpconnector.hpp
3131
include/cppwamp/udsconnector.hpp
32+
include/cppwamp/unpacker.hpp
3233
include/cppwamp/variant.hpp
3334
include/cppwamp/varianttuple.hpp
3435
include/cppwamp/version.hpp
@@ -47,15 +48,15 @@ set(HEADERS
4748
include/cppwamp/internal/legacyasioendpoint.hpp
4849
include/cppwamp/internal/legacyasiotransport.hpp
4950
include/cppwamp/internal/messagetraits.hpp
51+
include/cppwamp/internal/precompiled.hpp
5052
include/cppwamp/internal/rawsockhandshake.hpp
5153
include/cppwamp/internal/rawsockheader.hpp
52-
include/cppwamp/internal/registrationimpl.hpp
5354
include/cppwamp/internal/subscriber.hpp
54-
include/cppwamp/internal/subscriptionimpl.hpp
5555
include/cppwamp/internal/tcpacceptor.hpp
5656
include/cppwamp/internal/tcpopener.hpp
5757
include/cppwamp/internal/udsacceptor.hpp
5858
include/cppwamp/internal/udsopener.hpp
59+
include/cppwamp/internal/unpacker.ipp
5960
include/cppwamp/internal/variantbuilder.hpp
6061
include/cppwamp/internal/varianttraits.hpp
6162
include/cppwamp/internal/varianttraitsfwd.hpp
@@ -93,6 +94,8 @@ set(INLINES
9394
set(DOCUMENTS
9495
${PROJECT_SOURCE_DIR}/doc/concepts.dox
9596
${PROJECT_SOURCE_DIR}/doc/cppwamp.dox
97+
${PROJECT_SOURCE_DIR}/doc/registrations.dox
98+
${PROJECT_SOURCE_DIR}/doc/subscriptions.dox
9699
)
97100

98101
# Treat *.ipp files as header files

cppwamp/cppwamp.pro

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ HEADERS += \
3434
include/cppwamp/subscription.hpp \
3535
include/cppwamp/tcpconnector.hpp \
3636
include/cppwamp/udsconnector.hpp \
37+
include/cppwamp/unpacker.hpp \
3738
include/cppwamp/variant.hpp \
3839
include/cppwamp/varianttuple.hpp \
3940
include/cppwamp/version.hpp \
@@ -55,13 +56,12 @@ HEADERS += \
5556
include/cppwamp/internal/precompiled.hpp \
5657
include/cppwamp/internal/rawsockhandshake.hpp \
5758
include/cppwamp/internal/rawsockheader.hpp \
58-
include/cppwamp/internal/registrationimpl.hpp \
5959
include/cppwamp/internal/subscriber.hpp \
60-
include/cppwamp/internal/subscriptionimpl.hpp \
6160
include/cppwamp/internal/tcpacceptor.hpp \
6261
include/cppwamp/internal/tcpopener.hpp \
6362
include/cppwamp/internal/udsacceptor.hpp \
6463
include/cppwamp/internal/udsopener.hpp \
64+
include/cppwamp/internal/unpacker.ipp \
6565
include/cppwamp/internal/variantbuilder.hpp \
6666
include/cppwamp/internal/varianttraits.hpp \
6767
include/cppwamp/internal/varianttraitsfwd.hpp \
@@ -107,8 +107,8 @@ QMAKE_CXXFLAGS += -std=c++11
107107
#Enable support for threads
108108
QMAKE_CXXFLAGS += -pthread
109109

110-
#Stop compiling at first error
111-
#QMAKE_CXXFLAGS += -Wfatal-errors
110+
#Stop compiling after N errors
111+
QMAKE_CXXFLAGS += -fmax-errors=3
112112

113113
#Add debugging symbols if in debug configuration
114114
CONFIG(debug, debug|release) {
@@ -120,7 +120,6 @@ CONFIG(debug, debug|release) {
120120
INCLUDEPATH += \
121121
$$PWD/include \
122122
$$PWD/../ext/boost \
123-
$$PWD/../ext/endian/include \
124123
$$PWD/../ext/msgpack-c/include \
125124
$$PWD/../ext/rapidjson/include
126125

cppwamp/include/cppwamp/corosession.hpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class CoroSession : public TBase
106106
using EventSlot = std::function<void (Event)>;
107107

108108
/** Function type for handling remote procedure calls. */
109-
using CallSlot = std::function<void (Invocation)>;
109+
using CallSlot = std::function<Outcome (Invocation)>;
110110

111111
/** Yield context type used by the boost::asio::spawn handler. */
112112
template <typename TSpawnHandler>
@@ -150,19 +150,13 @@ class CoroSession : public TBase
150150
/// @{
151151
/** Subscribes to WAMP pub/sub events having the given topic. */
152152
template <typename H>
153-
Subscription::Ptr subscribe(Topic topic, EventSlot slot,
154-
YieldContext<H> yield, std::error_code* ec = nullptr);
155-
156-
/** Subscribes to WAMP pub/sub events having the given topic. */
157-
template <typename THead, typename... TTail,
158-
typename TEventSlot, typename H>
159-
Subscription::Ptr subscribe(Topic topic, TEventSlot&& slot,
153+
Subscription subscribe(Topic topic, EventSlot slot,
160154
YieldContext<H> yield, std::error_code* ec = nullptr);
161155

162156
/** Unsubscribes a subscription to a topic and waits for router
163157
acknowledgement if necessary. */
164158
template <typename H>
165-
bool unsubscribe(Subscription::Ptr sub, YieldContext<H> yield,
159+
bool unsubscribe(const Subscription& sub, YieldContext<H> yield,
166160
std::error_code* ec = nullptr);
167161

168162
/** Publishes an event and waits for an acknowledgement from the router. */
@@ -175,18 +169,12 @@ class CoroSession : public TBase
175169
/// @{
176170
/** Registers a WAMP remote procedure call. */
177171
template <typename H>
178-
Registration::Ptr enroll(Procedure procedure, CallSlot slot,
179-
YieldContext<H> yield, std::error_code* ec = nullptr);
180-
181-
/** Registers a WAMP remote procedure call. */
182-
template <typename THead, typename... TTail,
183-
typename TCallSlot, typename H>
184-
Registration::Ptr enroll(Procedure procedure, TCallSlot&& slot,
172+
Registration enroll(Procedure procedure, CallSlot slot,
185173
YieldContext<H> yield, std::error_code* ec = nullptr);
186174

187175
/** Unregisters a remote procedure call. */
188176
template <typename H>
189-
bool unregister(Registration::Ptr reg, YieldContext<H> yield,
177+
bool unregister(const Registration& reg, YieldContext<H> yield,
190178
std::error_code* ec = nullptr);
191179

192180
/** Calls a remote procedure */

cppwamp/include/cppwamp/internal/callee.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,28 @@
1414
#include "../asyncresult.hpp"
1515
#include "../dialoguedata.hpp"
1616
#include "../sessiondata.hpp"
17-
#include "../variant.hpp"
17+
#include "../wampdefs.hpp"
1818

1919
namespace wamp
2020
{
2121

22+
class Registration;
23+
2224
namespace internal
2325
{
2426

2527
//------------------------------------------------------------------------------
2628
class Callee
2729
{
2830
public:
29-
using Ptr = std::shared_ptr<Callee>;
30-
using WeakPtr = std::weak_ptr<Callee>;
31-
using RegistrationId = uint64_t;
32-
using RequestId = uint64_t;
33-
using UnregisterHandler = AsyncHandler<bool>;
31+
using WeakPtr = std::weak_ptr<Callee>;
3432

3533
virtual ~Callee() {}
3634

37-
virtual void unregister(RegistrationId regId) = 0;
35+
virtual void unregister(const Registration& handle) = 0;
3836

39-
virtual void unregister(RegistrationId regId,
40-
UnregisterHandler handler) = 0;
37+
virtual void unregister(const Registration& handle,
38+
AsyncHandler<bool> handler) = 0;
4139

4240
virtual void yield(RequestId reqId, wamp::Result&& result) = 0;
4341

0 commit comments

Comments
 (0)