pax_global_header00006660000000000000000000000064137174451120014517gustar00rootroot0000000000000052 comment=84972fc81181bde635329bf0474e3874cc5c9091 crossbario-autobahn-cpp-d7a4346/000077500000000000000000000000001371744511200166025ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/.gitignore000066400000000000000000000015021371744511200205700ustar00rootroot00000000000000.build .qemu *.sublime-workspace website/build web/build web/reports* *.pyc # Compiled Object files *.slo *.lo *.o # Compiled Dynamic libraries *.so *.dylib # Compiled Static libraries *.lai *.la *.a .sconsign.dblite build doc/_upload* doc/_doxygen* # Qt Creator CMakeLists.txt.user *.key *.pid ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. # User-specific files *.suo *.user *.userosscache *.sln.docstates # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ x64/ x86/ bld/ [Bb]in/ [Oo]bj/ [Ll]og/ # Visual Studio 2015 cache/options directory .vs/ # Visual C++ cache files ipch/ *.aps *.ncb *.opendb *.opensdf *.sdf *.cachefile # IntelliJ/Clion .idea/ cmake-build-*/ *.bz2 *.gz crossbario-autobahn-cpp-d7a4346/CMakeLists.txt000066400000000000000000000004171371744511200213440ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8) project(autobahn-cpp) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Includes/CMakeLists.txt) option(AUTOBAHN_BUILD_EXAMPLES "Build examples" ON) if(AUTOBAHN_BUILD_EXAMPLES) add_subdirectory(examples) endif(AUTOBAHN_BUILD_EXAMPLES) crossbario-autobahn-cpp-d7a4346/LICENSE000066400000000000000000000025701371744511200176130ustar00rootroot00000000000000Copyright (c) Crossbar.io Technologies GmbH and contributors Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. crossbario-autobahn-cpp-d7a4346/Makefile000066400000000000000000000026521371744511200202470ustar00rootroot00000000000000.PHONY: build clean publish HOSTIP=$(shell ip route get 1 | awk '{print $$NF;exit}') # # Don't forget: set and source docker/versions.sh before # building and publishing the toolchain images! # # build toolchain images build: build_gcc build_clang build_gcc: time docker build \ --no-cache \ --build-arg BUILD_DATE=${BUILD_DATE} \ --build-arg AUTOBAHN_CPP_VCS_REF=${AUTOBAHN_CPP_VCS_REF} \ --build-arg AUTOBAHN_CPP_VERSION=${AUTOBAHN_CPP_VERSION} \ -t crossbario/autobahn-cpp \ -t crossbario/autobahn-cpp:gcc \ -t crossbario/autobahn-cpp:gcc-${AUTOBAHN_CPP_VERSION} \ -f docker/Dockerfile.gcc . build_clang: time docker build \ --no-cache \ --build-arg BUILD_DATE=${BUILD_DATE} \ --build-arg AUTOBAHN_CPP_VCS_REF=${AUTOBAHN_CPP_VCS_REF} \ --build-arg AUTOBAHN_CPP_VERSION=${AUTOBAHN_CPP_VERSION} \ -t crossbario/autobahn-cpp:clang \ -t crossbario/autobahn-cpp:clang-${AUTOBAHN_CPP_VERSION} \ -f docker/Dockerfile.clang . # publish toolchain images publish: publish_gcc publish_clang publish_gcc: docker push crossbario/autobahn-cpp docker push crossbario/autobahn-cpp:gcc docker push crossbario/autobahn-cpp:gcc-${AUTOBAHN_CPP_VERSION} publish_clang: docker push crossbario/autobahn-cpp:clang docker push crossbario/autobahn-cpp:clang-${AUTOBAHN_CPP_VERSION} # list/clean (local) toolchain images list: -docker images crossbario/autobahn-cpp:* clean: ./docker/removeall.sh crossbar: crossbar start crossbario-autobahn-cpp-d7a4346/README.md000066400000000000000000000415361371744511200200720ustar00rootroot00000000000000# AutobahnC++ WAMP for C++ on Boost/ASIO. [![Documentation](https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat)](https://crossbario.github.io/autobahn-cpp-docs/) [![Docker toolchain image](https://img.shields.io/badge/docker-ready-blue.svg)](https://hub.docker.com/r/crossbario/autobahn-cpp/) --- **[See here](https://crossbario.github.io/autobahn-cpp-docs/) for the Autobahn C++ reference documentation.** Get in touch on IRC `#autobahn` on `chat.freenode.net`, follow us on [Twitter](https://twitter.com/autobahnws) or join the [mailing list](http://groups.google.com/group/autobahnws). --- ## Introduction AutobahnC++ is a subproject of [Autobahn](http://autobahn.ws/) which provides a C++ [WAMP](http://wamp.ws/) implementation that is able to talk WAMP over `stdio` pipes. * **Caller** * **Callee** * **Publisher** * **Subscriber** AutobahnC++ is open-source, licensed under the [Boost Software License](LICENSE). The API and implementation make use of modern C++ 11 and new asynchronous idioms using (upcoming) features of the standard C++ library, in particular **Futures**, [**Continuations**](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3634.pdf) and **Lambdas**. > [Continuations](http://en.wikipedia.org/wiki/Continuation) are *one* way of managing control flow in an asynchronous program. Other styles include: asynchronous [Callbacks](http://en.wikipedia.org/wiki/Callback_%28computer_programming%29), [Coroutines](http://en.wikipedia.org/wiki/Coroutine) (`yield` or `await`), Actors ([Erlang/OTP](http://www.erlang.org/), [Scala](http://www.scala-lang.org/)/[Akka](http://akka.io/) or [Rust](https://www.rust-lang.org/)) and [Transactional memory](http://en.wikipedia.org/wiki/Transactional_Synchronization_Extensions). > AutobahnC++ supports running WAMP (`rawsocket-msgpack`) over **TCP(-TLS)**, **Unix domain sockets** or **pipes** (`stdio`). The library is "header-only", light-weight (< 2k code lines) and **depends on** the following: * C++11 compiler * [`boost::future`](http://www.boost.org/doc/libs/1_66_0/doc/html/thread/synchronization.html#thread.synchronization.futures) * [`boost::asio`](http://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio.html) * [`msgpack-c`](https://github.com/msgpack/msgpack-c) * [`WebSocket++`](https://github.com/zaphoyd/websocketpp) For getting help, questions or feedback, get in touch on the **[mailing list](https://groups.google.com/forum/#!forum/autobahnws)**, **[Twitter](https://twitter.com/autobahnws)** or **IRC `#autobahn`** (Freenode). --- ## Show me some code! Here is how programming with C++ and AutobahnC++ looks like. **Calling a remote Procedure** ```c++ auto c1 = session.call("com.mathservice.add2", std::make_tuple(23, 777)) .then([&](boost::future result) { std::cout << "Got call result " << result.get().argument(0) << std::endl; }); ``` **Registering a remoted Procedure** ```c++ auto r1 = session.provide("com.myapp.cpp.square", [](autobahn::wamp_invocation invocation) { std::cout << "Procedure is invoked .." << endl; uint64_t x = invocation->argument(0); return x * x; }) .then([](boost::future reg) { std::cout << "Registered with ID " << reg.get().id() << std::endl; }); ``` **Publishing an Event** ```c++ session.publish("com.myapp.topic2", std::make_tuple(23, true, std::string("hello"))); ``` **Publishing an Event (acknowledged)** ```c++ auto opts = PublishOptions(); opts.acknowledge = True; session.publish("com.myapp.topic2", std::make_tuple(23, true, std::string("hello")), opts) .then([](boost::future pub) { std::cout << "Published with ID " << pub.get().id() << std::endl; }); ``` **Subscribing to a Topic** ```c++ auto s1 = session.subscribe("com.myapp.topic1", [](const autobahn::wamp_event& event) { std::cout << "Got event: " << event.argument(0) << std::endl; }) .then([](boost::future sub) { std::cout << "Subscribed with ID " << sub.get().id() << std::endl; }); ``` Here is JavaScript running in Chrome call into C++ running on command line. Both are connected via a WAMP router, in this case [**Autobahn**|Python](http://autobahn.ws/python) based. ![](doc/_static/cpp_from_js.png) * [Example C++ code](https://github.com/crossbario/autobahn-cpp/blob/master/examples/register2.cpp) * [Example JavaScript code](https://github.com/crossbario/autobahn-cpp/blob/master/examples/web/index.html) ## Installation Autobahn C++ is a "header-only" library, which means there isn't anything to build (for the library itself), and the only thing to install are the header files. For using Autobahn C++ in your project, clone the project, checkout a Git release tag (optional) and copy the library header files to your system (or project include directory): ```console cd ~ git clone https://github.com/crossbario/autobahn-cpp.git cd autobahn-cpp cp -r autobahn/ /usr/local/include/ ``` --- ## Examples The Autobahn C++ repository contains a number of [examples](examples) that demonstrate all 4 basic patterns of using WAMP. There are also examples for WAMP-CRA and Unix domain sockets. ### Building dependencies The instructions below were tested on Debian/Ubuntu and build and install the following: * Boost in `/opt/boost` * MsgPack-C in `/opt/msgpackc` * WebSocketC++ in `/opt/websocketpp` * AutobahnC++ in `/opt/autobahncpp` > *Notes* > > * The library code is written in standard C++ 11. Target toolchains currently include **clang** and **gcc**. Support for MSVC is tracked on this [issue](https://github.com/crossbario/autobahn-cpp/issues/2). > * While C++ 11 includes `std::future` in the standard library, this lacks continuations. `boost::future.then` allows attaching continuations to futures as outlined in the proposal [here](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3634.pdf). This feature will come to standard C++, but probably not before 2017 (see [C++ Standardisation Roadmap](http://isocpp.org/std/status)) > * Support for `when_all` and `when_any` as described in above proposal depends on Boost 1.56 or higher. > * The library and example programs were tested and developed with **clang 3.4**, **libc++** and **Boost trunk/1.56** on an Ubuntu 13.10 x86-64 bit system. It also works with **gcc 4.8**, **libstdc++** and **Boost trunk/1.56**. Your mileage with other versions of the former may vary, but we accept PRs;) --- #### System libraries and cmake Install some libs and build tools (these are for Debian/Ubuntu): ```console sudo apt-get install -y libbz2-dev libssl-dev ``` Install cmake ```console cd ~ wget https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh chmod +x cmake-3.11.0-Linux-x86_64.sh sudo ./cmake-3.11.0-Linux-x86_64.sh --prefix=/opt sudo mv /opt/cmake-3.11.0-Linux-x86_64 /opt/cmake ``` --- #### Clang (alternative) If you want to work with Clang (rather than GCC), install [clang](http://clang.llvm.org/) and [libc++](http://libcxx.llvm.org/) (these are for Ubuntu): ```console sudo apt-get install -y clang libc++1 libc++-dev ``` Then make Clang available: ```console $ sudo update-alternatives --config c++ There are 2 choices for the alternative c++ (providing /usr/bin/c++). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/g++ 20 auto mode 1 /usr/bin/clang++ 10 manual mode 2 /usr/bin/clang++-libc++ 5 manual mode 3 /usr/bin/g++ 20 manual mode Press to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/bin/clang++ to provide /usr/bin/c++ (c++) in manual mode ``` --- #### Boost Most of the time, your distro's Boost libraries will be outdated (unless you're using Arch or Homebrew). Don't waste time with those. To build the latest Boost 1.66 (current release as of 2018/4) from sources. Get Boost: ```console cd ~ wget https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2 tar xvjf boost_1_66_0.tar.bz2 cd boost_1_66_0 ``` Then, to build using the *GCC* toolchain: ```console ./bootstrap.sh --with-toolset=gcc ./b2 toolset=gcc -j4 sudo ./b2 install --prefix=/opt/boost ``` > Note: The `-j 4` option will allow use of 4 CPU cores for building. Instead, to build using the *Clang* toolchain: ```console ./bootstrap.sh --with-toolset=clang ./b2 toolset=clang -j4 \ cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++" sudo ./b2 install --prefix=/opt/boost ``` Then add the following to your `~/.profile` or `~/.bashrc`: ```shell export BOOST_ROOT=/opt/boost export LD_LIBRARY_PATH=${BOOST_ROOT}/lib:${LD_LIBRARY_PATH} ``` --- #### MsgPack-C Get [MsgPack-C](https://github.com/msgpack/msgpack-c) and install: ```console cd ~ git clone https://github.com/msgpack/msgpack-c.git cd msgpack-c git checkout cpp-1.4.2 cmake -DMSGPACK_CXX11=ON -DCMAKE_INSTALL_PREFIX=/opt/msgpack . make sudo make install ``` > On FreeBSD, you need to `pkg install autotools` and invoke `gmake` instead of `make`. Then add the following to your `~/.profile` or `~/.bashrc`: ```shell export MSGPACK_ROOT=/opt/msgpack export LD_LIBRARY_PATH=${MSGPACK_ROOT}/lib:${LD_LIBRARY_PATH} ``` --- #### WebSocket++ Get [WebSocket++](https://github.com/zaphoyd/websocketpp) and install: ```console cd ~ git clone https://github.com/zaphoyd/websocketpp.git cd websocketpp cmake -DCMAKE_INSTALL_PREFIX=/opt/websocketpp . sudo make install ``` Then add the following to your `~/.profile` or `~/.bashrc`: ```shell export WEBSOCKETPP_ROOT=/opt/websocketpp export LD_LIBRARY_PATH=${WEBSOCKETPP_ROOT}/lib:${LD_LIBRARY_PATH} ``` --- ### Building the examples Now that we have all the dependencies, to build the examples: ```console mkdir build cd build /opt/cmake/bin/cmake .. make -j4 sudo make install ``` You should see a clean build like in the following output: ```console oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp/build$ /opt/cmake/bin/cmake .. -- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Boost version: 1.66.0 -- Found the following Boost libraries: -- program_options -- system -- thread -- random -- chrono -- date_time -- atomic -- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.0.2g") -- AUTOBAHN_BUILD_EXAMPLES: ON -- CMAKE_ROOT: /opt/cmake/share/cmake-3.11 -- Boost_INCLUDE_DIRS: /opt/boost/include -- Boost_LIBRARIES: /opt/boost/lib/libboost_program_options.so/opt/boost/lib/libboost_system.so/opt/boost/lib/libboost_thread.so/opt/boost/lib/libboost_random.so/opt/boost/lib/libboost_chrono.so/opt/boost/lib/libboost_date_time.so/opt/boost/lib/libboost_atomic.so -- Msgpack_INCLUDE_DIRS: /opt/msgpack/include -- Msgpack_LIBRARIES: /opt/msgpack/libs -- Websocketpp_INCLUDE_DIRS: /opt/websocketpp/include -- Websocketpp_LIBRARIES: /opt/websocketpp/libs -- Configuring done -- Generating done -- Build files have been written to: /home/oberstet/scm/crossbario/autobahn-cpp/build oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp/build$ make -j4 Scanning dependencies of target examples_parameters [ 5%] Building CXX object examples/CMakeFiles/examples_parameters.dir/parameters.cpp.o [ 11%] Linking CXX static library libexamples_parameters.a [ 11%] Built target examples_parameters Scanning dependencies of target callee Scanning dependencies of target caller Scanning dependencies of target provide_prefix Scanning dependencies of target wampcra [ 16%] Building CXX object examples/CMakeFiles/caller.dir/caller.cpp.o [ 22%] Building CXX object examples/CMakeFiles/callee.dir/callee.cpp.o [ 27%] Building CXX object examples/CMakeFiles/provide_prefix.dir/callee.cpp.o [ 33%] Building CXX object examples/CMakeFiles/wampcra.dir/wampcra.cpp.o [ 38%] Linking CXX executable wampcra [ 38%] Built target wampcra Scanning dependencies of target subscriber [ 44%] Linking CXX executable caller [ 50%] Building CXX object examples/CMakeFiles/subscriber.dir/subscriber.cpp.o [ 50%] Built target caller Scanning dependencies of target uds [ 55%] Linking CXX executable callee [ 61%] Linking CXX executable provide_prefix [ 66%] Building CXX object examples/CMakeFiles/uds.dir/uds.cpp.o [ 66%] Built target callee Scanning dependencies of target publisher [ 66%] Built target provide_prefix Scanning dependencies of target websocket_callee [ 72%] Building CXX object examples/CMakeFiles/publisher.dir/publisher.cpp.o [ 77%] Building CXX object examples/CMakeFiles/websocket_callee.dir/websocket_callee.cpp.o [ 83%] Linking CXX executable subscriber [ 83%] Built target subscriber [ 88%] Linking CXX executable publisher [ 94%] Linking CXX executable uds [ 94%] Built target publisher [ 94%] Built target uds [100%] Linking CXX executable websocket_callee [100%] Built target websocket_callee oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp/build$ ``` And here are some details for one of the built example binaries: ```console oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp/build$ file examples/websocket_callee examples/websocket_callee: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=bfcab40b2350acd5869d913226723999cf0b822e, not stripped oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp/build$ ldd examples/websocket_callee linux-vdso.so.1 => (0x00007fff44760000) libboost_program_options.so.1.66.0 => /opt/boost/lib/libboost_program_options.so.1.66.0 (0x00007f8518873000) libboost_system.so.1.66.0 => /opt/boost/lib/libboost_system.so.1.66.0 (0x00007f851866f000) libboost_thread.so.1.66.0 => /opt/boost/lib/libboost_thread.so.1.66.0 (0x00007f8518446000) libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f85181dd000) libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f8517d99000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8517b7c000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f85177fa000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f85175e4000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f851721a000) librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f8517012000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8516e0e000) /lib64/ld-linux-x86-64.so.2 (0x00007f8518af3000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8516b05000) oberstet@thinkpad-t430s:~/scm/crossbario/autobahn-cpp/build$ ``` --- ## Resources * [ASIO C++11 Examples](http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/examples/cpp11_examples.html) * [Using Asio with C++11](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3388.pdf) * [C++17: I See a Monad in Your Future! ](http://bartoszmilewski.com/2014/02/26/c17-i-see-a-monad-in-your-future/) * [Boost Thread](http://www.boost.org/doc/libs/1_55_0/doc/html/thread.html) * [Boost Issue: when_all](https://svn.boost.org/trac/boost/ticket/7447) * [Boost Issue. when_any](https://svn.boost.org/trac/boost/ticket/7446) * [Boost Issue: future fires twice](https://svn.boost.org/trac/boost/ticket/9711) * [Boost C++ 1y](http://www.boost.org/doc/libs/1_55_0/doc/html/thread/compliance.html#thread.compliance.cxx1y.async) * [Asynchronous API in C++ and the Continuation Monad](https://www.fpcomplete.com/blog/2012/06/asynchronous-api-in-c-and-the-continuation-monad) --- ## Closures Cheatsheet * `[]` Capture nothing (or, a scorched earth strategy?) * `[&]` Capture any referenced variable by reference * `[=]` Capture any referenced variable by making a copy * `[=, &foo]` Capture any referenced variable by making a copy, but capture variable `foo` by reference * `[bar]` Capture `bar` by making a copy; don't copy anything else * `[this]` Capture the this pointer of the enclosing class --- ## Release process To push a new release of the toolchain Docker image: ```console git tag -a v20.8.1 -m "tagged release" source docker/versions.sh make build_gcc make publish_gcc ``` > Note: clang is currently broken. crossbario-autobahn-cpp-d7a4346/autobahn/000077500000000000000000000000001371744511200204035ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/autobahn/autobahn.hpp000066400000000000000000000076221371744511200227240ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_HPP #define AUTOBAHN_HPP #ifdef _WIN32 #define MSGPACK_DISABLE_LEGACY_CONVERT #define MSGPACK_DEFAULT_API_VERSION 1 #define MSGPACK_DISABLE_LEGACY_CONVERT #endif #include "wamp_event.hpp" #include "wamp_invocation.hpp" #include "wamp_session.hpp" #include "wamp_tcp_transport.hpp" #include "wamp_transport.hpp" #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS #include "wamp_uds_transport.hpp" #endif /*! \mainpage Autobahn-C++ Documentation Welcome to the [Autobahn-C++](https://github.com/crossbario/autobahn-cpp) documentation. \n\n Autobahn-C++ is a client library for the [WAMP protocol](http://wamp-proto.org/) that allows developers to create WAMP application components in C++. Application components connect to a WAMP router like [Crossbar.io](http://crossbar.io) which acts as a messaging layer that allows seamless, secure and cross-language communication with other components. With Autobahn-C++, application components can be (optionally) compiled and linked into small (<2MB), single file executables for a specific CPU architecture, and then run on all Linux distributions of that architecture. This comes with a number of deployment, resource efficiency and other advantages. \n\n We provide the documentation here, full working examples and Docker Autobahn-C++ images with complete pre-integrated toolchains: - **[Examples](https://github.com/crossbario/autobahn-cpp/tree/master/examples)** - **[Docker toolchain images](https://hub.docker.com/r/crossbario/autobahn-cpp/)** This should you get started from working code examples that you can gradually modify to your needs. All example code is MIT licensed, so you can safely use it in any software developement context. If you have questions, you can reach out at: - [Mailing list](https://groups.google.com/forum/#!forum/autobahnws) - IRC #autobahn on Freenode If you found a bug in the documentation or have a correction, improvement or addition you would like see merged, awesome! Please submit an issue or submit a PR directly to the Autobahn-C++ source repository [here](https://github.com/crossbario/autobahn-cpp), as all the HTML documentation is built from comments in the code using Doxygen. \n\n However, if you have a question, please use the mailing list or IRC as mentioned above rather than misusing the issue tracker;) */ #endif // AUTOBAHN_HPP crossbario-autobahn-cpp-d7a4346/autobahn/boost_config.hpp000066400000000000000000000006571371744511200235770ustar00rootroot00000000000000// http://stackoverflow.com/questions/22597948/using-boostfuture-with-then-continuations/ #ifndef BOOST_THREAD_PROVIDES_FUTURE #define BOOST_THREAD_PROVIDES_FUTURE #endif #ifndef BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION #define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION #endif #ifndef BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY #define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY #endif #include crossbario-autobahn-cpp-d7a4346/autobahn/exceptions.hpp000066400000000000000000000047531371744511200233060ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_EXCEPTIONS_HPP #define AUTOBAHN_EXCEPTIONS_HPP #include #include namespace autobahn { class abort_error : public std::runtime_error { public: abort_error(const std::string& message) : std::runtime_error(message) {}; }; class network_error : public std::runtime_error { public: network_error(const std::string& message) : std::runtime_error(message) {}; }; class no_session_error : public std::runtime_error { public: no_session_error() : std::runtime_error("session not joined") {}; }; class no_transport_error : public std::runtime_error { public: no_transport_error() : std::runtime_error("session not attached") {}; }; class protocol_error : public std::runtime_error { public: protocol_error(const std::string& message) : std::runtime_error(message) {}; }; } // namespace autobahn #endif // AUTOBAHN_EXCEPTIONS_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_arguments.hpp000066400000000000000000000114031371744511200241440ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_ARGUMENTS_HPP #define AUTOBAHN_WAMP_ARGUMENTS_HPP #include #include #include #include #include #include namespace autobahn { using wamp_arguments = std::vector; using wamp_kw_arguments = std::unordered_map; static msgpack::zone EMPTY_ARGUMENTS_ZONE; static msgpack::zone EMPTY_KW_ARGUMENTS_ZONE; static const msgpack::object EMPTY_ARGUMENTS(std::array(), EMPTY_ARGUMENTS_ZONE); static const msgpack::object EMPTY_KW_ARGUMENTS(wamp_kw_arguments(), EMPTY_KW_ARGUMENTS_ZONE); //msgpack map utilities. //TODO: refactor event & invocation to used these template inline T value_for_key(const msgpack::object& object, const std::string& key) { if (object.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < object.via.map.size; ++i) { const msgpack::object_kv& kv = object.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } throw std::out_of_range(key + " keyword argument doesn't exist"); } template inline T value_for_key(const msgpack::object& object, const char* key) { if (object.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < object.via.map.size; ++i) { const msgpack::object_kv& kv = object.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } throw std::out_of_range(std::string(key) + " keyword argument doesn't exist"); } template inline T value_for_key_or(const msgpack::object& object, const std::string& key, const T& fallback) { if (object.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < object.via.map.size; ++i) { const msgpack::object_kv& kv = object.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } return fallback; } template inline T value_for_key_or(const msgpack::object& object, const char* key, const T& fallback) { if (object.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < object.via.map.size; ++i) { const msgpack::object_kv& kv = object.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } return fallback; } } // namespace autobahn #endif // AUTOBAHN_WAMP_ARGUMENTS_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_auth_utils.hpp000066400000000000000000000136141371744511200243260ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef WAMP_AUTH_UTILS_HPP #define WAMP_AUTH_UTILS_HPP #include #include #include #include // // Execpetion thrown when something gets wrong // creating the derived auth key..... // class derived_key_error : public std::exception { virtual const char* what() const throw() { return "Error occured when calulcate a derived key"; } }; ////////////////////////////////////////////////////// // - using openssl crypto lib // see openssl at : https://www.openssl.org ////////////////////////////////////////////////////// #include #include #include #include #include /*! * base64 encoding * * \param data The data to be encoded * \return A encoded string */ inline std::string base_64_encode(const std::string & data ) { BIO *bio, *b64; BUF_MEM *pBuf; b64 = BIO_new(BIO_f_base64()); bio = BIO_new(BIO_s_mem()); bio = BIO_push(b64, bio); BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); BIO_write(bio, (const unsigned char *) data.c_str(), data.size()); (void)BIO_flush(bio); BIO_get_mem_ptr(bio, &pBuf); (void)BIO_set_close(bio, BIO_NOCLOSE); std::string str_out; str_out.assign( pBuf->data, pBuf->length ); BIO_free_all(bio); return str_out; } /*! * create a derived key from a password/secret * * \param passwd A secret string to make a derived key for * \param salt A random salt added to the key * \param iterations A number of intertions used to create the derived key * \param keylen The length of the derived key returned. * \return a PBKDF2-sha256 derived key */ inline std::string derive_key( const std::string & passwd, const std::string & salt, int iterations, int keylen ) { int passwdLen = passwd.size(); const char * pwd = passwd.c_str(); int saltLen = salt.size(); unsigned char * salt_value = (unsigned char * ) salt.c_str(); std::string str_out; str_out.resize( keylen ); unsigned char * out = (unsigned char *) str_out.c_str(); int result = PKCS5_PBKDF2_HMAC( pwd, passwdLen, salt_value, saltLen, iterations, EVP_sha256(), keylen, out); if ( result != 0 ) { return base_64_encode( str_out ); } else { throw derived_key_error(); } } /*! * make a keyed-hash from a key using the HMAC-sha256 and a challenge * * \param key The key to make a digest for * \param challenge Some data mixin - identify the specific digest * \return a base64 encoded digest */ inline std::string compute_wcs( const std::string & key, const std::string & challenge ) { unsigned int len = 32; unsigned char hash[32]; #if (OPENSSL_VERSION_NUMBER < 0x10100000L) HMAC_CTX hmac; HMAC_CTX_init(&hmac); HMAC_Init_ex(&hmac, key.data(), key.length(), EVP_sha256(), NULL); HMAC_Update(&hmac, (unsigned char*) challenge.data(), challenge.length()); HMAC_Final(&hmac, hash, &len); HMAC_CTX_cleanup(&hmac); #else HMAC_CTX *hmac = HMAC_CTX_new(); if (!hmac) return ""; HMAC_Init_ex(hmac, key.data(), key.length(), EVP_sha256(), NULL); HMAC_Update(hmac, ( unsigned char* ) challenge.data(), challenge.length()); HMAC_Final(hmac, hash, &len); HMAC_CTX_free(hmac); #endif std::string str_out; str_out.assign( ( char * ) &hash , 32 ); return base_64_encode( str_out ); } /*! * Generates a new random secret for use with WAMP-CRA. * The secret generated is a random character sequence drawn from * * - upper and lower case latin letters * - digits * - * * \param length The length of the secret to generate. * \param challenge Some data mixin - identify the specific digest * \return The generated secret. The length of the generated is ``length`` octets. */ inline std::string generate_wcs(int length=14){ // // The characters from which to generate the secret. // static const char WCS_SECRET_CHARSET[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; std::string s; for (int i = 0; i < length; ++i) { s.push_back( WCS_SECRET_CHARSET[ rand() % (sizeof(WCS_SECRET_CHARSET) - 1) ] ); } return s; } #endif //WAMP_AUTH_UTILS_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_authenticate.hpp000066400000000000000000000040101371744511200246110ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_AUTHENTICATE_HPP #define AUTOBAHN_WAMP_AUTHENTICATE_HPP namespace autobahn { /// Represents an challenge-response. class wamp_authenticate { public: wamp_authenticate(const std::string & signature = ""); const std::string & signature() const; private: std::string m_signature; }; } // namespace autobahn #include "wamp_authenticate.ipp" #endif // AUTOBAHN_WAMP_AUTHENTICATE_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_authenticate.ipp000066400000000000000000000035351371744511200246250ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_authenticate::wamp_authenticate(const std::string & signature ) : m_signature( signature ) { } inline const std::string & wamp_authenticate::signature() const { return m_signature; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_call.hpp000066400000000000000000000040621371744511200230550ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_CALL_HPP #define AUTOBAHN_WAMP_CALL_HPP #include "wamp_call_result.hpp" #include "boost_config.hpp" namespace autobahn { /// An outstanding wamp call. class wamp_call { public: wamp_call(); boost::promise& result(); void set_result(wamp_call_result&& value); private: boost::promise m_result; }; } // namespace autobahn #include "wamp_call.ipp" #endif // AUTOBAHN_WAMP_CALL_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_call.ipp000066400000000000000000000036121371744511200230560ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_call::wamp_call() : m_result() { } inline boost::promise& wamp_call::result() { return m_result; } inline void wamp_call::set_result(wamp_call_result&& value) { m_result.set_value(std::move(value)); } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_call_options.hpp000066400000000000000000000044711371744511200246340ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_CALL_OPTIONS_HPP #define AUTOBAHN_WAMP_CALL_OPTIONS_HPP #include namespace autobahn { class wamp_call_options { public: wamp_call_options(); wamp_call_options(wamp_call_options&& other) = delete; wamp_call_options(const wamp_call_options& other) = delete; wamp_call_options& operator=(wamp_call_options&& other) = delete; wamp_call_options& operator=(const wamp_call_options& other) = delete; const std::chrono::milliseconds& timeout() const; void set_timeout(const std::chrono::milliseconds& timeout); private: std::chrono::milliseconds m_timeout; }; } // namespace autobahn #include "wamp_call_options.ipp" #endif // AUTOBAHN_WAMP_CALL_OPTIONS_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_call_options.ipp000066400000000000000000000073311371744511200246330ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include #include #include namespace autobahn { inline wamp_call_options::wamp_call_options() : m_timeout() { } inline const std::chrono::milliseconds& wamp_call_options::timeout() const { return m_timeout; } inline void wamp_call_options::set_timeout(const std::chrono::milliseconds& timeout) { m_timeout = timeout; } } // namespace autobahn namespace msgpack { MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { namespace adaptor { template<> struct convert { msgpack::object const& operator()( msgpack::object const& object, autobahn::wamp_call_options& options) const { std::unordered_map options_map; object >> options_map; const auto options_map_itr = options_map.find("timeout"); if (options_map_itr != options_map.end()) { options.set_timeout(std::chrono::milliseconds(options_map_itr->second.as())); } return object; } }; template<> struct pack { template msgpack::packer& operator()( msgpack::packer& packer, autobahn::wamp_call_options const& options) const { std::unordered_map options_map; const auto& timeout = options.timeout(); if (timeout.count() > 0) { options_map["timeout"] = timeout.count(); } packer.pack(options_map); return packer; } }; template <> struct object_with_zone { void operator()( msgpack::object::with_zone& object, const autobahn::wamp_call_options& options) { std::unordered_map options_map; const auto& timeout = options.timeout(); if (timeout.count() != 0) { options_map["timeout"] = msgpack::object(timeout.count()); } object << options_map; } }; } // namespace adaptor } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) } // namespace msgpack crossbario-autobahn-cpp-d7a4346/autobahn/wamp_call_result.hpp000066400000000000000000000156611371744511200244620ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_CALL_RESULT_HPP #define AUTOBAHN_WAMP_CALL_RESULT_HPP #include #include #include namespace autobahn { class wamp_call_result { public: wamp_call_result(); wamp_call_result(msgpack::zone&& zone); wamp_call_result(const wamp_call_result& other) = delete; wamp_call_result(wamp_call_result&& other); wamp_call_result& operator=(const wamp_call_result& other) = delete; wamp_call_result& operator=(wamp_call_result&& other); /*! * The number of positional arguments returned from the call. */ std::size_t number_of_arguments() const; /*! * The number of keyword arguments returned from the call. */ std::size_t number_of_kw_arguments() const; /*! * The positional argument returned from the call with the given @p index, converted to type T. * * Example: * `std::string id = result.argument(0); // first positional argument` * * @throw std::out_of_range * @throw std::bad_cast */ template T argument(std::size_t index) const; /*! * The positional arguments returned from the call, converted to a list type. * * Example: * `auto args = result.arguments>();` * * @throw std::bad_cast */ template List arguments() const; /*! * Convert and assign the positional arguments returned from the call to the given @p args list. * * Example: * ``` * std::tuple args; * result.get_arguments(args); * ``` * * @throw std::bad_cast */ template void get_arguments(List& args) const; /*! * Convert and assign the positional arguments to a given list of individual parameters. * * Enables a syntax that lets you declare variables individually, but list them in a * single space to empathize parameter order. This will also throw if the number of * arguments to the invocation doesn't match the number of given parameters. * * Example: * ``` * uint64_t id; * std::string name; * invocation->get_each_argument(id, name); * ``` * * @throw std::bad_cast */ template inline void get_each_argument(T&... args) const; /*! * The keyword argument returned from the call with the given @p key, converted to type T. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use kw_arguments() or * get_kw_arguments(map), then access the items from there. * * Example: * `std::string id = result.kw_argument("id");` * * @throw std::out_of_range * @throw std::bad_cast */ template T kw_argument(const std::string& key) const; template T kw_argument(const char* key) const; /*! * The keyword argument returned from the call with the given @p key, converted to type T, * or the given @p fallback if no such key was passed. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use kw_arguments() or * get_kw_arguments(map), then access the items from there. * * Example: * `std::string id = result.kw_argument_or("id", std::string());` * * @throw std::bad_cast */ template T kw_argument_or(const std::string& key, const T& fallback) const; template T kw_argument_or(const char* key, const T& fallback) const; /*! * The keyword arguments returned from the call, converted to a map type. * * Example: * `auto kw_args = result.kw_arguments>();` * * @throw std::bad_cast */ template Map kw_arguments() const; /*! * Convert and assign the keyword arguments returned from the call to the given @p kw_args map. * * Example: * ``` * std::unordered_map kw_args; * result.get_kw_arguments(kw_args); * ``` * * @throw std::bad_cast */ template void get_kw_arguments(Map& kw_args) const; // // functions only called internally by wamp_session void set_arguments(const msgpack::object& arguments); void set_kw_arguments(const msgpack::object& kw_arguments); private: msgpack::zone m_zone; msgpack::object m_arguments; msgpack::object m_kw_arguments; }; } // namespace autobahn #include "wamp_call_result.ipp" #endif // AUTOBAHN_WAMP_CALL_RESULT_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_call_result.ipp000066400000000000000000000152351371744511200244600ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "wamp_arguments.hpp" #include #include namespace autobahn { inline wamp_call_result::wamp_call_result() : m_zone() , m_arguments(EMPTY_ARGUMENTS) , m_kw_arguments(EMPTY_KW_ARGUMENTS) { } inline wamp_call_result::wamp_call_result(msgpack::zone&& zone) : m_zone(std::move(zone)) , m_arguments(EMPTY_ARGUMENTS) , m_kw_arguments(EMPTY_KW_ARGUMENTS) { } inline wamp_call_result::wamp_call_result(wamp_call_result&& other) : m_zone(std::move(other.m_zone)) , m_arguments(other.m_arguments) , m_kw_arguments(other.m_kw_arguments) { other.m_arguments = EMPTY_ARGUMENTS; other.m_kw_arguments = EMPTY_KW_ARGUMENTS; } inline wamp_call_result& wamp_call_result::operator=(wamp_call_result&& other) { if (this == &other) { return *this; } m_arguments = other.m_arguments; m_kw_arguments = other.m_kw_arguments; m_zone = std::move(other.m_zone); other.m_arguments = EMPTY_ARGUMENTS; other.m_kw_arguments = EMPTY_KW_ARGUMENTS; return *this; } inline std::size_t wamp_call_result::number_of_arguments() const { return m_arguments.type == msgpack::type::ARRAY ? m_arguments.via.array.size : 0; } inline std::size_t wamp_call_result::number_of_kw_arguments() const { return m_kw_arguments.type == msgpack::type::MAP ? m_kw_arguments.via.map.size : 0; } template inline T wamp_call_result::argument(std::size_t index) const { if (m_arguments.type != msgpack::type::ARRAY || m_arguments.via.array.size <= index) { throw std::out_of_range("no argument at index " + boost::lexical_cast(index)); } return m_arguments.via.array.ptr[index].as(); } template inline List wamp_call_result::arguments() const { return m_arguments.as(); } template inline void wamp_call_result::get_arguments(List& args) const { m_arguments.convert(args); } template inline void wamp_call_result::get_each_argument(T&... args) const { auto args_tuple = std::make_tuple(std::ref(args)...); m_arguments.convert(args_tuple); } template inline T wamp_call_result::kw_argument(const std::string& key) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } throw std::out_of_range(key + " keyword argument doesn't exist"); } template inline T wamp_call_result::kw_argument(const char* key) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } throw std::out_of_range(std::string(key) + " keyword argument doesn't exist"); } template inline T wamp_call_result::kw_argument_or(const std::string& key, const T& fallback) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } return fallback; } template inline T wamp_call_result::kw_argument_or(const char* key, const T& fallback) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } throw fallback; } template inline Map wamp_call_result::kw_arguments() const { return m_kw_arguments.as(); } template inline void wamp_call_result::get_kw_arguments(Map& kw_args) const { m_kw_arguments.convert(kw_args); } inline void wamp_call_result::set_arguments(const msgpack::object& arguments) { m_arguments = arguments; } inline void wamp_call_result::set_kw_arguments(const msgpack::object& kw_arguments) { m_kw_arguments = kw_arguments; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_challenge.hpp000066400000000000000000000052271371744511200240700ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_CHALLENGE_HPP #define AUTOBAHN_WAMP_CHALLENGE_HPP namespace autobahn { /// Represents a topic subscription. class wamp_challenge { public: wamp_challenge( const std::string & authmethod, const std::string & challenge = "", const std::string & salt = "", int iteratons = -1, int keylen = -1 ); wamp_challenge( const wamp_challenge & ); const std::string & challenge() const; const std::string & authmethod() const; const std::string & salt() const; int iterations() const; int keylen() const; private: // authmethod std::string m_authmethod; // used to "digest" the secret for transport std::string m_challenge; ///////////////////////////////////////// // if authmethod is "wampcra" // and the secret is stored as a derived_key // with salt, iterations and a given keylen. std::string m_salt; int m_iterations; int m_keylen; }; } // namespace autobahn #include "wamp_challenge.ipp" #endif // AUTOBAHN_WAMP_CHALLENGE_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_challenge.ipp000066400000000000000000000050751371744511200240720ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_challenge::wamp_challenge( const std::string & authmethod, const std::string & challenge, const std::string & salt, int iterations, int keylen) : m_authmethod( authmethod ) , m_challenge( challenge ) , m_salt( salt ) , m_iterations( iterations ) , m_keylen( keylen ) {} inline wamp_challenge::wamp_challenge( const wamp_challenge & ch ) { m_authmethod = ch.authmethod(); m_challenge = ch.challenge(); m_salt = ch.salt(); m_iterations = ch.iterations(); m_keylen = ch.keylen(); } inline const std::string & wamp_challenge::authmethod() const { return m_authmethod; } inline const std::string & wamp_challenge::challenge() const { return m_challenge; } inline const std::string & wamp_challenge::salt() const { return m_salt; } inline int wamp_challenge::iterations() const { return m_iterations; } inline int wamp_challenge::keylen() const { return m_keylen; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_event.hpp000066400000000000000000000157021371744511200232660ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_EVENT_HPP #define AUTOBAHN_WAMP_EVENT_HPP #include "wamp_arguments.hpp" #include #include #include #include namespace autobahn { class wamp_event_impl { public: wamp_event_impl(msgpack::zone&& zone); //add URI and details /*! * Event URI. Used by prefix & wildcard subscriptions */ const std::string& uri() const; /*! * The number of positional arguments published by the event. */ std::size_t number_of_arguments() const; /*! * The number of keyword arguments published by the event. */ std::size_t number_of_kw_arguments() const; /*! * The positional argument published by the event with the given @p index, converted to type T. * * Example: * `std::string id = event.argument(0); // first positional argument` * * @throw std::out_of_range * @throw std::bad_cast */ template T argument(std::size_t index) const; /*! * The positional arguments published by the event, converted to a list type. * * Example: * `auto args = event.arguments>();` * * @throw std::bad_cast */ template List arguments() const; /*! * Convert and assign the positional arguments published by the event to the given @p args list. * * Example: * ``` * std::tuple args; * event.get_arguments(args); * ``` * * @throw std::bad_cast */ template void get_arguments(List& args) const; /*! * Convert and assign the positional arguments to a given list of individual parameters. * * Enables a syntax that lets you declare variables individually, but list them in a * single space to empathize parameter order. This will also throw if the number of * arguments to the invocation doesn't match the number of given parameters. * * Example: * ``` * uint64_t id; * std::string name; * invocation->get_each_argument(id, name); * ``` * * @throw std::bad_cast */ template inline void get_each_argument(T&... args) const; /*! * The keyword argument published by the event with the given @p key, converted to type T. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use kw_arguments() or * get_kw_arguments(map), then access the items from there. * * Example: * `std::string id = event.kw_argument("id");` * * @throw std::out_of_range * @throw std::bad_cast */ template T kw_argument(const std::string& key) const; template T kw_argument(const char* key) const; /*! * The keyword argument published by the event with the given @p key, converted to type T, * or the given @p fallback if no such key was passed. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use kw_arguments() or * get_kw_arguments(map), then access the items from there. * * Example: * `std::string id = event.kw_argument_or("id", std::string());` * * @throw std::bad_cast */ template T kw_argument_or(const std::string& key, const T& fallback) const; template T kw_argument_or(const char* key, const T& fallback) const; /*! * The keyword arguments published by the event, converted to a map type. * * Example: * `auto kw_args = event.kw_arguments>();` * * @throw std::bad_cast */ template Map kw_arguments() const; /*! * Convert and assign the keyword arguments published by the event to the given @p kw_args map. * * Example: * ``` * std::unordered_map kw_args; * event.get_kw_arguments(kw_args); * ``` * * @throw std::bad_cast */ template void get_kw_arguments(Map& kw_args) const; // // functions only called internally by wamp_session void set_arguments(const msgpack::object& arguments); void set_kw_arguments(const msgpack::object& kw_arguments); void set_details(const msgpack::object& details); private: msgpack::zone m_zone; msgpack::object m_arguments; msgpack::object m_kw_arguments; std::string m_uri; }; using wamp_event = std::shared_ptr; } // namespace autobahn #include "wamp_event.ipp" #endif // AUTOBAHN_WAMP_EVENT_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_event.ipp000066400000000000000000000141441371744511200232660ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include #include #include "wamp_arguments.hpp" namespace autobahn { inline wamp_event_impl::wamp_event_impl(msgpack::zone&& zone) : m_zone(std::move(zone)) , m_arguments(EMPTY_ARGUMENTS) , m_kw_arguments(EMPTY_KW_ARGUMENTS) { } inline const std::string& wamp_event_impl::uri() const { return m_uri; } inline std::size_t wamp_event_impl::number_of_arguments() const { return m_arguments.type == msgpack::type::ARRAY ? m_arguments.via.array.size : 0; } inline std::size_t wamp_event_impl::number_of_kw_arguments() const { return m_kw_arguments.type == msgpack::type::MAP ? m_kw_arguments.via.map.size : 0; } template inline T wamp_event_impl::argument(std::size_t index) const { if (m_arguments.type != msgpack::type::ARRAY || m_arguments.via.array.size <= index) { throw std::out_of_range("no argument at index " + boost::lexical_cast(index)); } return m_arguments.via.array.ptr[index].as(); } template inline List wamp_event_impl::arguments() const { return m_arguments.as(); } template inline void wamp_event_impl::get_arguments(List& args) const { m_arguments.convert(args); } template inline void wamp_event_impl::get_each_argument(T&... args) const { auto args_tuple = std::make_tuple(std::ref(args)...); m_arguments.convert(args_tuple); } template inline T wamp_event_impl::kw_argument(const std::string& key) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } throw std::out_of_range(key + " keyword argument doesn't exist"); } template inline T wamp_event_impl::kw_argument(const char* key) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } throw std::out_of_range(std::string(key) + " keyword argument doesn't exist"); } template inline T wamp_event_impl::kw_argument_or(const std::string& key, const T& fallback) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } return fallback; } template inline T wamp_event_impl::kw_argument_or(const char* key, const T& fallback) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } throw fallback; } template inline Map wamp_event_impl::kw_arguments() const { return m_kw_arguments.as(); } template inline void wamp_event_impl::get_kw_arguments(Map& kw_args) const { m_kw_arguments.convert(kw_args); } inline void wamp_event_impl::set_arguments(const msgpack::object& arguments) { m_arguments = arguments; } inline void wamp_event_impl::set_kw_arguments(const msgpack::object& kw_arguments) { m_kw_arguments = kw_arguments; } inline void wamp_event_impl::set_details(const msgpack::object& details) { m_uri = value_for_key_or(details, "topic", std::string()); } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_event_handler.hpp000066400000000000000000000036451371744511200247660ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_EVENT_HANDLER_HPP #define AUTOBAHN_WAMP_EVENT_HANDLER_HPP #include "wamp_event.hpp" namespace autobahn { /// Handler type for use with wamp_session::subscribe typedef std::function wamp_event_handler; } // namespace autobahn #endif // AUTOBAHN_WAMP_EVENT_HANDLER_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_invocation.hpp000066400000000000000000000275761371744511200243320ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_INVOCATION_HPP #define AUTOBAHN_WAMP_INVOCATION_HPP #include "wamp_arguments.hpp" #include #include #include #include #include #include namespace autobahn { class wamp_message; class wamp_invocation_impl { public: wamp_invocation_impl(); wamp_invocation_impl(wamp_invocation_impl&&) = delete; // copy wamp_invocation instead ~wamp_invocation_impl(); //add URI and details /*! * Invocatition procedure URI. Used by prefix & wildcard registered procedures */ const std::string& uri() const; /*! * The number of positional arguments passed to the invocation. */ std::size_t number_of_arguments() const; /*! * The number of keyword arguments passed to the invocation. */ std::size_t number_of_kw_arguments() const; /*! * The positional argument passed to the invocation with the given @p index, converted to type T. * * Example: * `std::string id = invocation->argument(0); // first positional argument` * * @throw std::out_of_range * @throw std::bad_cast */ template T argument(std::size_t index) const; /*! * The positional arguments passed to the invocation, converted to a list type. * * Example: * `auto args = invocation->arguments>();` * * @throw std::bad_cast */ template List arguments() const; /*! * Convert and assign the positional arguments to the given @p args list. * * Example: * ``` * std::tuple args; * invocation->get_arguments(args); * ``` * * @throw std::bad_cast */ template void get_arguments(List& args) const; /*! * Convert and assign the positional arguments to a given list of individual parameters. * * Enables a syntax that lets you declare variables individually, but list them in a * single space to empathize parameter order. This will also throw if the number of * arguments to the invocation doesn't match the number of given parameters. * * Example: * ``` * uint64_t id; * std::string name; * invocation->get_each_argument(id, name); * ``` * * @throw std::bad_cast */ template inline void get_each_argument(T&... args) const; /*! * The keyword argument passed to the invocation with the given @p key, converted to type T. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use kw_arguments() or * get_kw_arguments(map), then access the items from there. * * Example: * `std::string id = invocation->kw_argument("id");` * * @throw std::out_of_range * @throw std::bad_cast */ template T kw_argument(const std::string& key) const; template T kw_argument(const char* key) const; /*! * The keyword argument passed to the invocation with the given @p key, converted to type T, * or the given @p fallback if no such key was passed. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use kw_arguments() or * get_kw_arguments(map), then access the items from there. * * Example: * `std::string id = invocation->kw_argument_or("id", std::string());` * * @throw std::bad_cast */ template T kw_argument_or(const std::string& key, const T& fallback) const; template T kw_argument_or(const char* key, const T& fallback) const; /*! * The keyword arguments passed to the invocation, converted to a map type. * * Example: * `auto kw_args = invocation->kw_arguments>();` * * @throw std::bad_cast */ template Map kw_arguments() const; /*! * Convert and assign the keyword arguments to the given @p kw_args map. * * Example: * ``` * std::unordered_map kw_args; * invocation->get_kw_arguments(kw_args); * ``` * * @throw std::bad_cast */ template void get_kw_arguments(Map& kw_args) const; /*! * The call detail passed to the invocation with the given @p key, converted to type T. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use details() or * get_details(map), then access the items from there. * * Example: * `std::string caller_authid = invocation->detail("caller_authid");` * * @throw std::out_of_range * @throw std::bad_cast */ template T detail(const std::string& key) const; template T detail(const char* key) const; /*! * The call detail passed to the invocation with the given @p key, converted to type T, * or the given @p fallback if no such key was passed. * * Overloads are provided for `std::string` and `char*` as @p key type. * * This function uses key string comparisons to find the matching value, O(n) with n being * the number of map elements. Memory allocation for keys is avoided though. For larger maps, * you might want to prioritize look-up performance by using `std::map`, `std::unordered_map` * or custom types with custom deserialization. To do this, use details() or * get_details(map), then access the items from there. * * Example: * `std::string caller_authid = invocation->detail_or("caller_authid", std::string());` * * @throw std::bad_cast */ template T detail_or(const std::string& key, const T& fallback) const; template T detail_or(const char* key, const T& fallback) const; /*! * The call details passed to the invocation, converted to a map type. * * Example: * `auto kw_args = invocation->details>();` * * @throw std::bad_cast */ template Map details() const; /*! * Convert and assign the call details to the given @p details map. * * Example: * ``` * std::unordered_map kw_args; * invocation->get_details(details); * ``` * * @throw std::bad_cast */ template void get_details(Map& details) const; /*! * Checks if caller expects progressive results. */ bool progressive_results_expected() const; /*! * Reply to the invocation with an empty result. */ void empty_result(); /*! * Send progressive/partial result with positional arguments. */ template void progress(const List& arguments); /*! * Send progressive/partial result with positional and keyword arguments. */ template void progress(const List& arguments, const Map& kw_arguments); /*! * Reply to the invocation with positional arguments. */ template void result(const List& arguments); /*! * Reply to the invocation with positional and keyword arguments. */ template void result(const List& arguments, const Map& kw_arguments); /*! * Reply to the invocation with an error and no further details. */ void error(const std::string& error_uri); /*! * Reply to the invocation with an error, including positional arguments. */ template void error(const std::string& error_uri, const List& arguments); /*! * Reply to the invocation with an error, including positional and keyword arguments. */ template void error( const std::string& error_uri, const List& arguments, const Map& kw_arguments); // // functions only called internally by wamp_session using result_type = enum { final = 0, intermediary } ; using send_result_fn = std::function&)>; void set_send_result_fn(send_result_fn&&); void set_details(const msgpack::object& details); void set_request_id(std::uint64_t); void set_zone(msgpack::zone&&); void set_arguments(const msgpack::object& arguments); void set_kw_arguments(const msgpack::object& kw_arguments); bool sendable() const; private: void throw_if_not_sendable() const; template void send_result(const List& arguments, result_type resultType); template void send_result(const List& arguments, const Map& kw_arguments, result_type resultType); private: msgpack::zone m_zone; msgpack::object m_arguments; msgpack::object m_kw_arguments; msgpack::object m_details; send_result_fn m_send_result_fn; std::uint64_t m_request_id; std::string m_uri; bool m_progressive_results_expected; }; using wamp_invocation = std::shared_ptr; } // namespace autobahn #include "wamp_invocation.ipp" #endif // AUTOBAHN_WAMP_INVOCATION_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_invocation.ipp000066400000000000000000000363641371744511200243260ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "wamp_message.hpp" #include "wamp_message_type.hpp" #include #include #include namespace autobahn { inline wamp_invocation_impl::wamp_invocation_impl() : m_zone() , m_arguments(EMPTY_ARGUMENTS) , m_kw_arguments(EMPTY_KW_ARGUMENTS) , m_send_result_fn() , m_request_id(0) , m_progressive_results_expected(false) { } inline wamp_invocation_impl::~wamp_invocation_impl() { // If still sendable, send default empty result if(sendable()) { empty_result(); } } inline const std::string& wamp_invocation_impl::uri() const { return m_uri; } inline std::size_t wamp_invocation_impl::number_of_arguments() const { return m_arguments.type == msgpack::type::ARRAY ? m_arguments.via.array.size : 0; } inline std::size_t wamp_invocation_impl::number_of_kw_arguments() const { return m_kw_arguments.type == msgpack::type::MAP ? m_kw_arguments.via.map.size : 0; } template inline T wamp_invocation_impl::argument(std::size_t index) const { if (m_arguments.type != msgpack::type::ARRAY || m_arguments.via.array.size <= index) { throw std::out_of_range("no argument at index " + boost::lexical_cast(index)); } return m_arguments.via.array.ptr[index].as(); } template inline List wamp_invocation_impl::arguments() const { return m_arguments.as(); } template inline void wamp_invocation_impl::get_arguments(List& args) const { m_arguments.convert(args); } template inline void wamp_invocation_impl::get_each_argument(T&... args) const { auto args_tuple = std::make_tuple(std::ref(args)...); m_arguments.convert(args_tuple); } template inline T wamp_invocation_impl::kw_argument(const std::string& key) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } throw std::out_of_range(key + " keyword argument doesn't exist"); } template inline T wamp_invocation_impl::kw_argument(const char* key) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } throw std::out_of_range(std::string(key) + " keyword argument doesn't exist"); } template inline T wamp_invocation_impl::kw_argument_or(const std::string& key, const T& fallback) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } return fallback; } template inline T wamp_invocation_impl::kw_argument_or(const char* key, const T& fallback) const { if (m_kw_arguments.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_kw_arguments.via.map.size; ++i) { const msgpack::object_kv& kv = m_kw_arguments.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } return fallback; } template inline Map wamp_invocation_impl::kw_arguments() const { return m_kw_arguments.as(); } template inline void wamp_invocation_impl::get_kw_arguments(Map& kw_args) const { m_kw_arguments.convert(kw_args); } template inline T wamp_invocation_impl::detail(const std::string& key) const { if (m_details.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_details.via.map.size; ++i) { const msgpack::object_kv& kv = m_details.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } throw std::out_of_range(key + " call detail doesn't exist"); } template inline T wamp_invocation_impl::detail(const char* key) const { if (m_details.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_details.via.map.size; ++i) { const msgpack::object_kv& kv = m_details.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } throw std::out_of_range(std::string(key) + " call detail doesn't exist"); } template inline T wamp_invocation_impl::detail_or(const std::string& key, const T& fallback) const { if (m_details.type != msgpack::type::MAP) { throw msgpack::type_error(); } for (std::size_t i = 0; i < m_details.via.map.size; ++i) { const msgpack::object_kv& kv = m_details.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) { return kv.val.as(); } } return fallback; } template inline T wamp_invocation_impl::detail_or(const char* key, const T& fallback) const { if (m_details.type != msgpack::type::MAP) { throw msgpack::type_error(); } std::size_t key_size = strlen(key); for (std::size_t i = 0; i < m_details.via.map.size; ++i) { const msgpack::object_kv& kv = m_details.via.map.ptr[i]; if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size && memcmp(key, kv.key.via.str.ptr, key_size) == 0) { return kv.val.as(); } } return fallback; } template inline Map wamp_invocation_impl::details() const { return m_details.as(); } template inline void wamp_invocation_impl::get_details(Map& details) const { m_details.convert(details); } inline bool wamp_invocation_impl::progressive_results_expected() const { return m_progressive_results_expected; } inline void wamp_invocation_impl::empty_result() { throw_if_not_sendable(); // [YIELD, INVOCATION.Request|id, Options|dict] auto message = std::make_shared(3); message->set_field(0, static_cast(message_type::YIELD)); message->set_field(1, m_request_id); message->set_field(2, std::map() /* No details */); m_send_result_fn(message); m_send_result_fn = send_result_fn(); } template inline void wamp_invocation_impl::send_result(const List& arguments, wamp_invocation_impl::result_type resultType) { throw_if_not_sendable(); if (resultType == intermediary && !m_progressive_results_expected) { //Discard intermediate results. Other option is to throw, since method could check if progressive results are expected return; } // [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list] auto message = std::make_shared(4); message->set_field(0, static_cast(message_type::YIELD)); message->set_field(1, m_request_id); if (resultType == intermediary) { message->set_field(2, std::map{ {"progress", true} }); } else { message->set_field(2, std::map() /* No details */); } message->set_field(3, arguments); m_send_result_fn(message); if (resultType != intermediary) { //Final result clears send function m_send_result_fn = send_result_fn(); } } template inline void wamp_invocation_impl::send_result( const List& arguments, const Map& kw_arguments, wamp_invocation_impl::result_type resultType) { throw_if_not_sendable(); if (resultType == intermediary && !m_progressive_results_expected) { //Discard intermediate results. Other option is to throw, since method could check if progressive results are expected return; } // [YIELD, INVOCATION.Request|id, Options|dict, Arguments|list, ArgumentsKw|dict] auto message = std::make_shared(5); message->set_field(0, static_cast(message_type::YIELD)); message->set_field(1, m_request_id); if (resultType == intermediary) { message->set_field(2, std::map{ {"progress", true} }); } else { message->set_field(2, std::map() /* No details */); } message->set_field(3, arguments); message->set_field(4, kw_arguments); m_send_result_fn(message); if (resultType != intermediary) { //Final result clears send function m_send_result_fn = send_result_fn(); } } template inline void wamp_invocation_impl::progress(const List& arguments) { send_result(arguments, intermediary); } template inline void wamp_invocation_impl::progress(const List& arguments, const Map& kw_arguments) { send_result(arguments, kw_arguments, intermediary); } template inline void wamp_invocation_impl::result(const List& arguments) { send_result(arguments, final); } template inline void wamp_invocation_impl::result(const List& arguments, const Map& kw_arguments) { send_result(arguments, kw_arguments, final); } inline void wamp_invocation_impl::error(const std::string& error_uri) { throw_if_not_sendable(); // [ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri] auto message = std::make_shared(5); message->set_field(0, static_cast(message_type::ERROR)); message->set_field(1, static_cast(message_type::INVOCATION)); message->set_field(2, m_request_id); message->set_field(3, std::map() /* No details */); message->set_field(4, error_uri); m_send_result_fn(message); m_send_result_fn = send_result_fn(); } template inline void wamp_invocation_impl::error(const std::string& error_uri, const List& arguments) { throw_if_not_sendable(); // [ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri, Arguments|list] auto message = std::make_shared(6); message->set_field(0, static_cast(message_type::ERROR)); message->set_field(1, static_cast(message_type::INVOCATION)); message->set_field(2, m_request_id); message->set_field(3, std::map() /* No details */); message->set_field(4, error_uri); message->set_field(5, arguments); m_send_result_fn(message); m_send_result_fn = send_result_fn(); } template inline void wamp_invocation_impl::error( const std::string& error_uri, const List& arguments, const Map& kw_arguments) { throw_if_not_sendable(); // [ERROR, INVOCATION, INVOCATION.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict] auto message = std::make_shared(7); message->set_field(0, static_cast(message_type::ERROR)); message->set_field(1, static_cast(message_type::INVOCATION)); message->set_field(2, m_request_id); message->set_field(3, std::map() /* No details */); message->set_field(4, error_uri); message->set_field(5, arguments); message->set_field(6, kw_arguments); m_send_result_fn(message); m_send_result_fn = send_result_fn(); } inline void wamp_invocation_impl::set_send_result_fn(send_result_fn&& send_result) { m_send_result_fn = std::move(send_result); } inline void wamp_invocation_impl::set_details(const msgpack::object& details) { m_uri = value_for_key_or(details, "procedure", std::string()); m_progressive_results_expected = value_for_key_or(details, "receive_progress", false); m_details = details; } inline void wamp_invocation_impl::set_request_id(std::uint64_t request_id) { m_request_id = request_id; } inline void wamp_invocation_impl::set_zone(msgpack::zone&& zone) { m_zone = std::move(zone); } inline void wamp_invocation_impl::set_arguments(const msgpack::object& arguments) { m_arguments = arguments; } inline void wamp_invocation_impl::set_kw_arguments(const msgpack::object& kw_arguments) { m_kw_arguments = kw_arguments; } inline bool wamp_invocation_impl::sendable() const { return static_cast(m_send_result_fn); } inline void wamp_invocation_impl::throw_if_not_sendable() const { if (!sendable()) { throw std::runtime_error("tried to call result() or error() but wamp_invocation " "is not sendable (double call?)"); } } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_message.hpp000066400000000000000000000133511371744511200235670ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_MESSAGE_HPP #define AUTOBAHN_WAMP_MESSAGE_HPP #include #include #include #include namespace autobahn { /*! * A class that represents a wamp message in its simplest form. * * [field1, field2, field3, ...] * * Although not all arrays are valid wamp messages, this class * simply provides the building blocks to construct any type of * message. * * TODO: Investigate the benefits of creating a hierarchy of * wamp message types similar to what has been done for * bonefish. */ class wamp_message { public: /*! * A convenience type for representing message fields */ using message_fields = std::vector; public: /*! * Constructs a wamp message with the given number of fields. * * @param num_fields The number of fields in the message. */ wamp_message(std::size_t num_fields); /*! * Constructs a wamp message with the given number of fields. * * @param num_fields The number of fields in the message. * @param zone The zone used to allocate fields in the message. */ wamp_message(std::size_t num_fields, msgpack::zone&& zone); /*! * Constructs a wamp message with the given fields. * * @param fields The fields in the message. * @param zone The zone used to allocate fields in the message. */ wamp_message(message_fields&& fields, msgpack::zone&& zone); wamp_message(const wamp_message& other) = delete; wamp_message(wamp_message&& other); wamp_message& operator=(const wamp_message& other) = delete; wamp_message& operator=(wamp_message&& other); /*! * Retrieves the field at the specified index. Throws an exception * if the index is out of bounds. * * @param index The index of the target field. * * @return The retrieved type. */ const msgpack::object& field(std::size_t index) const; /*! * Retrieves the field at the specified index. Throws an exception * if the index is out of bounds or if the field cannot be retrieved * as the specified type. * * @tparam Type The field's type. * @param index The index of the target field. * * @return The retrieved type. */ template Type field(std::size_t index); /*! * Sets the field at the specified index. Throws an exception if the * index is out of bounds. * * @tparam Type The field's type. * @param index The index of the target field. * @param type The type to store in the target field. */ template void set_field(std::size_t index, const Type& type); /*! * Determines if the field at the specified index is of the given type. * * @param index The index of the target field. * @param type The field type to check against. */ bool is_field_type(std::size_t index, msgpack::type::object_type type) const; /*! * Retrieves the number of fields in the message. * * @return The number of fields in the message. */ std::size_t size() const; /*! * The message fields. * * @return The message fields. */ const message_fields& fields() const; /*! * Pilfers the message fields. * * @return The message fields. */ message_fields&& fields(); /*! * Pilfers the message zone. * * @return The message zone. */ msgpack::zone&& zone(); private: /*! * The zone used to allocate message fields. The zone must outlive * the fields. If the fields are pilfered then the zone must also * be pilferred and stored along with the fields. */ msgpack::zone m_zone; /*! * The fields comprising of the message. It is up to the user of this * class to ensure that a valid wamp message has been constructed. */ message_fields m_fields; }; /// Convenience operator for outputting a raw wamp message. std::ostream& operator<<(std::ostream& os, const wamp_message& message); } // namespace autobahn #include "wamp_message.ipp" #endif // AUTOBAHN_WAMP_MESSAGE_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_message.ipp000066400000000000000000000104071371744511200235670ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "wamp_message_type.hpp" #include namespace autobahn { inline wamp_message::wamp_message(std::size_t num_fields) : m_zone() , m_fields(num_fields) { } inline wamp_message::wamp_message(std::size_t num_fields, msgpack::zone&& zone) : m_zone(std::move(zone)) , m_fields(num_fields) { } inline wamp_message::wamp_message(message_fields&& fields, msgpack::zone&& zone) : m_zone(std::move(zone)) , m_fields(std::move(fields)) { } inline wamp_message::wamp_message(wamp_message&& other) { m_zone = std::move(other.m_zone); m_fields = std::move(other.m_fields); } inline wamp_message& wamp_message::operator=(wamp_message&& other) { if (this == &other) { return *this; } m_zone = std::move(other.m_zone); m_fields = std::move(other.m_fields); return *this; } inline const msgpack::object& wamp_message::field(std::size_t index) const { if (index >= m_fields.size()) { throw std::out_of_range("invalid message field index"); } return m_fields[index]; } template inline Type wamp_message::field(std::size_t index) { if (index >= m_fields.size()) { throw std::out_of_range("invalid message field index"); } return m_fields[index].as(); } template inline void wamp_message::set_field(std::size_t index, const Type& type) { if (index >= m_fields.size()) { throw std::out_of_range("invalid message field index"); } m_fields[index] = msgpack::object(type, m_zone); } inline bool wamp_message::is_field_type(std::size_t index, msgpack::type::object_type type) const { if (index >= m_fields.size()) { throw std::out_of_range("invalid message field index"); } return m_fields[index].type == type; } inline std::size_t wamp_message::size() const { return m_fields.size(); } inline wamp_message::message_fields&& wamp_message::fields() { return std::move(m_fields); } inline msgpack::zone&& wamp_message::zone() { return std::move(m_zone); } inline std::ostream& operator<<(std::ostream& os, const wamp_message& message) { std::size_t num_fields = message.size(); if (num_fields == 0) { os << "unknown []"; return os; } const msgpack::object& type_field = message.field(0); message_type type = static_cast(type_field.as()); if (num_fields == 1) { os << to_string(type) << " []"; return os; } os << to_string(type) << " ["; os << message.field(1); for (std::size_t index = 2; index < num_fields; ++index) { os << ", " << message.field(index); } os << "]"; return os; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_message_type.hpp000066400000000000000000000050031371744511200246230ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_MESSAGE_TYPE_HPP #define AUTOBAHN_WAMP_MESSAGE_TYPE_HPP #include #ifdef ERROR #undef ERROR #endif #ifdef REGISTERED #undef REGISTERED #endif namespace autobahn { /// WAMP message types. enum class message_type : int { HELLO = 1, WELCOME = 2, ABORT = 3, CHALLENGE = 4, AUTHENTICATE = 5, GOODBYE = 6, HEARTBEAT = 7, ERROR = 8, PUBLISH = 16, PUBLISHED = 17, SUBSCRIBE = 32, SUBSCRIBED = 33, UNSUBSCRIBE = 34, UNSUBSCRIBED = 35, EVENT = 36, CALL = 48, CANCEL = 49, RESULT = 50, REGISTER = 64, REGISTERED = 65, UNREGISTER = 66, UNREGISTERED = 67, INVOCATION = 68, INTERRUPT = 69, YIELD = 70 }; /// Convert message type enum to human readable string. std::string to_string(message_type type); } // namespace autobahn #include "wamp_message_type.ipp" #endif // AUTOBAHN_WAMP_MESSAGE_TYPE_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_message_type.ipp000066400000000000000000000061521371744511200246320ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include namespace autobahn { inline std::string to_string(message_type type) { static std::map type_names = { { message_type::HELLO, "hello" }, { message_type::WELCOME, "welcome" }, { message_type::ABORT, "abort" }, { message_type::CHALLENGE, "challenge" }, { message_type::AUTHENTICATE, "authenticate" }, { message_type::GOODBYE, "goodbye" }, { message_type::HEARTBEAT, "heartbeat" }, { message_type::ERROR, "error" }, { message_type::PUBLISH, "publish" }, { message_type::PUBLISHED, "published" }, { message_type::SUBSCRIBE, "subscribe" }, { message_type::SUBSCRIBED, "subscribed" }, { message_type::UNSUBSCRIBE, "unsubscribe" }, { message_type::UNSUBSCRIBED, "unsubscribed" }, { message_type::EVENT, "event" }, { message_type::CALL, "call" }, { message_type::CANCEL, "cancel" }, { message_type::RESULT, "result" }, { message_type::REGISTER, "register" }, { message_type::REGISTERED, "registered" }, { message_type::UNREGISTER, "unregister" }, { message_type::UNREGISTERED, "unregistered" }, { message_type::INVOCATION, "invocation" }, { message_type::INTERRUPT, "interrupt" }, { message_type::YIELD, "yield" } }; auto result = type_names.find(type); if (result == type_names.end()) { return std::string("unknown"); } return result->second; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_procedure.hpp000066400000000000000000000037401371744511200241340ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_PROCEDURE_HPP #define AUTOBAHN_WAMP_PROCEDURE_HPP #include "wamp_arguments.hpp" #include "wamp_invocation.hpp" namespace autobahn { /// Handler type for use with wamp_session::provide using wamp_procedure = std::function; using provide_options = wamp_kw_arguments; } // namespace autobahn #endif // AUTOBAHN_WAMP_PROCEDURE_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_publication.hpp000066400000000000000000000037721371744511200244620ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_PUBLICATION_HPP #define AUTOBAHN_WAMP_PUBLICATION_HPP #include namespace autobahn { /// Represents a topic subscription. class wamp_publication { public: wamp_publication(); wamp_publication(uint64_t id); uint64_t id() const; private: uint64_t m_id; }; } // namespace autobahn #include "wamp_publication.ipp" #endif // AUTOBAHN_WAMP_PUBLICATION_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_publication.ipp000066400000000000000000000035411371744511200244550ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_publication::wamp_publication() : m_id(0) { } inline wamp_publication::wamp_publication(uint64_t id) : m_id(id) { } inline uint64_t wamp_publication::id() const { return m_id; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_publish_options.hpp000066400000000000000000000045441371744511200253700ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_PUBLISH_OPTIONS_HPP #define AUTOBAHN_WAMP_PUBLISH_OPTIONS_HPP #include namespace autobahn { /*! * \ingroup PUB * Options for publishing. */ class wamp_publish_options { public: wamp_publish_options(); wamp_publish_options(wamp_publish_options&& other) = delete; wamp_publish_options(const wamp_publish_options& other) = delete; wamp_publish_options& operator=(wamp_publish_options&& other) = delete; wamp_publish_options& operator=(const wamp_publish_options& other) = delete; const bool& exclude_me() const; void set_exclude_me(const bool& exclude_me); private: bool m_exclude_me; }; } // namespace autobahn #include "wamp_publish_options.ipp" #endif // AUTOBAHN_WAMP_PUBLISH_OPTIONS_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_publish_options.ipp000066400000000000000000000074771371744511200254010ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include #include #include namespace autobahn { inline wamp_publish_options::wamp_publish_options() : m_exclude_me(true) //default { } inline const bool& wamp_publish_options::exclude_me() const { return m_exclude_me; } inline void wamp_publish_options::set_exclude_me(const bool& exclude_me) { m_exclude_me = exclude_me; } } // namespace autobahn namespace msgpack { MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { namespace adaptor { template<> struct convert { msgpack::object const& operator()( msgpack::object const& object, autobahn::wamp_publish_options& options) const { std::unordered_map options_map; object >> options_map; const auto options_map_itr = options_map.find("exclude_me"); if (options_map_itr != options_map.end()) { options.set_exclude_me( options_map_itr->second.as()); } return object; } }; template<> struct pack { template msgpack::packer& operator()( msgpack::packer& packer, autobahn::wamp_publish_options const& options) const { std::unordered_map options_map; const auto& exclude_me = options.exclude_me(); if (exclude_me != true) { //true is default, only false msut be transfered options_map["exclude_me"] = exclude_me; } packer.pack(options_map); return packer; } }; template <> struct object_with_zone { void operator()( msgpack::object::with_zone& object, const autobahn::wamp_publish_options& options) { std::unordered_map options_map; const auto& exclude_me = options.exclude_me(); if (exclude_me != true) { //true is default, only false must be transfered options_map["exclude_me"] = msgpack::object(exclude_me); } object << options_map; } }; } // namespace adaptor } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) } // namespace msgpack crossbario-autobahn-cpp-d7a4346/autobahn/wamp_rawsocket_transport.hpp000066400000000000000000000146331371744511200262650ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_NETWORK_TRANSPORT_HPP #define AUTOBAHN_WAMP_NETWORK_TRANSPORT_HPP #include "boost_config.hpp" #include "wamp_transport.hpp" #include #include #include #include namespace autobahn { class wamp_message; class wamp_transport_handler; /*! * A class that represents a rawsocket transport. It is templated based * on the socket type * * @tparam Socket The socket type for the transport. * @tparam Endpoint The endpoint type for the socket to connect to. */ template class wamp_rawsocket_transport : public wamp_transport, public std::enable_shared_from_this> { public: /*! * Convenience type for the socket being used. */ typedef Socket socket_type; /*! * Convenience type for the endpoint being used. */ typedef typename Socket::endpoint_type endpoint_type; public: /*! * Constructs a rawsocket transport. * * @param io_service The io service to use for asynchronous operations. * @param remote_endpoint The remote endpoint to connect to. */ wamp_rawsocket_transport( boost::asio::io_service& io_service, const endpoint_type& remote_endpoint, bool debug_enabled=false); virtual ~wamp_rawsocket_transport() override = default; /* * CONNECTION INTERFACE */ /*! * @copydoc wamp_transport::connect() */ virtual boost::future connect() override; /*! * @copydoc wamp_transport::disconnect() */ virtual boost::future disconnect() override; /*! * @copydoc wamp_transport::is_connected() */ virtual bool is_connected() const override; /* * SENDER INTERFACE */ /*! * @copydoc wamp_transport::send_message() */ virtual void send_message(wamp_message&& message) override; /*! * @copydoc wamp_transport::set_pause_handler() */ virtual void set_pause_handler(pause_handler&& handler) override; /*! * @copydoc wamp_transport::set_resume_handler() */ virtual void set_resume_handler(resume_handler&& handler) override; /* * RECEIVER INTERFACE */ /*! * Pause receiving of messages. This will prevent the transport from receiving * any more messages until it has been resumed. This is used to excert * backpressure on the sending peer. */ virtual void pause() override; /*! * Resume receiving of messages. The transport will now begin receiving messsages * again and lift backpressure from the sending peer. */ virtual void resume() override; /*! * @copydoc wamp_transport::attach() */ virtual void attach( const std::shared_ptr& handler) override; /*! * @copydoc wamp_transport::detach() */ virtual void detach() override; /*! * @copydoc wamp_transport::has_handler() */ virtual bool has_handler() const override; protected: socket_type& socket(); private: void handshake_reply_handler( const boost::system::error_code& error_code, std::size_t /* bytes_transferred */); void receive_message(); void receive_message_header( const boost::system::error_code& error, std::size_t /* bytes transferred */); void receive_message_body( const boost::system::error_code& error, std::size_t /* bytes transferred */); private: /*! * The underlying socket for the transport. */ socket_type m_socket; /*! * The remote endpoint to connect the socket to. */ endpoint_type m_remote_endpoint; /*! * The promise that is fulfilled when the connect attempt is complete. */ boost::promise m_connect; /*! * The promise that is fulfilled when the disconnect attempt is complete. */ boost::promise m_disconnect; /*! * The handler to be called when pausing. */ pause_handler m_pause_handler; /*! * The handler to be called when resuming. */ resume_handler m_resume_handler; /*! * The transport handler to be notified of events/messages. */ std::shared_ptr m_handler; /*! * Buffer used for sending and receiving the handshake. */ uint8_t m_handshake_buffer[4]; /*! * Stores the length of the next serialized message to receive. */ uint32_t m_message_length; /*! * Used for unpacking serialized messages. */ msgpack::unpacker m_message_unpacker; /*! * Whether or not debugging is enabled. */ bool m_debug_enabled; }; } // namespace autobahn #include "wamp_rawsocket_transport.ipp" #endif // AUTOBAHN_WAMP_NETWORK_TRANSPORT_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_rawsocket_transport.ipp000066400000000000000000000303441371744511200262630ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "exceptions.hpp" #include "wamp_message.hpp" #include "wamp_transport_handler.hpp" #include #include #include #include #include namespace autobahn { template wamp_rawsocket_transport::wamp_rawsocket_transport( boost::asio::io_service& io_service, const endpoint_type& remote_endpoint, bool debug_enabled) : wamp_transport() , m_socket(io_service) , m_remote_endpoint(remote_endpoint) , m_connect() , m_disconnect() , m_handshake_buffer() , m_message_length(0) , m_message_unpacker() , m_debug_enabled(debug_enabled) { memset(m_handshake_buffer, 0, sizeof(m_handshake_buffer)); } template boost::future wamp_rawsocket_transport::connect() { m_connect = boost::promise(); // reset the promise if (m_socket.is_open()) { m_connect.set_exception(boost::copy_exception(network_error("network transport already connected"))); return m_connect.get_future(); } std::weak_ptr> weak_self = this->shared_from_this(); auto connect_handler = [this, weak_self](const boost::system::error_code& error_code) { auto shared_self = weak_self.lock(); if (!shared_self) { return; } if (error_code) { m_socket.close(); // async_connect will leave it open m_connect.set_exception(boost::copy_exception( std::system_error(error_code.value(), std::system_category(), "connect"))); return; } // FIXME: There should be a wamp_rawsocket_properties object or something // similar that can be passed in to help deal with overiding these // handshake parameters. // // Send the initial handshake packet informing the server which // serialization format we wish to use, and our maximum message size. m_handshake_buffer[0] = 0x7F; // magic byte m_handshake_buffer[1] = 0xF2; // we are ready to receive messages up to 2**24 octets and encoded using MsgPack m_handshake_buffer[2] = 0x00; // reserved m_handshake_buffer[3] = 0x00; // reserved boost::asio::write( m_socket, boost::asio::buffer(m_handshake_buffer, sizeof(m_handshake_buffer))); auto handshake_reply = [this, weak_self]( const boost::system::error_code& error, std::size_t bytes_transferred) { auto shared_self = weak_self.lock(); if (shared_self) { handshake_reply_handler(error, bytes_transferred); } }; try { // Read the 4-byte handshake reply from the server boost::asio::async_read( m_socket, boost::asio::buffer(m_handshake_buffer, sizeof(m_handshake_buffer)), handshake_reply); } catch (const std::exception& e) { m_connect.set_exception(boost::copy_exception(e)); } }; m_socket.async_connect(m_remote_endpoint, connect_handler); return m_connect.get_future(); } template boost::future wamp_rawsocket_transport::disconnect() { if (!m_socket.is_open()) { throw network_error("network transport already disconnected"); } m_socket.close(); m_disconnect.set_value(); return m_disconnect.get_future(); } template bool wamp_rawsocket_transport::is_connected() const { return m_socket.is_open(); } template void wamp_rawsocket_transport::send_message(wamp_message&& message) { auto buffer = std::make_shared(); msgpack::packer packer(*buffer); packer.pack(message.fields()); // Write the length prefix as the message header. uint32_t length = htonl(buffer->size()); boost::asio::write(m_socket, boost::asio::buffer(&length, sizeof(length))); // Write actual serialized message. boost::asio::write(m_socket, boost::asio::buffer(buffer->data(), buffer->size())); if (m_debug_enabled) { std::cerr << "TX message (" << buffer->size() << " octets) ..." << std::endl; std::cerr << "TX message: " << message << std::endl; } } template void wamp_rawsocket_transport::set_pause_handler(pause_handler&& handler) { m_pause_handler = std::move(handler); } template void wamp_rawsocket_transport::set_resume_handler(resume_handler&& handler) { m_resume_handler = std::move(handler); } template void wamp_rawsocket_transport::pause() { if (m_pause_handler) { m_pause_handler(); } } template void wamp_rawsocket_transport::resume() { if (m_resume_handler) { m_resume_handler(); } } template void wamp_rawsocket_transport::attach( const std::shared_ptr& handler) { if (m_handler) { throw std::logic_error("handler already attached"); } m_handler = handler; m_handler->on_attach(this->shared_from_this()); } template void wamp_rawsocket_transport::detach() { if (!m_handler) { throw std::logic_error("no handler attached"); } m_handler->on_detach(true, "wamp.error.goodbye"); m_handler.reset(); } template bool wamp_rawsocket_transport::has_handler() const { return m_handler != nullptr; } template Socket& wamp_rawsocket_transport::socket() { return m_socket; } template void wamp_rawsocket_transport::handshake_reply_handler( const boost::system::error_code& error_code, std::size_t /* bytes_transferred */) { if (error_code) { if (m_debug_enabled) { std::cerr << "rawsocket handshake error: " << error_code << std::endl; } m_connect.set_exception(boost::copy_exception( std::system_error(error_code.value(), std::system_category(), "async_read"))); return; } if (m_debug_enabled) { std::cerr << "RawSocket handshake reply received" << std::endl; } if (m_handshake_buffer[0] != 0x7F) { m_connect.set_exception(boost::copy_exception(protocol_error("invalid handshake frame"))); return; } // Indicates that the handshake reply is an error. if ((m_handshake_buffer[1] & 0x0F) == 0x00) { uint32_t error = m_handshake_buffer[1] & 0xF0; if (m_debug_enabled) { std::cerr << "rawsocket handshake error: " << std::hex << error << std::endl; } std::stringstream error_string; if (error == 0x00) { error_string << "illegal error code (" << error << ")"; } else if (error == 0x10) { error_string << "serializer unsupported"; } else if (error == 0x20) { error_string << "maximum message length unacceptable"; } else if (error == 0x30) { error_string << "use of reserved bits (unsupported feature)"; } else if (error == 0x40) { error_string << "maximum connection count reached"; } else { error_string << "unknown/reserved error code (" << error << ")"; } m_connect.set_exception(boost::copy_exception(protocol_error(error_string.str()))); return; } uint32_t serializer_type = (m_handshake_buffer[1] & 0x0F); if (serializer_type == 0x01) { m_connect.set_exception(boost::copy_exception(protocol_error("json currently not supported"))); } else if (serializer_type == 0x02) { if (m_debug_enabled) { std::cerr << "connect successful: valid handshake" << std::endl; } m_connect.set_value(); receive_message(); } else { std::stringstream error_string; error_string << "rawsocket handshake error: invalid serializer type (" << serializer_type << ")"; m_connect.set_exception(boost::copy_exception(protocol_error(error_string.str()))); } } template void wamp_rawsocket_transport::receive_message() { if (m_debug_enabled) { std::cerr << "RX preparing to receive message .." << std::endl; } boost::asio::async_read( m_socket, boost::asio::buffer(&m_message_length, sizeof(m_message_length)), bind(&wamp_rawsocket_transport::receive_message_header, this->shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); } template void wamp_rawsocket_transport::receive_message_header( const boost::system::error_code& error_code, std::size_t /* bytes transferred */) { if (!error_code) { m_message_length = ntohl(m_message_length); if (m_debug_enabled) { std::cerr << "RX message (" << m_message_length << " octets) ..." << std::endl; } m_message_unpacker.reserve_buffer(m_message_length); boost::asio::async_read( m_socket, boost::asio::buffer(m_message_unpacker.buffer(), m_message_length), bind(&wamp_rawsocket_transport::receive_message_body, this->shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); return; } } template void wamp_rawsocket_transport::receive_message_body( const boost::system::error_code& error_code, std::size_t /* bytes transferred */) { if (error_code) { if (m_debug_enabled && error_code != boost::asio::error::operation_aborted) { std::cerr << "Receive error: " << error_code << std::endl; } return; } if (m_debug_enabled) { std::cerr << "RX message received." << std::endl; } if (m_handler) { m_message_unpacker.buffer_consumed(m_message_length); msgpack::unpacked result; while (m_message_unpacker.next(result)) { wamp_message::message_fields fields; result.get().convert(fields); wamp_message message(std::move(fields), std::move(*(result.zone()))); if (m_debug_enabled) { std::cerr << "RX message: " << message << std::endl; } m_handler->on_message(std::move(message)); } } else { std::cerr << "RX message ignored: no handler attached" << std::endl; } receive_message(); } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_register_request.hpp000066400000000000000000000046511371744511200255420ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_REGISTER_REQUEST_HPP #define AUTOBAHN_WAMP_REGISTER_REQUEST_HPP #include "wamp_procedure.hpp" #include "wamp_registration.hpp" #include "boost_config.hpp" namespace autobahn { /// An outstanding wamp call. class wamp_register_request { public: wamp_register_request(); wamp_register_request(const wamp_procedure& procedure); wamp_register_request(wamp_register_request&& other); const wamp_procedure& procedure() const; boost::promise& response(); void set_procedure(wamp_procedure procedure) const; void set_response(const wamp_registration& registration); private: wamp_procedure m_procedure; boost::promise m_response; }; } // namespace autobahn #include "wamp_register_request.ipp" #endif // AUTOBAHN_WAMP_REGISTER_REQUEST_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_register_request.ipp000066400000000000000000000046051371744511200255420ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_register_request::wamp_register_request() : m_procedure() , m_response() { } inline wamp_register_request::wamp_register_request(const wamp_procedure& procedure) : m_procedure(procedure) , m_response() { } inline wamp_register_request::wamp_register_request(wamp_register_request&& other) : m_procedure(std::move(other.m_procedure)) , m_response(std::move(other.m_response)) { } inline const wamp_procedure& wamp_register_request::procedure() const { return m_procedure; } inline boost::promise& wamp_register_request::response() { return m_response; } inline void wamp_register_request::set_response(const wamp_registration& registration) { m_response.set_value(registration); } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_registration.hpp000066400000000000000000000040011371744511200246450ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_REGISTRATION_HPP #define AUTOBAHN_WAMP_REGISTRATION_HPP #include namespace autobahn { /// Represents a topic subscription. class wamp_registration { public: wamp_registration(); wamp_registration(uint64_t id); uint64_t id() const; private: uint64_t m_id; }; } // namespace autobahn #include "wamp_registration.ipp" #endif // AUTOBAHN_WAMP_REGISTRATION_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_registration.ipp000066400000000000000000000035461371744511200246630ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_registration::wamp_registration() : m_id(0) { } inline wamp_registration::wamp_registration(uint64_t id) : m_id(id) { } inline uint64_t wamp_registration::id() const { return m_id; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_session.hpp000066400000000000000000000350131371744511200236250ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_SESSION_HPP #define AUTOBAHN_SESSION_HPP #include "wamp_call_options.hpp" #include "wamp_call_result.hpp" #include "wamp_event_handler.hpp" #include "wamp_message.hpp" #include "wamp_procedure.hpp" #include "wamp_publish_options.hpp" #include "wamp_subscribe_options.hpp" #include "wamp_transport_handler.hpp" #include "boost_config.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #if defined(_WIN32) || defined(WIN32) #define WIN32_LEAN_AND_MEAN #endif #ifdef ERROR #undef ERROR #endif namespace autobahn { class wamp_call; class wamp_message; class wamp_register_request; class wamp_registration; class wamp_subscribe_request; class wamp_subscription; class wamp_transport; class wamp_unregister_request; class wamp_unsubscribe_request; class wamp_authenticate; class wamp_challenge; /** \defgroup PUB Publishing events \brief Publishing events is done from a session using one of the following functions When a WAMP session has been established, the session can be used to publish event at the router, which in turn will dispatch the event to all eligible and authorized subscribes to the topic. */ /// Representation of a WAMP session. class wamp_session : public wamp_transport_handler, public std::enable_shared_from_this { public: /*! * Create a new WAMP session. * * \param io_service The io service to drive event dispatching. * \param debug_enabled Whether or not to run in debug mode. */ wamp_session( boost::asio::io_service& io_service, bool debug_enabled = false); ~wamp_session(); /*! * Establishes a session with the router. * * \return A future that indicates if the session was successfully started. */ boost::future start(); /*! * Stops the session with the router. * * \return A future that indicates if the session was successfully stopped. */ boost::future stop(); /*! * Join a realm with the session. * * \param realm The realm to join on the application router. * \param authmethods The authentication methods this instance support e.g. "wampcra","ticket" * \param authid The username or maybe an other identifier for the user to join. * \return A future that resolves with the session ID when the realm was joined. */ boost::future join( const std::string& realm, const std::vector& authmethods = std::vector(), const std::string& authid = ""); /*! * Leave the realm. * * \param reason An optional WAMP URI providing a reason for leaving. * \return A future that resolves with the reason sent by the peer. */ boost::future leave( const std::string& reason = std::string("wamp.error.close_realm")); /*! * \ingroup PUB * Publish an event with empty payload to a topic. * * * \param topic The URI of the topic to publish to. * \return A future that resolves once the the topic has been published to. */ boost::future publish(const std::string& topic, const wamp_publish_options& options = wamp_publish_options()); /*! * \ingroup PUB * Publish an event with positional payload to a topic. * * \param topic The URI of the topic to publish to. * \param arguments The positional payload for the event. * \return A future that resolves once the the topic has been published to. */ template boost::future publish(const std::string& topic, const List& arguments, const wamp_publish_options& options = wamp_publish_options()); /*! * \ingroup PUB * Publish an event with both positional and keyword payload to a topic. * * \param topic The URI of the topic to publish to. * \param arguments The positional payload for the event. * \param kw_arguments The keyword payload for the event. * \return A future that resolves once the the topic has been published to. */ template boost::future publish( const std::string& topic, const List& arguments, const Map& kw_arguments, const wamp_publish_options& options = wamp_publish_options()); /*! * Subscribe a handler to a topic to receive events. * * \param topic The URI of the topic to subscribe to. * \param handler The handler that will receive events under the subscription. * \param options The options to pass in the subscribe request to the router. * \return A future that resolves to the autobahn::subscription. */ boost::future subscribe( const std::string& topic, const wamp_event_handler& handler, const wamp_subscribe_options& options = wamp_subscribe_options()); /*! * Unubscribe a handler to previously subscribed topic. * * \param subscription The subscription to unsubscribe from. * \return A future that resolves to the unsubscribed response. */ boost::future unsubscribe(const wamp_subscription& subscription); /*! * Calls a remote procedure with no arguments. * * \param procedure The URI of the remote procedure to call. * \param options The options to pass in the call to the router. * \return A future that resolves to the result of the remote procedure call. */ boost::future call( const std::string& procedure, const wamp_call_options& options = wamp_call_options()); /*! * Calls a remote procedure with positional arguments. * * \param procedure The URI of the remote procedure to call. * \param arguments The positional arguments for the call. * \param options The options to pass in the call to the router. * \return A future that resolves to the result of the remote procedure call. */ template boost::future call( const std::string& procedure, const List& arguments, const wamp_call_options& options = wamp_call_options()); /*! * Calls a remote procedure with positional and keyword arguments. * * \param procedure The URI of the remote procedure to call. * \param arguments The positional arguments for the call. * \param kw_arguments The keyword arguments for the call. * \param options The options to pass in the call to the router. * \return A future that resolves to the result of the remote procedure call. */ template boost::future call( const std::string& procedure, const List& arguments, const Map& kw_arguments, const wamp_call_options& options = wamp_call_options()); /*! * Register a procedure that can be called remotely. * * \param uri The URI associated with the procedure. * \param procedure The procedure to be exposed as a remotely callable procedure. * \param options Options for registering the procedure. * \return A future that resolves to a autobahn::registration */ boost::future provide( const std::string& uri, const wamp_procedure& procedure, const provide_options& options = provide_options()); /*! * Unregister a handler to previosly registered service. * * \param registration The registration to unregister. * \return A future that resolves to the unregistered response. */ boost::future unprovide(const wamp_registration& registration); /*! * Function called by the session when authenticating. It always has to be * re-implemented (if authentication is part of the system). * * \param challenge The challenge from the router containing enough information * for the system to prove membership. * \return A future that resolves to an authentication response. */ virtual boost::future on_challenge(const wamp_challenge& challenge); /*! * Accessor method to WELCOME DETAILS dictionary containing router roles * and corresponding features, authid, authrole, ...) * * * \return A dictionary of objects received with WELCOME message upon joining. * i.e. * { * "realm": "", * "authprovider": "dynamic", * "roles": { * "broker": { * "features": { * "publisher_identification": true, * "pattern_based_subscription": true, * ... * } * }, * "dealer": { * "features": { * "pattern_based_registration": true, * "progressive_call_results": true, * ... * } * } * }, * "authid": "", * "authrole": "", * "authmethod": "wampcra", * ... * } */ const std::unordered_map& welcome_details(); private: // Implements the wamp transport handler interface. virtual void on_attach(const std::shared_ptr& transport) override; virtual void on_detach(bool was_clean, const std::string& reason) override; virtual void on_message(wamp_message&& message) override; // WAMP message processing void process_error(wamp_message&& message); void process_welcome(wamp_message&& message); void process_abort(wamp_message&& message); void process_challenge(wamp_message&& message); void process_call_result(wamp_message&& message); void process_subscribed(wamp_message&& message); void process_unsubscribed(wamp_message&& message); void process_event(wamp_message&& message); void process_registered(wamp_message&& message); void process_unregistered(wamp_message&& message); void process_invocation(wamp_message&& message); void process_goodbye(wamp_message&& message); // Transmitting/receiving messages void send_message(wamp_message&& message, bool session_established = true); void receive_message(); void got_handshake_reply(const boost::system::error_code& error); void got_message_header(const boost::system::error_code& error); void got_message_body(const boost::system::error_code& error); void got_message(wamp_message&& message); bool m_debug_enabled; boost::asio::io_service& m_io_service; // The transport this session runs on. std::shared_ptr m_transport; // Last request ID of outgoing WAMP requests. std::atomic m_request_id; // WAMP session ID (if the session is joined to a realm). uint64_t m_session_id; // Synchronization for dealing with starting the session. boost::promise m_session_start; // Future to be fired when session was joined. boost::promise m_session_join; // Whether or not we have already sent a goodbye when leaving the session. bool m_goodbye_sent; boost::promise m_session_leave; // Set to true when the session is stopped. bool m_running; // Synchronization for dealing with stopping the session boost::promise m_session_stop; ////////////////////////////////////////////////////////////////////////////////////// // Caller // Track pending calls by request id. std::map> m_calls; ////////////////////////////////////////////////////////////////////////////////////// // Subscriber // Pending subscribe requests by request id. std::map> m_subscribe_requests; // Pending unsubscribe requests by request id. std::map> m_unsubscribe_requests; // Event handlers by subscription id. std::multimap m_subscription_handlers; ////////////////////////////////////////////////////////////////////////////////////// // Callee // Map of outstanding WAMP register requests (request ID -> register request). std::map> m_register_requests; // Map of outstanding WAMP unregister requests (request ID -> unregister request). std::map> m_unregister_requests; // Map of registered procedures (registration ID -> procedure) std::map m_procedures; // Welcome details std::unordered_map m_welcome_details; }; } // namespace autobahn #include "wamp_session.ipp" #endif // AUTOBAHN_SESSION_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_session.ipp000066400000000000000000001401651371744511200236330ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "exceptions.hpp" #include "wamp_call.hpp" #include "wamp_event.hpp" #include "wamp_invocation.hpp" #include "wamp_message.hpp" #include "wamp_message_type.hpp" #include "wamp_publication.hpp" #include "wamp_registration.hpp" #include "wamp_register_request.hpp" #include "wamp_subscribe_request.hpp" #include "wamp_subscription.hpp" #include "wamp_transport.hpp" #include "wamp_unregister_request.hpp" #include "wamp_unsubscribe_request.hpp" #include "wamp_authenticate.hpp" #include "wamp_challenge.hpp" #include "wamp_auth_utils.hpp" #if !(defined(_WIN32) || defined(WIN32)) #include #include #endif #include #include #include #include #include #include namespace autobahn { inline wamp_session::wamp_session( boost::asio::io_service& io_service, bool debug_enabled) : m_debug_enabled(debug_enabled) , m_io_service(io_service) , m_transport() , m_request_id(0) , m_session_id(0) , m_goodbye_sent(false) , m_running(false) { } inline wamp_session::~wamp_session() { } inline boost::future wamp_session::start() { auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } if (m_running) { m_session_start.set_exception(boost::copy_exception(protocol_error("session already started"))); return; } if (!m_transport) { m_session_start.set_exception(boost::copy_exception(no_transport_error())); return; } m_running = true; m_session_start.set_value(); }); return m_session_start.get_future(); } inline boost::future wamp_session::stop() { auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } if (!m_running) { m_session_stop.set_exception(boost::copy_exception(protocol_error("session already stopped"))); return; } if (!m_transport) { m_session_start.set_exception(boost::copy_exception(no_transport_error())); return; } if (m_session_id) { m_session_stop.set_exception(boost::copy_exception(protocol_error("session still joined"))); return; } m_running = false; m_session_stop.set_value(); }); return m_session_stop.get_future(); } inline boost::future wamp_session::join( const std::string& realm, const std::vector& authentication_methods, const std::string& authentication_id) { msgpack::zone zone; std::unordered_map roles; std::unordered_map caller_features; caller_features["call_timeout"] = true; std::unordered_map caller; caller["features"] = msgpack::object(caller_features, zone); roles["caller"] = msgpack::object(caller, zone); std::unordered_map callee_features; callee_features["call_timeout"] = true; std::unordered_map callee; callee["features"] = msgpack::object(callee_features, zone); roles["callee"] = msgpack::object(callee, zone); std::unordered_map publisher; roles["publisher"] = msgpack::object(publisher, zone); std::unordered_map subscriber; roles["subscriber"] = msgpack::object(subscriber, zone); std::unordered_map details; details["roles"] = msgpack::object(roles, zone); details["authmethods"] = msgpack::object(authentication_methods, zone); details["authid"] = msgpack::object(authentication_id, zone); auto message = std::make_shared(3, std::move(zone)); message->set_field(0, static_cast(message_type::HELLO)); message->set_field(1, realm); message->set_field(2, details); auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self, message]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } if (m_session_id) { m_session_join.set_exception(boost::copy_exception(protocol_error("session already joined"))); return; } try { send_message(std::move(*message), false); } catch (const std::exception& e) { m_session_join.set_exception(boost::copy_exception(e)); } }); return m_session_join.get_future(); } inline boost::future wamp_session::leave(const std::string& reason) { auto message = std::make_shared(3); message->set_field(0, static_cast(message_type::GOODBYE)); message->set_field(1, std::unordered_map() /* No Details */); message->set_field(2, reason); auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self, message]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } if (m_goodbye_sent) { m_session_leave.set_exception(boost::copy_exception(protocol_error("goodbye already sent"))); } try { send_message(std::move(*message), false); m_goodbye_sent = true; } catch (const std::exception& e) { m_session_leave.set_exception(boost::copy_exception(e)); } m_session_id = 0; }); return m_session_leave.get_future(); } inline boost::future wamp_session::publish(const std::string& topic,const wamp_publish_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(4); message->set_field(0, static_cast(message_type::PUBLISH)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, topic); auto result = std::make_shared>(); auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self, message, result]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); result->set_value(); } catch (const std::exception& e) { result->set_exception(boost::copy_exception(e)); } }); return result->get_future(); } template inline boost::future wamp_session::publish(const std::string& topic, const List& arguments,const wamp_publish_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(5); message->set_field(0, static_cast(message_type::PUBLISH)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, topic); message->set_field(4, arguments); auto result = std::make_shared>(); auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self, message, result]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); result->set_value(); } catch (const std::exception& e) { result->set_exception(boost::copy_exception(e)); } }); return result->get_future(); } template inline boost::future wamp_session::publish( const std::string& topic, const List& arguments, const Map& kw_arguments,const wamp_publish_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(6); message->set_field(0, static_cast(message_type::PUBLISH)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, topic); message->set_field(4, arguments); message->set_field(5, kw_arguments); auto result = std::make_shared>(); auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self, message, result]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); result->set_value(); } catch (const std::exception& e) { result->set_exception(boost::copy_exception(e)); } }); return result->get_future(); } inline boost::future wamp_session::subscribe( const std::string& topic, const wamp_event_handler& handler, const wamp_subscribe_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(4); message->set_field(0, static_cast(message_type::SUBSCRIBE)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, topic); auto weak_self = std::weak_ptr(this->shared_from_this()); auto subscribe_request = std::make_shared(handler); m_io_service.dispatch([this, weak_self, message, request_id, subscribe_request]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); m_subscribe_requests.emplace(request_id, subscribe_request); } catch (const std::exception& e) { subscribe_request->response().set_exception(boost::copy_exception(e)); } }); return subscribe_request->response().get_future(); } inline boost::future wamp_session::unsubscribe(const wamp_subscription& subscription) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(3); message->set_field(0, static_cast(message_type::UNSUBSCRIBE)); message->set_field(1, request_id); message->set_field(2, subscription.id()); auto weak_self = std::weak_ptr(this->shared_from_this()); auto unsubscribe_request = std::make_shared(subscription); m_io_service.dispatch([this, weak_self, message, request_id, unsubscribe_request]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); m_unsubscribe_requests.emplace(request_id, unsubscribe_request); } catch (const std::exception& e) { unsubscribe_request->response().set_exception(boost::copy_exception(e)); } }); return unsubscribe_request->response().get_future(); } inline boost::future wamp_session::call( const std::string& procedure, const wamp_call_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(4); message->set_field(0, static_cast(message_type::CALL)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, procedure); auto weak_self = std::weak_ptr(this->shared_from_this()); auto call = std::make_shared(); m_io_service.dispatch([this, weak_self, message, request_id, call]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); m_calls.emplace(request_id, call); } catch (const std::exception& e) { call->result().set_exception(boost::copy_exception(e)); } }); return call->result().get_future(); } template inline boost::future wamp_session::call( const std::string& procedure, const List& arguments, const wamp_call_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(5); message->set_field(0, static_cast(message_type::CALL)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, procedure); message->set_field(4, arguments); auto weak_self = std::weak_ptr(this->shared_from_this()); auto call = std::make_shared(); m_io_service.dispatch([this, weak_self, message, request_id, call]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); m_calls.emplace(request_id, call); } catch (const std::exception& e) { call->result().set_exception(boost::copy_exception(e)); } }); return call->result().get_future(); } template inline boost::future wamp_session::call( const std::string& procedure, const List& arguments, const Map& kw_arguments, const wamp_call_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(6); message->set_field(0, static_cast(message_type::CALL)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, procedure); message->set_field(4, arguments); message->set_field(5, kw_arguments); auto weak_self = std::weak_ptr(this->shared_from_this()); auto call = std::make_shared(); m_io_service.dispatch([this, weak_self, message, request_id, call]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); m_calls.emplace(request_id, call); } catch (const std::exception& e) { call->result().set_exception(boost::copy_exception(e)); } }); return call->result().get_future(); } inline boost::future wamp_session::provide( const std::string& name, const wamp_procedure& procedure, const provide_options& options) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(4); message->set_field(0, static_cast(message_type::REGISTER)); message->set_field(1, request_id); message->set_field(2, options); message->set_field(3, name); auto weak_self = std::weak_ptr(this->shared_from_this()); auto register_request = std::make_shared(procedure); m_io_service.dispatch([this, weak_self, message, request_id, register_request]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); m_register_requests.emplace(request_id, register_request); } catch (const std::exception& e) { register_request->response().set_exception(boost::copy_exception(e)); } }); return register_request->response().get_future(); } inline boost::future wamp_session::unprovide(const wamp_registration& registration) { uint64_t request_id = ++m_request_id; auto message = std::make_shared(3); message->set_field(0, static_cast(message_type::UNREGISTER)); message->set_field(1, request_id); message->set_field(2, registration.id()); auto weak_self = std::weak_ptr(this->shared_from_this()); auto unregister_request = std::make_shared(registration); m_io_service.dispatch([this, weak_self, message, request_id, unregister_request]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message)); m_unregister_requests.emplace(request_id, unregister_request); } catch (const std::exception& e) { unregister_request->response().set_exception(boost::copy_exception(e)); } }); return unregister_request->response().get_future(); } inline boost::future wamp_session::on_challenge(const wamp_challenge& challenge) { // a dummy implementation boost::promise dummy; dummy.set_value( wamp_authenticate( "" ) ); return dummy.get_future(); } inline void wamp_session::on_attach(const std::shared_ptr& transport) { // FIXME: We should be deferring this operation to the io service. This // will almost certainly require us to return a future here to // all the caller to sync up with the actual attaching of the // transport. if (m_transport) { throw protocol_error("Transport already attached to session"); } // This should never be possible as you cannot start a session without // having a transport already attached. assert(!m_running); m_transport = transport; } inline void wamp_session::on_detach(bool was_clean, const std::string& reason) { // FIXME: We should be deferring this operation to the io service. This // will almost certainly require us to return a future here to // all the caller to sync up with the actual detaching of the // transport. if (!m_transport) { throw protocol_error("Transport already detached from session"); } // FIXME: Figure out what to do if we are detaching a transport // from a session that is still running. Ideally we would // not detach the transport until m_session_stop is satisfied. // Perhaps we could use the same promise/future discussed above. // One side effect here will be if the transport is re-used for // another session as it may still receive messages for the old // session. assert(!m_running); m_transport.reset(); } inline void wamp_session::on_message(wamp_message&& message) { // FIXME: Move this check into the transport //if (obj.type != msgpack::type::ARRAY) { // throw protocol_error("invalid message structure - message is not an array"); //} if (message.size() < 1) { throw protocol_error("invalid message structure - missing message code"); } if (!message.is_field_type(0, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("invalid message code type - not an integer"); } message_type code = static_cast(message.field(0)); switch (code) { case message_type::HELLO: throw protocol_error("received HELLO message unexpected for WAMP client roles"); case message_type::WELCOME: process_welcome(std::move(message)); break; case message_type::ABORT: process_abort(std::move(message)); break; case message_type::CHALLENGE: process_challenge(std::move(message)); break; case message_type::AUTHENTICATE: throw protocol_error("received AUTHENTICATE message unexpected for WAMP client roles"); case message_type::GOODBYE: process_goodbye(std::move(message)); break; case message_type::HEARTBEAT: // FIXME break; case message_type::ERROR: process_error(std::move(message)); break; case message_type::PUBLISH: throw protocol_error("received PUBLISH message unexpected for WAMP client roles"); case message_type::PUBLISHED: // FIXME break; case message_type::SUBSCRIBE: throw protocol_error("received SUBSCRIBE message unexpected for WAMP client roles"); case message_type::SUBSCRIBED: process_subscribed(std::move(message)); break; case message_type::UNSUBSCRIBE: throw protocol_error("received UNSUBSCRIBE message unexpected for WAMP client roles"); case message_type::UNSUBSCRIBED: process_unsubscribed(std::move(message)); break; case message_type::EVENT: process_event(std::move(message)); break; case message_type::CALL: throw protocol_error("received CALL message unexpected for WAMP client roles"); case message_type::CANCEL: throw protocol_error("received CANCEL message unexpected for WAMP client roles"); case message_type::RESULT: process_call_result(std::move(message)); break; case message_type::REGISTER: throw protocol_error("received REGISTER message unexpected for WAMP client roles"); case message_type::REGISTERED: process_registered(std::move(message)); break; case message_type::UNREGISTER: throw protocol_error("received UNREGISTER message unexpected for WAMP client roles"); case message_type::UNREGISTERED: process_unregistered(std::move(message)); break; case message_type::INVOCATION: process_invocation(std::move(message)); break; case message_type::INTERRUPT: throw protocol_error("received INTERRUPT message - not implemented"); case message_type::YIELD: throw protocol_error("received YIELD message unexpected for WAMP client roles"); } } inline void wamp_session::process_challenge(wamp_message&& message) { // kind of authentication std::string whatAuth = message.field(1); ///////////////////////////////////////// // wampcra authentication ///////////////////////////////////////// wamp_challenge challenge_object(""); if (whatAuth == "wampcra") { if (!message.is_field_type(2, msgpack::type::MAP)) { throw protocol_error("CHALLENGE - Details must be a dictionary"); } std::string challenge, salt; int iterations = 0 , keylen = 0; // parse the details, and fill variables above try { std::unordered_map details; message.field(2).convert(details); auto itr = details.find("challenge"); if (itr != details.end()) { challenge = itr->second.as(); } else { throw protocol_error("wampcra must always introduce a challenge ( in details )"); } itr = details.find("salt"); if (itr != details.end()) { // ok we must salt our secret salt = itr->second.as(); itr = details.find("iterations"); if (itr == details.end()) { throw protocol_error("wampcra must always tell a number of iterations when introducing salting ( in details )"); } iterations = itr->second.as(); itr = details.find("keylen"); if (itr == details.end()) { throw protocol_error("wampcra must always tell a key length (keylen) when introducing salting ( in details )"); } keylen = itr->second.as(); } // make the challenge object challenge_object = wamp_challenge("wampcra",challenge,salt,iterations,keylen); } catch (const std::exception&) { if (m_debug_enabled) { std::cerr << "failed to parse challenge details" << std::endl; } throw protocol_error("wampcra authentication: Failed parse challange details"); }; ///////////////////////////////////////// // ticket authentication ///////////////////////////////////////// } else if ( whatAuth == "ticket" ) { // make the challenge object challenge_object = wamp_challenge("ticket"); } else { throw protocol_error("not supported challenge type - can now only handle 'wampcra' and 'ticket'"); } // I am not sure if this is neccesary. Looking at other // comments in this code and the examples, it seems like the // context_response should live at least until the end of // the lambda callback - below std::shared_ptr< boost::future< void > > context_response = std::make_shared< boost::future >(); // call the context, to get a signature... (*context_response) = on_challenge(challenge_object).then([this, context_response]( boost::future fu_auth) { try { const wamp_authenticate sig = fu_auth.get(); auto message = std::make_shared(3); message->set_field(0, static_cast(message_type::AUTHENTICATE)); message->set_field(1, sig.signature()); message->set_field(2, std::unordered_map() /* No Extra/Dict */); auto weak_self = std::weak_ptr(this->shared_from_this()); m_io_service.dispatch([this, weak_self, message, context_response]() { auto shared_self = weak_self.lock(); if (!shared_self) { return; } try { send_message(std::move(*message), false); } catch (const std::exception&) { if (m_debug_enabled) { std::cerr << "failed to handle authentication" << std::endl; } throw protocol_error("authentication error: failed send signature"); } }); // make sure the context_response is copied into this lambda... context_response.get(); } catch (const std::exception&) { if (m_debug_enabled) { std::cerr << "failed to handle authentication" << std::endl; } throw protocol_error("authentication error: failed send signature"); } }); } inline void wamp_session::process_welcome(wamp_message&& message) { m_session_id = message.field(1); message.field(2).convert(m_welcome_details); m_session_join.set_value(m_session_id); } inline void wamp_session::process_abort(wamp_message&& message) { // [ABORT, Details|dict, Reason|uri] if (message.size() != 3 ) { throw protocol_error("ABORT - length must be 3"); } // Details|dict if (!message.is_field_type(1, msgpack::type::MAP)) { throw protocol_error("ABORT - Details must be a dictionary"); } // Reason|uri if (!message.is_field_type(2, msgpack::type::STR)) { throw protocol_error("ABORT - REASON must be a string (URI)"); } std::string uri = message.field(2); m_session_join.set_exception(boost::copy_exception(abort_error(uri))); } inline void wamp_session::process_goodbye(wamp_message&& message) { m_session_id = 0; // if we did not initiate closing, reply .. if (!m_goodbye_sent) { // [GOODBYE, Details|dict, Reason|uri] wamp_message goodbye(3); goodbye.set_field(0, static_cast(message_type::GOODBYE)); goodbye.set_field(1, std::unordered_map() /* No Details */); goodbye.set_field(2, std::string("wamp.error.goodbye_and_out")); send_message(std::move(goodbye)); } else { // we previously initiated closing, so this // is the peer reply. } std::string reason = message.field(2); m_session_leave.set_value(reason); } inline void wamp_session::process_error(wamp_message&& message) { // [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri] // [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list] // [ERROR, REQUEST.Type|int, REQUEST.Request|id, Details|dict, Error|uri, Arguments|list, ArgumentsKw|dict] if (message.size() < 5 || message.size() > 7) { throw protocol_error("invalid ERROR message structure - length must be 5, 6 or 7"); } // REQUEST.Type|int // if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("invalid ERROR message structure - REQUEST.Type must be an integer"); } auto request_type = static_cast(message.field(1)); if (request_type != message_type::CALL && request_type != message_type::REGISTER && request_type != message_type::UNREGISTER && request_type != message_type::PUBLISH && request_type != message_type::SUBSCRIBE && request_type != message_type::UNSUBSCRIBE) { throw protocol_error("invalid ERROR message - ERROR.Type must one of CALL, REGISTER, UNREGISTER, SUBSCRIBE, UNSUBSCRIBE"); } // REQUEST.Request|id if (!message.is_field_type(2, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("invalid ERROR message structure - REQUEST.Request must be an integer"); } auto request_id = message.field(2); // Details if (!message.is_field_type(3, msgpack::type::MAP)) { throw protocol_error("invalid ERROR message structure - Details must be a dictionary"); } // Error|uri if (!message.is_field_type(4, msgpack::type::STR)) { throw protocol_error("invalid ERROR message - Error must be a string (URI)"); } auto error = message.field(4); // Arguments|list if (message.size() > 5) { if (!message.is_field_type(5, msgpack::type::ARRAY)) { throw protocol_error("invalid ERROR message structure - Arguments must be a list"); } } // ArgumentsKw|list if (message.size() > 6) { if (!message.is_field_type(6, msgpack::type::MAP)) { throw protocol_error("invalid ERROR message structure - ArgumentsKw must be a dictionary"); } try { auto kw_args = message.field>(6); const auto itr = kw_args.find("what"); if (itr != kw_args.end()) { error += ": "; error += itr->second; } } catch (const std::exception&) { if (m_debug_enabled) { std::cerr << "failed to parse error message keyword arguments" << std::endl; } error += ": unknown exception"; } } switch (request_type) { case message_type::CALL: { // // process CALL ERROR // auto call_itr = m_calls.find(request_id); if (call_itr != m_calls.end()) { // FIXME: Forward all error info. call_itr->second->result().set_exception(boost::copy_exception(std::runtime_error(error))); m_calls.erase(call_itr); } else { throw protocol_error("bogus ERROR message for non-pending CALL request ID: " + error); } } break; case message_type::REGISTER: { auto reg_itr = m_register_requests.find(request_id); if (reg_itr != m_register_requests.end()) { reg_itr->second->response().set_exception(boost::copy_exception(std::runtime_error(error))); m_register_requests.erase(reg_itr); } else { throw protocol_error("bogus ERROR message for non-pending REGISTER request ID: " + error); } } break; case message_type::UNREGISTER: { auto unreg_itr = m_unregister_requests.find(request_id); if (unreg_itr != m_unregister_requests.end()) { unreg_itr->second->response().set_exception(boost::copy_exception(std::runtime_error(error))); m_unregister_requests.erase(unreg_itr); } else { throw protocol_error("bogus ERROR message for non-pending UNREGISTER request ID: " + error); } } break; case message_type::PUBLISH: { //TODO: there's currently no way to get to the future returned by the publish function // but there needs to be something more sensibly then just propagating the error to the // function running the io_service throw protocol_error("Received ERROR for a PUBLISH request: " + error); } break; case message_type::SUBSCRIBE: { auto sub_itr = m_subscribe_requests.find(request_id); if (sub_itr != m_subscribe_requests.end()) { sub_itr->second->response().set_exception(boost::copy_exception(std::runtime_error(error))); m_subscribe_requests.erase(sub_itr); } else { throw protocol_error("bogus ERROR message for non-pending SUBSCRIBE request ID: " + error); } } break; case message_type::UNSUBSCRIBE: { auto unsub_itr = m_unsubscribe_requests.find(request_id); if (unsub_itr != m_unsubscribe_requests.end()) { unsub_itr->second->response().set_exception(boost::copy_exception(std::runtime_error(error))); m_unsubscribe_requests.erase(unsub_itr); } else { throw protocol_error("bogus ERROR message for non-pending UNSUBSCRIBE request ID: " + error); } } break; default: throw protocol_error("unhandled ERROR message: " + error); break; } } inline void wamp_session::process_invocation(wamp_message&& message) { // [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict] // [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list] // [INVOCATION, Request|id, REGISTERED.Registration|id, Details|dict, CALL.Arguments|list, CALL.ArgumentsKw|dict] if (message.size() < 4 || message.size() > 6) { throw protocol_error("INVOCATION message length must be 4, 5 or 6"); } if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("INVOCATION.Request must be an integer"); } uint64_t request_id = message.field(1); if (!message.is_field_type(2, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("INVOCATION.Registration must be an integer"); } uint64_t registration_id = message.field(2); auto procedure_itr = m_procedures.find(registration_id); if (procedure_itr != m_procedures.end()) { if (!message.is_field_type(3, msgpack::type::MAP)) { throw protocol_error("INVOCATION.Details must be a map"); } wamp_invocation invocation = std::make_shared(); invocation->set_request_id(request_id); invocation->set_details(message.field(3)); if (message.size() > 4) { if (!message.is_field_type(4, msgpack::type::ARRAY)) { throw protocol_error("INVOCATION.Arguments must be an array/vector"); } invocation->set_arguments(message.field(4)); if (message.size() > 5) { if (!message.is_field_type(5, msgpack::type::MAP)) { throw protocol_error("INVOCATION.KwArguments must be a map"); } invocation->set_kw_arguments(message.field(5)); } } invocation->set_zone(std::move(message.zone())); auto weak_this = std::weak_ptr(this->shared_from_this()); auto send_result_fn = [weak_this] (const std::shared_ptr& message) { // Make sure the session still exists, since the invocation could run // on a different thread. auto shared_this = weak_this.lock(); if (!shared_this) { return; // FIXME: or throw exception? } // Send to the io_service thread, and make sure the session still exists (again). shared_this->m_io_service.dispatch([weak_this, message] { auto shared_this = weak_this.lock(); if (!shared_this) { return; // FIXME: or throw exception? } shared_this->send_message(std::move(*message)); }); }; invocation->set_send_result_fn(std::move(send_result_fn)); try { if (m_debug_enabled) { std::cerr << "Invoking procedure registered under " << registration_id << std::endl; } procedure_itr->second(invocation); } // FIXME: implement Autobahn-specific exception with error URI catch (const std::exception& e) { // we can at least describe the error with e.what() // if (invocation->sendable()) { std::map error_kw_arguments; error_kw_arguments["what"] = e.what(); invocation->error("wamp.error.runtime_error", EMPTY_ARGUMENTS, error_kw_arguments); } } catch (...) { // no information available on actual error // if (invocation->sendable()) { invocation->error("wamp.error.runtime_error"); } } } else { throw protocol_error("bogus INVOCATION message for non-registered registration ID"); } } inline void wamp_session::process_call_result(wamp_message&& message) { // [RESULT, CALL.Request|id, Details|dict] // [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list] // [RESULT, CALL.Request|id, Details|dict, YIELD.Arguments|list, YIELD.ArgumentsKw|dict] if (message.size() < 3 || message.size() > 5) { throw protocol_error("RESULT - length must be 3, 4 or 5"); } if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("RESULT - CALL.Request must be an id"); } uint64_t request_id = message.field(1); auto call_itr = m_calls.find(request_id); if (call_itr != m_calls.end()) { if (!message.is_field_type(2, msgpack::type::MAP)) { throw protocol_error("RESULT - Details must be a dictionary"); } wamp_call_result result(std::move(message.zone())); if (message.size() > 3) { if (!message.is_field_type(3, msgpack::type::ARRAY)) { throw protocol_error("RESULT - YIELD.Arguments must be a list"); } result.set_arguments(message.field(3)); if (message.size() > 4) { if (!message.is_field_type(4, msgpack::type::MAP)) { throw protocol_error("RESULT - YIELD.ArgumentsKw must be a dictionary"); } result.set_kw_arguments(message.field(4)); } } call_itr->second->set_result(std::move(result)); m_calls.erase(call_itr); } else { throw protocol_error("bogus RESULT message for non-pending request ID"); } } inline void wamp_session::process_subscribed(wamp_message&& message) { // [SUBSCRIBED, SUBSCRIBE.Request|id, Subscription|id] if (message.size() != 3) { throw protocol_error("SUBSCRIBED - length must be 3"); } if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("SUBSCRIBED - SUBSCRIBED.Request must be an integer"); } uint64_t request_id = message.field(1); auto subscribe_request_itr = m_subscribe_requests.find(request_id); if (subscribe_request_itr != m_subscribe_requests.end()) { if (!message.is_field_type(2, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("SUBSCRIBED - SUBSCRIBED.Subscription must be an integer"); } uint64_t subscription_id = message.field(2); m_subscription_handlers.insert( std::make_pair(subscription_id, subscribe_request_itr->second->handler())); subscribe_request_itr->second->set_response(wamp_subscription(subscription_id)); m_subscribe_requests.erase(request_id); } else { throw protocol_error("SUBSCRIBED - no pending request ID"); } } inline void wamp_session::process_unsubscribed(wamp_message&& message) { // [UNSUBSCRIBED, UNSUBSCRIBE.Request|id] if (message.size() != 2) { throw protocol_error("UNSUBSCRIBED - length must be 2"); } if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("UNSUBSCRIBED - UNSUBSCRIBED.Request must be an integer"); } uint64_t request_id = message.field(1); auto unsubscribe_request_itr = m_unsubscribe_requests.find(request_id); if (unsubscribe_request_itr != m_unsubscribe_requests.end()) { uint64_t subscription_id = unsubscribe_request_itr->second->subscription().id(); m_subscription_handlers.erase(subscription_id); unsubscribe_request_itr->second->set_response(); m_unsubscribe_requests.erase(request_id); } else { throw protocol_error("UNSUBSCRIBED - no pending request ID"); } } inline void wamp_session::process_event(wamp_message&& message) { // [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict] // [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list] // [EVENT, SUBSCRIBED.Subscription|id, PUBLISHED.Publication|id, Details|dict, PUBLISH.Arguments|list, PUBLISH.ArgumentsKw|dict] if (message.size() < 4 || message.size() > 6) { throw protocol_error("EVENT - length must be 4, 5 or 6"); } if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("EVENT - SUBSCRIBED.Subscription must be an integer"); } uint64_t subscription_id = message.field(1); auto subscription_handlers_itr = m_subscription_handlers.lower_bound(subscription_id); auto subscription_handlers_end = m_subscription_handlers.upper_bound(subscription_id); if (subscription_handlers_itr != m_subscription_handlers.end() && subscription_handlers_itr != subscription_handlers_end) { if (!message.is_field_type(2, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("EVENT - PUBLISHED.Publication must be an id"); } //uint64_t publication_id = message[2].as(); if (!message.is_field_type(3, msgpack::type::MAP)) { throw protocol_error("EVENT - Details must be a dictionary"); } wamp_event event = std::make_shared(std::move(message.zone())); event->set_details(message.field(3)); if (message.size() > 4) { if (!message.is_field_type(4, msgpack::type::ARRAY)) { throw protocol_error("EVENT - EVENT.Arguments must be a list"); } event->set_arguments(message.field(4)); if (message.size() > 5) { if (!message.is_field_type(5, msgpack::type::MAP)) { throw protocol_error("EVENT - EVENT.ArgumentsKw must be a dictionary"); } event->set_kw_arguments(message.field(5)); } } try { // now trigger the user supplied event handler .. // while (subscription_handlers_itr != subscription_handlers_end) { (subscription_handlers_itr->second)(event); ++subscription_handlers_itr; } } catch (...) { if (m_debug_enabled) { std::cerr << "Warning: event handler threw exception" << std::endl; } } } else { // silently swallow EVENT for non-existent subscription IDs. // We may have just unsubscribed, this EVENT might be have // already been in-flight. if (m_debug_enabled) { std::cerr << "EVENT - non-existent subscription ID " << subscription_id << std::endl; } } } inline void wamp_session::process_registered(wamp_message&& message) { // [REGISTERED, REGISTER.Request|id, Registration|id] if (message.size() != 3) { throw protocol_error("REGISTERED - length must be 3"); } if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("REGISTERED - REGISTERED.Request must be an integer"); } uint64_t request_id = message.field(1); auto register_request_itr = m_register_requests.find(request_id); if (register_request_itr != m_register_requests.end()) { if (!message.is_field_type(2, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("REGISTERED - REGISTERED.Registration must be an integer"); } uint64_t registration_id = message.field(2); m_procedures[registration_id] = register_request_itr->second->procedure(); register_request_itr->second->set_response(wamp_registration(registration_id)); m_register_requests.erase(register_request_itr); } else { throw protocol_error("REGISTERED - no pending request ID"); } } inline void wamp_session::process_unregistered(wamp_message&& message) { // [UNREGISTERED, UNREGISTER.Request|id] if (message.size() != 2) { throw protocol_error("UNREGISTERED - length must be 2"); } if (!message.is_field_type(1, msgpack::type::POSITIVE_INTEGER)) { throw protocol_error("UNREGISTERED - UNREGISTERED.Request must be an integer"); } uint64_t request_id = message.field(1); auto unregister_request_itr = m_unregister_requests.find(request_id); if (unregister_request_itr != m_unregister_requests.end()) { uint64_t registration_id = unregister_request_itr->second->registration().id(); m_procedures.erase(registration_id); unregister_request_itr->second->set_response(); m_unregister_requests.erase(request_id); } else { throw protocol_error("UNREGISTERED - no pending request ID"); } } inline void wamp_session::send_message(wamp_message&& message, bool session_established) { if (!m_running) { throw protocol_error("session not running"); } if (!m_transport) { throw no_transport_error(); } if (!m_transport->is_connected()) { throw no_transport_error(); } if (session_established && !m_session_id) { throw no_session_error(); } m_transport->send_message(std::move(message)); } inline const std::unordered_map& wamp_session::welcome_details() { return m_welcome_details; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_subscribe_options.hpp000066400000000000000000000047441371744511200257050ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_SUBSCRIBE_OPTIONS_HPP #define AUTOBAHN_WAMP_SUBSCRIBE_OPTIONS_HPP #include namespace autobahn { class wamp_subscribe_options { public: wamp_subscribe_options(); //Convenience constructor wamp_subscribe_options(const std::string& match); wamp_subscribe_options(wamp_subscribe_options&& other) = delete; wamp_subscribe_options(const wamp_subscribe_options& other) = delete; wamp_subscribe_options& operator=(wamp_subscribe_options&& other) = delete; wamp_subscribe_options& operator=(const wamp_subscribe_options& other) = delete; const std::string& match() const; void set_match(const std::string& match); const bool is_match_set() const; private: boost::optional m_match; }; } // namespace autobahn #include "wamp_subscribe_options.ipp" #endif // AUTOBAHN_WAMP_SUBSCRIBE_OPTIONS_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_subscribe_options.ipp000066400000000000000000000073271371744511200257060ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include #include #include namespace autobahn { inline wamp_subscribe_options::wamp_subscribe_options() : m_match() { } inline wamp_subscribe_options::wamp_subscribe_options(const std::string& match) : m_match() { //Verify match type set_match(match); } inline const std::string& wamp_subscribe_options::match() const { return *m_match; } inline const bool wamp_subscribe_options::is_match_set() const { return m_match.is_initialized(); } inline void wamp_subscribe_options::set_match(const std::string& match) { if (!(match == "exact" || match == "prefix" || match == "wildcard")) { throw std::runtime_error("The value of 'match' must be 'exact', 'prefix', or 'wildcard'."); } m_match = match; } } // namespace autobahn namespace msgpack { MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { namespace adaptor { template<> struct convert { msgpack::object const& operator()( msgpack::object const& object, autobahn::wamp_subscribe_options& options) const { return object; } }; template<> struct pack { template msgpack::packer& operator()( msgpack::packer& packer, autobahn::wamp_subscribe_options const& options) const { std::map options_map; if (options.is_match_set()) { options_map["match"] = options.match(); } packer.pack(options_map); return packer; } }; template <> struct object_with_zone { void operator()( msgpack::object::with_zone& object, const autobahn::wamp_subscribe_options& options) { std::map options_map; if (options.is_match_set()) { options_map["match"] = options.match(); } object << options_map; } }; } // namespace adaptor } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) } // namespace msgpack crossbario-autobahn-cpp-d7a4346/autobahn/wamp_subscribe_request.hpp000066400000000000000000000046071371744511200257000ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_SUBSCRIBE_REQUEST_HPP #define AUTOBAHN_WAMP_SUBSCRIBE_REQUEST_HPP #include "wamp_event_handler.hpp" #include "wamp_subscription.hpp" #include "boost_config.hpp" namespace autobahn { /// An outstanding wamp call. class wamp_subscribe_request { public: wamp_subscribe_request(); wamp_subscribe_request(const wamp_event_handler& handler); const wamp_event_handler& handler() const; boost::promise& response(); void set_handler(const wamp_event_handler& handler) const; void set_response(const wamp_subscription& subscription); private: wamp_event_handler m_handler; boost::promise m_response; }; } // namespace autobahn #include "wamp_subscribe_request.ipp" #endif // AUTOBAHN_WAMP_SUBSCRIBE_REQUEST_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_subscribe_request.ipp000066400000000000000000000043221371744511200256730ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_subscribe_request::wamp_subscribe_request() : m_handler() , m_response() { } inline wamp_subscribe_request::wamp_subscribe_request(const wamp_event_handler& handler) : m_handler(handler) , m_response() { } inline const wamp_event_handler& wamp_subscribe_request::handler() const { return m_handler; } inline boost::promise& wamp_subscribe_request::response() { return m_response; } inline void wamp_subscribe_request::set_response(const wamp_subscription& subscription) { m_response.set_value(subscription); } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_subscription.hpp000066400000000000000000000040011371744511200246570ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_SUBSCRIPTION_HPP #define AUTOBAHN_WAMP_SUBSCRIPTION_HPP #include namespace autobahn { /// Represents a topic subscription. class wamp_subscription { public: wamp_subscription(); wamp_subscription(uint64_t id); uint64_t id() const; private: uint64_t m_id; }; } // namespace autobahn #include "wamp_subscription.ipp" #endif // AUTOBAHN_WAMP_SUBSCRIPTION_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_subscription.ipp000066400000000000000000000035461371744511200246750ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_subscription::wamp_subscription() : m_id(0) { } inline wamp_subscription::wamp_subscription(uint64_t id) : m_id(id) { } inline uint64_t wamp_subscription::id() const { return m_id; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_tcp_transport.hpp000066400000000000000000000046031371744511200250450ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_TCP_TRANSPORT_HPP #define AUTOBAHN_WAMP_TCP_TRANSPORT_HPP #include "boost_config.hpp" #include "wamp_rawsocket_transport.hpp" #include #include namespace autobahn { /*! * A transport that provides rawsocket support over TCP. */ class wamp_tcp_transport : public wamp_rawsocket_transport { public: wamp_tcp_transport( boost::asio::io_service& io_service, const boost::asio::ip::tcp::endpoint& remote_endpoint, bool debug_enabled=false); virtual ~wamp_tcp_transport() override; virtual boost::future connect() override; }; } // namespace autobahn #include "wamp_tcp_transport.ipp" #endif // AUTOBAHN_WAMP_TCP_TRANSPORT_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_tcp_transport.ipp000066400000000000000000000050121371744511200250410ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "wamp_tcp_transport.hpp" #include namespace autobahn { inline wamp_tcp_transport::wamp_tcp_transport( boost::asio::io_service& io_service, const boost::asio::ip::tcp::endpoint& remote_endpoint, bool debug_enabled) : wamp_rawsocket_transport( io_service, remote_endpoint, debug_enabled) { } inline wamp_tcp_transport::~wamp_tcp_transport() { } inline boost::future wamp_tcp_transport::connect() { return wamp_rawsocket_transport::connect().then( [&](boost::future connected) { // Check the originating future for exceptions. connected.get(); // Disable naggle for improved performance. boost::asio::ip::tcp::no_delay option(true); socket().set_option(option); } ); } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_transport.hpp000066400000000000000000000116711371744511200242020ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_TRANSPORT_HPP #define AUTOBAHN_WAMP_TRANSPORT_HPP #include "boost_config.hpp" #include #include namespace autobahn { class wamp_message; class wamp_transport_handler; /*! * Provides an abstraction for a transport to be used by the session. A wamp * transport is defined as being message based, bidirectional, reliable, and * ordered. */ class wamp_transport { public: /*! * Handler to invoke when pausing transport transmission. */ using pause_handler = std::function; /*! * Handler to invoke when resuming transport transmission. */ using resume_handler = std::function; public: /*! * Default virtual destructor. */ virtual ~wamp_transport() = default; /* * CONNECTION INTERFACE */ /*! * Attempts to connect the transport. * * @return A future that will be satisfied when the connect attempt * has been made. */ virtual boost::future connect() = 0; /*! * Attempts to disconnect the transport. * * @return A future that will be satisfied when the disconnect attempt * has been made. */ virtual boost::future disconnect() = 0; /*! * Determines if the transport is connected. * * @return Whether or not the transport is connected. */ virtual bool is_connected() const = 0; /* * SENDER INTERFACE */ /*! * Send the message synchronously over the transport. * * @param message The message to be sent. */ virtual void send_message(wamp_message&& message) = 0; /*! * Set the handler to be invoked when the transport detects congestion * sending to the remote peer and needs to apply backpressure on the * application. * * @param handler The pause handler to be invoked. */ virtual void set_pause_handler(pause_handler&& handler) = 0; /*! * Set the handler to be invoked when the transport detects congestion * has subsided on the remote peer and the application can resume sending * messages. * * @param handler The resume handler to be invoked. */ virtual void set_resume_handler(resume_handler&& handler) = 0; /* * RECEIVER INTERFACE */ /*! * Pause receiving of messages. This will prevent the transport from receiving * any more messages until it has been resumed. This is used to excert * backpressure on the sending peer. */ virtual void pause() = 0; /*! * Resume receiving of messages. The transport will now begin receiving messsages * again and lift backpressure from the sending peer. */ virtual void resume() = 0; /*! * Attaches a handler to the transport. Only one handler may * be attached at any given time. * * @param handler The handler to attach to this transport. */ virtual void attach( const std::shared_ptr& handler) = 0; /*! * Detaches the handler currently attached to the transport. */ virtual void detach() = 0; /*! * Determines if the transport has a handler attached. * * @return Whether or not a handler is attached. */ virtual bool has_handler() const = 0; }; } // namespace autobahn #endif // AUTOBAHN_WAMP_TRANSPORT_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_transport_handler.hpp000066400000000000000000000054471371744511200257030ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_TRANSPORT_HANDLER_HPP #define AUTOBAHN_WAMP_TRANSPORT_HANDLER_HPP #include "boost_config.hpp" #include "wamp_message.hpp" #include #include namespace autobahn { class wamp_transport; /*! * Provides an abstraction for associating a handler with a transport. */ class wamp_transport_handler { public: /*! * Called by the transport when attaching a handler. * * @param transport The transport being attached to. */ virtual void on_attach(const std::shared_ptr& transport) = 0; /*! * Called by the transport when detaching a handler. * * @param was_clean Whether or not the transport is cleanly detaching. * @param reason The reason for detaching. */ virtual void on_detach(bool was_clean, const std::string& reason) = 0; /*! * Called by the transport when a message is received. * * @param message The message that has been received. */ virtual void on_message(wamp_message&& message) = 0; /*! * Default virtual destructor. */ virtual ~wamp_transport_handler() = default; }; } // namespace autobahn #endif // AUTOBAHN_WAMP_TRANSPORT_HANDLER_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_uds_transport.hpp000066400000000000000000000040751371744511200250550ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_UDS_TRANSPORT_HPP #define AUTOBAHN_WAMP_UDS_TRANSPORT_HPP #include "wamp_rawsocket_transport.hpp" #include namespace autobahn { /*! * A transport that provides rawsocket support over unix domain sockets (UDS). */ using wamp_uds_transport = wamp_rawsocket_transport< boost::asio::local::stream_protocol::socket>; } // namespace autobahn #endif // AUTOBAHN_WAMP_UDS_TRANSPORT_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_unregister_request.hpp000066400000000000000000000026101371744511200260760ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_UNREGISTER_REQUEST_HPP #define AUTOBAHN_WAMP_UNREGISTER_REQUEST_HPP #include "boost_config.hpp" #include "wamp_registration.hpp" namespace autobahn { /// An outstanding wamp call. class wamp_unregister_request { public: wamp_unregister_request(const wamp_registration& registration); boost::promise& response(); void set_response(); wamp_registration& registration(); private: wamp_registration m_registration; boost::promise m_response; }; } // namespace autobahn #include "wamp_unregister_request.ipp" #endif // AUTOBAHN_WAMP_UNREGISTER_REQUEST_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_unregister_request.ipp000066400000000000000000000023731371744511200261050ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_unregister_request::wamp_unregister_request(const wamp_registration& registration) : m_registration(registration) , m_response() { } inline boost::promise& wamp_unregister_request::response() { return m_response; } inline void wamp_unregister_request::set_response() { m_response.set_value(); } inline wamp_registration& wamp_unregister_request::registration() { return m_registration; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_unsubscribe_request.hpp000066400000000000000000000043251371744511200262400ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WAMP_UNSUBSCRIBE_REQUEST_HPP #define AUTOBAHN_WAMP_UNSUBSCRIBE_REQUEST_HPP #include "boost_config.hpp" #include "wamp_subscription.hpp" namespace autobahn { /// An outstanding wamp call. class wamp_unsubscribe_request { public: wamp_unsubscribe_request(const wamp_subscription& subscription); boost::promise& response(); void set_response(); wamp_subscription &subscription(); private: wamp_subscription m_subscription; boost::promise m_response; }; } // namespace autobahn #include "wamp_unsubscribe_request.ipp" #endif // AUTOBAHN_WAMP_UNSUBSCRIBE_REQUEST_HPP crossbario-autobahn-cpp-d7a4346/autobahn/wamp_unsubscribe_request.ipp000066400000000000000000000041061371744511200262360ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// namespace autobahn { inline wamp_unsubscribe_request::wamp_unsubscribe_request(const wamp_subscription &subscription) : m_subscription(subscription) , m_response() { } inline boost::promise& wamp_unsubscribe_request::response() { return m_response; } inline void wamp_unsubscribe_request::set_response() { m_response.set_value(); } inline wamp_subscription& wamp_unsubscribe_request::subscription() { return m_subscription; } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_websocket_transport.hpp000066400000000000000000000137561371744511200262560ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WEBSOCKET_TRANSPORT_HPP #define AUTOBAHN_WEBSOCKET_TRANSPORT_HPP #include "boost_config.hpp" #include "wamp_transport.hpp" #include #include #include #include namespace autobahn { class wamp_message; class wamp_transport_handler; /*! * A class that represents a base websocket transport * * Unlike raw socket base class, there is nothing to share about underlying websocket, * It is completely up to derived class to handle specific websocket implementation */ class wamp_websocket_transport : public wamp_transport, public std::enable_shared_from_this { public: /*! * Constructs a websocket transport. * * @param uri The remote endpoint to connect to. */ wamp_websocket_transport( const std::string& uri, bool debug_enabled = false); virtual ~wamp_websocket_transport() override = default; /* * CONNECTION INTERFACE */ /*! * @copydoc wamp_transport::connect() */ virtual boost::future connect() override; /*! * @copydoc wamp_transport::disconnect() */ virtual boost::future disconnect() override; /*! * @copydoc wamp_transport::is_connected() */ virtual bool is_connected() const override; /* * SENDER INTERFACE */ /*! * @copydoc wamp_transport::send_message() */ virtual void send_message(wamp_message&& message) override; /*! * @copydoc wamp_transport::set_pause_handler() */ virtual void set_pause_handler(pause_handler&& handler) override; /*! * @copydoc wamp_transport::set_resume_handler() */ virtual void set_resume_handler(resume_handler&& handler) override; /* * RECEIVER INTERFACE */ /*! * Pause receiving of messages. This will prevent the transport from receiving * any more messages until it has been resumed. This is used to excert * backpressure on the sending peer. */ virtual void pause() override; /*! * Resume receiving of messages. The transport will now begin receiving messsages * again and lift backpressure from the sending peer. */ virtual void resume() override; /*! * @copydoc wamp_transport::attach() */ virtual void attach( const std::shared_ptr& handler) override; /*! * @copydoc wamp_transport::detach() */ virtual void detach() override; /*! * @copydoc wamp_transport::has_handler() */ virtual bool has_handler() const override; protected: virtual bool is_open() const = 0; virtual void async_connect(const std::string& m_uri, boost::promise& connect_promise) = 0; virtual void close() = 0; virtual void write(void const * payload, size_t len) = 0; void receive_message(const std::string& msg); /*! * The promise that is fulfilled when the connect attempt is complete. */ boost::promise m_connect; /*! * The promise that is fulfilled when the disconnect attempt is complete. */ boost::promise m_disconnect; private: private: /*! * The handler to be called when pausing. */ pause_handler m_pause_handler; /*! * The handler to be called when resuming. */ resume_handler m_resume_handler; /*! * The transport handler to be notified of events/messages. */ std::shared_ptr m_handler; /*! * Used for unpacking serialized messages. */ msgpack::unpacker m_message_unpacker; /*! * Whether or not debugging is enabled. */ bool m_debug_enabled; /*! * Websocket endpoint URI */ std::string m_uri; }; } // namespace autobahn #include "wamp_websocket_transport.ipp" #endif // AUTOBAHN_WEBSOCKET_TRANSPORT_HPPcrossbario-autobahn-cpp-d7a4346/autobahn/wamp_websocket_transport.ipp000066400000000000000000000123511371744511200262450ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "exceptions.hpp" #include "wamp_message.hpp" #include "wamp_transport_handler.hpp" #include #include #include #include #include namespace autobahn { inline wamp_websocket_transport::wamp_websocket_transport( const std::string& uri, bool debug_enabled) : wamp_transport() , m_connect() , m_disconnect() , m_message_unpacker() , m_debug_enabled(debug_enabled) , m_uri(uri) { } inline boost::future wamp_websocket_transport::connect() { if (is_open()) { m_connect.set_exception(boost::copy_exception(network_error("network transport already connected"))); return m_connect.get_future(); } async_connect(m_uri, m_connect); return m_connect.get_future(); } inline boost::future wamp_websocket_transport::disconnect() { if (!is_open()) { throw network_error("network transport already disconnected"); } close(); m_disconnect.set_value(); return m_disconnect.get_future(); } inline bool wamp_websocket_transport::is_connected() const { return is_open(); } inline void wamp_websocket_transport::send_message(wamp_message&& message) { auto buffer = std::make_shared(); msgpack::packer packer(*buffer); packer.pack(message.fields()); // Write actual serialized message. write(buffer->data(), buffer->size()); if (m_debug_enabled) { std::cerr << "TX message (" << buffer->size() << " octets) ..." << std::endl; std::cerr << "TX message: " << message << std::endl; } } inline void wamp_websocket_transport::set_pause_handler(pause_handler&& handler) { m_pause_handler = std::move(handler); } inline void wamp_websocket_transport::set_resume_handler(resume_handler&& handler) { m_resume_handler = std::move(handler); } inline void wamp_websocket_transport::pause() { if (m_pause_handler) { m_pause_handler(); } } inline void wamp_websocket_transport::resume() { if (m_resume_handler) { m_resume_handler(); } } inline void wamp_websocket_transport::attach( const std::shared_ptr& handler) { if (m_handler) { throw std::logic_error("handler already attached"); } m_handler = handler; m_handler->on_attach(this->shared_from_this()); } inline void wamp_websocket_transport::detach() { if (!m_handler) { throw std::logic_error("no handler attached"); } m_handler->on_detach(true, "wamp.error.goodbye"); m_handler.reset(); } inline bool wamp_websocket_transport::has_handler() const { return m_handler != nullptr; } inline void wamp_websocket_transport::receive_message(const std::string& msg) { if (m_debug_enabled) { std::cerr << "RX message received." << std::endl; } if (m_handler) { m_message_unpacker.reserve_buffer(msg.size()); memcpy(m_message_unpacker.buffer(), msg.data(), msg.size()); m_message_unpacker.buffer_consumed(msg.size()); msgpack::unpacked result; while (m_message_unpacker.next(result)) { wamp_message::message_fields fields; result.get().convert(fields); wamp_message message(std::move(fields), std::move(*(result.zone()))); if (m_debug_enabled) { std::cerr << "RX message: " << message << std::endl; } m_handler->on_message(std::move(message)); } } else { std::cerr << "RX message ignored: no handler attached" << std::endl; } } } //namespace autobahn crossbario-autobahn-cpp-d7a4346/autobahn/wamp_websocketpp_websocket_transport.hpp000066400000000000000000000074641371744511200306630ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP #define AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP #include "boost_config.hpp" #ifdef _WIN32 #ifdef _MSC_VER #pragma warning(disable:4996) //Windows XP cancel async IO always fails with operation_not_supported #endif //Recommended WebSocket++ settings for Windows #define _WEBSOCKETPP_CPP11_FUNCTIONAL_ #define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ #define _WEBSOCKETPP_CPP11_RANDOM_DEVICE_ #define _WEBSOCKETPP_CPP11_MEMORY_ #define _WEBSOCKETPP_NOEXCEPT_ #endif #include "wamp_websocket_transport.hpp" #include #include namespace autobahn { /*! * A transport that provides websocket support using WebSocket++ https://github.com/zaphoyd/websocketpp */ template class wamp_websocketpp_websocket_transport : public wamp_websocket_transport { public: typedef websocketpp::client client_type; typedef boost::lock_guard scoped_lock; wamp_websocketpp_websocket_transport( client_type& client, const std::string& uri, bool debug_enabled = false); virtual ~wamp_websocketpp_websocket_transport() override; virtual bool is_connected() const override; private: virtual bool is_open() const override; virtual void close() override; virtual void async_connect(const std::string& uri, boost::promise& connect_promise) override; virtual void write(void const * payload, size_t len) override; private: void on_ws_open(websocketpp::connection_hdl); void on_ws_close(websocketpp::connection_hdl); void on_ws_fail(websocketpp::connection_hdl); void on_ws_message(websocketpp::connection_hdl, typename client_type::message_ptr msg); private: /*! * The underlying socket for the transport. */ client_type &m_client; websocketpp::connection_hdl m_hdl; boost::mutex m_lock; bool m_open; bool m_done; }; } // namespace autobahn #include "wamp_websocketpp_websocket_transport.ipp" #endif //AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPPcrossbario-autobahn-cpp-d7a4346/autobahn/wamp_websocketpp_websocket_transport.ipp000066400000000000000000000140451371744511200306550ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "wamp_websocket_transport.hpp" #include #include namespace autobahn { template inline wamp_websocketpp_websocket_transport::wamp_websocketpp_websocket_transport( client_type& client, const std::string& uri, bool debug_enabled) : wamp_websocket_transport(uri, debug_enabled) , m_client(client) , m_hdl() , m_open(false) , m_done(false) { // Bind the handlers we are using using websocketpp::lib::placeholders::_1; using websocketpp::lib::bind; m_client.set_open_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_open, this, _1)); m_client.set_close_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_close, this, _1)); m_client.set_fail_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_fail, this, _1)); m_client.set_message_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_message, this, ::_1, ::_2)); if(!debug_enabled) { m_client.clear_access_channels(websocketpp::log::alevel::all); } } template inline wamp_websocketpp_websocket_transport::~wamp_websocketpp_websocket_transport() { } template inline bool wamp_websocketpp_websocket_transport::is_open() const { return m_open; } template inline bool wamp_websocketpp_websocket_transport::is_connected() const { return is_open() && !m_done; } // The open handler will signal that we are ready to start sending telemetry template inline void wamp_websocketpp_websocket_transport::on_ws_open(websocketpp::connection_hdl) { scoped_lock guard(m_lock); m_open = true; //No handshake for websockets beyond declaring sub-protocol m_connect.set_value(); } template inline void wamp_websocketpp_websocket_transport::on_ws_close(websocketpp::connection_hdl hdl) { //Log "Connection closed!"); scoped_lock guard(m_lock); m_done = true; } template inline void wamp_websocketpp_websocket_transport::on_ws_fail(websocketpp::connection_hdl hdl) { //Log "Connection failed!"); if (!m_open) m_connect.set_exception(boost::copy_exception(network_error("failed to connect"))); scoped_lock guard(m_lock); m_done = true; } template inline void wamp_websocketpp_websocket_transport::on_ws_message(websocketpp::connection_hdl, typename client_type::message_ptr msg) { if (msg->get_opcode() == websocketpp::frame::opcode::binary) { receive_message(msg->get_payload()); } else { //m_messages.push_back("<< " + websocketpp::utility::to_hex(msg->get_payload())); } } template inline void wamp_websocketpp_websocket_transport::async_connect(const std::string& uri, boost::promise& connect_promise) { websocketpp::lib::error_code ec; typename client_type::connection_ptr con = m_client.get_connection(uri, ec); if (ec) { //Log "Get Connection Error: " + ec.message()); connect_promise.set_exception(boost::copy_exception(websocketpp::lib::system_error(ec.value(), ec.category(), "connect"))); return; } //TODO: need to abstract encoding and get subprotocol con->add_subprotocol("wamp.2.msgpack"); // Grab a handle for this connection so we can talk to it in a thread // safe manor after the event loop starts. m_hdl = con->get_handle(); // Queue the connection. No DNS queries or network connections will be // made until the io_service event loop is run. m_client.connect(con); } template inline void wamp_websocketpp_websocket_transport::write(void const * payload, size_t len) { websocketpp::lib::error_code ec; m_client.send(m_hdl, payload, len, websocketpp::frame::opcode::binary, ec); } template inline void wamp_websocketpp_websocket_transport::close() { m_client.close(m_hdl, websocketpp::close::status::normal, "disconnect"); } } // namespace autobahn crossbario-autobahn-cpp-d7a4346/cmake/000077500000000000000000000000001371744511200176625ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/cmake/Includes/000077500000000000000000000000001371744511200214305ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/cmake/Includes/CMakeLists.txt000066400000000000000000000151141371744511200241720ustar00rootroot00000000000000# AutobahnC++ cmake build script. # # This script uses the following environment variables (if defined): # # * BOOST_ROOT # * MSGPACK_ROOT # * WEBSOCKETPP_ROOT # # When those are defined, they take precedence over any host system # installations for the respective library. When an explicit library # root location hasn't been set, cmake will look in other places. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_CXX_FLAGS "-stdlib=libc++ -Wno-unused-local-typedefs -Wno-unknown-warning-option ${CMAKE_CXX_FLAGS}") if ("${CMAKE_GENERATOR}" STREQUAL "Ninja") set(CMAKE_CXX_FLAGS "-fcolor-diagnostics ${CMAKE_CXX_FLAGS}") endif() endif() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9.0") # i.e. if >= 4.9.0 if (CMAKE_GENERATOR STREQUAL "Ninja") set(CMAKE_CXX_FLAGS "-fdiagnostics-color=always ${CMAKE_CXX_FLAGS}") else() set(CMAKE_CXX_FLAGS "-fdiagnostics-color=auto ${CMAKE_CXX_FLAGS}") endif() endif() endif() if(NOT MSVC) # https://stackoverflow.com/a/31010221/884770 set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Werror -Wno-unused-variable ${CMAKE_CXX_FLAGS}") endif() set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") find_package(Threads REQUIRED) find_package(OpenSSL REQUIRED) if(BUILD_SHARED_LIBS) set(Boost_USE_STATIC_LIBS OFF ) else() # https://stackoverflow.com/a/3176086/884770 set(Boost_USE_STATIC_LIBS ON ) endif() find_package(Boost REQUIRED COMPONENTS program_options system thread random) find_package(Msgpack REQUIRED) find_package(Websocketpp REQUIRED) MESSAGE( STATUS "AUTOBAHN_BUILD_EXAMPLES: " ${AUTOBAHN_BUILD_EXAMPLES} ) MESSAGE( STATUS "CMAKE_ROOT: " ${CMAKE_ROOT} ) MESSAGE( STATUS "CMAKE_INSTALL_PREFIX: " ${CMAKE_INSTALL_PREFIX} ) MESSAGE( STATUS "Boost_INCLUDE_DIRS: " ${Boost_INCLUDE_DIRS} ) MESSAGE( STATUS "Boost_LIBRARIES: " ${Boost_LIBRARIES} ) MESSAGE( STATUS "Msgpack_INCLUDE_DIRS: " ${Msgpack_INCLUDE_DIRS} ) MESSAGE( STATUS "Msgpack_LIBRARIES: " ${Msgpack_LIBRARIES} ) MESSAGE( STATUS "Websocketpp_INCLUDE_DIRS: " ${Websocketpp_INCLUDE_DIRS} ) MESSAGE( STATUS "Websocketpp_LIBRARIES: " ${Websocketpp_LIBRARIES} ) set(PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/autobahn.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/boost_config.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/exceptions.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_arguments.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_auth_utils.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_authenticate.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_authenticate.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_call.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_call.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_call_options.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_call_options.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_call_result.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_call_result.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_challenge.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_challenge.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_event.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_event.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_event_handler.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_invocation.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_invocation.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_message.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_message.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_message_type.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_message_type.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_procedure.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_publication.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_publication.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_publish_options.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_publish_options.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_rawsocket_transport.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_rawsocket_transport.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_register_request.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_register_request.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_registration.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_registration.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_transport.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_transport_handler.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_session.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_session.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_subscribe_options.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_subscribe_options.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_subscribe_request.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_subscribe_request.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_subscription.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_subscription.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_tcp_transport.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_tcp_transport.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_transport_handler.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_transport.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_uds_transport.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_unregister_request.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_unregister_request.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_unsubscribe_request.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_unsubscribe_request.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_websocket_transport.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_websocket_transport.ipp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_websocketpp_websocket_transport.hpp ${CMAKE_CURRENT_SOURCE_DIR}/autobahn/wamp_websocketpp_websocket_transport.ipp ) add_library(autobahn_cpp INTERFACE) target_include_directories(autobahn_cpp INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ${Websocketpp_INCLUDE_DIRS} ${Msgpack_INCLUDE_DIRS}) target_link_libraries(autobahn_cpp INTERFACE ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) foreach(h ${PUBLIC_HEADERS}) string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "include/" include "${h}") get_filename_component(HEADER_INCLUDE_DIRECTORY ${include} DIRECTORY) install(FILES ${h} DESTINATION ${HEADER_INCLUDE_DIRECTORY} COMPONENT "headers") endforeach() crossbario-autobahn-cpp-d7a4346/cmake/Modules/000077500000000000000000000000001371744511200212725ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/cmake/Modules/FindMsgpack.cmake000066400000000000000000000020251371744511200244610ustar00rootroot00000000000000# - Try to find msgpack # Once done this will define # Msgpack_FOUND - System has msgpack # Msgpack_INCLUDE_DIRS - The msgpack include directories set(_env "$ENV{MSGPACK_ROOT}") if(_env) set(Msgpack_FOUND TRUE) set(Msgpack_INCLUDE_DIRS "$ENV{MSGPACK_ROOT}/include") set(Msgpack_LIBRARIES "$ENV{MSGPACK_ROOT}/libs") else() find_package(PkgConfig QUIET) if (PKG_CONFIG_FOUND) pkg_check_modules(PC_MSGPACK QUIET msgpack) endif (PKG_CONFIG_FOUND) find_path(Msgpack_INCLUDE_DIR msgpack.hpp HINTS ${PC_MSGPACK_INCLUDEDIR} ${PC_MSGPACK_INCLUDE_DIRS}) set(Msgpack_INCLUDE_DIRS ${Msgpack_INCLUDE_DIR}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set Msgpack_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(Msgpack DEFAULT_MSG Msgpack_INCLUDE_DIR Msgpack_INCLUDE_DIRS) mark_as_advanced(Msgpack_INCLUDE_DIR) endif() crossbario-autobahn-cpp-d7a4346/cmake/Modules/FindWebsocketpp.cmake000066400000000000000000000021611371744511200253630ustar00rootroot00000000000000# - Try to find websocketpp # Once done this will define # Websocketpp_FOUND - System has websocketpp # Websocketpp_INCLUDE_DIRS - The websocketpp include directories set(_env "$ENV{WEBSOCKETPP_ROOT}") if(_env) set(Websocketpp_FOUND TRUE) set(Websocketpp_INCLUDE_DIRS "$ENV{WEBSOCKETPP_ROOT}/include") set(Websocketpp_LIBRARIES "$ENV{WEBSOCKETPP_ROOT}/libs") else() find_package(PkgConfig QUIET) if (PKG_CONFIG_FOUND) pkg_check_modules(PC_WEBSOCKETPP QUIET websocketpp) endif (PKG_CONFIG_FOUND) find_path(Websocketpp_INCLUDE_DIR websocketpp HINTS ${PC_WEBSOCKETPP_INCLUDEDIR} ${PC_WEBSOCKETPP_INCLUDE_DIRS}) set(Websocketpp_INCLUDE_DIRS ${Websocketpp_INCLUDE_DIR}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set Websocketpp_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(Websocketpp DEFAULT_MSG Websocketpp_INCLUDE_DIR Websocketpp_INCLUDE_DIRS) mark_as_advanced(Websocketpp_INCLUDE_DIR) endif() crossbario-autobahn-cpp-d7a4346/docker/000077500000000000000000000000001371744511200200515ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/docker/Dockerfile.clang000066400000000000000000000072511371744511200231330ustar00rootroot00000000000000FROM ubuntu:xenial MAINTAINER The Crossbar.io Project # Metadata ARG BUILD_DATE ARG AUTOBAHN_CPP_VERSION ARG AUTOBAHN_CPP_VCS_REF # Metadata labeling LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.name="AutobahnCpp Starter Template" \ org.label-schema.description="Quickstart template for application development with AutobahnCpp" \ org.label-schema.url="http://crossbar.io" \ org.label-schema.vcs-ref=$AUTOBAHN_CPP_VCS_REF \ org.label-schema.vcs-url="https://github.com/crossbario/autobahn-cpp" \ org.label-schema.vendor="The Crossbar.io Project" \ org.label-schema.version=$AUTOBAHN_CPP_VERSION \ org.label-schema.schema-version="1.0" # Crossbar.io connection defaults ENV CBURL ws://localhost:8080/ws ENV CBREALM realm1 # user env ENV DEBIAN_FRONTEND noninteractive ENV HOME /autobahn ENV PATH /autobahn:$PATH ENV LD_LIBRARY_PATH /usr/local/lib # env vars to configure websocketpp ENV WSPP_ENABLE_CPP11 1 # update system, get dev tools and libs RUN apt-get update \ && apt-get install -y wget curl unzip git-core \ clang libc++1 libc++-dev libc++abi-dev \ build-essential autotools-dev autoconf libtool cmake \ zlib1g-dev libbz2-dev libssl-dev \ libboost-all-dev \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # use clang, not gcc ENV CC /usr/bin/clang ENV CXX /usr/bin/clang++ RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 \ && update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 \ && update-alternatives --query c++ \ && update-alternatives --query cc # get, build and install Boost from upstream # RUN cd /tmp \ # && wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2 \ # && tar xvjf boost_1_69_0.tar.bz2 # RUN cd /tmp/boost_1_69_0 \ # && ./bootstrap.sh --with-toolset=clang \ # && ./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++" link=shared link=static threading=single threading=multi --layout=tagged --without-python -j 8 install \ # && cd / \ # && rm -rf /tmp/boost* # https://askubuntu.com/a/486184 # RUN cd /usr/local/lib && \ # ln -s libboost_thread-mt.a libboost_thread.a # get, build and install msgpack-c from upstream RUN cd /tmp \ && wget https://github.com/msgpack/msgpack-c/archive/cpp-1.4.2.zip -O msgpack-c.zip \ && unzip msgpack-c.zip && cd msgpack-c-cpp-1.4.2 \ && export CXXFLAGS="$CXXFLAGS -std=c++11" \ && ./bootstrap && ./configure && make install \ && cd / && rm -rf /tmp/msgpack* # get and install websocketpp from upstream RUN cd /tmp \ && wget https://github.com/zaphoyd/websocketpp/archive/master.zip -O websocketpp.zip \ && unzip websocketpp.zip \ && cp -r /tmp/websocketpp-master/websocketpp/ /usr/local/include/ \ && cd / && rm -rf /tmp/websocketpp* # get and install cmake from upstream # RUN cd /tmp \ # && wget https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh \ # && sh cmake-3.11.0-Linux-x86_64.sh --skip-license --prefix=/usr/local \ # && which cmake && cmake --version #### all dependencies and tools are now in place # setup and build example project RUN mkdir -p /autobahn/build WORKDIR /autobahn COPY autobahn /autobahn/autobahn COPY examples /autobahn/examples COPY cmake /autobahn/cmake COPY cmake/Modules /autobahn/cmake/Modules COPY cmake/Includes /autobahn/cmake/Includes COPY CMakeLists.txt /autobahn/CMakeLists.txt RUN cd build \ && cmake .. \ && make -j4 \ && find examples/ -executable -type f -exec file {} \; # drop into shell by default CMD ["bash"] crossbario-autobahn-cpp-d7a4346/docker/Dockerfile.gcc000066400000000000000000000064031371744511200226010ustar00rootroot00000000000000FROM ubuntu:xenial MAINTAINER The Crossbar.io Project # Metadata ARG BUILD_DATE ARG AUTOBAHN_CPP_VERSION ARG AUTOBAHN_CPP_VCS_REF # Metadata labeling LABEL org.label-schema.build-date=$BUILD_DATE \ org.label-schema.name="AutobahnCpp Starter Template" \ org.label-schema.description="Quickstart template for application development with AutobahnCpp" \ org.label-schema.url="http://crossbar.io" \ org.label-schema.vcs-ref=$AUTOBAHN_CPP_VCS_REF \ org.label-schema.vcs-url="https://github.com/crossbario/autobahn-cpp" \ org.label-schema.vendor="The Crossbar.io Project" \ org.label-schema.version=$AUTOBAHN_CPP_VERSION \ org.label-schema.schema-version="1.0" # Crossbar.io connection defaults ENV CBURL ws://localhost:8080/ws ENV CBREALM realm1 # user env ENV DEBIAN_FRONTEND noninteractive ENV HOME /autobahn ENV PATH /autobahn:$PATH ENV LD_LIBRARY_PATH /usr/local/lib # env vars to configure websocketpp ENV WSPP_ENABLE_CPP11 1 # update system, get dev tools and libs RUN apt-get update \ && apt-get install -y wget curl unzip git-core \ build-essential autotools-dev autoconf libtool cmake \ zlib1g-dev libbz2-dev libssl-dev \ libboost-all-dev \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # get, build and install Boost from upstream # RUN cd /tmp \ # && wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2 \ # && tar xvjf boost_1_69_0.tar.bz2 # RUN cd /tmp/boost_1_69_0 \ # && ./bootstrap.sh --with-toolset=gcc \ # && ./b2 toolset=gcc link=shared link=static threading=single threading=multi --layout=tagged --without-python -j 8 install \ # && cd / \ # && rm -rf /tmp/boost* # https://askubuntu.com/a/486184 # RUN cd /usr/local/lib && \ # ln -s libboost_thread-mt.a libboost_thread.a # get, build and install msgpack-c from upstream RUN cd /tmp \ && wget https://github.com/msgpack/msgpack-c/archive/cpp-1.4.2.zip -O msgpack-c.zip \ && unzip msgpack-c.zip && cd msgpack-c-cpp-1.4.2 \ && export CXXFLAGS="$CXXFLAGS -std=c++11" \ && ./bootstrap && ./configure && make install \ && cd / && rm -rf /tmp/msgpack* # get and install websocketpp from upstream RUN cd /tmp \ && wget https://github.com/zaphoyd/websocketpp/archive/master.zip -O websocketpp.zip \ && unzip websocketpp.zip \ && cp -r /tmp/websocketpp-master/websocketpp/ /usr/local/include/ \ && cd / && rm -rf /tmp/websocketpp* # get and install cmake from upstream # RUN cd /tmp \ # && wget https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh \ # && sh cmake-3.11.0-Linux-x86_64.sh --skip-license --prefix=/usr/local \ # && which cmake && cmake --version #### all dependencies and tools are now in place # setup and build example project RUN mkdir -p /autobahn/build WORKDIR /autobahn COPY autobahn /autobahn/autobahn COPY examples /autobahn/examples COPY cmake /autobahn/cmake COPY cmake/Modules /autobahn/cmake/Modules COPY cmake/Includes /autobahn/cmake/Includes COPY CMakeLists.txt /autobahn/CMakeLists.txt RUN cd build \ && cmake .. \ && make -j4 \ && find examples/ -executable -type f -exec file {} \; # drop into shell by default CMD ["bash"] crossbario-autobahn-cpp-d7a4346/docker/removeall.sh000077500000000000000000000002201371744511200223700ustar00rootroot00000000000000#!/bin/bash #docker stop $(docker ps -a -q) #docker rm $(docker ps -a -q) docker rmi -f $(docker images -q crossbario/autobahn-cpp*:* | uniq) crossbario-autobahn-cpp-d7a4346/docker/versions.sh000077500000000000000000000010701371744511200222560ustar00rootroot00000000000000#!/bin/sh # # CHANGE FOR NEW RELEASES (these need to be proper Git tags in the respective repo): # export AUTOBAHN_CPP_VERSION='20.8.1' # # END OF CONFIG # # # Git working directories of all relevant repos must reside # in parallel (as siblings) to this repository # export AUTOBAHN_CPP_VCS_REF=`git --git-dir=".git" rev-list -n 1 v${AUTOBAHN_CPP_VERSION} --abbrev-commit` export BUILD_DATE=`date -u +"%Y-%m-%d"` echo "" echo "The Crossbar.io Project (build date ${BUILD_DATE})" echo "" echo "autobahn-cpp ${AUTOBAHN_CPP_VERSION} [${AUTOBAHN_CPP_VCS_REF}]" echo "" crossbario-autobahn-cpp-d7a4346/examples/000077500000000000000000000000001371744511200204205ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/examples/CMakeLists.txt000066400000000000000000000030361371744511200231620ustar00rootroot00000000000000set(CMAKE_EXE_LINKER_FLAGS " -static") set(PARAMETERS_SOURCES parameters.cpp) set(PARAMETERS_HEADERS parameters.hpp) add_library(examples_parameters ${PARAMETERS_SOURCES} ${PARAMETERS_HEADERS}) set(CALLER_SOURCES caller.cpp) set(CALLEE_SOURCES callee.cpp) set(PROVIDE_PREFIX_SOURCES callee.cpp) set(PUBLISHER_SOURCES publisher.cpp) set(SUBSCRIBER_SOURCES subscriber.cpp) set(WAMPCRA_SOURCES wampcra.cpp) set(WEBSOCKET_CALLEE_SOURCES websocket_callee.cpp) add_executable(caller ${CALLER_SOURCES} ${PUBLIC_HEADERS}) add_executable(callee ${CALLEE_SOURCES} ${PUBLIC_HEADERS}) add_executable(provide_prefix ${PROVIDE_PREFIX_SOURCES} ${PUBLIC_HEADERS}) add_executable(publisher ${PUBLISHER_SOURCES} ${PUBLIC_HEADERS}) add_executable(subscriber ${SUBSCRIBER_SOURCES} ${PUBLIC_HEADERS}) add_executable(wampcra ${WAMPCRA_SOURCES} ${PUBLIC_HEADERS}) add_executable(websocket_callee ${WEBSOCKET_CALLEE_SOURCES} ${PUBLIC_HEADERS}) target_link_libraries(caller examples_parameters autobahn_cpp) target_link_libraries(callee examples_parameters autobahn_cpp) target_link_libraries(provide_prefix examples_parameters autobahn_cpp) target_link_libraries(publisher examples_parameters autobahn_cpp) target_link_libraries(subscriber examples_parameters autobahn_cpp) target_link_libraries(wampcra examples_parameters crypto autobahn_cpp) target_link_libraries(websocket_callee examples_parameters autobahn_cpp) if(UNIX) set(UDS_SOURCES uds.cpp) add_executable(uds ${UDS_SOURCES} ${PUBLIC_HEADERS}) target_link_libraries(uds examples_parameters autobahn_cpp) endif() crossbario-autobahn-cpp-d7a4346/examples/callee.cpp000066400000000000000000000146601371744511200223600ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include #include #include #include #include void add2(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); auto b = invocation->argument(1); std::cerr << "Procedure com.examples.calculator.add2 invoked: " << a << ", " << b << std::endl; invocation->result(std::make_tuple(a + b)); } void longop(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); std::cerr << "Procedure com.myapp.longop invoked: " << a << std::endl; uint64_t i = 0; for (; i < a; i++) { boost::this_thread::sleep(boost::posix_time::milliseconds(3000)); if (i < a) { invocation->progress(std::make_tuple(i)); } } invocation->result(std::make_tuple(i)); } int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared( io, parameters->rawsocket_endpoint(), debug); auto session = std::make_shared(io, debug); transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future provide_future_add; boost::future provide_future_longop; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } provide_future_add = session->provide("com.examples.calculator.add2", &add2).then( [&](boost::future registration) { try { std::cerr << "registered procedure:" << registration.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); provide_future_longop = session->provide("com.myapp.longop", &longop).then( [&](boost::future registration) { try { std::cerr << "registered procedure:" << registration.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (const std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return -1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/callee_new.cpp000066400000000000000000000075031371744511200232270ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include void log (const std::string& msg) { std::cerr << msg << " [thread " << boost::this_thread::get_id() << "]" << std::endl; } void add2(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); auto b = invocation->argument(1); std::ostringstream oss; oss << "Procedure com.examples.calculator.add2 invoked: " << a << ", " << b << std::endl; log(oss.str()); invocation->result(std::make_tuple(a + b)); } void longop(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); std::ostringstream oss; oss << "Procedure com.myapp.longop invoked: " << a << std::endl; log(oss.str()); uint64_t i = 0; for (; i < a; i++) { boost::this_thread::sleep(boost::posix_time::milliseconds(3000)); if (i < a) { invocation->progress(std::make_tuple(i)); } } invocation->result(std::make_tuple(i)); } int main(int argc, char** argv) { if (argc != 3) { std::cerr << "Usage: callee " << std::endl; return -1; } try { log("starting program .."); log(argv[1]); log(argv[1]); boost::asio::io_service io; bool debug = true; // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future f1, f2, f3; auto endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(argv[1]), atoi(argv[2])); auto transport = std::make_shared(io, endpoint, debug); auto session = std::make_shared(io, debug); transport->attach(std::static_pointer_cast(session)); f1 = transport->connect().then([&](boost::future connected) { connected.get(); log("transport connected"); f2 = session->start().then(boost::launch::deferred, [&](boost::future started) { started.get(); log("session started"); f3 = session->join("realm1").then(boost::launch::deferred, [&](boost::future joined) { joined.get(); log("joined realm"); auto f4 = session->provide("com.examples.calculator.add2", &add2).then( boost::launch::deferred, [&](boost::future registration) { log("registered procedure com.examples.calculator.add2"); }); auto f5 = session->provide("com.myapp.longop", &longop).then( boost::launch::deferred, [&](boost::future registration) { log("registered procedure com.myapp.longop"); }); f5.get(); f4.get(); }); f3.get(); }); f2.get(); }); log("starting io service .."); io.run(); log("stopped io service"); } catch (const std::exception& e) { log(e.what()); return -1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/caller.cpp000066400000000000000000000140741371744511200223740ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include #include #include #include int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared( io, parameters->rawsocket_endpoint(), debug); auto session = std::make_shared(io, debug); transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future call_future; boost::future leave_future; boost::future stop_future; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } autobahn::wamp_call_options call_options; call_options.set_timeout(std::chrono::seconds(10)); std::tuple arguments(23, 777); call_future = session->call("com.examples.calculator.add2", arguments, call_options).then( [&](boost::future result) { try { uint64_t sum = result.get().argument(0); std::cerr << "call result: " << sum << std::endl; } catch (const std::exception& e) { std::cerr << "call failed: " << e.what() << std::endl; io.stop(); return; } leave_future = session->leave().then([&](boost::future reason) { try { std::cerr << "left session (" << reason.get() << ")" << std::endl; } catch (const std::exception& e) { std::cerr << "failed to leave session: " << e.what() << std::endl; io.stop(); return; } stop_future = session->stop().then([&](boost::future stopped) { std::cerr << "stopped session" << std::endl; io.stop(); }); }); }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; transport->detach(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return 1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/parameters.cpp000066400000000000000000000123161371744511200232720ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include namespace { const std::string LOCALHOST_IP_ADDRESS_STRING("127.0.0.1"); const boost::asio::ip::address LOCALHOST_IP_ADDRESS( boost::asio::ip::address::from_string(LOCALHOST_IP_ADDRESS_STRING)); const std::string DEFAULT_REALM("realm1"); const uint16_t DEFAULT_RAWSOCKET_PORT(8000); const std::string DEFAULT_UDS_PATH("/tmp/crossbar.sock"); } parameters::parameters() : m_debug(false) , m_realm(DEFAULT_REALM) , m_rawsocket_endpoint(LOCALHOST_IP_ADDRESS, DEFAULT_RAWSOCKET_PORT) #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS , m_uds_endpoint(DEFAULT_UDS_PATH) #endif { } bool parameters::debug() const { return m_debug; } const std::string& parameters::realm() const { return m_realm; } const boost::asio::ip::tcp::endpoint& parameters::rawsocket_endpoint() const { return m_rawsocket_endpoint; } #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS const boost::asio::local::stream_protocol::endpoint& parameters::uds_endpoint() const { return m_uds_endpoint; } #endif void parameters::set_debug(bool value) { m_debug = value; } void parameters::set_realm(const std::string& realm) { m_realm = realm; } void parameters::set_rawsocket_endpoint(const std::string& ip_address, uint16_t port) { m_rawsocket_endpoint = boost::asio::ip::tcp::endpoint( boost::asio::ip::address::from_string(ip_address), port); } #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS void parameters::set_uds_endpoint(const std::string& path) { m_uds_endpoint = boost::asio::local::stream_protocol::endpoint(path); } #endif std::unique_ptr get_parameters(int argc, char** argv) { std::unique_ptr params(new parameters); namespace po = boost::program_options; po::options_description description("options"); description.add_options() ("help", "Display this help message") ("debug,d", po::bool_switch()->default_value(false), "Enable debug logging.") ("realm,r", po::value()->default_value(DEFAULT_REALM), "The realm to join on the wamp router.") ("uds-path,u", po::value()->default_value(DEFAULT_UDS_PATH), "The unix domain socket path the wamp router is listening for connections on.") ("rawsocket-ip,h", po::value()->default_value(LOCALHOST_IP_ADDRESS_STRING), "The ip address of the host running the wamp router.") ("rawsocket-port,p", po::value()->default_value(DEFAULT_RAWSOCKET_PORT), "The port that the wamp router is listening for connections on."); po::variables_map variables; try { po::store(po::parse_command_line(argc, argv, description), variables); if (variables.count("help")) { std::cout << "Example Parameters" << std::endl << description << std::endl; exit(0); } po::notify(variables); } catch(po::error& e) { std::cerr << "error: " << e.what() << std::endl << std::endl; std::cerr << description << std::endl; exit(-1); } params->set_debug(variables["debug"].as()); params->set_realm(variables["realm"].as()); params->set_rawsocket_endpoint( variables["rawsocket-ip"].as(), variables["rawsocket-port"].as()); #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS params->set_uds_endpoint( variables["uds-path"].as()); #endif return params; } crossbario-autobahn-cpp-d7a4346/examples/parameters.hpp000066400000000000000000000052231371744511200232760ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #ifndef EXAMPLES_PARAMETERS_HPP #define EXAMPLES_PARAMETERS_HPP #include #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS # include #endif #include #include class parameters { public: parameters(); bool debug() const; const std::string& realm() const; const boost::asio::ip::tcp::endpoint& rawsocket_endpoint() const; #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS void set_uds_endpoint(const std::string& path); const boost::asio::local::stream_protocol::endpoint& uds_endpoint() const; #endif void set_debug(bool enabled); void set_realm(const std::string& realm); void set_rawsocket_endpoint(const std::string& ip_address, uint16_t port); private: bool m_debug; std::string m_realm; boost::asio::ip::tcp::endpoint m_rawsocket_endpoint; #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS boost::asio::local::stream_protocol::endpoint m_uds_endpoint; #endif }; std::unique_ptr get_parameters(int argc, char** argv); #endif // EXAMPLES_PARAMETERS_HPP crossbario-autobahn-cpp-d7a4346/examples/projects/000077500000000000000000000000001371744511200222515ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/000077500000000000000000000000001371744511200231115ustar00rootroot00000000000000crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/autobahn-cpp-examples.vs2015.sln000066400000000000000000000140071371744511200307650ustar00rootroot00000000000000 Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wampcra", "wampcra.vcxproj", "{4357F288-DC34-40E3-9AAA-80C1E3EFD633}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "autobahn-cpp", "autobahn-cpp.vcxproj", "{94DB2E6B-5051-43EB-A4BD-D41F4D70D597}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "callee", "callee.vcxproj", "{5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "caller", "caller.vcxproj", "{BF87E140-28C2-41F8-BF65-7776DD215B87}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "publisher", "publisher.vcxproj", "{352DB303-2BBA-4C01-B22F-35A1196FDE4C}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "subscriber", "subscriber.vcxproj", "{62501761-0470-453F-99BC-36FC69B339FA}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "provide_prefix", "provide_prefix.vcxproj", "{B18D21E0-843C-4AC5-8365-495BED662808}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "websocket", "websocket.vcxproj", "{DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x64.ActiveCfg = Debug|x64 {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x64.Build.0 = Debug|x64 {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x86.ActiveCfg = Debug|Win32 {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x86.Build.0 = Debug|Win32 {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x64.ActiveCfg = Release|x64 {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x64.Build.0 = Release|x64 {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x86.ActiveCfg = Release|Win32 {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x86.Build.0 = Release|Win32 {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Debug|x64.ActiveCfg = Release|Win32 {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Debug|x86.ActiveCfg = Release|Win32 {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Release|x64.ActiveCfg = Release|Win32 {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Release|x86.ActiveCfg = Release|Win32 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x64.ActiveCfg = Debug|x64 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x64.Build.0 = Debug|x64 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x86.ActiveCfg = Debug|Win32 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x86.Build.0 = Debug|Win32 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x64.ActiveCfg = Release|x64 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x64.Build.0 = Release|x64 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x86.ActiveCfg = Release|Win32 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x86.Build.0 = Release|Win32 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x64.ActiveCfg = Debug|x64 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x64.Build.0 = Debug|x64 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x86.ActiveCfg = Debug|Win32 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x86.Build.0 = Debug|Win32 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x64.ActiveCfg = Release|x64 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x64.Build.0 = Release|x64 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x86.ActiveCfg = Release|Win32 {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x86.Build.0 = Release|Win32 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x64.ActiveCfg = Debug|x64 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x64.Build.0 = Debug|x64 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x86.ActiveCfg = Debug|Win32 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x86.Build.0 = Debug|Win32 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x64.ActiveCfg = Release|x64 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x64.Build.0 = Release|x64 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x86.ActiveCfg = Release|Win32 {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x86.Build.0 = Release|Win32 {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x64.ActiveCfg = Debug|x64 {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x64.Build.0 = Debug|x64 {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x86.ActiveCfg = Debug|Win32 {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x86.Build.0 = Debug|Win32 {62501761-0470-453F-99BC-36FC69B339FA}.Release|x64.ActiveCfg = Release|x64 {62501761-0470-453F-99BC-36FC69B339FA}.Release|x64.Build.0 = Release|x64 {62501761-0470-453F-99BC-36FC69B339FA}.Release|x86.ActiveCfg = Release|Win32 {62501761-0470-453F-99BC-36FC69B339FA}.Release|x86.Build.0 = Release|Win32 {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x64.ActiveCfg = Debug|x64 {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x64.Build.0 = Debug|x64 {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x86.ActiveCfg = Debug|Win32 {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x86.Build.0 = Debug|Win32 {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x64.ActiveCfg = Release|x64 {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x64.Build.0 = Release|x64 {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x86.ActiveCfg = Release|Win32 {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x86.Build.0 = Release|Win32 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x64.ActiveCfg = Debug|x64 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x64.Build.0 = Debug|x64 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x86.ActiveCfg = Debug|Win32 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x86.Build.0 = Debug|Win32 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x64.ActiveCfg = Release|x64 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x64.Build.0 = Release|x64 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x86.ActiveCfg = Release|Win32 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/autobahn-cpp.vcxproj000066400000000000000000000225271371744511200271170ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {94DB2E6B-5051-43EB-A4BD-D41F4D70D597} Win32Proj autobahncpp 8.1 true v140 Unicode StaticLibrary false v140 true Unicode StaticLibrary true v140 Unicode StaticLibrary false v140 true Unicode Level3 Disabled WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) Windows Level3 Disabled _DEBUG;_LIB;%(PreprocessorDefinitions) Windows Level3 MaxSpeed true true WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) Windows true true Level3 MaxSpeed true true NDEBUG;_LIB;%(PreprocessorDefinitions) Windows true true crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/callee.vcxproj000066400000000000000000000272331371744511200257620ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE} Win32Proj autobahncppexamples 8.1 callee Application true v140 Unicode Application false v140 true Unicode Application true v140 Unicode Application false v140 true Unicode true $(Configuration)\$(ProjectName)\ true $(Platform)\$(Configuration)\$(ProjectName)\ false $(Configuration)\$(ProjectName)\ false $(Platform)\$(Configuration)\$(ProjectName)\ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 Disabled _DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/caller.vcxproj000066400000000000000000000272331371744511200257770ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {BF87E140-28C2-41F8-BF65-7776DD215B87} Win32Proj autobahncppexamples 8.1 caller Application true v140 Unicode Application false v140 true Unicode Application true v140 Unicode Application false v140 true Unicode true $(Configuration)\$(ProjectName)\ true $(Platform)\$(Configuration)\$(ProjectName)\ false $(Configuration)\$(ProjectName)\ false $(Platform)\$(Configuration)\$(ProjectName)\ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 Disabled _DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/provide_prefix.vcxproj000066400000000000000000000272531371744511200275640ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {B18D21E0-843C-4AC5-8365-495BED662808} Win32Proj autobahncppexamples 8.1 provide_prefix Application true v140 Unicode Application false v140 true Unicode Application true v140 Unicode Application false v140 true Unicode true $(Configuration)\$(ProjectName)\ true $(Platform)\$(Configuration)\$(ProjectName)\ false $(Configuration)\$(ProjectName)\ false $(Platform)\$(Configuration)\$(ProjectName)\ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 Disabled _DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/publisher.vcxproj000066400000000000000000000272411371744511200265310ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {352DB303-2BBA-4C01-B22F-35A1196FDE4C} Win32Proj autobahncppexamples 8.1 publisher Application true v140 Unicode Application false v140 true Unicode Application true v140 Unicode Application false v140 true Unicode true $(Configuration)\$(ProjectName)\ true $(Platform)\$(Configuration)\$(ProjectName)\ false $(Configuration)\$(ProjectName)\ false $(Platform)\$(Configuration)\$(ProjectName)\ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 Disabled _DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/subscriber.vcxproj000066400000000000000000000272431371744511200267010ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {62501761-0470-453F-99BC-36FC69B339FA} Win32Proj autobahncppexamples 8.1 subscriber Application true v140 Unicode Application false v140 true Unicode Application true v140 Unicode Application false v140 true Unicode true $(Configuration)\$(ProjectName)\ true $(Platform)\$(Configuration)\$(ProjectName)\ false $(Configuration)\$(ProjectName)\ false $(Platform)\$(Configuration)\$(ProjectName)\ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 Disabled _DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/wampcra.vcxproj000066400000000000000000000272351371744511200261710ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {4357F288-DC34-40E3-9AAA-80C1E3EFD633} Win32Proj autobahncppexamples 8.1 wampcra Application true v140 Unicode Application false v140 true Unicode Application true v140 Unicode Application false v140 true Unicode true $(Configuration)\$(ProjectName)\ true $(Platform)\$(Configuration)\$(ProjectName)\ false $(Configuration)\$(ProjectName)\ false $(Platform)\$(Configuration)\$(ProjectName)\ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 Disabled _DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../ MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config crossbario-autobahn-cpp-d7a4346/examples/projects/VS2015/websocket.vcxproj000066400000000000000000000274641371744511200265310ustar00rootroot00000000000000 Debug Win32 Release Win32 Debug x64 Release x64 {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73} Win32Proj autobahncppexamples 8.1 websocket Application true v140 Unicode Application false v140 true Unicode Application true v140 Unicode Application false v140 true Unicode true $(Configuration)\$(ProjectName)\ true $(Platform)\$(Configuration)\$(ProjectName)\ false $(Configuration)\$(ProjectName)\ false $(Platform)\$(Configuration)\$(ProjectName)\ Level3 Disabled WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../;C:\Projects\OpenSource\websocketpp MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 Disabled _DEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../;C:\Projects\OpenSource\websocketpp MultiThreadedDebug Console true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../;C:\Projects\OpenSource\websocketpp MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config Level3 MaxSpeed true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) $(BOOST_DIR);$(OPENSSL_DIR)\inc32;$(MSGPACK_DIR)\include;../../../;C:\Projects\OpenSource\websocketpp MultiThreaded Console true true true $(BOOST_DIR)\stage\lib;$(OPENSSL_DIR)\build\Win32\VC14\DLL Release;%(AdditionalLibraryDirectories) libeay32.lib;ssleay32.lib;%(AdditionalDependencies) @if NOT [%BOOST_DIR%] ==[] GOTO CHECKMSGPACK @ECHO Boost directory not defined. Set environment variable BOOST_DIR or change project settings :CHECKMSGPACK @if NOT [%MSGPACK_DIR%] ==[] GOTO CHECKOPENSSL @ECHO MsgPack-c directory not defined. Set environment variable MSGPACK_DIR or change project settings :CHECKOPENSSL @if NOT [%OPENSSL_DIR%] ==[] GOTO SUCCESS ECHO OpenSSL directory not defined. Set environment variable OPENSSL_DIR or change project settings :SUCCESS EXIT 0 Checking project config crossbario-autobahn-cpp-d7a4346/examples/provide_prefix.cpp000066400000000000000000000150261371744511200241550ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include #include #include #include const std::string PREFIX("com.examples.calculator"); void calculator(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); auto b = invocation->argument(1); std::cerr << "Procedure " << invocation->uri() << "invoked: " << a << ", " << b << std::endl; auto suffix = invocation->uri().substr(PREFIX.size()); if (suffix == ".add") { invocation->result(std::make_tuple(a + b)); } else if (suffix == ".mul2") { invocation->result(std::make_tuple(a * b)); } else { throw std::runtime_error("procedure not implemented " + invocation->uri()); } } void on_topic(const autobahn::wamp_event& event) { std::cerr << "received event: " << event.uri() << " with argument " << event.argument(0) << std::endl; } int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; boost::asio::io_service io; auto transport = std::make_shared( io, parameters->rawsocket_endpoint(), true); bool debug = parameters->debug(); auto session = std::make_shared(io, debug); transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future provide_future; boost::future subscribe_future; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } provide_future = session->provide(PREFIX, &calculator, { { "match", msgpack::object("prefix") } }).then( [&](boost::future registration) { try { std::cerr << "registered procedure:" << registration.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); subscribe_future = session->subscribe("com.examples.subscriptions", &on_topic, autobahn::wamp_subscribe_options("prefix")).then([&](boost::future subscribed) { try { std::cerr << "subscribed to topic: " << subscribed.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (const std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return -1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/publisher.cpp000066400000000000000000000127151371744511200231270ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include #include #include #include int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared( io, parameters->rawsocket_endpoint(), debug); // create a WAMP session that talks WAMP-RawSocket over TCP // auto session = std::make_shared(io, debug); transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future leave_future; boost::future stop_future; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::tuple arguments(std::string("hello")); session->publish("com.examples.subscriptions.topic1", arguments); std::cerr << "event published" << std::endl; leave_future = session->leave().then([&](boost::future reason) { try { std::cerr << "left session (" << reason.get() << ")" << std::endl; } catch (const std::exception& e) { std::cerr << "failed to leave session: " << e.what() << std::endl; io.stop(); return; } stop_future = session->stop().then([&](boost::future stopped) { std::cerr << "stopped session" << std::endl; io.stop(); }); }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; transport->detach(); } catch (const std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return 1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/subscriber.cpp000066400000000000000000000123321371744511200232700ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include void on_topic1(const autobahn::wamp_event& event) { std::cerr << "received event: " << event->argument(0) << std::endl; } int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared( io, parameters->rawsocket_endpoint(), debug); // create a WAMP session that talks WAMP-RawSocket over TCP // auto session = std::make_shared(io, debug); transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future subscribe_future; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } subscribe_future = session->subscribe("com.examples.subscriptions.topic1", &on_topic1).then([&] (boost::future subscribed) { try { std::cerr << "subscribed to topic: " << subscribed.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return 1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/uds.cpp000066400000000000000000000122621371744511200217220ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include #include #include #include int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared( io, parameters->uds_endpoint(), debug); auto session = std::make_shared(io, debug); transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future call_future; boost::future leave_future; boost::future stop_future; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } leave_future = session->leave().then([&](boost::future reason) { try { std::cerr << "left session (" << reason.get() << ")" << std::endl; } catch (const std::exception& e) { std::cerr << "failed to leave session: " << e.what() << std::endl; io.stop(); return; } stop_future = session->stop().then([&](boost::future stopped) { std::cerr << "stopped session" << std::endl; io.stop(); }); }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; transport->detach(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return 1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/wampcra.cpp000066400000000000000000000154521371744511200225650ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include void calculator(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); auto b = invocation->argument(1); std::cerr << "Procedure com.examples.calculator.add2 invoked: " << a << ", " << b << std::endl; invocation->result(std::make_tuple(a + b)); } void math(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); auto b = invocation->argument(1); std::cerr << "Procedure com.examples.calculator.add2 invoked: " << a << ", " << b << std::endl; invocation->result(std::make_tuple(a + b)); } class auth_wamp_session : public autobahn::wamp_session { public: boost::promise challenge_future; std::string m_secret; auth_wamp_session( boost::asio::io_service& io, bool debug_enabled, const std::string& secret) : autobahn::wamp_session(io, debug_enabled) , m_secret(secret) { } boost::future on_challenge(const autobahn::wamp_challenge& challenge) { std::cerr << "responding to auth challenge: " << challenge.challenge() << std::endl; std::string signature = compute_wcs(m_secret, challenge.challenge()); challenge_future.set_value(autobahn::wamp_authenticate(signature)); std::cerr << "signature: " << signature << std::endl; return challenge_future.get_future(); } }; int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); boost::asio::io_service io; bool debug = parameters->debug(); auto transport = std::make_shared( io, parameters->rawsocket_endpoint(), debug); std::string secret = "secret123"; auto session = std::make_shared(io, debug, secret); transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future leave_future; boost::future stop_future; boost::future provide_future; boost::future prefix_provide_future; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::string authid = "homer"; std::vector authmethods = { "wampcra" }; join_future = session->join(parameters->realm(), authmethods, authid).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; leave_future = session->leave().then([&](boost::future reason) { try { std::cerr << "left session (" << reason.get() << ")" << std::endl; } catch (const std::exception& e) { std::cerr << "failed to leave session: " << e.what() << std::endl; io.stop(); return; } stop_future = session->stop().then([&](boost::future stopped) { std::cerr << "stopped session" << std::endl; io.stop(); }); }); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; } return 0; } crossbario-autobahn-cpp-d7a4346/examples/websocket_callee.cpp000066400000000000000000000132201371744511200244150ustar00rootroot00000000000000/////////////////////////////////////////////////////////////////////////////// // // Copyright (c) Crossbar.io Technologies GmbH and contributors // // Boost Software License - Version 1.0 - August 17th, 2003 // // Permission is hereby granted, free of charge, to any person or organization // obtaining a copy of the software and accompanying documentation covered by // this license (the "Software") to use, reproduce, display, distribute, // execute, and transmit the Software, and to prepare derivative works of the // Software, and to permit third-parties to whom the Software is furnished to // do so, all subject to the following: // // The copyright notices in the Software and this entire statement, including // the above license grant, this restriction and the following disclaimer, // must be included in all copies of the Software, in whole or in part, and // all derivative works of the Software, unless such copies or derivative // works are solely in the form of machine-executable object code generated by // a source language processor. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // /////////////////////////////////////////////////////////////////////////////// #include "parameters.hpp" #include #include #include #include #include #include #include #include #include void add2(autobahn::wamp_invocation invocation) { auto a = invocation->argument(0); auto b = invocation->argument(1); std::cerr << "Procedure com.examples.calculator.add2 invoked: " << a << ", " << b << std::endl; invocation->result(std::make_tuple(a + b)); } typedef websocketpp::client client; int main(int argc, char** argv) { std::cerr << "Boost: " << BOOST_VERSION << std::endl; try { auto parameters = get_parameters(argc, argv); std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; boost::asio::io_service io; bool debug = parameters->debug(); client ws_clinet; ws_clinet.init_asio(&io); auto transport = std::make_shared < autobahn::wamp_websocketpp_websocket_transport >( ws_clinet, "ws://127.0.0.1:8080/ws", debug); auto session = std::make_shared(io, debug); // Create a thread to run the telemetry loop transport->attach(std::static_pointer_cast(session)); // Make sure the continuation futures we use do not run out of scope prematurely. // Since we are only using one thread here this can cause the io service to block // as a future generated by a continuation will block waiting for its promise to be // fulfilled when it goes out of scope. This would prevent the session from receiving // responses from the router. boost::future connect_future; boost::future start_future; boost::future join_future; boost::future provide_future; connect_future = transport->connect().then([&](boost::future connected) { try { connected.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "transport connected" << std::endl; start_future = session->start().then([&](boost::future started) { try { started.get(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } std::cerr << "session started" << std::endl; join_future = session->join(parameters->realm()).then([&](boost::future joined) { try { std::cerr << "joined realm: " << joined.get() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } provide_future = session->provide("com.examples.calculator.add2", &add2).then( [&](boost::future registration) { try { std::cerr << "registered procedure:" << registration.get().id() << std::endl; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; io.stop(); return; } }); }); }); }); std::cerr << "starting io service" << std::endl; io.run(); std::cerr << "stopped io service" << std::endl; } catch (const std::exception& e) { std::cerr << "exception: " << e.what() << std::endl; return -1; } return 0; }