| 1 |
#ifndef PROTON_RECEIVER_HPP |
| 2 |
#define PROTON_RECEIVER_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 "./link.hpp" |
| 28 |
|
| 29 |
#include <proton/type_compat.h> |
| 30 |
|
| 31 |
struct pn_link_t; |
| 32 |
struct pn_session_t; |
| 33 |
|
| 34 |
/// @file |
| 35 |
/// @copybrief proton::receiver |
| 36 |
|
| 37 |
namespace proton { |
| 38 |
|
| 39 |
/// A channel for receiving messages. |
| 40 |
class |
| 41 |
PN_CPP_CLASS_EXTERN receiver : public link { |
| 42 |
/// @cond INTERNAL |
| 43 |
PN_CPP_EXTERN receiver(pn_link_t* r); |
| 44 |
/// @endcond |
| 45 |
|
| 46 |
public: |
| 47 |
/// Create an empty receiver. |
| 48 |
receiver() = default; |
| 49 |
|
| 50 |
PN_CPP_EXTERN ~receiver(); |
| 51 |
|
| 52 |
/// Open the receiver. |
| 53 |
PN_CPP_EXTERN void open(); |
| 54 |
|
| 55 |
/// @copydoc open |
| 56 |
PN_CPP_EXTERN void open(const receiver_options &opts); |
| 57 |
|
| 58 |
/// Get the source node. |
| 59 |
PN_CPP_EXTERN class source source() const; |
| 60 |
|
| 61 |
/// Get the target node. |
| 62 |
PN_CPP_EXTERN class target target() const; |
| 63 |
|
| 64 |
/// Increment the credit available to the sender. Credit granted |
| 65 |
/// during a drain cycle is not communicated to the receiver until |
| 66 |
/// the drain completes. |
| 67 |
PN_CPP_EXTERN void add_credit(uint32_t); |
| 68 |
|
| 69 |
/// **Unsettled API** - Commence a drain cycle. If there is |
| 70 |
/// positive credit, a request is sent to the sender to |
| 71 |
/// immediately use up all of the existing credit balance by |
| 72 |
/// sending messages that are immediately available and releasing |
| 73 |
/// any unused credit (see sender::return_credit). Throws |
| 74 |
/// proton::error if a drain cycle is already in progress. An |
| 75 |
/// on_receiver_drain_finish event will be generated when the |
| 76 |
/// outstanding drained credit reaches zero. |
| 77 |
PN_CPP_EXTERN void drain(); |
| 78 |
|
| 79 |
/// @cond INTERNAL |
| 80 |
friend class internal::factory<receiver>; |
| 81 |
friend class receiver_iterator; |
| 82 |
/// @endcond |
| 83 |
}; |
| 84 |
|
| 85 |
/// @cond INTERNAL |
| 86 |
|
| 87 |
/// An iterator of receivers. |
| 88 |
class receiver_iterator : public internal::iter_base<receiver, receiver_iterator> { |
| 89 |
explicit receiver_iterator(receiver r, pn_session_t* s = 0) : |
| 90 |
internal::iter_base<receiver, receiver_iterator>(r), session_(s) {} |
| 91 |
|
| 92 |
public: |
| 93 |
/// Create an iterator of receivers. |
| 94 |
explicit receiver_iterator() : |
| 95 |
internal::iter_base<receiver, receiver_iterator>(0), session_(0) {} |
| 96 |
|
| 97 |
/// Advance to the next receiver. |
| 98 |
PN_CPP_EXTERN receiver_iterator operator++(); |
| 99 |
|
| 100 |
private: |
| 101 |
pn_session_t* session_; |
| 102 |
|
| 103 |
friend class connection; |
| 104 |
friend class session; |
| 105 |
}; |
| 106 |
|
| 107 |
/// A range of receivers. |
| 108 |
typedef internal::iter_range<receiver_iterator> receiver_range; |
| 109 |
|
| 110 |
/// @endcond |
| 111 |
|
| 112 |
} // proton |
| 113 |
|
| 114 |
#endif // PROTON_RECEIVER_HPP |