| 1 |
#ifndef PROTON_ENDPOINT_HPP |
| 2 |
#define PROTON_ENDPOINT_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 "./error_condition.hpp" |
| 27 |
#include "./internal/export.hpp" |
| 28 |
|
| 29 |
/// @file |
| 30 |
/// @copybrief proton::endpoint |
| 31 |
|
| 32 |
namespace proton { |
| 33 |
|
| 34 |
/// The base class for session, connection, and link. |
| 35 |
class |
| 36 |
PN_CPP_CLASS_EXTERN endpoint { |
| 37 |
public: |
| 38 |
PN_CPP_EXTERN virtual ~endpoint(); |
| 39 |
|
| 40 |
// XXX Add the container accessor here. |
| 41 |
|
| 42 |
/// True if the local end is uninitialized. |
| 43 |
virtual bool uninitialized() const = 0; |
| 44 |
|
| 45 |
/// True if the local end is active. |
| 46 |
virtual bool active() const = 0; |
| 47 |
|
| 48 |
/// True if the local and remote ends are closed. |
| 49 |
virtual bool closed() const = 0; |
| 50 |
|
| 51 |
/// Get the error condition of the remote endpoint. |
| 52 |
virtual class error_condition error() const = 0; |
| 53 |
|
| 54 |
// XXX Add virtual open() and open(endpoint_options) |
| 55 |
|
| 56 |
/// Close the endpoint. |
| 57 |
virtual void close() = 0; |
| 58 |
|
| 59 |
/// Close the endpoint with an error condition. |
| 60 |
virtual void close(const error_condition&) = 0; |
| 61 |
|
| 62 |
/// @cond INTERNAL |
| 63 |
endpoint() = default; |
| 64 |
endpoint& operator=(const endpoint&) = default; |
| 65 |
endpoint(const endpoint&) = default; |
| 66 |
endpoint& operator=(endpoint&&) = default; |
| 67 |
endpoint(endpoint&&) = default; |
| 68 |
/// @endcond |
| 69 |
}; |
| 70 |
|
| 71 |
namespace internal { |
| 72 |
|
| 73 |
template <class T, class D> class iter_base { |
| 74 |
public: |
| 75 |
typedef T value_type; |
| 76 |
|
| 77 |
T operator*() const { return obj_; } |
| 78 |
T* operator->() const { return const_cast<T*>(&obj_); } |
| 79 |
D operator++(int) { D x(*this); ++(*this); return x; } |
| 80 |
bool operator==(const iter_base<T, D>& x) const { return obj_ == x.obj_; } |
| 81 |
bool operator!=(const iter_base<T, D>& x) const { return obj_ != x.obj_; } |
| 82 |
|
| 83 |
protected: |
| 84 |
explicit iter_base(T p = 0) : obj_(p) {} |
| 85 |
T obj_; |
| 86 |
}; |
| 87 |
|
| 88 |
template<class I> class iter_range { |
| 89 |
public: |
| 90 |
typedef I iterator; |
| 91 |
|
| 92 |
explicit iter_range(I begin = I(), I end = I()) : begin_(begin), end_(end) {} |
| 93 |
I begin() const { return begin_; } |
| 94 |
I end() const { return end_; } |
| 95 |
bool empty() const { return begin_ == end_; } |
| 96 |
|
| 97 |
private: |
| 98 |
I begin_, end_; |
| 99 |
}; |
| 100 |
|
| 101 |
} // internal |
| 102 |
} // proton |
| 103 |
|
| 104 |
#endif // PROTON_ENDPOINT_HPP |