| 1 |
#ifndef PROTON_SESSION_HPP |
| 2 |
#define PROTON_SESSION_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 "./endpoint.hpp" |
| 28 |
#include "./receiver.hpp" |
| 29 |
#include "./sender.hpp" |
| 30 |
|
| 31 |
#include <string> |
| 32 |
|
| 33 |
/// @file |
| 34 |
/// @copybrief proton::session |
| 35 |
|
| 36 |
struct pn_session_t; |
| 37 |
|
| 38 |
namespace proton { |
| 39 |
|
| 40 |
/// A container of senders and receivers. |
| 41 |
class |
| 42 |
PN_CPP_CLASS_EXTERN session : public internal::object<pn_session_t>, public endpoint { |
| 43 |
public: |
| 44 |
/// @cond INTERNAL |
| 45 |
PN_CPP_EXTERN session(pn_session_t* s) : internal::object<pn_session_t>(s) {} |
| 46 |
/// @endcond |
| 47 |
|
| 48 |
public: |
| 49 |
/// Create an empty session. |
| 50 |
session() : internal::object<pn_session_t>(0) {} |
| 51 |
|
| 52 |
PN_CPP_EXTERN ~session(); |
| 53 |
|
| 54 |
PN_CPP_EXTERN bool uninitialized() const; |
| 55 |
PN_CPP_EXTERN bool active() const; |
| 56 |
PN_CPP_EXTERN bool closed() const; |
| 57 |
|
| 58 |
PN_CPP_EXTERN class error_condition error() const; |
| 59 |
|
| 60 |
/// Open the session. |
| 61 |
PN_CPP_EXTERN void open(); |
| 62 |
|
| 63 |
/// @copydoc open |
| 64 |
PN_CPP_EXTERN void open(const session_options &opts); |
| 65 |
|
| 66 |
PN_CPP_EXTERN void close(); |
| 67 |
PN_CPP_EXTERN void close(const error_condition&); |
| 68 |
|
| 69 |
/// Get the container for this session. |
| 70 |
PN_CPP_EXTERN class container &container() const; |
| 71 |
|
| 72 |
/// Get the work_queue for the session. |
| 73 |
PN_CPP_EXTERN class work_queue& work_queue() const; |
| 74 |
|
| 75 |
/// Get the connection this session belongs to. |
| 76 |
PN_CPP_EXTERN class connection connection() const; |
| 77 |
|
| 78 |
/// Open a sender for `addr`. |
| 79 |
PN_CPP_EXTERN sender open_sender(const std::string &addr); |
| 80 |
|
| 81 |
/// @copydoc open_sender |
| 82 |
PN_CPP_EXTERN sender open_sender(const std::string &addr, const sender_options &opts); |
| 83 |
|
| 84 |
/// Open a receiver for `addr`. |
| 85 |
PN_CPP_EXTERN receiver open_receiver(const std::string &addr); |
| 86 |
|
| 87 |
/// @copydoc open_receiver |
| 88 |
PN_CPP_EXTERN receiver open_receiver(const std::string &addr, const receiver_options &opts); |
| 89 |
|
| 90 |
/// The number of incoming bytes currently buffered. |
| 91 |
PN_CPP_EXTERN size_t incoming_bytes() const; |
| 92 |
|
| 93 |
/// The number of outgoing bytes currently buffered. |
| 94 |
PN_CPP_EXTERN size_t outgoing_bytes() const; |
| 95 |
|
| 96 |
/// Return the senders on this session. |
| 97 |
PN_CPP_EXTERN sender_range senders() const; |
| 98 |
|
| 99 |
/// Return the receivers on this session. |
| 100 |
PN_CPP_EXTERN receiver_range receivers() const; |
| 101 |
|
| 102 |
/// @cond INTERNAL |
| 103 |
friend class internal::factory<session>; |
| 104 |
friend class session_iterator; |
| 105 |
/// @endcond |
| 106 |
}; |
| 107 |
|
| 108 |
/// @cond INTERNAL |
| 109 |
|
| 110 |
/// An iterator of sessions. |
| 111 |
class session_iterator : public internal::iter_base<session, session_iterator> { |
| 112 |
public: |
| 113 |
explicit session_iterator(session s = 0) : internal::iter_base<session, session_iterator>(s) {} |
| 114 |
|
| 115 |
/// Advance to the next session. |
| 116 |
PN_CPP_EXTERN session_iterator operator++(); |
| 117 |
}; |
| 118 |
|
| 119 |
/// A range of sessions. |
| 120 |
typedef internal::iter_range<session_iterator> session_range; |
| 121 |
|
| 122 |
/// @endcond |
| 123 |
|
| 124 |
} // proton |
| 125 |
|
| 126 |
#endif // PROTON_SESSION_HPP |