Debian Codegraph @

cpp/include/proton/connection.hpp

raw
1 #ifndef PROTON_CONNECTION_HPP
2 #define PROTON_CONNECTION_HPP
3
4 /*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25 #include "./fwd.hpp"
26 #include "./internal/export.hpp"
27 #include "./internal/object.hpp"
28 #include "./endpoint.hpp"
29 #include "./session.hpp"
30 #include "./symbol.hpp"
31 #include "./value.hpp"
32
33 #include <proton/type_compat.h>
34
35 #include <map>
36 #include <string>
37
38 /// @file
39 /// @copybrief proton::connection
40
41 struct pn_connection_t;
42
43 namespace proton {
44
45 /// A connection to a remote AMQP peer.
46 class
47 PN_CPP_CLASS_EXTERN connection : public internal::object<pn_connection_t>, public endpoint {
48 /// @cond INTERNAL
49 PN_CPP_EXTERN connection(pn_connection_t* c) : internal::object<pn_connection_t>(c) {}
50 /// @endcond
51
52 public:
53 /// Create an empty connection.
54 connection() : internal::object<pn_connection_t>(0) {}
55
56 PN_CPP_EXTERN ~connection();
57
58 PN_CPP_EXTERN bool uninitialized() const;
59 PN_CPP_EXTERN bool active() const;
60 PN_CPP_EXTERN bool closed() const;
61
62 PN_CPP_EXTERN class error_condition error() const;
63
64 /// Get the container.
65 ///
66 /// @throw proton::error if this connection is not managed by a
67 /// container
68 PN_CPP_EXTERN class container& container() const;
69
70 /// Get the work_queue for the connection.
71 PN_CPP_EXTERN class work_queue& work_queue() const;
72
73 /// Get the transport for the connection.
74 PN_CPP_EXTERN class transport transport() const;
75
76 /// Return the remote AMQP hostname attribute for the connection.
77 PN_CPP_EXTERN std::string virtual_host() const;
78
79 /// Return the remote container ID for the connection.
80 PN_CPP_EXTERN std::string container_id() const;
81
82 /// Return authenticated user for the connection
83 /// Note: The value returned is not stable until the on_transport_open event is received
84 PN_CPP_EXTERN std::string user() const;
85
86 /// Open the connection.
87 /// @see messaging_handler
88 PN_CPP_EXTERN void open();
89
90 /// @copydoc open
91 PN_CPP_EXTERN void open(const connection_options&);
92
93 /// Close the connection.
94 /// @see messaging_handler
95 PN_CPP_EXTERN void close();
96
97 /// @copydoc close
98 PN_CPP_EXTERN void close(const error_condition&);
99
100 /// Open a new session.
101 PN_CPP_EXTERN session open_session();
102
103 /// @copydoc open_session
104 PN_CPP_EXTERN session open_session(const session_options&);
105
106 /// Get the default session. A default session is created on the
107 /// first call and reused for the lifetime of the connection.
108 PN_CPP_EXTERN session default_session();
109
110 /// Open a sender for `addr` on default_session().
111 PN_CPP_EXTERN sender open_sender(const std::string& addr);
112
113 /// @copydoc open_sender
114 PN_CPP_EXTERN sender open_sender(const std::string& addr, const sender_options&);
115
116 /// Open a receiver for `addr` on default_session().
117 PN_CPP_EXTERN receiver open_receiver(const std::string& addr);
118
119 /// @copydoc open_receiver
120 PN_CPP_EXTERN receiver open_receiver(const std::string& addr,
121 const receiver_options&);
122
123 /// @see proton::container::sender_options()
124 PN_CPP_EXTERN class sender_options sender_options() const;
125
126 /// @see container::receiver_options()
127 PN_CPP_EXTERN class receiver_options receiver_options() const;
128
129 /// Return all sessions on this connection.
130 PN_CPP_EXTERN session_range sessions() const;
131
132 /// Return all receivers on this connection.
133 PN_CPP_EXTERN receiver_range receivers() const;
134
135 /// Return all senders on this connection.
136 PN_CPP_EXTERN sender_range senders() const;
137
138 /// Get the maximum frame size allowed by the remote peer.
139 ///
140 /// @see @ref connection_options::max_frame_size
141 PN_CPP_EXTERN uint32_t max_frame_size() const;
142
143 /// Get the maximum number of open sessions allowed by the remote
144 /// peer.
145 ///
146 /// @see @ref connection_options::max_sessions
147 PN_CPP_EXTERN uint16_t max_sessions() const;
148
149 /// **Unsettled API** - Extension capabilities offered by the remote peer.
150 PN_CPP_EXTERN std::vector<symbol> offered_capabilities() const;
151
152 /// **Unsettled API** - Extension capabilities desired by the remote peer.
153 PN_CPP_EXTERN std::vector<symbol> desired_capabilities() const;
154
155 /// **Unsettled API** - Connection properties
156 PN_CPP_EXTERN std::map<symbol, value> properties() const;
157
158 /// Get the idle timeout set by the remote peer.
159 ///
160 /// @see @ref connection_options::idle_timeout
161 PN_CPP_EXTERN uint32_t idle_timeout() const;
162
163 /// **Unsettled API** - Trigger an event from another thread.
164 ///
165 /// This method can be called from any thread. The Proton library
166 /// will call `messaging_handler::on_connection_wake()` as soon as
167 /// possible in the correct event-handling thread.
168 ///
169 /// **Thread-safety** - This is the *only* `proton::connection`
170 /// function that can be called from outside the handler thread.
171 ///
172 /// @note Spurious `messaging_handler::on_connection_wake()` calls
173 /// can occur even if the application does not call `wake()`.
174 ///
175 /// @note Multiple calls to `wake()` may be coalesced into a
176 /// single call to `messaging_handler::on_connection_wake()` that
177 /// occurs after all of them.
178 ///
179 /// The `proton::work_queue` interface provides an easier way
180 /// execute code safely in the event-handler thread.
181 PN_CPP_EXTERN void wake() const;
182
183 /// **Unsettled API** - True if this connection has been automatically
184 /// re-connected.
185 ///
186 /// @see reconnect_options, messaging_handler
187 PN_CPP_EXTERN bool reconnected() const;
188
189 /// **Unsettled API** - Update the connection options for this connection
190 ///
191 /// This method can be used to update the connection options used with this
192 /// connection. Usually the connection options are only used during the initial
193 /// connection attempt so this ability is only useful when automatically
194 /// reconnect is enabled and you wish to change the connection options before
195 /// the next reconnect attempt. This would usually be in the handler for the
196 /// `on_transport_error` event @see messaging_handler.
197 ///
198 /// @note Connection options supplied in the parameter will be merged with the
199 /// existing parameters as if `connection_options::update()` was used.
200 PN_CPP_EXTERN void update_options(const connection_options&);
201
202 /// @cond INTERNAL
203 friend class internal::factory<connection>;
204 friend class container;
205 /// @endcond
206 };
207
208 } // proton
209
210 #endif // PROTON_CONNECTION_HPP