Debian Codegraph @

cpp/src/session_options.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/session_options.hpp"
23 #include "proton/session.hpp"
24 #include "proton/connection.hpp"
25 #include "proton/container.hpp"
26
27 #include <proton/session.h>
28
29 #include "messaging_adapter.hpp"
30 #include "proactor_container_impl.hpp"
31 #include "proton_bits.hpp"
32
33 namespace proton {
34
35 template <class T> struct option {
36 T value;
37 bool set;
38
39 option() : value(), set(false) {}
40 option& operator=(const T& x) { value = x; set = true; return *this; }
41 void update(const option<T>& x) { if (x.set) *this = x.value; }
42 };
43
44 class session_options::impl {
45 public:
46 option<messaging_handler *> handler;
47
48 void apply(session& s) {
49 if (s.uninitialized()) {
50 if (handler.set && handler.value) container::impl::set_handler(s, handler.value);
51 }
52 }
53
54 };
55
56 session_options::session_options() : impl_(new impl()) {}
57 session_options::session_options(const session_options& x) : impl_(new impl()) {
58 *this = x;
59 }
60 session_options::~session_options() = default;
61
62 session_options& session_options::operator=(const session_options& x) {
63 *impl_ = *x.impl_;
64 return *this;
65 }
66
67 session_options& session_options::handler(class messaging_handler &h) { impl_->handler = &h; return *this; }
68
69 void session_options::apply(session& s) const { impl_->apply(s); }
70
71
72
73
74 } // namespace proton