├── .github └── workflows │ ├── ci-linux.yaml │ └── ci-windows.yaml ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── Makefile ├── README.md ├── autobahn ├── autobahn.hpp ├── boost_config.hpp ├── exceptions.hpp ├── wamp_arguments.hpp ├── wamp_auth_utils.hpp ├── wamp_authenticate.hpp ├── wamp_authenticate.ipp ├── wamp_call.hpp ├── wamp_call.ipp ├── wamp_call_options.hpp ├── wamp_call_options.ipp ├── wamp_call_result.hpp ├── wamp_call_result.ipp ├── wamp_challenge.hpp ├── wamp_challenge.ipp ├── wamp_event.hpp ├── wamp_event.ipp ├── wamp_event_handler.hpp ├── wamp_invocation.hpp ├── wamp_invocation.ipp ├── wamp_message.hpp ├── wamp_message.ipp ├── wamp_message_type.hpp ├── wamp_message_type.ipp ├── wamp_procedure.hpp ├── wamp_publication.hpp ├── wamp_publication.ipp ├── wamp_publish_options.hpp ├── wamp_publish_options.ipp ├── wamp_rawsocket_transport.hpp ├── wamp_rawsocket_transport.ipp ├── wamp_register_request.hpp ├── wamp_register_request.ipp ├── wamp_registration.hpp ├── wamp_registration.ipp ├── wamp_session.hpp ├── wamp_session.ipp ├── wamp_subscribe_options.hpp ├── wamp_subscribe_options.ipp ├── wamp_subscribe_request.hpp ├── wamp_subscribe_request.ipp ├── wamp_subscription.hpp ├── wamp_subscription.ipp ├── wamp_tcp_transport.hpp ├── wamp_tcp_transport.ipp ├── wamp_transport.hpp ├── wamp_transport_handler.hpp ├── wamp_uds_transport.hpp ├── wamp_unregister_request.hpp ├── wamp_unregister_request.ipp ├── wamp_unsubscribe_request.hpp ├── wamp_unsubscribe_request.ipp ├── wamp_websocket_transport.hpp ├── wamp_websocket_transport.ipp ├── wamp_websocketpp_websocket_transport.hpp └── wamp_websocketpp_websocket_transport.ipp ├── cmake ├── Includes │ └── CMakeLists.txt └── Modules │ ├── FindBotan2.cmake │ ├── FindMsgpack.cmake │ └── FindWebsocketpp.cmake ├── conanfile.py ├── docker ├── Dockerfile.clang ├── Dockerfile.gcc ├── removeall.sh └── versions.sh └── examples ├── CMakeLists.txt ├── callee.cpp ├── callee_new.cpp ├── caller.cpp ├── cryptosign-botan.cpp ├── cryptosign-openssl.cpp ├── parameters.cpp ├── parameters.hpp ├── projects └── VS2015 │ ├── autobahn-cpp-examples.vs2015.sln │ ├── autobahn-cpp.vcxproj │ ├── callee.vcxproj │ ├── caller.vcxproj │ ├── provide_prefix.vcxproj │ ├── publisher.vcxproj │ ├── subscriber.vcxproj │ ├── wampcra.vcxproj │ └── websocket.vcxproj ├── provide_prefix.cpp ├── publisher.cpp ├── subscriber.cpp ├── uds.cpp ├── wampcra.cpp └── websocket_callee.cpp /.github/workflows/ci-linux.yaml: -------------------------------------------------------------------------------- 1 | name: Linux CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | ci: 7 | name: ${{ matrix.name }} 8 | runs-on: ${{ matrix.os }} 9 | 10 | env: 11 | CTEST_OUTPUT_ON_FAILURE: ON 12 | CTEST_PARALLEL_LEVEL: 2 13 | 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | include: 18 | - name: ubuntu-20.04-gcc-10 19 | os: ubuntu-20.04 20 | compiler: gcc 21 | version: "10" 22 | 23 | - name: ubuntu-20.04-gcc-10-conan 24 | os: ubuntu-20.04 25 | compiler: gcc 26 | version: "10" 27 | conan: true 28 | cmake-args: -DCMAKE_PREFIX_PATH=`pwd`/build -DCMAKE_MODULE_PATH=`pwd`/build 29 | 30 | - name: ubuntu-20.04-clang-10 31 | os: ubuntu-20.04 32 | compiler: clang 33 | version: "10" 34 | cmake-args: -DAUTOBAHN_USE_LIBCXX=NO 35 | 36 | - name: ubuntu-20.04-clang-10-conan 37 | os: ubuntu-20.04 38 | compiler: clang 39 | version: "10" 40 | conan: true 41 | cmake-args: -DCMAKE_PREFIX_PATH=`pwd`/build -DCMAKE_MODULE_PATH=`pwd`/build -DAUTOBAHN_USE_LIBCXX=NO 42 | 43 | steps: 44 | - uses: actions/checkout@v2 45 | 46 | - uses: actions/setup-python@v2 47 | with: 48 | python-version: 3.8 49 | 50 | - name: Set env vars 51 | run: | 52 | echo "CC=${{ matrix.compiler }}-${{ matrix.version }}" >> $GITHUB_ENV 53 | if [ "${{ matrix.compiler }}" == "clang" ]; then 54 | echo "CXX=clang++-${{ matrix.version }}" >> $GITHUB_ENV 55 | else 56 | echo "CXX=g++-${{ matrix.version }}" >> $GITHUB_ENV 57 | fi 58 | 59 | - name: Install 60 | run: | 61 | python -m pip install cmake==3.22.2 conan==1.44.1 --upgrade 62 | 63 | wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - 64 | sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-10 main' -y 65 | sudo apt update 66 | 67 | if [ "${{ matrix.compiler }}" = "gcc" ]; then 68 | sudo apt-get install -y g++-${{ matrix.version }} g++-${{ matrix.version }}-multilib 69 | else 70 | sudo apt-get install -y clang-${{ matrix.version }} clang-tidy-${{ matrix.version }} g++-multilib 71 | fi 72 | 73 | - name: Install dependencies (system) 74 | run: sudo apt-get install -y libboost-all-dev libmsgpack-dev libwebsocketpp-dev 75 | if: ${{ !matrix.conan }} 76 | 77 | - name: Install dependencies (conan) 78 | run: | 79 | conan profile new default --detect --force 80 | conan profile update settings.compiler.libcxx=libstdc++11 default 81 | mkdir -p build && cd build 82 | conan install .. --build=missing 83 | if: ${{ matrix.conan }} 84 | 85 | - name: Build 86 | run: | 87 | cmake -S . -B build ${{ matrix.cmake-args }} -DCMAKE_BUILD_TYPE=Debug 88 | cmake --build build --config Debug 89 | -------------------------------------------------------------------------------- /.github/workflows/ci-windows.yaml: -------------------------------------------------------------------------------- 1 | name: Windows CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | ci: 7 | name: ${{ matrix.name }} 8 | runs-on: ${{ matrix.os }} 9 | 10 | env: 11 | CTEST_OUTPUT_ON_FAILURE: ON 12 | CTEST_PARALLEL_LEVEL: 2 13 | 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | include: 18 | - name: windows-2019-cl-x86 19 | os: windows-2019 20 | generator: Visual Studio 16 2019 21 | type: Debug 22 | platform: Win32 23 | conan_arch: x86 24 | 25 | - name: windows-2019-cl-x64 26 | os: windows-2019 27 | generator: Visual Studio 16 2019 28 | type: Debug 29 | platform: x64 30 | conan_arch: x86_64 31 | 32 | steps: 33 | - uses: actions/checkout@v2 34 | 35 | - uses: actions/setup-python@v2 36 | with: 37 | python-version: 3.8 38 | 39 | - name: Install 40 | run: | 41 | python -m pip install cmake==3.22.2 conan==1.44.1 --upgrade 42 | conan profile new default --detect --force 43 | mkdir -p build && cd build 44 | conan install .. --build=missing -s arch=${{ matrix.conan_arch }} -s build_type=${{ matrix.type }} 45 | 46 | - name: Build 47 | shell: bash # CMake doesn't like paths with backslashes. 48 | run: | 49 | cmake -S . -B build -G "${{ matrix.generator }}" -A ${{ matrix.platform }} -DCMAKE_PREFIX_PATH=`pwd`/build -DCMAKE_MODULE_PATH=`pwd`/build 50 | cmake --build build --config ${{ matrix.type }} 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .build 2 | .qemu 3 | *.sublime-workspace 4 | website/build 5 | web/build 6 | web/reports* 7 | *.pyc 8 | 9 | # Compiled Object files 10 | *.slo 11 | *.lo 12 | *.o 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | 18 | # Compiled Static libraries 19 | *.lai 20 | *.la 21 | *.a 22 | .sconsign.dblite 23 | build 24 | doc/_upload* 25 | doc/_doxygen* 26 | 27 | # Qt Creator 28 | CMakeLists.txt.user 29 | *.key 30 | *.pid 31 | 32 | ## Ignore Visual Studio temporary files, build results, and 33 | ## files generated by popular Visual Studio add-ons. 34 | 35 | # User-specific files 36 | *.suo 37 | *.user 38 | *.userosscache 39 | *.sln.docstates 40 | 41 | # User-specific files (MonoDevelop/Xamarin Studio) 42 | *.userprefs 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Dd]ebugPublic/ 47 | [Rr]elease/ 48 | [Rr]eleases/ 49 | x64/ 50 | x86/ 51 | bld/ 52 | [Bb]in/ 53 | [Oo]bj/ 54 | [Ll]og/ 55 | 56 | # Visual Studio 2015 cache/options directory 57 | .vs/ 58 | 59 | # Visual C++ cache files 60 | ipch/ 61 | *.aps 62 | *.ncb 63 | *.opendb 64 | *.opensdf 65 | *.sdf 66 | *.cachefile 67 | 68 | # IntelliJ/Clion 69 | .idea/ 70 | cmake-build-*/ 71 | *.bz2 72 | *.gz 73 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(autobahn-cpp) 4 | 5 | option(AUTOBAHN_BUILD_EXAMPLES "Build examples" ON) 6 | option(AUTOBAHN_BUILD_EXAMPLES_BOTAN "Build Botan cryptosign example" OFF) 7 | option(AUTOBAHN_USE_LIBCXX "Use libc++ instead of libstdc++ when building with Clang" ON) 8 | 9 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Includes/CMakeLists.txt) 10 | 11 | if(AUTOBAHN_BUILD_EXAMPLES) 12 | add_subdirectory(examples) 13 | endif(AUTOBAHN_BUILD_EXAMPLES) 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Crossbar.io Technologies GmbH and contributors 2 | 3 | Boost Software License - Version 1.0 - August 17th, 2003 4 | 5 | Permission is hereby granted, free of charge, to any person or organization 6 | obtaining a copy of the software and accompanying documentation covered by 7 | this license (the "Software") to use, reproduce, display, distribute, 8 | execute, and transmit the Software, and to prepare derivative works of the 9 | Software, and to permit third-parties to whom the Software is furnished to 10 | do so, all subject to the following: 11 | 12 | The copyright notices in the Software and this entire statement, including 13 | the above license grant, this restriction and the following disclaimer, 14 | must be included in all copies of the Software, in whole or in part, and 15 | all derivative works of the Software, unless such copies or derivative 16 | works are solely in the form of machine-executable object code generated by 17 | a source language processor. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build clean publish 2 | 3 | HOSTIP=$(shell ip route get 1 | awk '{print $$NF;exit}') 4 | 5 | # 6 | # Don't forget: set and source docker/versions.sh before 7 | # building and publishing the toolchain images! 8 | # 9 | 10 | # build toolchain images 11 | build: build_gcc build_clang 12 | 13 | build_gcc: 14 | time docker build \ 15 | --no-cache \ 16 | --build-arg BUILD_DATE=${BUILD_DATE} \ 17 | --build-arg AUTOBAHN_CPP_VCS_REF=${AUTOBAHN_CPP_VCS_REF} \ 18 | --build-arg AUTOBAHN_CPP_VERSION=${AUTOBAHN_CPP_VERSION} \ 19 | -t crossbario/autobahn-cpp \ 20 | -t crossbario/autobahn-cpp:gcc \ 21 | -t crossbario/autobahn-cpp:gcc-${AUTOBAHN_CPP_VERSION} \ 22 | -f docker/Dockerfile.gcc . 23 | 24 | build_clang: 25 | time docker build \ 26 | --no-cache \ 27 | --build-arg BUILD_DATE=${BUILD_DATE} \ 28 | --build-arg AUTOBAHN_CPP_VCS_REF=${AUTOBAHN_CPP_VCS_REF} \ 29 | --build-arg AUTOBAHN_CPP_VERSION=${AUTOBAHN_CPP_VERSION} \ 30 | -t crossbario/autobahn-cpp:clang \ 31 | -t crossbario/autobahn-cpp:clang-${AUTOBAHN_CPP_VERSION} \ 32 | -f docker/Dockerfile.clang . 33 | 34 | # publish toolchain images 35 | publish: publish_gcc publish_clang 36 | 37 | publish_gcc: 38 | docker push crossbario/autobahn-cpp 39 | docker push crossbario/autobahn-cpp:gcc 40 | docker push crossbario/autobahn-cpp:gcc-${AUTOBAHN_CPP_VERSION} 41 | 42 | publish_clang: 43 | docker push crossbario/autobahn-cpp:clang 44 | docker push crossbario/autobahn-cpp:clang-${AUTOBAHN_CPP_VERSION} 45 | 46 | # list/clean (local) toolchain images 47 | list: 48 | -docker images crossbario/autobahn-cpp:* 49 | 50 | clean: 51 | ./docker/removeall.sh 52 | 53 | 54 | crossbar: 55 | crossbar start 56 | -------------------------------------------------------------------------------- /autobahn/autobahn.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_HPP 32 | #define AUTOBAHN_HPP 33 | 34 | #ifdef _WIN32 35 | #define MSGPACK_DISABLE_LEGACY_CONVERT 36 | #define MSGPACK_DEFAULT_API_VERSION 1 37 | #define MSGPACK_DISABLE_LEGACY_CONVERT 38 | #endif 39 | 40 | #include "wamp_event.hpp" 41 | #include "wamp_invocation.hpp" 42 | #include "wamp_session.hpp" 43 | #include "wamp_tcp_transport.hpp" 44 | #include "wamp_transport.hpp" 45 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 46 | #include "wamp_uds_transport.hpp" 47 | #endif 48 | 49 | /*! \mainpage Autobahn-C++ Documentation 50 | 51 | Welcome to the [Autobahn-C++](https://github.com/crossbario/autobahn-cpp) documentation. 52 | \n\n 53 | 54 | Autobahn-C++ is a client library for the [WAMP protocol](http://wamp-proto.org/) that 55 | allows developers to create WAMP application components in C++. 56 | 57 | Application components connect to a WAMP router like [Crossbar.io](http://crossbar.io) 58 | which acts as a messaging layer that allows seamless, secure and cross-language 59 | communication with other components. 60 | 61 | With Autobahn-C++, application components can be (optionally) compiled and linked into 62 | small (<2MB), single file executables for a specific CPU architecture, and then run 63 | on all Linux distributions of that architecture. 64 | 65 | This comes with a number of deployment, resource efficiency and other advantages. 66 | \n\n 67 | 68 | We provide the documentation here, full working examples and Docker Autobahn-C++ images with 69 | complete pre-integrated toolchains: 70 | 71 | - **[Examples](https://github.com/crossbario/autobahn-cpp/tree/master/examples)** 72 | - **[Docker toolchain images](https://hub.docker.com/r/crossbario/autobahn-cpp/)** 73 | 74 | This should you get started from working code examples that you can gradually modify 75 | to your needs. All example code is MIT licensed, so you can safely use it in any software 76 | developement context. 77 | 78 | If you have questions, you can reach out at: 79 | 80 | - [Mailing list](https://groups.google.com/forum/#!forum/autobahnws) 81 | - IRC #autobahn on Freenode 82 | 83 | If you found a bug in the documentation or have a correction, improvement or addition you 84 | would like see merged, awesome! 85 | Please submit an issue or submit a PR directly to the 86 | Autobahn-C++ source repository 87 | [here](https://github.com/crossbario/autobahn-cpp), as all the HTML documentation is built from 88 | comments in the code using Doxygen. 89 | \n\n 90 | 91 | However, if you have a question, please use the mailing list or IRC as mentioned above 92 | rather than misusing the issue tracker;) 93 | */ 94 | 95 | #endif // AUTOBAHN_HPP 96 | -------------------------------------------------------------------------------- /autobahn/boost_config.hpp: -------------------------------------------------------------------------------- 1 | // http://stackoverflow.com/questions/22597948/using-boostfuture-with-then-continuations/ 2 | #ifndef BOOST_THREAD_PROVIDES_FUTURE 3 | #define BOOST_THREAD_PROVIDES_FUTURE 4 | #endif 5 | #ifndef BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION 6 | #define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION 7 | #endif 8 | #ifndef BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY 9 | #define BOOST_THREAD_PROVIDES_FUTURE_WHEN_ALL_WHEN_ANY 10 | #endif 11 | 12 | #include 13 | -------------------------------------------------------------------------------- /autobahn/exceptions.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_EXCEPTIONS_HPP 32 | #define AUTOBAHN_EXCEPTIONS_HPP 33 | 34 | #include 35 | #include 36 | 37 | namespace autobahn { 38 | 39 | class abort_error : public std::runtime_error { 40 | public: 41 | abort_error(const std::string& message) : std::runtime_error(message) {}; 42 | }; 43 | 44 | class network_error : public std::runtime_error { 45 | public: 46 | network_error(const std::string& message) : std::runtime_error(message) {}; 47 | }; 48 | 49 | class no_session_error : public std::runtime_error { 50 | public: 51 | no_session_error() : std::runtime_error("session not joined") {}; 52 | }; 53 | 54 | class no_transport_error : public std::runtime_error { 55 | public: 56 | no_transport_error() : std::runtime_error("session not attached") {}; 57 | }; 58 | 59 | class protocol_error : public std::runtime_error { 60 | public: 61 | protocol_error(const std::string& message) : std::runtime_error(message) {}; 62 | }; 63 | 64 | } // namespace autobahn 65 | 66 | #endif // AUTOBAHN_EXCEPTIONS_HPP 67 | -------------------------------------------------------------------------------- /autobahn/wamp_arguments.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_ARGUMENTS_HPP 32 | #define AUTOBAHN_WAMP_ARGUMENTS_HPP 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | namespace autobahn { 43 | 44 | using wamp_arguments = std::vector; 45 | using wamp_kw_arguments = std::unordered_map; 46 | 47 | static msgpack::zone EMPTY_ARGUMENTS_ZONE; 48 | static msgpack::zone EMPTY_KW_ARGUMENTS_ZONE; 49 | static const msgpack::object EMPTY_ARGUMENTS(std::array(), EMPTY_ARGUMENTS_ZONE); 50 | static const msgpack::object EMPTY_KW_ARGUMENTS(wamp_kw_arguments(), EMPTY_KW_ARGUMENTS_ZONE); 51 | 52 | 53 | //msgpack map utilities. 54 | //TODO: refactor event & invocation to used these 55 | template 56 | inline T value_for_key(const msgpack::object& object, const std::string& key) 57 | { 58 | if (object.type != msgpack::type::MAP) { 59 | throw msgpack::type_error(); 60 | } 61 | for (std::size_t i = 0; i < object.via.map.size; ++i) { 62 | const msgpack::object_kv& kv = object.via.map.ptr[i]; 63 | if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size 64 | && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) 65 | { 66 | return kv.val.as(); 67 | } 68 | } 69 | throw std::out_of_range(key + " keyword argument doesn't exist"); 70 | } 71 | 72 | template 73 | inline T value_for_key(const msgpack::object& object, const char* key) 74 | { 75 | if (object.type != msgpack::type::MAP) { 76 | throw msgpack::type_error(); 77 | } 78 | std::size_t key_size = strlen(key); 79 | for (std::size_t i = 0; i < object.via.map.size; ++i) { 80 | const msgpack::object_kv& kv = object.via.map.ptr[i]; 81 | if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size 82 | && memcmp(key, kv.key.via.str.ptr, key_size) == 0) 83 | { 84 | return kv.val.as(); 85 | } 86 | } 87 | throw std::out_of_range(std::string(key) + " keyword argument doesn't exist"); 88 | } 89 | 90 | template 91 | inline T value_for_key_or(const msgpack::object& object, const std::string& key, const T& fallback) 92 | { 93 | if (object.type != msgpack::type::MAP) { 94 | throw msgpack::type_error(); 95 | } 96 | for (std::size_t i = 0; i < object.via.map.size; ++i) { 97 | const msgpack::object_kv& kv = object.via.map.ptr[i]; 98 | if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size 99 | && key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) 100 | { 101 | return kv.val.as(); 102 | } 103 | } 104 | return fallback; 105 | } 106 | 107 | template 108 | inline T value_for_key_or(const msgpack::object& object, const char* key, const T& fallback) 109 | { 110 | if (object.type != msgpack::type::MAP) { 111 | throw msgpack::type_error(); 112 | } 113 | std::size_t key_size = strlen(key); 114 | for (std::size_t i = 0; i < object.via.map.size; ++i) { 115 | const msgpack::object_kv& kv = object.via.map.ptr[i]; 116 | if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size 117 | && memcmp(key, kv.key.via.str.ptr, key_size) == 0) 118 | { 119 | return kv.val.as(); 120 | } 121 | } 122 | return fallback; 123 | } 124 | } // namespace autobahn 125 | 126 | #endif // AUTOBAHN_WAMP_ARGUMENTS_HPP 127 | -------------------------------------------------------------------------------- /autobahn/wamp_auth_utils.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef WAMP_AUTH_UTILS_HPP 32 | #define WAMP_AUTH_UTILS_HPP 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | // 41 | // Execpetion thrown when something gets wrong 42 | // creating the derived auth key..... 43 | // 44 | class derived_key_error : public std::exception 45 | { 46 | virtual const char* what() const throw() 47 | { 48 | return "Error occured when calulcate a derived key"; 49 | } 50 | }; 51 | 52 | 53 | ////////////////////////////////////////////////////// 54 | // - using openssl crypto lib 55 | // see openssl at : https://www.openssl.org 56 | ////////////////////////////////////////////////////// 57 | 58 | 59 | #include 60 | #include 61 | #include 62 | #include 63 | 64 | #include 65 | 66 | 67 | /*! 68 | * base64 encoding 69 | * 70 | * \param data The data to be encoded 71 | * \return A encoded string 72 | */ 73 | inline std::string base_64_encode(const std::string & data ) 74 | { 75 | BIO *bio, *b64; 76 | BUF_MEM *pBuf; 77 | 78 | b64 = BIO_new(BIO_f_base64()); 79 | bio = BIO_new(BIO_s_mem()); 80 | bio = BIO_push(b64, bio); 81 | 82 | BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL); 83 | 84 | BIO_write(bio, (const unsigned char *) data.c_str(), (int) data.size()); 85 | (void)BIO_flush(bio); 86 | 87 | BIO_get_mem_ptr(bio, &pBuf); 88 | (void)BIO_set_close(bio, BIO_NOCLOSE); 89 | 90 | std::string str_out; 91 | str_out.assign( pBuf->data, pBuf->length ); 92 | 93 | BIO_free_all(bio); 94 | 95 | return str_out; 96 | } 97 | 98 | 99 | /*! 100 | * create a derived key from a password/secret 101 | * 102 | * \param passwd A secret string to make a derived key for 103 | * \param salt A random salt added to the key 104 | * \param iterations A number of intertions used to create the derived key 105 | * \param keylen The length of the derived key returned. 106 | * \return a PBKDF2-sha256 derived key 107 | */ 108 | inline std::string derive_key( 109 | const std::string & passwd, 110 | const std::string & salt, 111 | int iterations, 112 | int keylen 113 | ) 114 | { 115 | 116 | int passwdLen = (int) passwd.size(); 117 | const char * pwd = passwd.c_str(); 118 | 119 | int saltLen = (int) salt.size(); 120 | unsigned char * salt_value = (unsigned char * ) salt.c_str(); 121 | 122 | std::string str_out; 123 | str_out.resize( keylen ); 124 | 125 | 126 | unsigned char * out = (unsigned char *) str_out.c_str(); 127 | 128 | 129 | int result = PKCS5_PBKDF2_HMAC( 130 | pwd, passwdLen, 131 | salt_value, saltLen, 132 | iterations, 133 | EVP_sha256(), 134 | keylen, out); 135 | 136 | if ( result != 0 ) 137 | { 138 | return base_64_encode( str_out ); 139 | } 140 | else 141 | { 142 | throw derived_key_error(); 143 | } 144 | } 145 | 146 | 147 | /*! 148 | * make a keyed-hash from a key using the HMAC-sha256 and a challenge 149 | * 150 | * \param key The key to make a digest for 151 | * \param challenge Some data mixin - identify the specific digest 152 | * \return a base64 encoded digest 153 | */ 154 | inline std::string compute_wcs( 155 | const std::string & key, 156 | const std::string & challenge ) 157 | { 158 | 159 | unsigned int len = 32; 160 | unsigned char hash[32]; 161 | #if (OPENSSL_VERSION_NUMBER < 0x10100000L) 162 | HMAC_CTX hmac; 163 | HMAC_CTX_init(&hmac); 164 | HMAC_Init_ex(&hmac, key.data(), key.length(), EVP_sha256(), NULL); 165 | HMAC_Update(&hmac, (unsigned char*) challenge.data(), challenge.length()); 166 | HMAC_Final(&hmac, hash, &len); 167 | HMAC_CTX_cleanup(&hmac); 168 | #else 169 | HMAC_CTX *hmac = HMAC_CTX_new(); 170 | if (!hmac) 171 | return ""; 172 | HMAC_Init_ex(hmac, key.data(), (int) key.length(), EVP_sha256(), NULL); 173 | HMAC_Update(hmac, ( unsigned char* ) challenge.data(), challenge.length()); 174 | HMAC_Final(hmac, hash, &len); 175 | HMAC_CTX_free(hmac); 176 | #endif 177 | 178 | std::string str_out; 179 | str_out.assign( ( char * ) &hash , 32 ); 180 | 181 | return base_64_encode( str_out ); 182 | } 183 | 184 | 185 | 186 | /*! 187 | * Generates a new random secret for use with WAMP-CRA. 188 | * The secret generated is a random character sequence drawn from 189 | * 190 | * - upper and lower case latin letters 191 | * - digits 192 | * - 193 | * 194 | * \param length The length of the secret to generate. 195 | * \param challenge Some data mixin - identify the specific digest 196 | * \return The generated secret. The length of the generated is ``length`` octets. 197 | */ 198 | inline std::string generate_wcs(int length=14){ 199 | 200 | // 201 | // The characters from which to generate the secret. 202 | // 203 | static const char WCS_SECRET_CHARSET[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 204 | 205 | std::string s; 206 | for (int i = 0; i < length; ++i) { 207 | s.push_back( WCS_SECRET_CHARSET[ rand() % (sizeof(WCS_SECRET_CHARSET) - 1) ] ); 208 | } 209 | 210 | return s; 211 | } 212 | 213 | 214 | #endif //WAMP_AUTH_UTILS_HPP 215 | -------------------------------------------------------------------------------- /autobahn/wamp_authenticate.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_AUTHENTICATE_HPP 32 | #define AUTOBAHN_WAMP_AUTHENTICATE_HPP 33 | 34 | namespace autobahn { 35 | 36 | /// Represents an challenge-response. 37 | class wamp_authenticate 38 | { 39 | public: 40 | wamp_authenticate(const std::string & signature = ""); 41 | 42 | const std::string & signature() const; 43 | private: 44 | std::string m_signature; 45 | }; 46 | 47 | } // namespace autobahn 48 | 49 | #include "wamp_authenticate.ipp" 50 | 51 | #endif // AUTOBAHN_WAMP_AUTHENTICATE_HPP 52 | -------------------------------------------------------------------------------- /autobahn/wamp_authenticate.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_authenticate::wamp_authenticate(const std::string & signature ) 34 | : m_signature( signature ) 35 | { 36 | } 37 | 38 | inline const std::string & wamp_authenticate::signature() const { return m_signature; } 39 | 40 | } // namespace autobahn 41 | -------------------------------------------------------------------------------- /autobahn/wamp_call.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_CALL_HPP 32 | #define AUTOBAHN_WAMP_CALL_HPP 33 | 34 | #include "wamp_call_result.hpp" 35 | #include "boost_config.hpp" 36 | 37 | namespace autobahn { 38 | 39 | /// An outstanding wamp call. 40 | class wamp_call 41 | { 42 | public: 43 | wamp_call(); 44 | 45 | boost::promise& result(); 46 | void set_result(wamp_call_result&& value); 47 | 48 | private: 49 | boost::promise m_result; 50 | }; 51 | 52 | } // namespace autobahn 53 | 54 | #include "wamp_call.ipp" 55 | 56 | #endif // AUTOBAHN_WAMP_CALL_HPP 57 | -------------------------------------------------------------------------------- /autobahn/wamp_call.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_call::wamp_call() 34 | : m_result() 35 | { 36 | } 37 | 38 | inline boost::promise& wamp_call::result() 39 | { 40 | return m_result; 41 | } 42 | 43 | inline void wamp_call::set_result(wamp_call_result&& value) 44 | { 45 | m_result.set_value(std::move(value)); 46 | } 47 | 48 | } // namespace autobahn 49 | -------------------------------------------------------------------------------- /autobahn/wamp_call_options.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_CALL_OPTIONS_HPP 32 | #define AUTOBAHN_WAMP_CALL_OPTIONS_HPP 33 | 34 | #include 35 | 36 | namespace autobahn { 37 | 38 | class wamp_call_options 39 | { 40 | public: 41 | wamp_call_options(); 42 | 43 | wamp_call_options(wamp_call_options&& other) = delete; 44 | wamp_call_options(const wamp_call_options& other) = delete; 45 | wamp_call_options& operator=(wamp_call_options&& other) = delete; 46 | wamp_call_options& operator=(const wamp_call_options& other) = delete; 47 | 48 | const std::chrono::milliseconds& timeout() const; 49 | 50 | void set_timeout(const std::chrono::milliseconds& timeout); 51 | 52 | private: 53 | std::chrono::milliseconds m_timeout; 54 | }; 55 | 56 | } // namespace autobahn 57 | 58 | #include "wamp_call_options.ipp" 59 | 60 | #endif // AUTOBAHN_WAMP_CALL_OPTIONS_HPP 61 | -------------------------------------------------------------------------------- /autobahn/wamp_call_options.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | namespace autobahn { 36 | 37 | inline wamp_call_options::wamp_call_options() 38 | : m_timeout() 39 | { 40 | } 41 | 42 | inline const std::chrono::milliseconds& wamp_call_options::timeout() const 43 | { 44 | return m_timeout; 45 | } 46 | 47 | inline void wamp_call_options::set_timeout(const std::chrono::milliseconds& timeout) 48 | { 49 | m_timeout = timeout; 50 | } 51 | 52 | } // namespace autobahn 53 | 54 | namespace msgpack { 55 | MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { 56 | namespace adaptor { 57 | 58 | template<> 59 | struct convert 60 | { 61 | msgpack::object const& operator()( 62 | msgpack::object const& object, 63 | autobahn::wamp_call_options& options) const 64 | { 65 | std::unordered_map options_map; 66 | object >> options_map; 67 | 68 | const auto options_map_itr = options_map.find("timeout"); 69 | if (options_map_itr != options_map.end()) { 70 | options.set_timeout(std::chrono::milliseconds(options_map_itr->second.as())); 71 | } 72 | 73 | return object; 74 | } 75 | }; 76 | 77 | template<> 78 | struct pack 79 | { 80 | template 81 | msgpack::packer& operator()( 82 | msgpack::packer& packer, 83 | autobahn::wamp_call_options const& options) const 84 | { 85 | std::unordered_map options_map; 86 | const auto& timeout = options.timeout(); 87 | if (timeout.count() > 0) { 88 | options_map["timeout"] = timeout.count(); 89 | } 90 | 91 | packer.pack(options_map); 92 | 93 | return packer; 94 | } 95 | }; 96 | 97 | template <> 98 | struct object_with_zone 99 | { 100 | void operator()( 101 | msgpack::object::with_zone& object, 102 | const autobahn::wamp_call_options& options) 103 | { 104 | std::unordered_map options_map; 105 | 106 | const auto& timeout = options.timeout(); 107 | if (timeout.count() != 0) { 108 | options_map["timeout"] = msgpack::object(timeout.count()); 109 | } 110 | 111 | object << options_map; 112 | } 113 | }; 114 | 115 | } // namespace adaptor 116 | } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) 117 | } // namespace msgpack 118 | -------------------------------------------------------------------------------- /autobahn/wamp_challenge.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_CHALLENGE_HPP 32 | #define AUTOBAHN_WAMP_CHALLENGE_HPP 33 | 34 | namespace autobahn { 35 | 36 | /// Represents a topic subscription. 37 | class wamp_challenge 38 | { 39 | public: 40 | wamp_challenge( 41 | const std::string & authmethod, 42 | const std::string & challenge = "", 43 | const std::string & salt = "", 44 | int iteratons = -1, 45 | int keylen = -1 46 | ); 47 | 48 | const std::string & challenge() const; 49 | const std::string & authmethod() const; 50 | const std::string & salt() const; 51 | int iterations() const; 52 | int keylen() const; 53 | 54 | void set_channel_id(std::string channel_id); 55 | const std::string & channel_id() const; 56 | 57 | private: 58 | // authmethod 59 | std::string m_authmethod; 60 | 61 | // used to "digest" the secret for transport 62 | std::string m_challenge; 63 | 64 | ///////////////////////////////////////// 65 | // if authmethod is "wampcra" 66 | // and the secret is stored as a derived_key 67 | // with salt, iterations and a given keylen. 68 | std::string m_salt; 69 | int m_iterations; 70 | int m_keylen; 71 | 72 | // if authmethod is "cryptosign" 73 | std::string m_channel_id; 74 | }; 75 | 76 | } // namespace autobahn 77 | 78 | #include "wamp_challenge.ipp" 79 | 80 | #endif // AUTOBAHN_WAMP_CHALLENGE_HPP 81 | -------------------------------------------------------------------------------- /autobahn/wamp_challenge.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_challenge::wamp_challenge( 34 | const std::string & authmethod, 35 | const std::string & challenge, 36 | const std::string & salt, 37 | int iterations, 38 | int keylen) 39 | : m_authmethod( authmethod ) 40 | , m_challenge( challenge ) 41 | , m_salt( salt ) 42 | , m_iterations( iterations ) 43 | , m_keylen( keylen ) 44 | {} 45 | 46 | inline const std::string & wamp_challenge::authmethod() const { return m_authmethod; } 47 | inline const std::string & wamp_challenge::challenge() const { return m_challenge; } 48 | inline const std::string & wamp_challenge::salt() const { return m_salt; } 49 | inline int wamp_challenge::iterations() const { return m_iterations; } 50 | inline int wamp_challenge::keylen() const { return m_keylen; } 51 | inline void wamp_challenge::set_channel_id(std::string channel_id) { m_channel_id = std::move(channel_id); } 52 | inline const std::string & wamp_challenge::channel_id() const { return m_channel_id; } 53 | 54 | 55 | } // namespace autobahn 56 | -------------------------------------------------------------------------------- /autobahn/wamp_event_handler.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_EVENT_HANDLER_HPP 32 | #define AUTOBAHN_WAMP_EVENT_HANDLER_HPP 33 | 34 | #include "wamp_event.hpp" 35 | 36 | namespace autobahn { 37 | 38 | /// Handler type for use with wamp_session::subscribe 39 | typedef std::function wamp_event_handler; 40 | 41 | } // namespace autobahn 42 | 43 | #endif // AUTOBAHN_WAMP_EVENT_HANDLER_HPP 44 | -------------------------------------------------------------------------------- /autobahn/wamp_message.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_MESSAGE_HPP 32 | #define AUTOBAHN_WAMP_MESSAGE_HPP 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | namespace autobahn { 41 | 42 | /*! 43 | * A class that represents a wamp message in its simplest form. 44 | * 45 | * [field1, field2, field3, ...] 46 | * 47 | * Although not all arrays are valid wamp messages, this class 48 | * simply provides the building blocks to construct any type of 49 | * message. 50 | * 51 | * TODO: Investigate the benefits of creating a hierarchy of 52 | * wamp message types similar to what has been done for 53 | * bonefish. 54 | */ 55 | class wamp_message 56 | { 57 | public: 58 | /*! 59 | * A convenience type for representing message fields 60 | */ 61 | using message_fields = std::vector; 62 | 63 | public: 64 | /*! 65 | * Constructs a wamp message with the given number of fields. 66 | * 67 | * @param num_fields The number of fields in the message. 68 | */ 69 | wamp_message(std::size_t num_fields); 70 | 71 | /*! 72 | * Constructs a wamp message with the given number of fields. 73 | * 74 | * @param num_fields The number of fields in the message. 75 | * @param zone The zone used to allocate fields in the message. 76 | */ 77 | wamp_message(std::size_t num_fields, msgpack::zone&& zone); 78 | 79 | /*! 80 | * Constructs a wamp message with the given fields. 81 | * 82 | * @param fields The fields in the message. 83 | * @param zone The zone used to allocate fields in the message. 84 | */ 85 | wamp_message(message_fields&& fields, msgpack::zone&& zone); 86 | 87 | wamp_message(const wamp_message& other) = delete; 88 | wamp_message(wamp_message&& other); 89 | 90 | wamp_message& operator=(const wamp_message& other) = delete; 91 | wamp_message& operator=(wamp_message&& other); 92 | 93 | /*! 94 | * Retrieves the field at the specified index. Throws an exception 95 | * if the index is out of bounds. 96 | * 97 | * @param index The index of the target field. 98 | * 99 | * @return The retrieved type. 100 | */ 101 | const msgpack::object& field(std::size_t index) const; 102 | 103 | /*! 104 | * Retrieves the field at the specified index. Throws an exception 105 | * if the index is out of bounds or if the field cannot be retrieved 106 | * as the specified type. 107 | * 108 | * @tparam Type The field's type. 109 | * @param index The index of the target field. 110 | * 111 | * @return The retrieved type. 112 | */ 113 | template 114 | Type field(std::size_t index); 115 | 116 | /*! 117 | * Sets the field at the specified index. Throws an exception if the 118 | * index is out of bounds. 119 | * 120 | * @tparam Type The field's type. 121 | * @param index The index of the target field. 122 | * @param type The type to store in the target field. 123 | */ 124 | template 125 | void set_field(std::size_t index, const Type& type); 126 | 127 | /*! 128 | * Determines if the field at the specified index is of the given type. 129 | * 130 | * @param index The index of the target field. 131 | * @param type The field type to check against. 132 | */ 133 | bool is_field_type(std::size_t index, msgpack::type::object_type type) const; 134 | 135 | /*! 136 | * Retrieves the number of fields in the message. 137 | * 138 | * @return The number of fields in the message. 139 | */ 140 | std::size_t size() const; 141 | 142 | /*! 143 | * The message fields. 144 | * 145 | * @return The message fields. 146 | */ 147 | const message_fields& fields() const; 148 | 149 | /*! 150 | * Pilfers the message fields. 151 | * 152 | * @return The message fields. 153 | */ 154 | message_fields&& fields(); 155 | 156 | /*! 157 | * Pilfers the message zone. 158 | * 159 | * @return The message zone. 160 | */ 161 | msgpack::zone&& zone(); 162 | 163 | private: 164 | /*! 165 | * The zone used to allocate message fields. The zone must outlive 166 | * the fields. If the fields are pilfered then the zone must also 167 | * be pilferred and stored along with the fields. 168 | */ 169 | msgpack::zone m_zone; 170 | 171 | /*! 172 | * The fields comprising of the message. It is up to the user of this 173 | * class to ensure that a valid wamp message has been constructed. 174 | */ 175 | message_fields m_fields; 176 | }; 177 | 178 | /// Convenience operator for outputting a raw wamp message. 179 | std::ostream& operator<<(std::ostream& os, const wamp_message& message); 180 | 181 | } // namespace autobahn 182 | 183 | #include "wamp_message.ipp" 184 | 185 | #endif // AUTOBAHN_WAMP_MESSAGE_HPP 186 | -------------------------------------------------------------------------------- /autobahn/wamp_message.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "wamp_message_type.hpp" 32 | 33 | #include 34 | 35 | namespace autobahn { 36 | 37 | inline wamp_message::wamp_message(std::size_t num_fields) 38 | : m_zone() 39 | , m_fields(num_fields) 40 | { 41 | } 42 | 43 | inline wamp_message::wamp_message(std::size_t num_fields, msgpack::zone&& zone) 44 | : m_zone(std::move(zone)) 45 | , m_fields(num_fields) 46 | { 47 | } 48 | 49 | inline wamp_message::wamp_message(message_fields&& fields, msgpack::zone&& zone) 50 | : m_zone(std::move(zone)) 51 | , m_fields(std::move(fields)) 52 | { 53 | } 54 | 55 | inline wamp_message::wamp_message(wamp_message&& other) 56 | { 57 | m_zone = std::move(other.m_zone); 58 | m_fields = std::move(other.m_fields); 59 | } 60 | 61 | inline wamp_message& wamp_message::operator=(wamp_message&& other) 62 | { 63 | if (this == &other) { 64 | return *this; 65 | } 66 | 67 | m_zone = std::move(other.m_zone); 68 | m_fields = std::move(other.m_fields); 69 | 70 | return *this; 71 | } 72 | 73 | inline const msgpack::object& wamp_message::field(std::size_t index) const 74 | { 75 | if (index >= m_fields.size()) { 76 | throw std::out_of_range("invalid message field index"); 77 | } 78 | 79 | return m_fields[index]; 80 | } 81 | 82 | template 83 | inline Type wamp_message::field(std::size_t index) 84 | { 85 | if (index >= m_fields.size()) { 86 | throw std::out_of_range("invalid message field index"); 87 | } 88 | 89 | return m_fields[index].as(); 90 | } 91 | 92 | template 93 | inline void wamp_message::set_field(std::size_t index, const Type& type) 94 | { 95 | if (index >= m_fields.size()) { 96 | throw std::out_of_range("invalid message field index"); 97 | } 98 | 99 | m_fields[index] = msgpack::object(type, m_zone); 100 | } 101 | 102 | inline bool wamp_message::is_field_type(std::size_t index, msgpack::type::object_type type) const 103 | { 104 | if (index >= m_fields.size()) { 105 | throw std::out_of_range("invalid message field index"); 106 | } 107 | 108 | return m_fields[index].type == type; 109 | } 110 | 111 | inline std::size_t wamp_message::size() const 112 | { 113 | return m_fields.size(); 114 | } 115 | 116 | inline wamp_message::message_fields&& wamp_message::fields() 117 | { 118 | return std::move(m_fields); 119 | } 120 | 121 | inline msgpack::zone&& wamp_message::zone() 122 | { 123 | return std::move(m_zone); 124 | } 125 | 126 | inline std::ostream& operator<<(std::ostream& os, const wamp_message& message) 127 | { 128 | std::size_t num_fields = message.size(); 129 | if (num_fields == 0) { 130 | os << "unknown []"; 131 | return os; 132 | } 133 | 134 | const msgpack::object& type_field = message.field(0); 135 | message_type type = static_cast(type_field.as()); 136 | 137 | if (num_fields == 1) { 138 | os << to_string(type) << " []"; 139 | return os; 140 | } 141 | 142 | os << to_string(type) << " ["; 143 | os << message.field(1); 144 | for (std::size_t index = 2; index < num_fields; ++index) { 145 | os << ", " << message.field(index); 146 | } 147 | os << "]"; 148 | 149 | return os; 150 | } 151 | 152 | } // namespace autobahn 153 | -------------------------------------------------------------------------------- /autobahn/wamp_message_type.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_MESSAGE_TYPE_HPP 32 | #define AUTOBAHN_WAMP_MESSAGE_TYPE_HPP 33 | 34 | #include 35 | 36 | #ifdef ERROR 37 | #undef ERROR 38 | #endif 39 | 40 | #ifdef REGISTERED 41 | #undef REGISTERED 42 | #endif 43 | 44 | namespace autobahn { 45 | 46 | /// WAMP message types. 47 | enum class message_type : int 48 | { 49 | HELLO = 1, 50 | WELCOME = 2, 51 | ABORT = 3, 52 | CHALLENGE = 4, 53 | AUTHENTICATE = 5, 54 | GOODBYE = 6, 55 | HEARTBEAT = 7, 56 | ERROR = 8, 57 | PUBLISH = 16, 58 | PUBLISHED = 17, 59 | SUBSCRIBE = 32, 60 | SUBSCRIBED = 33, 61 | UNSUBSCRIBE = 34, 62 | UNSUBSCRIBED = 35, 63 | EVENT = 36, 64 | CALL = 48, 65 | CANCEL = 49, 66 | RESULT = 50, 67 | REGISTER = 64, 68 | REGISTERED = 65, 69 | UNREGISTER = 66, 70 | UNREGISTERED = 67, 71 | INVOCATION = 68, 72 | INTERRUPT = 69, 73 | YIELD = 70 74 | }; 75 | 76 | /// Convert message type enum to human readable string. 77 | std::string to_string(message_type type); 78 | 79 | } // namespace autobahn 80 | 81 | #include "wamp_message_type.ipp" 82 | 83 | #endif // AUTOBAHN_WAMP_MESSAGE_TYPE_HPP 84 | -------------------------------------------------------------------------------- /autobahn/wamp_message_type.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include 32 | 33 | namespace autobahn { 34 | 35 | inline std::string to_string(message_type type) 36 | { 37 | static std::map type_names = { 38 | { message_type::HELLO, "hello" }, 39 | { message_type::WELCOME, "welcome" }, 40 | { message_type::ABORT, "abort" }, 41 | { message_type::CHALLENGE, "challenge" }, 42 | { message_type::AUTHENTICATE, "authenticate" }, 43 | { message_type::GOODBYE, "goodbye" }, 44 | { message_type::HEARTBEAT, "heartbeat" }, 45 | { message_type::ERROR, "error" }, 46 | { message_type::PUBLISH, "publish" }, 47 | { message_type::PUBLISHED, "published" }, 48 | { message_type::SUBSCRIBE, "subscribe" }, 49 | { message_type::SUBSCRIBED, "subscribed" }, 50 | { message_type::UNSUBSCRIBE, "unsubscribe" }, 51 | { message_type::UNSUBSCRIBED, "unsubscribed" }, 52 | { message_type::EVENT, "event" }, 53 | { message_type::CALL, "call" }, 54 | { message_type::CANCEL, "cancel" }, 55 | { message_type::RESULT, "result" }, 56 | { message_type::REGISTER, "register" }, 57 | { message_type::REGISTERED, "registered" }, 58 | { message_type::UNREGISTER, "unregister" }, 59 | { message_type::UNREGISTERED, "unregistered" }, 60 | { message_type::INVOCATION, "invocation" }, 61 | { message_type::INTERRUPT, "interrupt" }, 62 | { message_type::YIELD, "yield" } 63 | }; 64 | 65 | auto result = type_names.find(type); 66 | if (result == type_names.end()) { 67 | return std::string("unknown"); 68 | } 69 | 70 | return result->second; 71 | } 72 | 73 | } // namespace autobahn 74 | -------------------------------------------------------------------------------- /autobahn/wamp_procedure.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_PROCEDURE_HPP 32 | #define AUTOBAHN_WAMP_PROCEDURE_HPP 33 | 34 | #include "wamp_arguments.hpp" 35 | #include "wamp_invocation.hpp" 36 | 37 | namespace autobahn { 38 | 39 | /// Handler type for use with wamp_session::provide 40 | using wamp_procedure = std::function; 41 | 42 | using provide_options = wamp_kw_arguments; 43 | 44 | } // namespace autobahn 45 | 46 | #endif // AUTOBAHN_WAMP_PROCEDURE_HPP 47 | -------------------------------------------------------------------------------- /autobahn/wamp_publication.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_PUBLICATION_HPP 32 | #define AUTOBAHN_WAMP_PUBLICATION_HPP 33 | 34 | #include 35 | 36 | namespace autobahn { 37 | 38 | /// Represents a topic subscription. 39 | class wamp_publication 40 | { 41 | public: 42 | wamp_publication(); 43 | wamp_publication(uint64_t id); 44 | uint64_t id() const; 45 | 46 | private: 47 | uint64_t m_id; 48 | }; 49 | 50 | } // namespace autobahn 51 | 52 | #include "wamp_publication.ipp" 53 | 54 | #endif // AUTOBAHN_WAMP_PUBLICATION_HPP 55 | -------------------------------------------------------------------------------- /autobahn/wamp_publication.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_publication::wamp_publication() 34 | : m_id(0) 35 | { 36 | } 37 | 38 | inline wamp_publication::wamp_publication(uint64_t id) 39 | : m_id(id) 40 | { 41 | } 42 | 43 | inline uint64_t wamp_publication::id() const 44 | { 45 | return m_id; 46 | } 47 | 48 | } // namespace autobahn 49 | -------------------------------------------------------------------------------- /autobahn/wamp_publish_options.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_PUBLISH_OPTIONS_HPP 32 | #define AUTOBAHN_WAMP_PUBLISH_OPTIONS_HPP 33 | 34 | #include 35 | 36 | namespace autobahn { 37 | 38 | /*! 39 | * \ingroup PUB 40 | * Options for publishing. 41 | */ 42 | class wamp_publish_options 43 | { 44 | public: 45 | wamp_publish_options(); 46 | 47 | wamp_publish_options(wamp_publish_options&& other) = delete; 48 | wamp_publish_options(const wamp_publish_options& other) = delete; 49 | wamp_publish_options& operator=(wamp_publish_options&& other) = delete; 50 | wamp_publish_options& operator=(const wamp_publish_options& other) = delete; 51 | 52 | 53 | const bool& exclude_me() const; 54 | 55 | void set_exclude_me(const bool& exclude_me); 56 | 57 | private: 58 | bool m_exclude_me; 59 | }; 60 | 61 | } // namespace autobahn 62 | 63 | #include "wamp_publish_options.ipp" 64 | 65 | #endif // AUTOBAHN_WAMP_PUBLISH_OPTIONS_HPP 66 | -------------------------------------------------------------------------------- /autobahn/wamp_publish_options.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | namespace autobahn { 36 | 37 | inline wamp_publish_options::wamp_publish_options() 38 | : m_exclude_me(true) //default 39 | { 40 | } 41 | 42 | inline const bool& wamp_publish_options::exclude_me() const 43 | { 44 | return m_exclude_me; 45 | } 46 | 47 | inline void wamp_publish_options::set_exclude_me(const bool& exclude_me) 48 | { 49 | m_exclude_me = exclude_me; 50 | } 51 | 52 | } // namespace autobahn 53 | 54 | namespace msgpack { 55 | MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { 56 | namespace adaptor { 57 | 58 | template<> 59 | struct convert 60 | { 61 | msgpack::object const& operator()( 62 | msgpack::object const& object, 63 | autobahn::wamp_publish_options& options) const 64 | { 65 | std::unordered_map options_map; 66 | object >> options_map; 67 | 68 | const auto options_map_itr = options_map.find("exclude_me"); 69 | if (options_map_itr != options_map.end()) { 70 | options.set_exclude_me( options_map_itr->second.as()); 71 | } 72 | 73 | return object; 74 | } 75 | }; 76 | 77 | template<> 78 | struct pack 79 | { 80 | template 81 | msgpack::packer& operator()( 82 | msgpack::packer& packer, 83 | autobahn::wamp_publish_options const& options) const 84 | { 85 | std::unordered_map options_map; 86 | const auto& exclude_me = options.exclude_me(); 87 | if (exclude_me != true) { //true is default, only false msut be transfered 88 | options_map["exclude_me"] = exclude_me; 89 | } 90 | 91 | packer.pack(options_map); 92 | 93 | return packer; 94 | } 95 | }; 96 | 97 | template <> 98 | struct object_with_zone 99 | { 100 | void operator()( 101 | msgpack::object::with_zone& object, 102 | const autobahn::wamp_publish_options& options) 103 | { 104 | std::unordered_map options_map; 105 | 106 | const auto& exclude_me = options.exclude_me(); 107 | if (exclude_me != true) { //true is default, only false must be transfered 108 | options_map["exclude_me"] = msgpack::object(exclude_me); 109 | } 110 | 111 | object << options_map; 112 | } 113 | }; 114 | 115 | } // namespace adaptor 116 | } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) 117 | } // namespace msgpack 118 | -------------------------------------------------------------------------------- /autobahn/wamp_register_request.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_REGISTER_REQUEST_HPP 32 | #define AUTOBAHN_WAMP_REGISTER_REQUEST_HPP 33 | 34 | #include "wamp_procedure.hpp" 35 | #include "wamp_registration.hpp" 36 | #include "boost_config.hpp" 37 | 38 | namespace autobahn { 39 | 40 | /// An outstanding wamp call. 41 | class wamp_register_request 42 | { 43 | public: 44 | wamp_register_request(); 45 | wamp_register_request(const wamp_procedure& procedure); 46 | wamp_register_request(wamp_register_request&& other); 47 | 48 | const wamp_procedure& procedure() const; 49 | boost::promise& response(); 50 | void set_procedure(wamp_procedure procedure) const; 51 | void set_response(const wamp_registration& registration); 52 | 53 | private: 54 | wamp_procedure m_procedure; 55 | boost::promise m_response; 56 | }; 57 | 58 | } // namespace autobahn 59 | 60 | #include "wamp_register_request.ipp" 61 | 62 | #endif // AUTOBAHN_WAMP_REGISTER_REQUEST_HPP 63 | -------------------------------------------------------------------------------- /autobahn/wamp_register_request.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_register_request::wamp_register_request() 34 | : m_procedure() 35 | , m_response() 36 | { 37 | } 38 | 39 | inline wamp_register_request::wamp_register_request(const wamp_procedure& procedure) 40 | : m_procedure(procedure) 41 | , m_response() 42 | { 43 | } 44 | 45 | inline wamp_register_request::wamp_register_request(wamp_register_request&& other) 46 | : m_procedure(std::move(other.m_procedure)) 47 | , m_response(std::move(other.m_response)) 48 | { 49 | } 50 | 51 | inline const wamp_procedure& wamp_register_request::procedure() const 52 | { 53 | return m_procedure; 54 | } 55 | 56 | inline boost::promise& wamp_register_request::response() 57 | { 58 | return m_response; 59 | } 60 | 61 | inline void wamp_register_request::set_response(const wamp_registration& registration) 62 | { 63 | m_response.set_value(registration); 64 | } 65 | 66 | } // namespace autobahn 67 | -------------------------------------------------------------------------------- /autobahn/wamp_registration.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_REGISTRATION_HPP 32 | #define AUTOBAHN_WAMP_REGISTRATION_HPP 33 | 34 | #include 35 | 36 | namespace autobahn { 37 | 38 | /// Represents a topic subscription. 39 | class wamp_registration 40 | { 41 | public: 42 | wamp_registration(); 43 | wamp_registration(uint64_t id); 44 | uint64_t id() const; 45 | 46 | private: 47 | uint64_t m_id; 48 | }; 49 | 50 | } // namespace autobahn 51 | 52 | #include "wamp_registration.ipp" 53 | 54 | #endif // AUTOBAHN_WAMP_REGISTRATION_HPP 55 | -------------------------------------------------------------------------------- /autobahn/wamp_registration.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_registration::wamp_registration() 34 | : m_id(0) 35 | { 36 | } 37 | 38 | inline wamp_registration::wamp_registration(uint64_t id) 39 | : m_id(id) 40 | { 41 | } 42 | 43 | inline uint64_t wamp_registration::id() const 44 | { 45 | return m_id; 46 | } 47 | 48 | } // namespace autobahn 49 | -------------------------------------------------------------------------------- /autobahn/wamp_subscribe_options.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_SUBSCRIBE_OPTIONS_HPP 32 | #define AUTOBAHN_WAMP_SUBSCRIBE_OPTIONS_HPP 33 | 34 | #include 35 | 36 | namespace autobahn { 37 | 38 | class wamp_subscribe_options 39 | { 40 | public: 41 | wamp_subscribe_options(); 42 | 43 | //Convenience constructor 44 | wamp_subscribe_options(const std::string& match); 45 | 46 | wamp_subscribe_options(wamp_subscribe_options&& other) = delete; 47 | wamp_subscribe_options(const wamp_subscribe_options& other) = delete; 48 | wamp_subscribe_options& operator=(wamp_subscribe_options&& other) = delete; 49 | wamp_subscribe_options& operator=(const wamp_subscribe_options& other) = delete; 50 | 51 | const std::string& match() const; 52 | void set_match(const std::string& match); 53 | bool is_match_set() const; 54 | 55 | private: 56 | boost::optional m_match; 57 | }; 58 | 59 | } // namespace autobahn 60 | 61 | #include "wamp_subscribe_options.ipp" 62 | 63 | #endif // AUTOBAHN_WAMP_SUBSCRIBE_OPTIONS_HPP 64 | 65 | -------------------------------------------------------------------------------- /autobahn/wamp_subscribe_options.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | namespace autobahn { 36 | 37 | inline wamp_subscribe_options::wamp_subscribe_options() 38 | : m_match() 39 | { 40 | } 41 | 42 | inline wamp_subscribe_options::wamp_subscribe_options(const std::string& match) 43 | : m_match() 44 | { 45 | //Verify match type 46 | set_match(match); 47 | } 48 | 49 | inline const std::string& wamp_subscribe_options::match() const 50 | { 51 | return *m_match; 52 | } 53 | 54 | inline bool wamp_subscribe_options::is_match_set() const 55 | { 56 | return m_match.is_initialized(); 57 | } 58 | 59 | inline void wamp_subscribe_options::set_match(const std::string& match) 60 | { 61 | if (!(match == "exact" || match == "prefix" || match == "wildcard")) 62 | { 63 | throw std::runtime_error("The value of 'match' must be 'exact', 'prefix', or 'wildcard'."); 64 | } 65 | m_match = match; 66 | } 67 | 68 | } // namespace autobahn 69 | 70 | namespace msgpack { 71 | MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { 72 | namespace adaptor { 73 | 74 | template<> 75 | struct convert 76 | { 77 | msgpack::object const& operator()( 78 | msgpack::object const& object, 79 | autobahn::wamp_subscribe_options& /*options*/) const 80 | { 81 | return object; 82 | } 83 | }; 84 | 85 | template<> 86 | struct pack 87 | { 88 | template 89 | msgpack::packer& operator()( 90 | msgpack::packer& packer, 91 | autobahn::wamp_subscribe_options const& options) const 92 | { 93 | std::map options_map; 94 | 95 | if (options.is_match_set()) 96 | { 97 | options_map["match"] = options.match(); 98 | } 99 | 100 | packer.pack(options_map); 101 | 102 | return packer; 103 | } 104 | }; 105 | 106 | template <> 107 | struct object_with_zone 108 | { 109 | void operator()( 110 | msgpack::object::with_zone& object, 111 | const autobahn::wamp_subscribe_options& options) 112 | { 113 | std::map options_map; 114 | 115 | if (options.is_match_set()) 116 | { 117 | options_map["match"] = options.match(); 118 | } 119 | 120 | object << options_map; 121 | } 122 | }; 123 | 124 | } // namespace adaptor 125 | } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) 126 | } // namespace msgpack 127 | 128 | -------------------------------------------------------------------------------- /autobahn/wamp_subscribe_request.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_SUBSCRIBE_REQUEST_HPP 32 | #define AUTOBAHN_WAMP_SUBSCRIBE_REQUEST_HPP 33 | 34 | #include "wamp_event_handler.hpp" 35 | #include "wamp_subscription.hpp" 36 | #include "boost_config.hpp" 37 | 38 | namespace autobahn { 39 | 40 | /// An outstanding wamp call. 41 | class wamp_subscribe_request 42 | { 43 | public: 44 | wamp_subscribe_request(); 45 | wamp_subscribe_request(const wamp_event_handler& handler); 46 | 47 | const wamp_event_handler& handler() const; 48 | boost::promise& response(); 49 | void set_handler(const wamp_event_handler& handler) const; 50 | void set_response(const wamp_subscription& subscription); 51 | 52 | private: 53 | wamp_event_handler m_handler; 54 | boost::promise m_response; 55 | }; 56 | 57 | } // namespace autobahn 58 | 59 | #include "wamp_subscribe_request.ipp" 60 | 61 | #endif // AUTOBAHN_WAMP_SUBSCRIBE_REQUEST_HPP 62 | -------------------------------------------------------------------------------- /autobahn/wamp_subscribe_request.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_subscribe_request::wamp_subscribe_request() 34 | : m_handler() 35 | , m_response() 36 | { 37 | } 38 | 39 | inline wamp_subscribe_request::wamp_subscribe_request(const wamp_event_handler& handler) 40 | : m_handler(handler) 41 | , m_response() 42 | { 43 | } 44 | 45 | inline const wamp_event_handler& wamp_subscribe_request::handler() const 46 | { 47 | return m_handler; 48 | } 49 | 50 | inline boost::promise& wamp_subscribe_request::response() 51 | { 52 | return m_response; 53 | } 54 | 55 | inline void wamp_subscribe_request::set_response(const wamp_subscription& subscription) 56 | { 57 | m_response.set_value(subscription); 58 | } 59 | 60 | } // namespace autobahn 61 | -------------------------------------------------------------------------------- /autobahn/wamp_subscription.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_SUBSCRIPTION_HPP 32 | #define AUTOBAHN_WAMP_SUBSCRIPTION_HPP 33 | 34 | #include 35 | 36 | namespace autobahn { 37 | 38 | /// Represents a topic subscription. 39 | class wamp_subscription 40 | { 41 | public: 42 | wamp_subscription(); 43 | wamp_subscription(uint64_t id); 44 | uint64_t id() const; 45 | 46 | private: 47 | uint64_t m_id; 48 | }; 49 | 50 | } // namespace autobahn 51 | 52 | #include "wamp_subscription.ipp" 53 | 54 | #endif // AUTOBAHN_WAMP_SUBSCRIPTION_HPP 55 | -------------------------------------------------------------------------------- /autobahn/wamp_subscription.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_subscription::wamp_subscription() 34 | : m_id(0) 35 | { 36 | } 37 | 38 | inline wamp_subscription::wamp_subscription(uint64_t id) 39 | : m_id(id) 40 | { 41 | } 42 | 43 | inline uint64_t wamp_subscription::id() const 44 | { 45 | return m_id; 46 | } 47 | 48 | } // namespace autobahn 49 | -------------------------------------------------------------------------------- /autobahn/wamp_tcp_transport.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_TCP_TRANSPORT_HPP 32 | #define AUTOBAHN_WAMP_TCP_TRANSPORT_HPP 33 | 34 | #include "boost_config.hpp" 35 | #include "wamp_rawsocket_transport.hpp" 36 | 37 | #include 38 | #include 39 | 40 | namespace autobahn { 41 | 42 | /*! 43 | * A transport that provides rawsocket support over TCP. 44 | */ 45 | class wamp_tcp_transport : 46 | public wamp_rawsocket_transport 47 | { 48 | public: 49 | wamp_tcp_transport( 50 | boost::asio::io_service& io_service, 51 | const boost::asio::ip::tcp::endpoint& remote_endpoint, 52 | bool debug_enabled=false); 53 | virtual ~wamp_tcp_transport() override; 54 | 55 | virtual boost::future connect() override; 56 | }; 57 | 58 | } // namespace autobahn 59 | 60 | #include "wamp_tcp_transport.ipp" 61 | 62 | #endif // AUTOBAHN_WAMP_TCP_TRANSPORT_HPP 63 | -------------------------------------------------------------------------------- /autobahn/wamp_tcp_transport.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "wamp_tcp_transport.hpp" 32 | 33 | #include 34 | 35 | namespace autobahn { 36 | 37 | inline wamp_tcp_transport::wamp_tcp_transport( 38 | boost::asio::io_service& io_service, 39 | const boost::asio::ip::tcp::endpoint& remote_endpoint, 40 | bool debug_enabled) 41 | : wamp_rawsocket_transport( 42 | io_service, remote_endpoint, debug_enabled) 43 | { 44 | } 45 | 46 | inline wamp_tcp_transport::~wamp_tcp_transport() 47 | { 48 | } 49 | 50 | inline boost::future wamp_tcp_transport::connect() 51 | { 52 | return wamp_rawsocket_transport::connect().then( 53 | [&](boost::future connected) { 54 | // Check the originating future for exceptions. 55 | connected.get(); 56 | 57 | // Disable naggle for improved performance. 58 | boost::asio::ip::tcp::no_delay option(true); 59 | socket().set_option(option); 60 | } 61 | ); 62 | } 63 | 64 | } // namespace autobahn 65 | -------------------------------------------------------------------------------- /autobahn/wamp_transport.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_TRANSPORT_HPP 32 | #define AUTOBAHN_WAMP_TRANSPORT_HPP 33 | 34 | #include "boost_config.hpp" 35 | 36 | #include 37 | #include 38 | 39 | namespace autobahn { 40 | 41 | class wamp_message; 42 | class wamp_transport_handler; 43 | 44 | /*! 45 | * Provides an abstraction for a transport to be used by the session. A wamp 46 | * transport is defined as being message based, bidirectional, reliable, and 47 | * ordered. 48 | */ 49 | class wamp_transport 50 | { 51 | public: 52 | /*! 53 | * Handler to invoke when pausing transport transmission. 54 | */ 55 | using pause_handler = std::function; 56 | 57 | /*! 58 | * Handler to invoke when resuming transport transmission. 59 | */ 60 | using resume_handler = std::function; 61 | 62 | public: 63 | /*! 64 | * Default virtual destructor. 65 | */ 66 | virtual ~wamp_transport() = default; 67 | 68 | /* 69 | * CONNECTION INTERFACE 70 | */ 71 | /*! 72 | * Attempts to connect the transport. 73 | * 74 | * @return A future that will be satisfied when the connect attempt 75 | * has been made. 76 | */ 77 | virtual boost::future connect() = 0; 78 | 79 | /*! 80 | * Attempts to disconnect the transport. 81 | * 82 | * @return A future that will be satisfied when the disconnect attempt 83 | * has been made. 84 | */ 85 | virtual boost::future disconnect() = 0; 86 | 87 | /*! 88 | * Determines if the transport is connected. 89 | * 90 | * @return Whether or not the transport is connected. 91 | */ 92 | virtual bool is_connected() const = 0; 93 | 94 | /* 95 | * SENDER INTERFACE 96 | */ 97 | /*! 98 | * Send the message synchronously over the transport. 99 | * 100 | * @param message The message to be sent. 101 | */ 102 | virtual void send_message(wamp_message&& message) = 0; 103 | 104 | /*! 105 | * Set the handler to be invoked when the transport detects congestion 106 | * sending to the remote peer and needs to apply backpressure on the 107 | * application. 108 | * 109 | * @param handler The pause handler to be invoked. 110 | */ 111 | virtual void set_pause_handler(pause_handler&& handler) = 0; 112 | 113 | /*! 114 | * Set the handler to be invoked when the transport detects congestion 115 | * has subsided on the remote peer and the application can resume sending 116 | * messages. 117 | * 118 | * @param handler The resume handler to be invoked. 119 | */ 120 | virtual void set_resume_handler(resume_handler&& handler) = 0; 121 | 122 | /* 123 | * RECEIVER INTERFACE 124 | */ 125 | /*! 126 | * Pause receiving of messages. This will prevent the transport from receiving 127 | * any more messages until it has been resumed. This is used to excert 128 | * backpressure on the sending peer. 129 | */ 130 | virtual void pause() = 0; 131 | 132 | /*! 133 | * Resume receiving of messages. The transport will now begin receiving messsages 134 | * again and lift backpressure from the sending peer. 135 | */ 136 | virtual void resume() = 0; 137 | 138 | /*! 139 | * Attaches a handler to the transport. Only one handler may 140 | * be attached at any given time. 141 | * 142 | * @param handler The handler to attach to this transport. 143 | */ 144 | virtual void attach( 145 | const std::shared_ptr& handler) = 0; 146 | 147 | /*! 148 | * Detaches the handler currently attached to the transport. 149 | */ 150 | virtual void detach() = 0; 151 | 152 | /*! 153 | * Determines if the transport has a handler attached. 154 | * 155 | * @return Whether or not a handler is attached. 156 | */ 157 | virtual bool has_handler() const = 0; 158 | }; 159 | 160 | } // namespace autobahn 161 | 162 | #endif // AUTOBAHN_WAMP_TRANSPORT_HPP 163 | -------------------------------------------------------------------------------- /autobahn/wamp_transport_handler.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_TRANSPORT_HANDLER_HPP 32 | #define AUTOBAHN_WAMP_TRANSPORT_HANDLER_HPP 33 | 34 | #include "boost_config.hpp" 35 | #include "wamp_message.hpp" 36 | 37 | #include 38 | #include 39 | 40 | namespace autobahn { 41 | 42 | class wamp_transport; 43 | 44 | /*! 45 | * Provides an abstraction for associating a handler with a transport. 46 | */ 47 | class wamp_transport_handler 48 | { 49 | public: 50 | /*! 51 | * Called by the transport when attaching a handler. 52 | * 53 | * @param transport The transport being attached to. 54 | */ 55 | virtual void on_attach(const std::shared_ptr& transport) = 0; 56 | 57 | /*! 58 | * Called by the transport when detaching a handler. 59 | * 60 | * @param was_clean Whether or not the transport is cleanly detaching. 61 | * @param reason The reason for detaching. 62 | */ 63 | virtual void on_detach(bool was_clean, const std::string& reason) = 0; 64 | 65 | /*! 66 | * Called by the transport when a message is received. 67 | * 68 | * @param message The message that has been received. 69 | */ 70 | virtual void on_message(wamp_message&& message) = 0; 71 | 72 | /*! 73 | * Default virtual destructor. 74 | */ 75 | virtual ~wamp_transport_handler() = default; 76 | }; 77 | 78 | } // namespace autobahn 79 | 80 | #endif // AUTOBAHN_WAMP_TRANSPORT_HANDLER_HPP 81 | -------------------------------------------------------------------------------- /autobahn/wamp_uds_transport.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_UDS_TRANSPORT_HPP 32 | #define AUTOBAHN_WAMP_UDS_TRANSPORT_HPP 33 | 34 | #include "wamp_rawsocket_transport.hpp" 35 | 36 | #include 37 | 38 | namespace autobahn { 39 | 40 | /*! 41 | * A transport that provides rawsocket support over unix domain sockets (UDS). 42 | */ 43 | using wamp_uds_transport = 44 | wamp_rawsocket_transport< 45 | boost::asio::local::stream_protocol::socket>; 46 | 47 | } // namespace autobahn 48 | 49 | #endif // AUTOBAHN_WAMP_UDS_TRANSPORT_HPP 50 | -------------------------------------------------------------------------------- /autobahn/wamp_unregister_request.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | #ifndef AUTOBAHN_WAMP_UNREGISTER_REQUEST_HPP 20 | #define AUTOBAHN_WAMP_UNREGISTER_REQUEST_HPP 21 | 22 | #include "boost_config.hpp" 23 | #include "wamp_registration.hpp" 24 | 25 | namespace autobahn { 26 | 27 | /// An outstanding wamp call. 28 | class wamp_unregister_request 29 | { 30 | public: 31 | wamp_unregister_request(const wamp_registration& registration); 32 | 33 | boost::promise& response(); 34 | void set_response(); 35 | wamp_registration& registration(); 36 | 37 | private: 38 | wamp_registration m_registration; 39 | boost::promise m_response; 40 | }; 41 | 42 | } // namespace autobahn 43 | 44 | #include "wamp_unregister_request.ipp" 45 | 46 | #endif // AUTOBAHN_WAMP_UNREGISTER_REQUEST_HPP 47 | -------------------------------------------------------------------------------- /autobahn/wamp_unregister_request.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); 6 | // you may not use this file except in compliance with the License. 7 | // You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, software 12 | // distributed under the License is distributed on an "AS IS" BASIS, 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | // See the License for the specific language governing permissions and 15 | // limitations under the License. 16 | // 17 | /////////////////////////////////////////////////////////////////////////////// 18 | 19 | namespace autobahn { 20 | 21 | inline wamp_unregister_request::wamp_unregister_request(const wamp_registration& registration) 22 | : m_registration(registration) 23 | , m_response() 24 | { 25 | } 26 | 27 | inline boost::promise& wamp_unregister_request::response() 28 | { 29 | return m_response; 30 | } 31 | 32 | inline void wamp_unregister_request::set_response() 33 | { 34 | m_response.set_value(); 35 | } 36 | 37 | inline wamp_registration& wamp_unregister_request::registration() 38 | { 39 | return m_registration; 40 | } 41 | 42 | } // namespace autobahn 43 | -------------------------------------------------------------------------------- /autobahn/wamp_unsubscribe_request.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WAMP_UNSUBSCRIBE_REQUEST_HPP 32 | #define AUTOBAHN_WAMP_UNSUBSCRIBE_REQUEST_HPP 33 | 34 | #include "boost_config.hpp" 35 | #include "wamp_subscription.hpp" 36 | 37 | namespace autobahn { 38 | 39 | /// An outstanding wamp call. 40 | class wamp_unsubscribe_request 41 | { 42 | public: 43 | wamp_unsubscribe_request(const wamp_subscription& subscription); 44 | 45 | boost::promise& response(); 46 | void set_response(); 47 | wamp_subscription &subscription(); 48 | 49 | private: 50 | wamp_subscription m_subscription; 51 | boost::promise m_response; 52 | }; 53 | 54 | } // namespace autobahn 55 | 56 | #include "wamp_unsubscribe_request.ipp" 57 | 58 | #endif // AUTOBAHN_WAMP_UNSUBSCRIBE_REQUEST_HPP 59 | -------------------------------------------------------------------------------- /autobahn/wamp_unsubscribe_request.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | namespace autobahn { 32 | 33 | inline wamp_unsubscribe_request::wamp_unsubscribe_request(const wamp_subscription &subscription) 34 | : m_subscription(subscription) 35 | , m_response() 36 | { 37 | } 38 | 39 | inline boost::promise& wamp_unsubscribe_request::response() 40 | { 41 | return m_response; 42 | } 43 | 44 | inline void wamp_unsubscribe_request::set_response() 45 | { 46 | m_response.set_value(); 47 | } 48 | 49 | inline wamp_subscription& wamp_unsubscribe_request::subscription() 50 | { 51 | return m_subscription; 52 | } 53 | 54 | } // namespace autobahn 55 | -------------------------------------------------------------------------------- /autobahn/wamp_websocket_transport.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WEBSOCKET_TRANSPORT_HPP 32 | #define AUTOBAHN_WEBSOCKET_TRANSPORT_HPP 33 | 34 | #include "boost_config.hpp" 35 | #include "wamp_transport.hpp" 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | namespace autobahn { 43 | 44 | class wamp_message; 45 | class wamp_transport_handler; 46 | 47 | /*! 48 | * A class that represents a base websocket transport 49 | * 50 | * Unlike raw socket base class, there is nothing to share about underlying websocket, 51 | * It is completely up to derived class to handle specific websocket implementation 52 | */ 53 | class wamp_websocket_transport : 54 | public wamp_transport, 55 | public std::enable_shared_from_this 56 | { 57 | public: 58 | /*! 59 | * Constructs a websocket transport. 60 | * 61 | * @param uri The remote endpoint to connect to. 62 | */ 63 | wamp_websocket_transport( 64 | const std::string& uri, 65 | bool debug_enabled = false); 66 | 67 | virtual ~wamp_websocket_transport() override = default; 68 | 69 | 70 | /* 71 | * CONNECTION INTERFACE 72 | */ 73 | /*! 74 | * @copydoc wamp_transport::connect() 75 | */ 76 | virtual boost::future connect() override; 77 | 78 | /*! 79 | * @copydoc wamp_transport::disconnect() 80 | */ 81 | virtual boost::future disconnect() override; 82 | 83 | /*! 84 | * @copydoc wamp_transport::is_connected() 85 | */ 86 | virtual bool is_connected() const override; 87 | 88 | /* 89 | * SENDER INTERFACE 90 | */ 91 | /*! 92 | * @copydoc wamp_transport::send_message() 93 | */ 94 | virtual void send_message(wamp_message&& message) override; 95 | 96 | /*! 97 | * @copydoc wamp_transport::set_pause_handler() 98 | */ 99 | virtual void set_pause_handler(pause_handler&& handler) override; 100 | 101 | /*! 102 | * @copydoc wamp_transport::set_resume_handler() 103 | */ 104 | virtual void set_resume_handler(resume_handler&& handler) override; 105 | 106 | /* 107 | * RECEIVER INTERFACE 108 | */ 109 | /*! 110 | * Pause receiving of messages. This will prevent the transport from receiving 111 | * any more messages until it has been resumed. This is used to excert 112 | * backpressure on the sending peer. 113 | */ 114 | virtual void pause() override; 115 | 116 | /*! 117 | * Resume receiving of messages. The transport will now begin receiving messsages 118 | * again and lift backpressure from the sending peer. 119 | */ 120 | virtual void resume() override; 121 | 122 | /*! 123 | * @copydoc wamp_transport::attach() 124 | */ 125 | virtual void attach( 126 | const std::shared_ptr& handler) override; 127 | 128 | /*! 129 | * @copydoc wamp_transport::detach() 130 | */ 131 | virtual void detach() override; 132 | 133 | /*! 134 | * @copydoc wamp_transport::has_handler() 135 | */ 136 | virtual bool has_handler() const override; 137 | 138 | 139 | protected: 140 | virtual bool is_open() const = 0; 141 | 142 | 143 | virtual void async_connect(const std::string& m_uri, boost::promise& connect_promise) = 0; 144 | virtual void close() = 0; 145 | 146 | virtual void write(void const * payload, size_t len) = 0; 147 | 148 | void receive_message(const std::string& msg); 149 | 150 | /*! 151 | * The promise that is fulfilled when the connect attempt is complete. 152 | */ 153 | boost::promise m_connect; 154 | 155 | /*! 156 | * The promise that is fulfilled when the disconnect attempt is complete. 157 | */ 158 | boost::promise m_disconnect; 159 | 160 | private: 161 | 162 | 163 | private: 164 | 165 | 166 | /*! 167 | * The handler to be called when pausing. 168 | */ 169 | pause_handler m_pause_handler; 170 | 171 | /*! 172 | * The handler to be called when resuming. 173 | */ 174 | resume_handler m_resume_handler; 175 | 176 | /*! 177 | * The transport handler to be notified of events/messages. 178 | */ 179 | std::shared_ptr m_handler; 180 | 181 | /*! 182 | * Used for unpacking serialized messages. 183 | */ 184 | msgpack::unpacker m_message_unpacker; 185 | 186 | /*! 187 | * Whether or not debugging is enabled. 188 | */ 189 | bool m_debug_enabled; 190 | 191 | /*! 192 | * Websocket endpoint URI 193 | */ 194 | std::string m_uri; 195 | }; 196 | } // namespace autobahn 197 | 198 | #include "wamp_websocket_transport.ipp" 199 | #endif // AUTOBAHN_WEBSOCKET_TRANSPORT_HPP -------------------------------------------------------------------------------- /autobahn/wamp_websocket_transport.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "exceptions.hpp" 32 | #include "wamp_message.hpp" 33 | #include "wamp_transport_handler.hpp" 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | namespace autobahn { 42 | 43 | inline wamp_websocket_transport::wamp_websocket_transport( 44 | const std::string& uri, 45 | bool debug_enabled) 46 | : wamp_transport() 47 | , m_connect() 48 | , m_disconnect() 49 | , m_message_unpacker() 50 | , m_debug_enabled(debug_enabled) 51 | , m_uri(uri) 52 | { 53 | } 54 | 55 | inline boost::future wamp_websocket_transport::connect() 56 | { 57 | if (is_open()) { 58 | m_connect.set_exception(boost::copy_exception(network_error("network transport already connected"))); 59 | return m_connect.get_future(); 60 | } 61 | 62 | async_connect(m_uri, m_connect); 63 | 64 | return m_connect.get_future(); 65 | } 66 | 67 | inline boost::future wamp_websocket_transport::disconnect() 68 | { 69 | if (!is_open()) { 70 | throw network_error("network transport already disconnected"); 71 | } 72 | 73 | close(); 74 | 75 | m_disconnect.set_value(); 76 | return m_disconnect.get_future(); 77 | } 78 | 79 | inline bool wamp_websocket_transport::is_connected() const 80 | { 81 | return is_open(); 82 | } 83 | 84 | inline void wamp_websocket_transport::send_message(wamp_message&& message) 85 | { 86 | auto buffer = std::make_shared(); 87 | msgpack::packer packer(*buffer); 88 | packer.pack(message.fields()); 89 | 90 | 91 | // Write actual serialized message. 92 | write(buffer->data(), buffer->size()); 93 | 94 | if (m_debug_enabled) { 95 | std::cerr << "TX message (" << buffer->size() << " octets) ..." << std::endl; 96 | std::cerr << "TX message: " << message << std::endl; 97 | } 98 | } 99 | 100 | inline void wamp_websocket_transport::set_pause_handler(pause_handler&& handler) 101 | { 102 | m_pause_handler = std::move(handler); 103 | } 104 | 105 | inline void wamp_websocket_transport::set_resume_handler(resume_handler&& handler) 106 | { 107 | m_resume_handler = std::move(handler); 108 | } 109 | 110 | inline void wamp_websocket_transport::pause() 111 | { 112 | if (m_pause_handler) { 113 | m_pause_handler(); 114 | } 115 | } 116 | 117 | inline void wamp_websocket_transport::resume() 118 | { 119 | if (m_resume_handler) { 120 | m_resume_handler(); 121 | } 122 | } 123 | 124 | inline void wamp_websocket_transport::attach( 125 | const std::shared_ptr& handler) 126 | { 127 | if (m_handler) { 128 | throw std::logic_error("handler already attached"); 129 | } 130 | 131 | m_handler = handler; 132 | 133 | m_handler->on_attach(this->shared_from_this()); 134 | } 135 | 136 | inline void wamp_websocket_transport::detach() 137 | { 138 | if (!m_handler) { 139 | throw std::logic_error("no handler attached"); 140 | } 141 | 142 | m_handler->on_detach(true, "wamp.error.goodbye"); 143 | m_handler.reset(); 144 | } 145 | 146 | inline bool wamp_websocket_transport::has_handler() const 147 | { 148 | return m_handler != nullptr; 149 | } 150 | 151 | 152 | inline void wamp_websocket_transport::receive_message(const std::string& msg) 153 | { 154 | if (m_debug_enabled) { 155 | std::cerr << "RX message received." << std::endl; 156 | } 157 | 158 | if (m_handler) { 159 | m_message_unpacker.reserve_buffer(msg.size()); 160 | memcpy(m_message_unpacker.buffer(), msg.data(), msg.size()); 161 | m_message_unpacker.buffer_consumed(msg.size()); 162 | 163 | msgpack::unpacked result; 164 | 165 | while (m_message_unpacker.next(result)) { 166 | wamp_message::message_fields fields; 167 | result.get().convert(fields); 168 | 169 | wamp_message message(std::move(fields), std::move(*(result.zone()))); 170 | if (m_debug_enabled) { 171 | std::cerr << "RX message: " << message << std::endl; 172 | } 173 | 174 | m_handler->on_message(std::move(message)); 175 | } 176 | } 177 | else { 178 | std::cerr << "RX message ignored: no handler attached" << std::endl; 179 | } 180 | } 181 | 182 | } //namespace autobahn 183 | -------------------------------------------------------------------------------- /autobahn/wamp_websocketpp_websocket_transport.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP 32 | #define AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP 33 | 34 | #include "boost_config.hpp" 35 | 36 | #ifdef _WIN32 37 | #ifdef _MSC_VER 38 | #pragma warning(disable:4996) //Windows XP cancel async IO always fails with operation_not_supported 39 | #endif 40 | //Recommended WebSocket++ settings for Windows 41 | #define _WEBSOCKETPP_CPP11_FUNCTIONAL_ 42 | #define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_ 43 | #define _WEBSOCKETPP_CPP11_RANDOM_DEVICE_ 44 | #define _WEBSOCKETPP_CPP11_MEMORY_ 45 | #define _WEBSOCKETPP_NOEXCEPT_ 46 | #endif 47 | 48 | 49 | #include "wamp_websocket_transport.hpp" 50 | 51 | 52 | #include 53 | #include 54 | 55 | namespace autobahn { 56 | 57 | /*! 58 | * A transport that provides websocket support using WebSocket++ https://github.com/zaphoyd/websocketpp 59 | */ 60 | template 61 | class wamp_websocketpp_websocket_transport : 62 | public wamp_websocket_transport 63 | { 64 | public: 65 | typedef websocketpp::client client_type; 66 | typedef boost::lock_guard scoped_lock; 67 | 68 | wamp_websocketpp_websocket_transport( 69 | client_type& client, 70 | const std::string& uri, 71 | bool debug_enabled = false); 72 | 73 | virtual ~wamp_websocketpp_websocket_transport() override; 74 | 75 | virtual bool is_connected() const override; 76 | 77 | private: 78 | virtual bool is_open() const override; 79 | virtual void close() override; 80 | virtual void async_connect(const std::string& uri, boost::promise& connect_promise) override; 81 | virtual void write(void const * payload, size_t len) override; 82 | 83 | private: 84 | 85 | void on_ws_open(websocketpp::connection_hdl); 86 | void on_ws_close(websocketpp::connection_hdl); 87 | void on_ws_fail(websocketpp::connection_hdl); 88 | void on_ws_message(websocketpp::connection_hdl, typename client_type::message_ptr msg); 89 | private: 90 | /*! 91 | * The underlying socket for the transport. 92 | */ 93 | client_type &m_client; 94 | 95 | websocketpp::connection_hdl m_hdl; 96 | boost::mutex m_lock; 97 | bool m_open; 98 | bool m_done; 99 | }; 100 | 101 | } // namespace autobahn 102 | 103 | #include "wamp_websocketpp_websocket_transport.ipp" 104 | #endif //AUTOBAHN_WEBSOCKETPP_WEBSOCKET_TRANSPORT_HPP -------------------------------------------------------------------------------- /autobahn/wamp_websocketpp_websocket_transport.ipp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors and contributors. 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "wamp_websocket_transport.hpp" 32 | 33 | #include 34 | #include 35 | 36 | namespace autobahn { 37 | 38 | template 39 | inline wamp_websocketpp_websocket_transport::wamp_websocketpp_websocket_transport( 40 | client_type& client, 41 | const std::string& uri, 42 | bool debug_enabled) 43 | : wamp_websocket_transport(uri, debug_enabled) 44 | , m_client(client) 45 | , m_hdl() 46 | , m_open(false) 47 | , m_done(false) 48 | { 49 | // Bind the handlers we are using 50 | using websocketpp::lib::placeholders::_1; 51 | using websocketpp::lib::placeholders::_2; 52 | using websocketpp::lib::bind; 53 | m_client.set_open_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_open, this, _1)); 54 | m_client.set_close_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_close, this, _1)); 55 | m_client.set_fail_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_fail, this, _1)); 56 | m_client.set_message_handler(bind(&wamp_websocketpp_websocket_transport::on_ws_message, this, _1, _2)); 57 | if(!debug_enabled) { 58 | m_client.clear_access_channels(websocketpp::log::alevel::all); 59 | } 60 | } 61 | 62 | template 63 | inline wamp_websocketpp_websocket_transport::~wamp_websocketpp_websocket_transport() 64 | { 65 | 66 | } 67 | 68 | template 69 | inline bool wamp_websocketpp_websocket_transport::is_open() const 70 | { 71 | return m_open; 72 | } 73 | 74 | template 75 | inline bool wamp_websocketpp_websocket_transport::is_connected() const 76 | { 77 | return is_open() && !m_done; 78 | } 79 | 80 | // The open handler will signal that we are ready to start sending telemetry 81 | template 82 | inline void wamp_websocketpp_websocket_transport::on_ws_open(websocketpp::connection_hdl) { 83 | scoped_lock guard(m_lock); 84 | m_open = true; 85 | 86 | //No handshake for websockets beyond declaring sub-protocol 87 | m_connect.set_value(); 88 | 89 | } 90 | 91 | template 92 | inline void wamp_websocketpp_websocket_transport::on_ws_close(websocketpp::connection_hdl hdl) { 93 | //Log "Connection closed!"); 94 | 95 | scoped_lock guard(m_lock); 96 | m_done = true; 97 | } 98 | 99 | template 100 | inline void wamp_websocketpp_websocket_transport::on_ws_fail(websocketpp::connection_hdl hdl) { 101 | //Log "Connection failed!"); 102 | if (!m_open) 103 | m_connect.set_exception(boost::copy_exception(network_error("failed to connect"))); 104 | 105 | scoped_lock guard(m_lock); 106 | m_done = true; 107 | } 108 | 109 | template 110 | inline void wamp_websocketpp_websocket_transport::on_ws_message(websocketpp::connection_hdl, typename client_type::message_ptr msg) { 111 | if (msg->get_opcode() == websocketpp::frame::opcode::binary) { 112 | receive_message(msg->get_payload()); 113 | } 114 | else { 115 | //m_messages.push_back("<< " + websocketpp::utility::to_hex(msg->get_payload())); 116 | } 117 | } 118 | 119 | template 120 | inline void wamp_websocketpp_websocket_transport::async_connect(const std::string& uri, boost::promise& connect_promise) 121 | { 122 | websocketpp::lib::error_code ec; 123 | typename client_type::connection_ptr con = m_client.get_connection(uri, ec); 124 | if (ec) { 125 | //Log "Get Connection Error: " + ec.message()); 126 | connect_promise.set_exception(boost::copy_exception(websocketpp::lib::system_error(ec.value(), ec.category(), "connect"))); 127 | return; 128 | } 129 | 130 | //TODO: need to abstract encoding and get subprotocol 131 | con->add_subprotocol("wamp.2.msgpack"); 132 | 133 | // Grab a handle for this connection so we can talk to it in a thread 134 | // safe manor after the event loop starts. 135 | m_hdl = con->get_handle(); 136 | 137 | // Queue the connection. No DNS queries or network connections will be 138 | // made until the io_service event loop is run. 139 | m_client.connect(con); 140 | } 141 | 142 | template 143 | inline void wamp_websocketpp_websocket_transport::write(void const * payload, size_t len) 144 | { 145 | websocketpp::lib::error_code ec; 146 | m_client.send(m_hdl, payload, len, websocketpp::frame::opcode::binary, ec); 147 | } 148 | 149 | template 150 | inline void wamp_websocketpp_websocket_transport::close() 151 | { 152 | m_client.close(m_hdl, websocketpp::close::status::normal, "disconnect"); 153 | } 154 | 155 | } // namespace autobahn 156 | -------------------------------------------------------------------------------- /cmake/Modules/FindBotan2.cmake: -------------------------------------------------------------------------------- 1 | if(MSVC OR MINGW) 2 | message(FATAL_ERROR "Using system Botan 2 library in Window not supported") 3 | endif() 4 | 5 | if(TARGET Botan2::Botan2) 6 | message(STATUS "Target Botan::Botan already exists. Skipping searching") 7 | return() 8 | endif() 9 | 10 | find_package(PkgConfig REQUIRED QUIET) 11 | find_package(PackageHandleStandardArgs REQUIRED QUIET) 12 | 13 | 14 | pkg_check_modules(Botan2 15 | botan-2 16 | ) 17 | 18 | find_library(Botan2_FullLibraryPath 19 | ${Botan2_LIBRARIES} 20 | PATHS ${Botan2_LIBRARY_DIRS} 21 | NO_DEFAULT_PATH 22 | ) 23 | 24 | find_package_handle_standard_args(Botan2 25 | REQUIRED_VARS Botan2_LIBRARIES Botan2_INCLUDE_DIRS 26 | VERSION_VAR Botan2_VERSION 27 | ) 28 | message("Botan2_INCLUDE_DIRS ${Botan2_INCLUDE_DIRS}") 29 | 30 | if(Botan2_FOUND) 31 | if(NOT TARGET Botan2::Botan2) 32 | add_library(Botan2::Botan2 33 | UNKNOWN IMPORTED GLOBAL 34 | ) 35 | set_target_properties(Botan2::Botan2 PROPERTIES 36 | INTERFACE_INCLUDE_DIRECTORIES ${Botan2_INCLUDE_DIRS} 37 | IMPORTED_LOCATION ${Botan2_FullLibraryPath} 38 | LINK_FLAGS ${Botan2_LDFLAGS_OTHER} 39 | ) 40 | endif() 41 | endif() 42 | -------------------------------------------------------------------------------- /cmake/Modules/FindMsgpack.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find msgpack 2 | # Once done this will define 3 | # msgpack_FOUND - System has msgpack 4 | # msgpack_INCLUDE_DIRS - The msgpack include directories 5 | 6 | set(_env "$ENV{MSGPACK_ROOT}") 7 | if(_env) 8 | 9 | set(msgpack_FOUND TRUE) 10 | set(msgpack_INCLUDE_DIRS "$ENV{MSGPACK_ROOT}/include") 11 | set(msgpack_LIBRARIES "$ENV{MSGPACK_ROOT}/libs") 12 | 13 | else() 14 | 15 | find_package(PkgConfig QUIET) 16 | 17 | if (PKG_CONFIG_FOUND) 18 | pkg_check_modules(PC_MSGPACK QUIET msgpack) 19 | endif (PKG_CONFIG_FOUND) 20 | 21 | find_path(msgpack_INCLUDE_DIR msgpack.hpp 22 | HINTS ${PC_MSGPACK_INCLUDEDIR} ${PC_MSGPACK_INCLUDE_DIRS}) 23 | 24 | set(msgpack_INCLUDE_DIRS ${msgpack_INCLUDE_DIR}) 25 | 26 | include(FindPackageHandleStandardArgs) 27 | # handle the QUIETLY and REQUIRED arguments and set Msgpack_FOUND to TRUE 28 | # if all listed variables are TRUE 29 | find_package_handle_standard_args(msgpack DEFAULT_MSG 30 | msgpack_INCLUDE_DIR 31 | msgpack_INCLUDE_DIRS) 32 | 33 | mark_as_advanced(msgpack_INCLUDE_DIR) 34 | 35 | endif() 36 | -------------------------------------------------------------------------------- /cmake/Modules/FindWebsocketpp.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find websocketpp 2 | # Once done this will define 3 | # websocketpp_FOUND - System has websocketpp 4 | # websocketpp_INCLUDE_DIRS - The websocketpp include directories 5 | 6 | set(_env "$ENV{WEBSOCKETPP_ROOT}") 7 | if(_env) 8 | 9 | set(websocketpp_FOUND TRUE) 10 | set(websocketpp_INCLUDE_DIRS "$ENV{WEBSOCKETPP_ROOT}/include") 11 | set(websocketpp_LIBRARIES "$ENV{WEBSOCKETPP_ROOT}/libs") 12 | 13 | else() 14 | 15 | find_package(PkgConfig QUIET) 16 | 17 | if (PKG_CONFIG_FOUND) 18 | pkg_check_modules(PC_WEBSOCKETPP QUIET websocketpp) 19 | endif (PKG_CONFIG_FOUND) 20 | 21 | find_path(websocketpp_INCLUDE_DIR websocketpp 22 | HINTS ${PC_WEBSOCKETPP_INCLUDEDIR} ${PC_WEBSOCKETPP_INCLUDE_DIRS}) 23 | 24 | set(websocketpp_INCLUDE_DIRS ${websocketpp_INCLUDE_DIR}) 25 | 26 | include(FindPackageHandleStandardArgs) 27 | # handle the QUIETLY and REQUIRED arguments and set websocketpp_FOUND to TRUE 28 | # if all listed variables are TRUE 29 | find_package_handle_standard_args(websocketpp DEFAULT_MSG 30 | websocketpp_INCLUDE_DIR 31 | websocketpp_INCLUDE_DIRS) 32 | 33 | mark_as_advanced(websocketpp_INCLUDE_DIR) 34 | 35 | endif() 36 | -------------------------------------------------------------------------------- /conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake, tools 2 | 3 | class autobahn_cppConan(ConanFile): 4 | name = "autobahn-cpp" 5 | version = "v20.8.1" 6 | license = "Boost Software License - Version 1.0 - August 17th, 2003" 7 | author = "Crossbar.io Technologies GmbH and contributors" 8 | description = "WAMP for C++ on Boost/ASIO" 9 | url = "https://github.com/crossbario/autobahn-cpp" 10 | requires = "boost/1.73.0","msgpack/3.2.1","websocketpp/0.8.2" 11 | generators = "cmake_find_package" 12 | scm = { 13 | "type": "git", 14 | "subfolder": ".", 15 | "url": "auto", 16 | "revision": "auto" 17 | } 18 | no_copy_source = True 19 | 20 | def package(self): 21 | self.copy("*.hpp", dst="include/autobahn", src="autobahn") 22 | self.copy("*.ipp", dst="include/autobahn", src="autobahn") 23 | 24 | def package_id(self): 25 | self.info.header_only() 26 | -------------------------------------------------------------------------------- /docker/Dockerfile.clang: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | MAINTAINER The Crossbar.io Project 4 | 5 | # Metadata 6 | ARG BUILD_DATE 7 | ARG AUTOBAHN_CPP_VERSION 8 | ARG AUTOBAHN_CPP_VCS_REF 9 | 10 | # Metadata labeling 11 | LABEL org.label-schema.build-date=$BUILD_DATE \ 12 | org.label-schema.name="AutobahnCpp Starter Template" \ 13 | org.label-schema.description="Quickstart template for application development with AutobahnCpp" \ 14 | org.label-schema.url="http://crossbar.io" \ 15 | org.label-schema.vcs-ref=$AUTOBAHN_CPP_VCS_REF \ 16 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-cpp" \ 17 | org.label-schema.vendor="The Crossbar.io Project" \ 18 | org.label-schema.version=$AUTOBAHN_CPP_VERSION \ 19 | org.label-schema.schema-version="1.0" 20 | 21 | # Crossbar.io connection defaults 22 | ENV CBURL ws://localhost:8080/ws 23 | ENV CBREALM realm1 24 | 25 | # user env 26 | ENV DEBIAN_FRONTEND noninteractive 27 | 28 | ENV HOME /autobahn 29 | ENV PATH /autobahn:$PATH 30 | ENV LD_LIBRARY_PATH /usr/local/lib 31 | 32 | # env vars to configure websocketpp 33 | ENV WSPP_ENABLE_CPP11 1 34 | 35 | # update system, get dev tools and libs 36 | RUN apt-get update \ 37 | && apt-get install -y wget curl unzip git-core \ 38 | clang libc++1 libc++-dev libc++abi-dev \ 39 | build-essential autotools-dev autoconf libtool cmake \ 40 | zlib1g-dev libbz2-dev libssl-dev \ 41 | libboost-all-dev \ 42 | && rm -rf /var/lib/apt/lists/* \ 43 | && apt-get clean 44 | 45 | # use clang, not gcc 46 | ENV CC /usr/bin/clang 47 | ENV CXX /usr/bin/clang++ 48 | RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 \ 49 | && update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100 \ 50 | && update-alternatives --query c++ \ 51 | && update-alternatives --query cc 52 | 53 | # get, build and install Boost from upstream 54 | # RUN cd /tmp \ 55 | # && wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2 \ 56 | # && tar xvjf boost_1_69_0.tar.bz2 57 | 58 | # RUN cd /tmp/boost_1_69_0 \ 59 | # && ./bootstrap.sh --with-toolset=clang \ 60 | # && ./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++" link=shared link=static threading=single threading=multi --layout=tagged --without-python -j 8 install \ 61 | # && cd / \ 62 | # && rm -rf /tmp/boost* 63 | 64 | # https://askubuntu.com/a/486184 65 | # RUN cd /usr/local/lib && \ 66 | # ln -s libboost_thread-mt.a libboost_thread.a 67 | 68 | # get, build and install msgpack-c from upstream 69 | RUN cd /tmp \ 70 | && wget https://github.com/msgpack/msgpack-c/archive/cpp-1.4.2.zip -O msgpack-c.zip \ 71 | && unzip msgpack-c.zip && cd msgpack-c-cpp-1.4.2 \ 72 | && export CXXFLAGS="$CXXFLAGS -std=c++11" \ 73 | && ./bootstrap && ./configure && make install \ 74 | && cd / && rm -rf /tmp/msgpack* 75 | 76 | # get and install websocketpp from upstream 77 | RUN cd /tmp \ 78 | && wget https://github.com/zaphoyd/websocketpp/archive/master.zip -O websocketpp.zip \ 79 | && unzip websocketpp.zip \ 80 | && cp -r /tmp/websocketpp-master/websocketpp/ /usr/local/include/ \ 81 | && cd / && rm -rf /tmp/websocketpp* 82 | 83 | # get and install cmake from upstream 84 | # RUN cd /tmp \ 85 | # && wget https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh \ 86 | # && sh cmake-3.11.0-Linux-x86_64.sh --skip-license --prefix=/usr/local \ 87 | # && which cmake && cmake --version 88 | 89 | #### all dependencies and tools are now in place 90 | 91 | 92 | # setup and build example project 93 | 94 | RUN mkdir -p /autobahn/build 95 | WORKDIR /autobahn 96 | 97 | COPY autobahn /autobahn/autobahn 98 | COPY examples /autobahn/examples 99 | COPY cmake /autobahn/cmake 100 | COPY cmake/Modules /autobahn/cmake/Modules 101 | COPY cmake/Includes /autobahn/cmake/Includes 102 | COPY CMakeLists.txt /autobahn/CMakeLists.txt 103 | 104 | RUN cd build \ 105 | && cmake .. \ 106 | && make -j4 \ 107 | && find examples/ -executable -type f -exec file {} \; 108 | 109 | 110 | # drop into shell by default 111 | 112 | CMD ["bash"] 113 | -------------------------------------------------------------------------------- /docker/Dockerfile.gcc: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | 3 | MAINTAINER The Crossbar.io Project 4 | 5 | # Metadata 6 | ARG BUILD_DATE 7 | ARG AUTOBAHN_CPP_VERSION 8 | ARG AUTOBAHN_CPP_VCS_REF 9 | 10 | # Metadata labeling 11 | LABEL org.label-schema.build-date=$BUILD_DATE \ 12 | org.label-schema.name="AutobahnCpp Starter Template" \ 13 | org.label-schema.description="Quickstart template for application development with AutobahnCpp" \ 14 | org.label-schema.url="http://crossbar.io" \ 15 | org.label-schema.vcs-ref=$AUTOBAHN_CPP_VCS_REF \ 16 | org.label-schema.vcs-url="https://github.com/crossbario/autobahn-cpp" \ 17 | org.label-schema.vendor="The Crossbar.io Project" \ 18 | org.label-schema.version=$AUTOBAHN_CPP_VERSION \ 19 | org.label-schema.schema-version="1.0" 20 | 21 | # Crossbar.io connection defaults 22 | ENV CBURL ws://localhost:8080/ws 23 | ENV CBREALM realm1 24 | 25 | # user env 26 | ENV DEBIAN_FRONTEND noninteractive 27 | 28 | ENV HOME /autobahn 29 | ENV PATH /autobahn:$PATH 30 | ENV LD_LIBRARY_PATH /usr/local/lib 31 | 32 | # env vars to configure websocketpp 33 | ENV WSPP_ENABLE_CPP11 1 34 | 35 | # update system, get dev tools and libs 36 | RUN apt-get update \ 37 | && apt-get install -y wget curl unzip git-core \ 38 | build-essential autotools-dev autoconf libtool cmake \ 39 | zlib1g-dev libbz2-dev libssl-dev \ 40 | libboost-all-dev \ 41 | && rm -rf /var/lib/apt/lists/* \ 42 | && apt-get clean 43 | 44 | # get, build and install Boost from upstream 45 | # RUN cd /tmp \ 46 | # && wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2 \ 47 | # && tar xvjf boost_1_69_0.tar.bz2 48 | 49 | # RUN cd /tmp/boost_1_69_0 \ 50 | # && ./bootstrap.sh --with-toolset=gcc \ 51 | # && ./b2 toolset=gcc link=shared link=static threading=single threading=multi --layout=tagged --without-python -j 8 install \ 52 | # && cd / \ 53 | # && rm -rf /tmp/boost* 54 | 55 | # https://askubuntu.com/a/486184 56 | # RUN cd /usr/local/lib && \ 57 | # ln -s libboost_thread-mt.a libboost_thread.a 58 | 59 | # get, build and install msgpack-c from upstream 60 | RUN cd /tmp \ 61 | && wget https://github.com/msgpack/msgpack-c/archive/cpp-1.4.2.zip -O msgpack-c.zip \ 62 | && unzip msgpack-c.zip && cd msgpack-c-cpp-1.4.2 \ 63 | && export CXXFLAGS="$CXXFLAGS -std=c++11" \ 64 | && ./bootstrap && ./configure && make install \ 65 | && cd / && rm -rf /tmp/msgpack* 66 | 67 | # get and install websocketpp from upstream 68 | RUN cd /tmp \ 69 | && wget https://github.com/zaphoyd/websocketpp/archive/master.zip -O websocketpp.zip \ 70 | && unzip websocketpp.zip \ 71 | && cp -r /tmp/websocketpp-master/websocketpp/ /usr/local/include/ \ 72 | && cd / && rm -rf /tmp/websocketpp* 73 | 74 | # get and install cmake from upstream 75 | # RUN cd /tmp \ 76 | # && wget https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh \ 77 | # && sh cmake-3.11.0-Linux-x86_64.sh --skip-license --prefix=/usr/local \ 78 | # && which cmake && cmake --version 79 | 80 | #### all dependencies and tools are now in place 81 | 82 | 83 | # setup and build example project 84 | 85 | RUN mkdir -p /autobahn/build 86 | WORKDIR /autobahn 87 | 88 | COPY autobahn /autobahn/autobahn 89 | COPY examples /autobahn/examples 90 | COPY cmake /autobahn/cmake 91 | COPY cmake/Modules /autobahn/cmake/Modules 92 | COPY cmake/Includes /autobahn/cmake/Includes 93 | COPY CMakeLists.txt /autobahn/CMakeLists.txt 94 | 95 | RUN cd build \ 96 | && cmake .. \ 97 | && make -j4 \ 98 | && find examples/ -executable -type f -exec file {} \; 99 | 100 | 101 | # drop into shell by default 102 | 103 | CMD ["bash"] 104 | -------------------------------------------------------------------------------- /docker/removeall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #docker stop $(docker ps -a -q) 4 | #docker rm $(docker ps -a -q) 5 | 6 | docker rmi -f $(docker images -q crossbario/autobahn-cpp*:* | uniq) 7 | -------------------------------------------------------------------------------- /docker/versions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # CHANGE FOR NEW RELEASES (these need to be proper Git tags in the respective repo): 5 | # 6 | export AUTOBAHN_CPP_VERSION='20.8.1' 7 | # 8 | # END OF CONFIG 9 | # 10 | 11 | # 12 | # Git working directories of all relevant repos must reside 13 | # in parallel (as siblings) to this repository 14 | # 15 | export AUTOBAHN_CPP_VCS_REF=`git --git-dir=".git" rev-list -n 1 v${AUTOBAHN_CPP_VERSION} --abbrev-commit` 16 | export BUILD_DATE=`date -u +"%Y-%m-%d"` 17 | 18 | echo "" 19 | echo "The Crossbar.io Project (build date ${BUILD_DATE})" 20 | echo "" 21 | echo "autobahn-cpp ${AUTOBAHN_CPP_VERSION} [${AUTOBAHN_CPP_VCS_REF}]" 22 | echo "" 23 | -------------------------------------------------------------------------------- /examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (!APPLE) 2 | set(CMAKE_EXE_LINKER_FLAGS " -static") 3 | endif() 4 | 5 | add_library(examples_parameters parameters.cpp parameters.hpp) 6 | target_include_directories(examples_parameters PUBLIC ${Boost_INCLUDE_DIRS}) 7 | target_link_libraries(examples_parameters PRIVATE ${Boost_LIBRARIES}) 8 | target_compile_definitions(examples_parameters PRIVATE ${Boost_DEFINITIONS}) 9 | 10 | function(make_example name src) 11 | add_executable(${name} ${src} ${PUBLIC_HEADERS}) 12 | target_link_libraries(${name} examples_parameters autobahn_cpp) 13 | endfunction() 14 | 15 | make_example(caller caller.cpp) 16 | make_example(callee callee.cpp) 17 | make_example(provide_prefix provide_prefix.cpp) 18 | make_example(publisher publisher.cpp) 19 | make_example(subscriber subscriber.cpp) 20 | make_example(wampcra wampcra.cpp) 21 | make_example(websocket_callee websocket_callee.cpp) 22 | make_example(cryptosign-openssl cryptosign-openssl.cpp) 23 | if (AUTOBAHN_BUILD_EXAMPLES_BOTAN) 24 | find_package(Botan2 REQUIRED) 25 | make_example(cryptosign-botan cryptosign-botan.cpp) 26 | target_include_directories(cryptosign-botan PRIVATE ${BOTAN_INCLUDE_DIRS}) 27 | target_link_libraries(cryptosign-botan Botan2::Botan2) 28 | endif() 29 | 30 | if(UNIX) 31 | make_example(uds uds.cpp) 32 | endif() 33 | 34 | # By default MSVC has a 2^16 limit on the number of sections in an object file, 35 | # and this needs more than that. 36 | if (MSVC) 37 | set_source_files_properties(websocket_callee.cpp PROPERTIES COMPILE_FLAGS /bigobj) 38 | endif() 39 | -------------------------------------------------------------------------------- /examples/callee_new.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | 16 | void log (const std::string& msg) { 17 | std::cerr << msg << " [thread " << boost::this_thread::get_id() << "]" << std::endl; 18 | } 19 | 20 | 21 | void add2(autobahn::wamp_invocation invocation) 22 | { 23 | auto a = invocation->argument(0); 24 | auto b = invocation->argument(1); 25 | 26 | std::ostringstream oss; 27 | oss << "Procedure com.examples.calculator.add2 invoked: " << a << ", " << b << std::endl; 28 | log(oss.str()); 29 | 30 | invocation->result(std::make_tuple(a + b)); 31 | } 32 | 33 | 34 | void longop(autobahn::wamp_invocation invocation) 35 | { 36 | auto a = invocation->argument(0); 37 | 38 | std::ostringstream oss; 39 | oss << "Procedure com.myapp.longop invoked: " << a << std::endl; 40 | log(oss.str()); 41 | 42 | uint64_t i = 0; 43 | for (; i < a; i++) 44 | { 45 | boost::this_thread::sleep(boost::posix_time::milliseconds(3000)); 46 | if (i < a) 47 | { 48 | invocation->progress(std::make_tuple(i)); 49 | } 50 | } 51 | invocation->result(std::make_tuple(i)); 52 | } 53 | 54 | 55 | int main(int argc, char** argv) 56 | { 57 | if (argc != 3) { 58 | std::cerr << "Usage: callee " << std::endl; 59 | return -1; 60 | } 61 | 62 | try { 63 | log("starting program .."); 64 | log(argv[1]); 65 | log(argv[1]); 66 | 67 | boost::asio::io_service io; 68 | 69 | bool debug = true; 70 | 71 | // Make sure the continuation futures we use do not run out of scope prematurely. 72 | // Since we are only using one thread here this can cause the io service to block 73 | // as a future generated by a continuation will block waiting for its promise to be 74 | // fulfilled when it goes out of scope. This would prevent the session from receiving 75 | // responses from the router. 76 | boost::future f1, f2, f3; 77 | 78 | auto endpoint = boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(argv[1]), atoi(argv[2])); 79 | 80 | auto transport = std::make_shared(io, endpoint, debug); 81 | 82 | auto session = std::make_shared(io, debug); 83 | 84 | transport->attach(std::static_pointer_cast(session)); 85 | 86 | f1 = transport->connect().then([&](boost::future connected) { 87 | 88 | connected.get(); 89 | 90 | log("transport connected"); 91 | 92 | f2 = session->start().then(boost::launch::deferred, [&](boost::future started) { 93 | 94 | started.get(); 95 | 96 | log("session started"); 97 | 98 | f3 = session->join("realm1").then(boost::launch::deferred, [&](boost::future joined) { 99 | 100 | joined.get(); 101 | 102 | log("joined realm"); 103 | 104 | auto f4 = session->provide("com.examples.calculator.add2", &add2).then( 105 | boost::launch::deferred, 106 | [&](boost::future registration) { 107 | log("registered procedure com.examples.calculator.add2"); 108 | }); 109 | 110 | auto f5 = session->provide("com.myapp.longop", &longop).then( 111 | boost::launch::deferred, 112 | [&](boost::future registration) { 113 | log("registered procedure com.myapp.longop"); 114 | }); 115 | 116 | f5.get(); 117 | f4.get(); 118 | }); 119 | f3.get(); 120 | 121 | }); 122 | f2.get(); 123 | }); 124 | 125 | log("starting io service .."); 126 | io.run(); 127 | log("stopped io service"); 128 | } 129 | catch (const std::exception& e) { 130 | log(e.what()); 131 | return -1; 132 | } 133 | 134 | return 0; 135 | } 136 | -------------------------------------------------------------------------------- /examples/caller.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "parameters.hpp" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int main(int argc, char** argv) 43 | { 44 | std::cerr << "Boost: " << BOOST_VERSION << std::endl; 45 | 46 | try { 47 | auto parameters = get_parameters(argc, argv); 48 | 49 | boost::asio::io_service io; 50 | bool debug = parameters->debug(); 51 | auto transport = std::make_shared( 52 | io, parameters->rawsocket_endpoint(), debug); 53 | 54 | auto session = std::make_shared(io, debug); 55 | 56 | transport->attach(std::static_pointer_cast(session)); 57 | 58 | // Make sure the continuation futures we use do not run out of scope prematurely. 59 | // Since we are only using one thread here this can cause the io service to block 60 | // as a future generated by a continuation will block waiting for its promise to be 61 | // fulfilled when it goes out of scope. This would prevent the session from receiving 62 | // responses from the router. 63 | boost::future connect_future; 64 | boost::future start_future; 65 | boost::future join_future; 66 | boost::future call_future; 67 | boost::future leave_future; 68 | boost::future stop_future; 69 | 70 | connect_future = transport->connect().then([&](boost::future connected) { 71 | try { 72 | connected.get(); 73 | } catch (const std::exception& e) { 74 | std::cerr << e.what() << std::endl; 75 | io.stop(); 76 | return; 77 | } 78 | std::cerr << "transport connected" << std::endl; 79 | 80 | start_future = session->start().then([&](boost::future started) { 81 | try { 82 | started.get(); 83 | } catch (const std::exception& e) { 84 | std::cerr << e.what() << std::endl; 85 | io.stop(); 86 | return; 87 | } 88 | 89 | std::cerr << "session started" << std::endl; 90 | 91 | join_future = session->join(parameters->realm()).then([&](boost::future joined) { 92 | try { 93 | std::cerr << "joined realm: " << joined.get() << std::endl; 94 | } catch (const std::exception& e) { 95 | std::cerr << e.what() << std::endl; 96 | io.stop(); 97 | return; 98 | } 99 | 100 | autobahn::wamp_call_options call_options; 101 | call_options.set_timeout(std::chrono::seconds(10)); 102 | 103 | std::tuple arguments(23, 777); 104 | call_future = session->call("com.examples.calculator.add2", arguments, call_options).then( 105 | [&](boost::future result) { 106 | try { 107 | uint64_t sum = result.get().argument(0); 108 | std::cerr << "call result: " << sum << std::endl; 109 | } catch (const std::exception& e) { 110 | std::cerr << "call failed: " << e.what() << std::endl; 111 | io.stop(); 112 | return; 113 | } 114 | 115 | leave_future = session->leave().then([&](boost::future reason) { 116 | try { 117 | std::cerr << "left session (" << reason.get() << ")" << std::endl; 118 | } catch (const std::exception& e) { 119 | std::cerr << "failed to leave session: " << e.what() << std::endl; 120 | io.stop(); 121 | return; 122 | } 123 | 124 | stop_future = session->stop().then([&](boost::future stopped) { 125 | std::cerr << "stopped session" << std::endl; 126 | io.stop(); 127 | }); 128 | }); 129 | }); 130 | }); 131 | }); 132 | }); 133 | 134 | std::cerr << "starting io service" << std::endl; 135 | io.run(); 136 | std::cerr << "stopped io service" << std::endl; 137 | 138 | transport->detach(); 139 | } 140 | catch (const std::exception& e) { 141 | std::cerr << e.what() << std::endl; 142 | return 1; 143 | } 144 | 145 | return 0; 146 | } 147 | -------------------------------------------------------------------------------- /examples/parameters.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "parameters.hpp" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | namespace { 39 | const std::string LOCALHOST_IP_ADDRESS_STRING("127.0.0.1"); 40 | const boost::asio::ip::address LOCALHOST_IP_ADDRESS( 41 | boost::asio::ip::address::from_string(LOCALHOST_IP_ADDRESS_STRING)); 42 | const std::string DEFAULT_REALM("realm1"); 43 | const uint16_t DEFAULT_RAWSOCKET_PORT(8000); 44 | const std::string DEFAULT_UDS_PATH("/tmp/crossbar.sock"); 45 | } 46 | 47 | parameters::parameters() 48 | : m_debug(false) 49 | , m_realm(DEFAULT_REALM) 50 | , m_rawsocket_endpoint(LOCALHOST_IP_ADDRESS, DEFAULT_RAWSOCKET_PORT) 51 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 52 | , m_uds_endpoint(DEFAULT_UDS_PATH) 53 | #endif 54 | { 55 | } 56 | 57 | bool parameters::debug() const 58 | { 59 | return m_debug; 60 | } 61 | 62 | const std::string& parameters::realm() const 63 | { 64 | return m_realm; 65 | } 66 | 67 | const boost::asio::ip::tcp::endpoint& parameters::rawsocket_endpoint() const 68 | { 69 | return m_rawsocket_endpoint; 70 | } 71 | 72 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 73 | const boost::asio::local::stream_protocol::endpoint& parameters::uds_endpoint() const 74 | { 75 | return m_uds_endpoint; 76 | } 77 | #endif 78 | 79 | void parameters::set_debug(bool value) 80 | { 81 | m_debug = value; 82 | } 83 | 84 | void parameters::set_realm(const std::string& realm) 85 | { 86 | m_realm = realm; 87 | } 88 | 89 | void parameters::set_rawsocket_endpoint(const std::string& ip_address, uint16_t port) 90 | { 91 | m_rawsocket_endpoint = boost::asio::ip::tcp::endpoint( 92 | boost::asio::ip::address::from_string(ip_address), port); 93 | } 94 | 95 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 96 | void parameters::set_uds_endpoint(const std::string& path) 97 | { 98 | m_uds_endpoint = boost::asio::local::stream_protocol::endpoint(path); 99 | } 100 | #endif 101 | 102 | std::unique_ptr get_parameters(int argc, char** argv) 103 | { 104 | std::unique_ptr params(new parameters); 105 | 106 | namespace po = boost::program_options; 107 | po::options_description description("options"); 108 | description.add_options() 109 | ("help", "Display this help message") 110 | ("debug,d", po::bool_switch()->default_value(false), 111 | "Enable debug logging.") 112 | ("realm,r", po::value()->default_value(DEFAULT_REALM), 113 | "The realm to join on the wamp router.") 114 | ("uds-path,u", po::value()->default_value(DEFAULT_UDS_PATH), 115 | "The unix domain socket path the wamp router is listening for connections on.") 116 | ("rawsocket-ip,h", po::value()->default_value(LOCALHOST_IP_ADDRESS_STRING), 117 | "The ip address of the host running the wamp router.") 118 | ("rawsocket-port,p", po::value()->default_value(DEFAULT_RAWSOCKET_PORT), 119 | "The port that the wamp router is listening for connections on."); 120 | 121 | po::variables_map variables; 122 | try { 123 | po::store(po::parse_command_line(argc, argv, description), variables); 124 | 125 | if (variables.count("help")) { 126 | std::cout << "Example Parameters" << std::endl 127 | << description << std::endl; 128 | exit(0); 129 | } 130 | 131 | po::notify(variables); 132 | } catch(po::error& e) { 133 | std::cerr << "error: " << e.what() << std::endl << std::endl; 134 | std::cerr << description << std::endl; 135 | exit(-1); 136 | } 137 | 138 | params->set_debug(variables["debug"].as()); 139 | params->set_realm(variables["realm"].as()); 140 | params->set_rawsocket_endpoint( 141 | variables["rawsocket-ip"].as(), 142 | variables["rawsocket-port"].as()); 143 | 144 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 145 | params->set_uds_endpoint( 146 | variables["uds-path"].as()); 147 | #endif 148 | return params; 149 | } 150 | -------------------------------------------------------------------------------- /examples/parameters.hpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #ifndef EXAMPLES_PARAMETERS_HPP 32 | #define EXAMPLES_PARAMETERS_HPP 33 | 34 | #include 35 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 36 | # include 37 | #endif 38 | #include 39 | #include 40 | 41 | class parameters 42 | { 43 | public: 44 | parameters(); 45 | 46 | bool debug() const; 47 | const std::string& realm() const; 48 | const boost::asio::ip::tcp::endpoint& rawsocket_endpoint() const; 49 | 50 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 51 | void set_uds_endpoint(const std::string& path); 52 | const boost::asio::local::stream_protocol::endpoint& uds_endpoint() const; 53 | #endif 54 | 55 | void set_debug(bool enabled); 56 | void set_realm(const std::string& realm); 57 | void set_rawsocket_endpoint(const std::string& ip_address, uint16_t port); 58 | private: 59 | bool m_debug; 60 | std::string m_realm; 61 | boost::asio::ip::tcp::endpoint m_rawsocket_endpoint; 62 | #ifdef BOOST_ASIO_HAS_LOCAL_SOCKETS 63 | boost::asio::local::stream_protocol::endpoint m_uds_endpoint; 64 | #endif 65 | }; 66 | 67 | std::unique_ptr get_parameters(int argc, char** argv); 68 | 69 | #endif // EXAMPLES_PARAMETERS_HPP 70 | -------------------------------------------------------------------------------- /examples/projects/VS2015/autobahn-cpp-examples.vs2015.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wampcra", "wampcra.vcxproj", "{4357F288-DC34-40E3-9AAA-80C1E3EFD633}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "autobahn-cpp", "autobahn-cpp.vcxproj", "{94DB2E6B-5051-43EB-A4BD-D41F4D70D597}" 9 | EndProject 10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "callee", "callee.vcxproj", "{5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "caller", "caller.vcxproj", "{BF87E140-28C2-41F8-BF65-7776DD215B87}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "publisher", "publisher.vcxproj", "{352DB303-2BBA-4C01-B22F-35A1196FDE4C}" 15 | EndProject 16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "subscriber", "subscriber.vcxproj", "{62501761-0470-453F-99BC-36FC69B339FA}" 17 | EndProject 18 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "provide_prefix", "provide_prefix.vcxproj", "{B18D21E0-843C-4AC5-8365-495BED662808}" 19 | EndProject 20 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "websocket", "websocket.vcxproj", "{DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|x64 = Debug|x64 25 | Debug|x86 = Debug|x86 26 | Release|x64 = Release|x64 27 | Release|x86 = Release|x86 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x64.ActiveCfg = Debug|x64 31 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x64.Build.0 = Debug|x64 32 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x86.ActiveCfg = Debug|Win32 33 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Debug|x86.Build.0 = Debug|Win32 34 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x64.ActiveCfg = Release|x64 35 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x64.Build.0 = Release|x64 36 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x86.ActiveCfg = Release|Win32 37 | {4357F288-DC34-40E3-9AAA-80C1E3EFD633}.Release|x86.Build.0 = Release|Win32 38 | {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Debug|x64.ActiveCfg = Release|Win32 39 | {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Debug|x86.ActiveCfg = Release|Win32 40 | {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Release|x64.ActiveCfg = Release|Win32 41 | {94DB2E6B-5051-43EB-A4BD-D41F4D70D597}.Release|x86.ActiveCfg = Release|Win32 42 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x64.ActiveCfg = Debug|x64 43 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x64.Build.0 = Debug|x64 44 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x86.ActiveCfg = Debug|Win32 45 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Debug|x86.Build.0 = Debug|Win32 46 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x64.ActiveCfg = Release|x64 47 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x64.Build.0 = Release|x64 48 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x86.ActiveCfg = Release|Win32 49 | {5D930CE9-EC02-4F5F-AEC9-D790E6D40DBE}.Release|x86.Build.0 = Release|Win32 50 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x64.ActiveCfg = Debug|x64 51 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x64.Build.0 = Debug|x64 52 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x86.ActiveCfg = Debug|Win32 53 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Debug|x86.Build.0 = Debug|Win32 54 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x64.ActiveCfg = Release|x64 55 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x64.Build.0 = Release|x64 56 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x86.ActiveCfg = Release|Win32 57 | {BF87E140-28C2-41F8-BF65-7776DD215B87}.Release|x86.Build.0 = Release|Win32 58 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x64.ActiveCfg = Debug|x64 59 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x64.Build.0 = Debug|x64 60 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x86.ActiveCfg = Debug|Win32 61 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Debug|x86.Build.0 = Debug|Win32 62 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x64.ActiveCfg = Release|x64 63 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x64.Build.0 = Release|x64 64 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x86.ActiveCfg = Release|Win32 65 | {352DB303-2BBA-4C01-B22F-35A1196FDE4C}.Release|x86.Build.0 = Release|Win32 66 | {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x64.ActiveCfg = Debug|x64 67 | {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x64.Build.0 = Debug|x64 68 | {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x86.ActiveCfg = Debug|Win32 69 | {62501761-0470-453F-99BC-36FC69B339FA}.Debug|x86.Build.0 = Debug|Win32 70 | {62501761-0470-453F-99BC-36FC69B339FA}.Release|x64.ActiveCfg = Release|x64 71 | {62501761-0470-453F-99BC-36FC69B339FA}.Release|x64.Build.0 = Release|x64 72 | {62501761-0470-453F-99BC-36FC69B339FA}.Release|x86.ActiveCfg = Release|Win32 73 | {62501761-0470-453F-99BC-36FC69B339FA}.Release|x86.Build.0 = Release|Win32 74 | {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x64.ActiveCfg = Debug|x64 75 | {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x64.Build.0 = Debug|x64 76 | {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x86.ActiveCfg = Debug|Win32 77 | {B18D21E0-843C-4AC5-8365-495BED662808}.Debug|x86.Build.0 = Debug|Win32 78 | {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x64.ActiveCfg = Release|x64 79 | {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x64.Build.0 = Release|x64 80 | {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x86.ActiveCfg = Release|Win32 81 | {B18D21E0-843C-4AC5-8365-495BED662808}.Release|x86.Build.0 = Release|Win32 82 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x64.ActiveCfg = Debug|x64 83 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x64.Build.0 = Debug|x64 84 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x86.ActiveCfg = Debug|Win32 85 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Debug|x86.Build.0 = Debug|Win32 86 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x64.ActiveCfg = Release|x64 87 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x64.Build.0 = Release|x64 88 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x86.ActiveCfg = Release|Win32 89 | {DF547C71-C634-4F5F-81AE-C0FF0E2A0F73}.Release|x86.Build.0 = Release|Win32 90 | EndGlobalSection 91 | GlobalSection(SolutionProperties) = preSolution 92 | HideSolutionNode = FALSE 93 | EndGlobalSection 94 | EndGlobal 95 | -------------------------------------------------------------------------------- /examples/publisher.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "parameters.hpp" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int main(int argc, char** argv) 43 | { 44 | std::cerr << "Boost: " << BOOST_VERSION << std::endl; 45 | 46 | try { 47 | auto parameters = get_parameters(argc, argv); 48 | 49 | boost::asio::io_service io; 50 | bool debug = parameters->debug(); 51 | 52 | auto transport = std::make_shared( 53 | io, parameters->rawsocket_endpoint(), debug); 54 | 55 | // create a WAMP session that talks WAMP-RawSocket over TCP 56 | // 57 | auto session = std::make_shared(io, debug); 58 | 59 | transport->attach(std::static_pointer_cast(session)); 60 | 61 | // Make sure the continuation futures we use do not run out of scope prematurely. 62 | // Since we are only using one thread here this can cause the io service to block 63 | // as a future generated by a continuation will block waiting for its promise to be 64 | // fulfilled when it goes out of scope. This would prevent the session from receiving 65 | // responses from the router. 66 | boost::future connect_future; 67 | boost::future start_future; 68 | boost::future join_future; 69 | boost::future leave_future; 70 | boost::future stop_future; 71 | 72 | connect_future = transport->connect().then([&](boost::future connected) { 73 | try { 74 | connected.get(); 75 | } catch (const std::exception& e) { 76 | std::cerr << e.what() << std::endl; 77 | io.stop(); 78 | return; 79 | } 80 | 81 | std::cerr << "transport connected" << std::endl; 82 | 83 | start_future = session->start().then([&](boost::future started) { 84 | try { 85 | started.get(); 86 | } catch (const std::exception& e) { 87 | std::cerr << e.what() << std::endl; 88 | io.stop(); 89 | return; 90 | } 91 | 92 | std::cerr << "session started" << std::endl; 93 | 94 | join_future = session->join(parameters->realm()).then([&](boost::future joined) { 95 | try { 96 | std::cerr << "joined realm: " << joined.get() << std::endl; 97 | } catch (const std::exception& e) { 98 | std::cerr << e.what() << std::endl; 99 | io.stop(); 100 | return; 101 | } 102 | 103 | std::tuple arguments(std::string("hello")); 104 | session->publish("com.examples.subscriptions.topic1", arguments); 105 | std::cerr << "event published" << std::endl; 106 | 107 | leave_future = session->leave().then([&](boost::future reason) { 108 | try { 109 | std::cerr << "left session (" << reason.get() << ")" << std::endl; 110 | } catch (const std::exception& e) { 111 | std::cerr << "failed to leave session: " << e.what() << std::endl; 112 | io.stop(); 113 | return; 114 | } 115 | 116 | stop_future = session->stop().then([&](boost::future stopped) { 117 | std::cerr << "stopped session" << std::endl; 118 | io.stop(); 119 | }); 120 | }); 121 | }); 122 | }); 123 | }); 124 | 125 | std::cerr << "starting io service" << std::endl; 126 | io.run(); 127 | std::cerr << "stopped io service" << std::endl; 128 | 129 | transport->detach(); 130 | } 131 | catch (const std::exception& e) { 132 | std::cerr << "exception: " << e.what() << std::endl; 133 | return 1; 134 | } 135 | return 0; 136 | } 137 | -------------------------------------------------------------------------------- /examples/subscriber.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "parameters.hpp" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | void on_topic1(const autobahn::wamp_event& event) 40 | { 41 | std::cerr << "received event: " << event->argument(0) << std::endl; 42 | } 43 | 44 | int main(int argc, char** argv) 45 | { 46 | std::cerr << "Boost: " << BOOST_VERSION << std::endl; 47 | 48 | try { 49 | auto parameters = get_parameters(argc, argv); 50 | 51 | std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; 52 | 53 | boost::asio::io_service io; 54 | bool debug = parameters->debug(); 55 | 56 | auto transport = std::make_shared( 57 | io, parameters->rawsocket_endpoint(), debug); 58 | 59 | // create a WAMP session that talks WAMP-RawSocket over TCP 60 | // 61 | auto session = std::make_shared(io, debug); 62 | 63 | transport->attach(std::static_pointer_cast(session)); 64 | 65 | // Make sure the continuation futures we use do not run out of scope prematurely. 66 | // Since we are only using one thread here this can cause the io service to block 67 | // as a future generated by a continuation will block waiting for its promise to be 68 | // fulfilled when it goes out of scope. This would prevent the session from receiving 69 | // responses from the router. 70 | boost::future connect_future; 71 | boost::future start_future; 72 | boost::future join_future; 73 | boost::future subscribe_future; 74 | connect_future = transport->connect().then([&](boost::future connected) { 75 | try { 76 | connected.get(); 77 | } catch (const std::exception& e) { 78 | std::cerr << e.what() << std::endl; 79 | io.stop(); 80 | return; 81 | } 82 | 83 | std::cerr << "transport connected" << std::endl; 84 | 85 | start_future = session->start().then([&](boost::future started) { 86 | try { 87 | started.get(); 88 | } catch (const std::exception& e) { 89 | std::cerr << e.what() << std::endl; 90 | io.stop(); 91 | return; 92 | } 93 | 94 | std::cerr << "session started" << std::endl; 95 | 96 | join_future = session->join(parameters->realm()).then([&](boost::future joined) { 97 | try { 98 | std::cerr << "joined realm: " << joined.get() << std::endl; 99 | } catch (const std::exception& e) { 100 | std::cerr << e.what() << std::endl; 101 | io.stop(); 102 | return; 103 | } 104 | 105 | subscribe_future = session->subscribe("com.examples.subscriptions.topic1", &on_topic1).then([&] (boost::future subscribed) 106 | { 107 | try { 108 | 109 | std::cerr << "subscribed to topic: " << subscribed.get().id() << std::endl; 110 | } 111 | catch (const std::exception& e) { 112 | std::cerr << e.what() << std::endl; 113 | io.stop(); 114 | return; 115 | } 116 | 117 | }); 118 | 119 | 120 | }); 121 | }); 122 | }); 123 | 124 | std::cerr << "starting io service" << std::endl; 125 | io.run(); 126 | std::cerr << "stopped io service" << std::endl; 127 | } 128 | catch (std::exception& e) { 129 | std::cerr << "exception: " << e.what() << std::endl; 130 | return 1; 131 | } 132 | return 0; 133 | } 134 | -------------------------------------------------------------------------------- /examples/uds.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "parameters.hpp" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | int main(int argc, char** argv) 43 | { 44 | std::cerr << "Boost: " << BOOST_VERSION << std::endl; 45 | 46 | try { 47 | auto parameters = get_parameters(argc, argv); 48 | 49 | boost::asio::io_service io; 50 | bool debug = parameters->debug(); 51 | 52 | auto transport = std::make_shared( 53 | io, parameters->uds_endpoint(), debug); 54 | 55 | auto session = std::make_shared(io, debug); 56 | 57 | transport->attach(std::static_pointer_cast(session)); 58 | 59 | // Make sure the continuation futures we use do not run out of scope prematurely. 60 | // Since we are only using one thread here this can cause the io service to block 61 | // as a future generated by a continuation will block waiting for its promise to be 62 | // fulfilled when it goes out of scope. This would prevent the session from receiving 63 | // responses from the router. 64 | boost::future connect_future; 65 | boost::future start_future; 66 | boost::future join_future; 67 | boost::future call_future; 68 | boost::future leave_future; 69 | boost::future stop_future; 70 | 71 | connect_future = transport->connect().then([&](boost::future connected) { 72 | try { 73 | connected.get(); 74 | } catch (const std::exception& e) { 75 | std::cerr << e.what() << std::endl; 76 | io.stop(); 77 | return; 78 | } 79 | std::cerr << "transport connected" << std::endl; 80 | 81 | start_future = session->start().then([&](boost::future started) { 82 | try { 83 | started.get(); 84 | } catch (const std::exception& e) { 85 | std::cerr << e.what() << std::endl; 86 | io.stop(); 87 | return; 88 | } 89 | 90 | std::cerr << "session started" << std::endl; 91 | 92 | join_future = session->join(parameters->realm()).then([&](boost::future joined) { 93 | try { 94 | std::cerr << "joined realm: " << joined.get() << std::endl; 95 | } catch (const std::exception& e) { 96 | std::cerr << e.what() << std::endl; 97 | io.stop(); 98 | return; 99 | } 100 | 101 | leave_future = session->leave().then([&](boost::future reason) { 102 | try { 103 | std::cerr << "left session (" << reason.get() << ")" << std::endl; 104 | } catch (const std::exception& e) { 105 | std::cerr << "failed to leave session: " << e.what() << std::endl; 106 | io.stop(); 107 | return; 108 | } 109 | 110 | stop_future = session->stop().then([&](boost::future stopped) { 111 | std::cerr << "stopped session" << std::endl; 112 | io.stop(); 113 | }); 114 | }); 115 | }); 116 | }); 117 | }); 118 | 119 | std::cerr << "starting io service" << std::endl; 120 | io.run(); 121 | std::cerr << "stopped io service" << std::endl; 122 | 123 | transport->detach(); 124 | } 125 | catch (const std::exception& e) { 126 | std::cerr << e.what() << std::endl; 127 | return 1; 128 | } 129 | 130 | return 0; 131 | } 132 | -------------------------------------------------------------------------------- /examples/websocket_callee.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // Copyright (c) Crossbar.io Technologies GmbH and contributors 4 | // 5 | // Boost Software License - Version 1.0 - August 17th, 2003 6 | // 7 | // Permission is hereby granted, free of charge, to any person or organization 8 | // obtaining a copy of the software and accompanying documentation covered by 9 | // this license (the "Software") to use, reproduce, display, distribute, 10 | // execute, and transmit the Software, and to prepare derivative works of the 11 | // Software, and to permit third-parties to whom the Software is furnished to 12 | // do so, all subject to the following: 13 | // 14 | // The copyright notices in the Software and this entire statement, including 15 | // the above license grant, this restriction and the following disclaimer, 16 | // must be included in all copies of the Software, in whole or in part, and 17 | // all derivative works of the Software, unless such copies or derivative 18 | // works are solely in the form of machine-executable object code generated by 19 | // a source language processor. 20 | // 21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 24 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 25 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 26 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | // DEALINGS IN THE SOFTWARE. 28 | // 29 | /////////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "parameters.hpp" 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | void add2(autobahn::wamp_invocation invocation) 44 | { 45 | auto a = invocation->argument(0); 46 | auto b = invocation->argument(1); 47 | 48 | std::cerr << "Procedure com.examples.calculator.add2 invoked: " << a << ", " << b << std::endl; 49 | 50 | invocation->result(std::make_tuple(a + b)); 51 | } 52 | 53 | typedef websocketpp::client client; 54 | 55 | int main(int argc, char** argv) 56 | { 57 | std::cerr << "Boost: " << BOOST_VERSION << std::endl; 58 | try { 59 | auto parameters = get_parameters(argc, argv); 60 | 61 | std::cerr << "Connecting to realm: " << parameters->realm() << std::endl; 62 | 63 | boost::asio::io_service io; 64 | bool debug = parameters->debug(); 65 | 66 | client ws_clinet; 67 | ws_clinet.init_asio(&io); 68 | auto transport = std::make_shared < autobahn::wamp_websocketpp_websocket_transport >( 69 | ws_clinet, "ws://127.0.0.1:8080/ws", debug); 70 | 71 | 72 | auto session = std::make_shared(io, debug); 73 | 74 | // Create a thread to run the telemetry loop 75 | transport->attach(std::static_pointer_cast(session)); 76 | 77 | // Make sure the continuation futures we use do not run out of scope prematurely. 78 | // Since we are only using one thread here this can cause the io service to block 79 | // as a future generated by a continuation will block waiting for its promise to be 80 | // fulfilled when it goes out of scope. This would prevent the session from receiving 81 | // responses from the router. 82 | boost::future connect_future; 83 | boost::future start_future; 84 | boost::future join_future; 85 | boost::future provide_future; 86 | 87 | connect_future = transport->connect().then([&](boost::future connected) { 88 | try { 89 | connected.get(); 90 | } catch (const std::exception& e) { 91 | std::cerr << e.what() << std::endl; 92 | io.stop(); 93 | return; 94 | } 95 | 96 | std::cerr << "transport connected" << std::endl; 97 | 98 | start_future = session->start().then([&](boost::future started) { 99 | try { 100 | started.get(); 101 | } catch (const std::exception& e) { 102 | std::cerr << e.what() << std::endl; 103 | io.stop(); 104 | return; 105 | } 106 | 107 | std::cerr << "session started" << std::endl; 108 | 109 | join_future = session->join(parameters->realm()).then([&](boost::future joined) { 110 | try { 111 | std::cerr << "joined realm: " << joined.get() << std::endl; 112 | } catch (const std::exception& e) { 113 | std::cerr << e.what() << std::endl; 114 | io.stop(); 115 | return; 116 | } 117 | 118 | provide_future = session->provide("com.examples.calculator.add2", &add2).then( 119 | [&](boost::future registration) { 120 | try { 121 | std::cerr << "registered procedure:" << registration.get().id() << std::endl; 122 | } catch (const std::exception& e) { 123 | std::cerr << e.what() << std::endl; 124 | io.stop(); 125 | return; 126 | } 127 | }); 128 | }); 129 | }); 130 | }); 131 | 132 | std::cerr << "starting io service" << std::endl; 133 | 134 | io.run(); 135 | 136 | std::cerr << "stopped io service" << std::endl; 137 | } 138 | catch (const std::exception& e) { 139 | std::cerr << "exception: " << e.what() << std::endl; 140 | return -1; 141 | } 142 | 143 | return 0; 144 | } 145 | --------------------------------------------------------------------------------