container.hpp
#ifndef PROTON_CONTAINER_HPP
#define PROTON_CONTAINER_HPP
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
#include "./connection_options.hpp"
#include "./function.hpp"
#include "./listener.hpp"
#include "./receiver_options.hpp"
#include "./sender_options.hpp"
#include "./thread_safe.hpp"
#include "./internal/config.hpp"
#include "./internal/export.hpp"
#include <string>
namespace proton {
class connection;
class connection_options;
class container_impl;
class messaging_handler;
class listen_handler;
class listener;
class receiver;
class receiver_options;
class sender;
class sender_options;
class task;
class PN_CPP_CLASS_EXTERN container {
public:
PN_CPP_EXTERN virtual ~container();
virtual returned<connection> connect(const std::string& url, const connection_options &) = 0;
virtual returned<connection> connect(const std::string& url) = 0;
virtual void stop_listening(const std::string& url) = 0;
virtual listener listen(const std::string& url, listen_handler& lh) = 0;
virtual listener listen(const std::string& url, const connection_options&) = 0;
virtual listener listen(const std::string& url) = 0;
virtual void run() = 0;
virtual void auto_stop(bool) = 0;
virtual void stop(const error_condition& err) = 0;
virtual void stop() = 0;
virtual returned<sender> open_sender(const std::string &url) = 0;
virtual returned<sender> open_sender(const std::string &url,
const proton::sender_options &o) = 0;
virtual returned<sender> open_sender(const std::string &url,
const connection_options &c) = 0;
virtual returned<sender> open_sender(const std::string &url,
const proton::sender_options &o,
const connection_options &c) = 0;
virtual returned<receiver> open_receiver(const std::string&url) = 0;
virtual returned<receiver> open_receiver(const std::string&url,
const proton::receiver_options &o) = 0;
virtual returned<receiver> open_receiver(const std::string&url,
const connection_options &c) = 0;
virtual returned<receiver> open_receiver(const std::string&url,
const proton::receiver_options &o,
const connection_options &c) = 0;
virtual std::string id() const = 0;
virtual void client_connection_options(const connection_options &) = 0;
virtual connection_options client_connection_options() const = 0;
virtual void server_connection_options(const connection_options &) = 0;
virtual connection_options server_connection_options() const = 0;
virtual void sender_options(const class sender_options &) = 0;
virtual class sender_options sender_options() const = 0;
virtual void receiver_options(const class receiver_options &) = 0;
virtual class receiver_options receiver_options() const = 0;
#if PN_CPP_HAS_STD_FUNCTION
virtual void schedule(duration, std::function<void()>) = 0;
#endif
virtual void schedule(duration, void_function0&) = 0;
};
class PN_CPP_CLASS_EXTERN standard_container : public container {
public:
// Pull in base class functions here so we don't need to define them again
using container::stop;
using container::connect;
using container::listen;
using container::open_receiver;
using container::open_sender;
PN_CPP_EXTERN returned<connection> connect(const std::string& url);
PN_CPP_EXTERN listener listen(const std::string& url, const connection_options&);
PN_CPP_EXTERN listener listen(const std::string& url);
PN_CPP_EXTERN void stop();
PN_CPP_EXTERN returned<sender> open_sender(const std::string &url);
PN_CPP_EXTERN returned<sender> open_sender(const std::string &url,
const proton::sender_options &o);
PN_CPP_EXTERN returned<sender> open_sender(const std::string &url,
const proton::connection_options &o);
PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url);
PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url,
const proton::receiver_options &o);
PN_CPP_EXTERN returned<receiver> open_receiver(const std::string&url,
const proton::connection_options &o);
};
template <class Ptr>
class container_ref : public container {
public:
#if PN_CPP_HAS_RVALUE_REFERENCES
container_ref(Ptr&& p) : impl_(std::move(p)) {}
#else
// This class will only work correctly if ownership is transferred here
// so using std::auto_ptr for Ptr is necessary for pre C++11
container_ref(Ptr p) : impl_(p) {}
#endif
returned<connection> connect(const std::string& url, const connection_options& opts) { return impl_->connect(url, opts); }
returned<connection> connect(const std::string& url) { return impl_->connect(url); }
listener listen(const std::string& url, listen_handler& l) { return impl_->listen(url, l); }
listener listen(const std::string& url, const connection_options& opts) { return impl_->listen(url, opts); }
listener listen(const std::string& url) { return impl_->listen(url); }
void stop_listening(const std::string& url) { impl_->stop_listening(url); }
void run() { impl_->run(); }
void auto_stop(bool set) { impl_->auto_stop(set); }
void stop(const error_condition& err) { impl_->stop(err); }
void stop() { impl_->stop(); }
returned<sender> open_sender(
const std::string &url,
const class sender_options &o,
const connection_options &c) { return impl_->open_sender(url, o, c); }
returned<sender> open_sender(
const std::string &url,
const class connection_options &o) { return impl_->open_sender(url, o); }
returned<sender> open_sender(
const std::string &url,
const class sender_options &o) { return impl_->open_sender(url, o); }
returned<sender> open_sender(
const std::string &url) { return impl_->open_sender(url); }
returned<receiver> open_receiver(
const std::string&url,
const class receiver_options &o,
const connection_options &c) { return impl_->open_receiver(url, o, c); }
returned<receiver> open_receiver(
const std::string&url,
const class receiver_options &o) { return impl_->open_receiver(url, o); }
returned<receiver> open_receiver(
const std::string&url,
const class connection_options &o) { return impl_->open_receiver(url, o); }
returned<receiver> open_receiver(
const std::string&url) { return impl_->open_receiver(url); }
std::string id() const { return impl_->id(); }
#if PN_CPP_HAS_STD_FUNCTION
PN_CPP_EXTERN void schedule(duration d, std::function<void()> f) { return impl_->schedule(d, f); }
#endif
PN_CPP_EXTERN void schedule(duration d, void_function0& f) { return impl_->schedule(d, f); }
void client_connection_options(const connection_options& c) { impl_->client_connection_options(c); }
connection_options client_connection_options() const { return impl_->client_connection_options(); }
void server_connection_options(const connection_options &o) { impl_->server_connection_options(o); }
connection_options server_connection_options() const { return impl_->server_connection_options(); }
void sender_options(const class sender_options &o) { impl_->sender_options(o); }
class sender_options sender_options() const { return impl_->sender_options(); }
void receiver_options(const class receiver_options & o) { impl_->receiver_options(o); }
class receiver_options receiver_options() const { return impl_->receiver_options(); }
private:
Ptr impl_;
};
} // proton
#endif // PROTON_CONTAINER_HPP
proton::container::connect
virtual returned< connection > connect(const std::string &url, const connection_options &)=0
Connect to url and send an open request to the remote peer.
proton::container_ref::id
std::string id() const
A unique identifier for the container.
Definition: container.hpp:316
proton::container
A top-level container of connections, sessions, senders, and receivers.
Definition: container.hpp:62
proton::container_ref::sender_options
void sender_options(const class sender_options &o)
Sender options applied to senders created by this container.
Definition: container.hpp:329
proton::container_ref::client_connection_options
connection_options client_connection_options() const
Connection options that will be to outgoing connections.
Definition: container.hpp:324
proton::container_ref::listen
listener listen(const std::string &url, listen_handler &l)
Start listening on url.
Definition: container.hpp:279
proton::container_ref
This is an header only class that can be used to help using containers more natural by allowing them ...
Definition: container.hpp:267
proton::listener
A listener for incoming connections.
Definition: listener.hpp:32
proton::container::open_sender
virtual returned< sender > open_sender(const std::string &url)=0
Open a connection and sender for url.
proton::container_ref::server_connection_options
connection_options server_connection_options() const
Connection options that will be applied to incoming connections.
Definition: container.hpp:327
proton::sender_options::sender_options
sender_options()
Create an empty set of options.
proton::container_ref::listen
listener listen(const std::string &url)
Start listening on URL.
Definition: container.hpp:281
proton::sender_options
Options for creating a sender.
Definition: sender_options.hpp:64
proton::duration
A span of time in milliseconds.
Definition: duration.hpp:34
proton::container_ref::open_receiver
returned< receiver > open_receiver(const std::string &url)
Open a connection and receiver for url.
Definition: container.hpp:313
proton::container::open_receiver
virtual returned< receiver > open_receiver(const std::string &url)=0
Open a connection and receiver for url.
proton::container_ref::auto_stop
void auto_stop(bool set)
If true, stop the container when all active connections and listeners are closed. ...
Definition: container.hpp:285
proton::container_ref::client_connection_options
void client_connection_options(const connection_options &c)
Connection options that will be to outgoing connections.
Definition: container.hpp:323
proton::container_ref::receiver_options
void receiver_options(const class receiver_options &o)
Receiver options applied to receivers created by this container.
Definition: container.hpp:332
proton::connection_options
Options for creating a connection.
Definition: connection_options.hpp:67
proton::container_ref::open_sender
returned< sender > open_sender(const std::string &url)
Open a connection and sender for url.
Definition: container.hpp:300
proton::void_function0
A C++03 compatible void no-argument callback function object, used by container::schedule() and event...
Definition: function.hpp:33
proton::container_ref::stop
void stop(const error_condition &err)
Experimental - Stop the container with an error_condition err.
Definition: container.hpp:287
proton::container::listen
virtual listener listen(const std::string &url, listen_handler &lh)=0
Start listening on url.
proton::container_ref::run
void run()
Run the container in this thread.
Definition: container.hpp:284
proton::url
A Proton URL.
Definition: url.hpp:55
proton::container_ref::connect
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
proton::container_ref::schedule
void schedule(duration d, void_function0 &f)
Schedule a function to be called after the duration.
Definition: container.hpp:321
proton::container_ref::connect
returned< connection > connect(const std::string &url)
Connect to url and send an open request to the remote peer.
Definition: container.hpp:278
proton::receiver_options
Options for creating a receiver.
Definition: receiver_options.hpp:62
proton::container::stop
virtual void stop()=0
Experimental - Stop the container with an empty error condition.
proton::listen_handler
Experimental - A handler for incoming connections.
Definition: listen_handler.hpp:32
proton::container_ref::listen
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
proton::container_ref::server_connection_options
void server_connection_options(const connection_options &o)
Connection options that will be applied to incoming connections.
Definition: container.hpp:326
proton::container_ref::stop
void stop()
Experimental - Stop the container with an empty error condition.
Definition: container.hpp:288
proton::receiver_options::receiver_options
receiver_options()
Create an empty set of options.
proton
Type traits for mapping between AMQP and C++ types.
Definition: annotation_key.hpp:28
proton::error_condition
Describes an endpoint error state.
Definition: error_condition.hpp:37