| 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 "contexts.hpp" |
| 23 |
|
| 24 |
#include "msg.hpp" |
| 25 |
#include "reconnect_options_impl.hpp" |
| 26 |
#include "proton_bits.hpp" |
| 27 |
|
| 28 |
#include "proton/connection_options.hpp" |
| 29 |
#include "proton/error.hpp" |
| 30 |
#include "proton/reconnect_options.hpp" |
| 31 |
|
| 32 |
#include <proton/connection.h> |
| 33 |
#include <proton/object.h> |
| 34 |
#include <proton/link.h> |
| 35 |
#include <proton/listener.h> |
| 36 |
#include <proton/message.h> |
| 37 |
#include <proton/session.h> |
| 38 |
|
| 39 |
#include <typeinfo> |
| 40 |
|
| 41 |
namespace proton { |
| 42 |
|
| 43 |
namespace { |
| 44 |
void cpp_context_finalize(void* v) { reinterpret_cast<context*>(v)->~context(); } |
| 45 |
#define CID_cpp_context CID_pn_object |
| 46 |
#define cpp_context_initialize NULL |
| 47 |
#define cpp_context_hashcode NULL |
| 48 |
#define cpp_context_compare NULL |
| 49 |
#define cpp_context_inspect NULL |
| 50 |
pn_class_t cpp_context_class = PN_CLASS(cpp_context); |
| 51 |
|
| 52 |
// Handles |
| 53 |
PN_HANDLE(CONNECTION_CONTEXT) |
| 54 |
PN_HANDLE(LISTENER_CONTEXT) |
| 55 |
PN_HANDLE(SESSION_CONTEXT) |
| 56 |
PN_HANDLE(LINK_CONTEXT) |
| 57 |
|
| 58 |
template <class T> |
| 59 |
T* get_context(pn_record_t* record, pn_handle_t handle) { |
| 60 |
return reinterpret_cast<T*>(pn_record_get(record, handle)); |
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
context::~context() {} |
| 66 |
|
| 67 |
void *context::alloc(size_t n) { return pn_object_new(&cpp_context_class, n); } |
| 68 |
|
| 69 |
pn_class_t* context::pn_class() { return &cpp_context_class; } |
| 70 |
|
| 71 |
connection_context::connection_context() : |
| 72 |
container(0), default_session(0), link_gen(0), handler(0), listener_context_(0) |
| 73 |
{} |
| 74 |
|
| 75 |
reconnect_context::reconnect_context(const reconnect_options_base& ro) : |
| 76 |
reconnect_options_(ro), retries_(0), current_url_(-1), stop_reconnect_(false), reconnected_(false) |
| 77 |
{} |
| 78 |
|
| 79 |
listener_context::listener_context() : listen_handler_(0) {} |
| 80 |
|
| 81 |
connection_context& connection_context::get(pn_connection_t *c) { |
| 82 |
return ref<connection_context>(id(pn_connection_attachments(c), CONNECTION_CONTEXT)); |
| 83 |
} |
| 84 |
|
| 85 |
listener_context& listener_context::get(pn_listener_t* l) { |
| 86 |
return ref<listener_context>(id(pn_listener_attachments(l), LISTENER_CONTEXT)); |
| 87 |
} |
| 88 |
|
| 89 |
link_context& link_context::get(pn_link_t* l) { |
| 90 |
return ref<link_context>(id(pn_link_attachments(l), LINK_CONTEXT)); |
| 91 |
} |
| 92 |
|
| 93 |
session_context& session_context::get(pn_session_t* s) { |
| 94 |
return ref<session_context>(id(pn_session_attachments(s), SESSION_CONTEXT)); |
| 95 |
} |
| 96 |
|
| 97 |
} |