CppWAMP
C++11 client library for the WAMP protocol
registration.hpp
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------
2  Copyright Butterfly Energy Systems 2014-2015, 2022.
3  Distributed under the Boost Software License, Version 1.0.
4  http://www.boost.org/LICENSE_1_0.txt
5 ------------------------------------------------------------------------------*/
6 
7 #ifndef CPPWAMP_REGISTRATION_HPP
8 #define CPPWAMP_REGISTRATION_HPP
9 
10 //------------------------------------------------------------------------------
13 //------------------------------------------------------------------------------
14 
15 #include <memory>
16 #include <string>
17 #include "api.hpp"
18 #include "erroror.hpp"
19 #include "peerdata.hpp"
20 #include "wampdefs.hpp"
21 #include "./internal/passkey.hpp"
22 
23 namespace wamp
24 {
25 
26 // Forward declaration
27 namespace internal { class Callee; }
28 
29 //------------------------------------------------------------------------------
41 //------------------------------------------------------------------------------
42 class CPPWAMP_API Registration
43 {
44 public:
46  Registration();
47 
49  Registration(const Registration& other);
50 
52  Registration(Registration&& other) noexcept;
53 
55  explicit operator bool() const;
56 
58  RegistrationId id() const;
59 
61  Registration& operator=(const Registration& other);
62 
64  Registration& operator=(Registration&& other) noexcept;
65 
67  void unregister() const;
68 
69 private:
70  using CalleePtr = std::weak_ptr<internal::Callee>;
71 
72  static constexpr RegistrationId invalidId_ = -1;
73  CalleePtr callee_;
74  RegistrationId id_ = invalidId_;
75 
76 public:
77  // Internal use only
78  Registration(CalleePtr callee, RegistrationId id, internal::PassKey);
79 
80 };
81 
82 
83 //------------------------------------------------------------------------------
88 //------------------------------------------------------------------------------
89 class CPPWAMP_API ScopedRegistration : public Registration
90 {
91 // This class is modeled after boost::signals2::scoped_connection.
92 public:
95 
97  ScopedRegistration(ScopedRegistration&& other) noexcept;
98 
100  ScopedRegistration(Registration registration);
101 
104 
106  ScopedRegistration& operator=(ScopedRegistration&& other) noexcept;
107 
110  ScopedRegistration& operator=(Registration subscription);
111 
114  void release();
115 
117  ScopedRegistration(const ScopedRegistration&) = delete;
118 
120  ScopedRegistration& operator=(const ScopedRegistration&) = delete;
121 
122 private:
123  using Base = Registration;
124 };
125 
126 } // namespace wamp
127 
128 #ifndef CPPWAMP_COMPILED_LIB
129 #include "internal/registration.ipp"
130 #endif
131 
132 #endif // CPPWAMP_REGISTRATION_HPP
wamp::RegistrationId
int64_t RegistrationId
Obtains the value representing a blank RequestId.
Definition: wampdefs.hpp:28
erroror.hpp
Contains the ErrorOr template class.
api.hpp
Defines macros related to exporting/importing APIs.
peerdata.hpp
Contains declarations for data structures exchanged between WAMP peers.
wamp
Definition: anyhandler.hpp:36
wamp::ScopedRegistration
Limits a Registration's lifetime to a particular scope.
Definition: registration.hpp:89
wamp::Registration
Represents a remote procedure registration.
Definition: registration.hpp:42
wampdefs.hpp
Contains type definitions related to WAMP IDs and sessions.