Qpid Proton C++  0.14.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
container.hpp
1 #ifndef PROTON_CONTAINER_HPP
2 #define PROTON_CONTAINER_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 "./connection_options.hpp"
26 #include "./function.hpp"
27 #include "./listener.hpp"
28 #include "./receiver_options.hpp"
29 #include "./sender_options.hpp"
30 #include "./thread_safe.hpp"
31 
32 #include "./internal/config.hpp"
33 #include "./internal/export.hpp"
34 
35 #include <string>
36 
37 namespace proton {
38 
39 class connection;
40 class connection_options;
41 class container_impl;
42 class messaging_handler;
43 class listen_handler;
44 class listener;
45 class receiver;
46 class receiver_options;
47 class sender;
48 class sender_options;
49 class task;
50 
62 class PN_CPP_CLASS_EXTERN container {
63  public:
64  PN_CPP_EXTERN virtual ~container();
65 
77  virtual returned<connection> connect(const std::string& url, const connection_options &) = 0;
78 
80  virtual returned<connection> connect(const std::string& url) = 0;
81 
85  virtual void stop_listening(const std::string& url) = 0;
87 
96  virtual listener listen(const std::string& url, listen_handler& lh) = 0;
97 
100  virtual listener listen(const std::string& url, const connection_options&) = 0;
101 
104  virtual listener listen(const std::string& url) = 0;
105 
111  virtual void run() = 0;
112 
117  virtual void auto_stop(bool) = 0;
118 
126  virtual void stop(const error_condition& err) = 0;
127 
132  virtual void stop() = 0;
133 
135  virtual returned<sender> open_sender(const std::string &url) = 0;
136 
141  virtual returned<sender> open_sender(const std::string &url,
142  const proton::sender_options &o) = 0;
143 
148  virtual returned<sender> open_sender(const std::string &url,
149  const connection_options &c) = 0;
150 
155  virtual returned<sender> open_sender(const std::string &url,
156  const proton::sender_options &o,
157  const connection_options &c) = 0;
158 
160  virtual returned<receiver> open_receiver(const std::string&url) = 0;
161 
162 
167  virtual returned<receiver> open_receiver(const std::string&url,
168  const proton::receiver_options &o) = 0;
169 
174  virtual returned<receiver> open_receiver(const std::string&url,
175  const connection_options &c) = 0;
176 
181  virtual returned<receiver> open_receiver(const std::string&url,
182  const proton::receiver_options &o,
183  const connection_options &c) = 0;
184 
186  virtual std::string id() const = 0;
187 
191  virtual void client_connection_options(const connection_options &) = 0;
192 
194  virtual connection_options client_connection_options() const = 0;
195 
200  virtual void server_connection_options(const connection_options &) = 0;
201 
203  virtual connection_options server_connection_options() const = 0;
204 
208  virtual void sender_options(const class sender_options &) = 0;
209 
211  virtual class sender_options sender_options() const = 0;
212 
216  virtual void receiver_options(const class receiver_options &) = 0;
217 
219  virtual class receiver_options receiver_options() const = 0;
220 
221 #if PN_CPP_HAS_STD_FUNCTION
222  virtual void schedule(duration, std::function<void()>) = 0;
224 #endif
225  virtual void schedule(duration, void_function0&) = 0;
228 };
229 
238 class PN_CPP_CLASS_EXTERN standard_container : public container {
239  public:
240  // Pull in base class functions here so we don't need to define them again
241  using container::stop;
242  using container::connect;
243  using container::listen;
246 
247  PN_CPP_EXTERN returned<connection> connect(const std::string& url);
248  PN_CPP_EXTERN listener listen(const std::string& url, const connection_options&);
249  PN_CPP_EXTERN listener listen(const std::string& url);
250  PN_CPP_EXTERN void stop();
251  PN_CPP_EXTERN returned<sender> open_sender(const std::string &url);
252  PN_CPP_EXTERN returned<sender> open_sender(const std::string &url,
253  const proton::sender_options &o);
254  PN_CPP_EXTERN returned<sender> open_sender(const std::string &url,
255  const proton::connection_options &o);
256  PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url);
257  PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url,
258  const proton::receiver_options &o);
259  PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url,
260  const proton::connection_options &o);
261 };
263 
266 template <class Ptr>
267 class container_ref : public container {
268  public:
269 #if PN_CPP_HAS_RVALUE_REFERENCES
270  container_ref(Ptr&& p) : impl_(std::move(p)) {}
271 #else
272  // This class will only work correctly if ownership is transferred here
273  // so using std::auto_ptr for Ptr is necessary for pre C++11
274  container_ref(Ptr p) : impl_(p) {}
275 #endif
276 
277  returned<connection> connect(const std::string& url, const connection_options& opts) { return impl_->connect(url, opts); }
278  returned<connection> connect(const std::string& url) { return impl_->connect(url); }
279  listener listen(const std::string& url, listen_handler& l) { return impl_->listen(url, l); }
280  listener listen(const std::string& url, const connection_options& opts) { return impl_->listen(url, opts); }
281  listener listen(const std::string& url) { return impl_->listen(url); }
282 
283  void stop_listening(const std::string& url) { impl_->stop_listening(url); }
284  void run() { impl_->run(); }
285  void auto_stop(bool set) { impl_->auto_stop(set); }
286 
287  void stop(const error_condition& err) { impl_->stop(err); }
288  void stop() { impl_->stop(); }
289 
290  returned<sender> open_sender(
291  const std::string &url,
292  const class sender_options &o,
293  const connection_options &c) { return impl_->open_sender(url, o, c); }
294  returned<sender> open_sender(
295  const std::string &url,
296  const class connection_options &o) { return impl_->open_sender(url, o); }
297  returned<sender> open_sender(
298  const std::string &url,
299  const class sender_options &o) { return impl_->open_sender(url, o); }
300  returned<sender> open_sender(
301  const std::string &url) { return impl_->open_sender(url); }
302 
303  returned<receiver> open_receiver(
304  const std::string&url,
305  const class receiver_options &o,
306  const connection_options &c) { return impl_->open_receiver(url, o, c); }
307  returned<receiver> open_receiver(
308  const std::string&url,
309  const class receiver_options &o) { return impl_->open_receiver(url, o); }
310  returned<receiver> open_receiver(
311  const std::string&url,
312  const class connection_options &o) { return impl_->open_receiver(url, o); }
313  returned<receiver> open_receiver(
314  const std::string&url) { return impl_->open_receiver(url); }
315 
316  std::string id() const { return impl_->id(); }
317 
318 #if PN_CPP_HAS_STD_FUNCTION
319  PN_CPP_EXTERN void schedule(duration d, std::function<void()> f) { return impl_->schedule(d, f); }
320 #endif
321  PN_CPP_EXTERN void schedule(duration d, void_function0& f) { return impl_->schedule(d, f); }
322 
323  void client_connection_options(const connection_options& c) { impl_->client_connection_options(c); }
324  connection_options client_connection_options() const { return impl_->client_connection_options(); }
325 
326  void server_connection_options(const connection_options &o) { impl_->server_connection_options(o); }
327  connection_options server_connection_options() const { return impl_->server_connection_options(); }
328 
329  void sender_options(const class sender_options &o) { impl_->sender_options(o); }
330  class sender_options sender_options() const { return impl_->sender_options(); }
331 
332  void receiver_options(const class receiver_options & o) { impl_->receiver_options(o); }
333  class receiver_options receiver_options() const { return impl_->receiver_options(); }
334 
335  private:
336  Ptr impl_;
337 };
338 
339 } // proton
340 
341 #endif // PROTON_CONTAINER_HPP
virtual returned< connection > connect(const std::string &url, const connection_options &)=0
Connect to url and send an open request to the remote peer.
A top-level container of connections, sessions, senders, and receivers.
Definition: container.hpp:62
void sender_options(const class sender_options &o)
Sender options applied to senders created by this container.
Definition: container.hpp:329
connection_options server_connection_options() const
Connection options that will be applied to incoming connections.
Definition: container.hpp:327
listener listen(const std::string &url, listen_handler &l)
Start listening on url.
Definition: container.hpp:279
This is an header only class that can be used to help using containers more natural by allowing them ...
Definition: container.hpp:267
A listener for incoming connections.
Definition: listener.hpp:32
virtual returned< sender > open_sender(const std::string &url)=0
Open a connection and sender for url.
sender_options()
Create an empty set of options.
listener listen(const std::string &url)
Start listening on URL.
Definition: container.hpp:281
Options for creating a sender.
Definition: sender_options.hpp:64
A span of time in milliseconds.
Definition: duration.hpp:34
returned< receiver > open_receiver(const std::string &url)
Open a connection and receiver for url.
Definition: container.hpp:313
virtual returned< receiver > open_receiver(const std::string &url)=0
Open a connection and receiver for url.
void auto_stop(bool set)
If true, stop the container when all active connections and listeners are closed. ...
Definition: container.hpp:285
void client_connection_options(const connection_options &c)
Connection options that will be to outgoing connections.
Definition: container.hpp:323
void receiver_options(const class receiver_options &o)
Receiver options applied to receivers created by this container.
Definition: container.hpp:332
connection_options client_connection_options() const
Connection options that will be to outgoing connections.
Definition: container.hpp:324
Options for creating a connection.
Definition: connection_options.hpp:67
std::string id() const
A unique identifier for the container.
Definition: container.hpp:316
returned< sender > open_sender(const std::string &url)
Open a connection and sender for url.
Definition: container.hpp:300
class sender_options sender_options() const
Sender options applied to senders created by this container.
Definition: container.hpp:330
A C++03 compatible void no-argument callback function object, used by container::schedule() and event...
Definition: function.hpp:33
void stop(const error_condition &err)
Experimental - Stop the container with an error_condition err.
Definition: container.hpp:287
virtual listener listen(const std::string &url, listen_handler &lh)=0
Start listening on url.
void run()
Run the container in this thread.
Definition: container.hpp:284
A Proton URL.
Definition: url.hpp:55
returned< connection > connect(const std::string &url, const connection_options &opts)
Connect to url and send an open request to the remote peer.
Definition: container.hpp:277
void schedule(duration d, void_function0 &f)
Schedule a function to be called after the duration.
Definition: container.hpp:321
returned< connection > connect(const std::string &url)
Connect to url and send an open request to the remote peer.
Definition: container.hpp:278
Options for creating a receiver.
Definition: receiver_options.hpp:62
class receiver_options receiver_options() const
Receiver options applied to receivers created by this container.
Definition: container.hpp:333
virtual void stop()=0
Experimental - Stop the container with an empty error condition.
Experimental - A handler for incoming connections.
Definition: listen_handler.hpp:32
listener listen(const std::string &url, const connection_options &opts)
Listen with a fixed set of options for all accepted connections.
Definition: container.hpp:280
void server_connection_options(const connection_options &o)
Connection options that will be applied to incoming connections.
Definition: container.hpp:326
void stop()
Experimental - Stop the container with an empty error condition.
Definition: container.hpp:288
receiver_options()
Create an empty set of options.
Type traits for mapping between AMQP and C++ types.
Definition: annotation_key.hpp:28
Describes an endpoint error state.
Definition: error_condition.hpp:37