Debian Codegraph @

cpp/src/link.cpp

raw
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21
22 #include "proton_bits.hpp"
23
24 #include "proton/codec/map.hpp"
25 #include "proton/link.hpp"
26 #include "proton/error.hpp"
27 #include "proton/connection.hpp"
28
29 #include <proton/connection.h>
30 #include <proton/session.h>
31 #include <proton/link.h>
32
33 #include "contexts.hpp"
34 #include "msg.hpp"
35 #include "proton_bits.hpp"
36
37 namespace proton {
38
39 void link::attach() {
40 pn_link_open(pn_object());
41 }
42
43 void link::close() {
44 pn_link_close(pn_object());
45 }
46
47 void link::detach() {
48 pn_link_detach(pn_object());
49 }
50
51 int link::credit() const {
52 pn_link_t *lnk = pn_object();
53 if (pn_link_is_sender(lnk))
54 return pn_link_credit(lnk);
55 link_context& lctx = link_context::get(lnk);
56 return pn_link_credit(lnk) + lctx.pending_credit;
57 }
58
59 bool link::draining() {
60 pn_link_t *lnk = pn_object();
61 link_context& lctx = link_context::get(lnk);
62 if (pn_link_is_sender(lnk))
63 return pn_link_credit(lnk) > 0 && lctx.draining;
64 else
65 return lctx.draining;
66 }
67
68 std::string link::name() const { return str(pn_link_name(pn_object()));}
69
70 container& link::container() const {
71 return connection().container();
72 }
73
74 work_queue& link::work_queue() const {
75 return connection().work_queue();
76 }
77
78 class connection link::connection() const {
79 return make_wrapper(pn_session_connection(pn_link_session(pn_object())));
80 }
81
82 class session link::session() const {
83 return make_wrapper(pn_link_session(pn_object()));
84 }
85
86 std::map<symbol, value> link::properties() const {
87 std::map<symbol, value> ret;
88 value props(pn_link_remote_properties(pn_object()));
89 if (!props.empty()) {
90 get(props, ret);
91 }
92 return ret;
93 }
94
95 error_condition link::error() const {
96 return make_wrapper(pn_link_remote_condition(pn_object()));
97 }
98 }