Qpid Proton C++  0.13.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 
130  virtual void stop() = 0;
131 
133  virtual returned<sender> open_sender(const std::string &url) = 0;
134 
139  virtual returned<sender> open_sender(const std::string &url,
140  const proton::sender_options &o) = 0;
141 
146  virtual returned<sender> open_sender(const std::string &url,
147  const proton::sender_options &o,
148  const connection_options &c) = 0;
149 
151  virtual returned<receiver> open_receiver(const std::string&url) = 0;
152 
153 
158  virtual returned<receiver> open_receiver(const std::string&url,
159  const proton::receiver_options &o) = 0;
160 
165  virtual returned<receiver> open_receiver(const std::string&url,
166  const proton::receiver_options &o,
167  const connection_options &c) = 0;
168 
170  virtual std::string id() const = 0;
171 
175  virtual void client_connection_options(const connection_options &) = 0;
176 
178  virtual connection_options client_connection_options() const = 0;
179 
184  virtual void server_connection_options(const connection_options &) = 0;
185 
187  virtual connection_options server_connection_options() const = 0;
188 
192  virtual void sender_options(const class sender_options &) = 0;
193 
195  virtual class sender_options sender_options() const = 0;
196 
200  virtual void receiver_options(const class receiver_options &) = 0;
201 
203  virtual class receiver_options receiver_options() const = 0;
204 
205 #if PN_CPP_HAS_STD_FUNCTION
206  virtual void schedule(duration, std::function<void()>) = 0;
208 #endif
209  virtual void schedule(duration, void_function0&) = 0;
212 };
213 
222 class PN_CPP_CLASS_EXTERN standard_container : public container {
223  public:
224  // Pull in base class functions here so we don't need to define them again
225  using container::stop;
226  using container::connect;
227  using container::listen;
230 
231  PN_CPP_EXTERN returned<connection> connect(const std::string& url);
232  PN_CPP_EXTERN listener listen(const std::string& url, const connection_options&);
233  PN_CPP_EXTERN listener listen(const std::string& url);
234  PN_CPP_EXTERN void stop();
235  PN_CPP_EXTERN returned<sender> open_sender(const std::string &url);
236  PN_CPP_EXTERN returned<sender> open_sender(const std::string &url,
237  const proton::sender_options &o);
238  PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url);
239  PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url,
240  const proton::receiver_options &o);
241 };
243 
246 template <class Ptr>
247 class container_ref : public container {
248  public:
249 #if PN_CPP_HAS_RVALUE_REFERENCES
250  container_ref(Ptr&& p) : impl_(std::move(p)) {}
251 #else
252  // This class will only work correctly if ownership is transferred here
253  // so using std::auto_ptr for Ptr is necessary for pre C++11
254  container_ref(Ptr p) : impl_(p) {}
255 #endif
256 
257  returned<connection> connect(const std::string& url, const connection_options& opts) { return impl_->connect(url, opts); }
258  returned<connection> connect(const std::string& url) { return impl_->connect(url); }
259  listener listen(const std::string& url, listen_handler& l) { return impl_->listen(url, l); }
260  listener listen(const std::string& url, const connection_options& opts) { return impl_->listen(url, opts); }
261  listener listen(const std::string& url) { return impl_->listen(url); }
262 
263  void stop_listening(const std::string& url) { impl_->stop_listening(url); }
264  void run() { impl_->run(); }
265  void auto_stop(bool set) { impl_->auto_stop(set); }
266 
267  void stop(const error_condition& err) { impl_->stop(err); }
268  void stop() { impl_->stop(); }
269 
270  returned<sender> open_sender(
271  const std::string &url,
272  const class sender_options &o,
273  const connection_options &c) { return impl_->open_sender(url, o, c); }
274  returned<sender> open_sender(
275  const std::string &url,
276  const class sender_options &o) { return impl_->open_sender(url, o); }
277  returned<sender> open_sender(
278  const std::string &url) { return impl_->open_sender(url); }
279 
280  returned<receiver> open_receiver(
281  const std::string&url,
282  const class receiver_options &o,
283  const connection_options &c) { return impl_->open_receiver(url, o, c); }
284  returned<receiver> open_receiver(
285  const std::string&url,
286  const class receiver_options &o) { return impl_->open_receiver(url, o); }
287  returned<receiver> open_receiver(
288  const std::string&url) { return impl_->open_receiver(url); }
289 
290  std::string id() const { return impl_->id(); }
291 
292 #if PN_CPP_HAS_STD_FUNCTION
293  PN_CPP_EXTERN void schedule(duration d, std::function<void()> f) { return impl_->schedule(d, f); }
294 #endif
295  PN_CPP_EXTERN void schedule(duration d, void_function0& f) { return impl_->schedule(d, f); }
296 
297  void client_connection_options(const connection_options& c) { impl_->client_connection_options(c); }
298  connection_options client_connection_options() const { return impl_->client_connection_options(); }
299 
300  void server_connection_options(const connection_options &o) { impl_->server_connection_options(o); }
301  connection_options server_connection_options() const { return impl_->server_connection_options(); }
302 
303  void sender_options(const class sender_options &o) { impl_->sender_options(o); }
304  class sender_options sender_options() const { return impl_->sender_options(); }
305 
306  void receiver_options(const class receiver_options & o) { impl_->receiver_options(o); }
307  class receiver_options receiver_options() const { return impl_->receiver_options(); }
308 
309  private:
310  Ptr impl_;
311 };
312 
313 } // proton
314 
315 #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:303
connection_options server_connection_options() const
Connection options that will be applied to incoming connections.
Definition: container.hpp:301
listener listen(const std::string &url, listen_handler &l)
Start listening on url.
Definition: container.hpp:259
This is an header only class that can be used to help using containers more natural by allowing them ...
Definition: container.hpp:247
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:261
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:287
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:265
void client_connection_options(const connection_options &c)
Connection options that will be to outgoing connections.
Definition: container.hpp:297
void receiver_options(const class receiver_options &o)
Receiver options applied to receivers created by this container.
Definition: container.hpp:306
connection_options client_connection_options() const
Connection options that will be to outgoing connections.
Definition: container.hpp:298
Options for creating a connection.
Definition: connection_options.hpp:67
std::string id() const
A unique identifier for the container.
Definition: container.hpp:290
returned< sender > open_sender(const std::string &url)
Open a connection and sender for url.
Definition: container.hpp:277
class sender_options sender_options() const
Sender options applied to senders created by this container.
Definition: container.hpp:304
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 optional error_condition err.
Definition: container.hpp:267
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:264
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:257
void schedule(duration d, void_function0 &f)
Schedule a function to be called after the duration.
Definition: container.hpp:295
returned< connection > connect(const std::string &url)
Connect to url and send an open request to the remote peer.
Definition: container.hpp:258
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:307
virtual void stop()=0
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:260
void server_connection_options(const connection_options &o)
Connection options that will be applied to incoming connections.
Definition: container.hpp:300
void stop()
Stop the container with an empty error condition.
Definition: container.hpp:268
receiver_options()
Create an empty set of options.
Describes an endpoint error state.
Definition: error_condition.hpp:37