| 1 |
#ifndef PROTON_SESSION_H |
| 2 |
#define PROTON_SESSION_H 1 |
| 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 <proton/import_export.h> |
| 26 |
#include <proton/type_compat.h> |
| 27 |
#include <proton/types.h> |
| 28 |
#include <proton/object.h> |
| 29 |
#include <proton/error.h> |
| 30 |
#include <proton/condition.h> |
| 31 |
#include <stddef.h> |
| 32 |
|
| 33 |
#ifdef __cplusplus |
| 34 |
extern "C" { |
| 35 |
#endif |
| 36 |
|
| 37 |
/** |
| 38 |
* @file |
| 39 |
* |
| 40 |
* @copybrief session |
| 41 |
* |
| 42 |
* @addtogroup session |
| 43 |
* @{ |
| 44 |
*/ |
| 45 |
|
| 46 |
/** |
| 47 |
* Factory for creating a new session on a given connection object. |
| 48 |
* |
| 49 |
* Creates a new session object and adds it to the set of sessions |
| 50 |
* maintained by the connection object. |
| 51 |
* |
| 52 |
* @param[in] connection the connection object |
| 53 |
* @return a pointer to the new session |
| 54 |
*/ |
| 55 |
PN_EXTERN pn_session_t *pn_session(pn_connection_t *connection); |
| 56 |
|
| 57 |
/** |
| 58 |
* Free a session object. |
| 59 |
* |
| 60 |
* When a session is freed it will no longer be retained by the |
| 61 |
* connection once any internal references to the session are no |
| 62 |
* longer needed. Freeing a session will free all links on that |
| 63 |
* session and settle any deliveries on those links. |
| 64 |
* |
| 65 |
* @param[in] session the session object to free (or NULL) |
| 66 |
*/ |
| 67 |
PN_EXTERN void pn_session_free(pn_session_t *session); |
| 68 |
|
| 69 |
/** |
| 70 |
* Get the application context that is associated with a session |
| 71 |
* object. |
| 72 |
* |
| 73 |
* The application context for a session may be set using |
| 74 |
* ::pn_session_set_context. |
| 75 |
* |
| 76 |
* @param[in] session the session whose context is to be returned. |
| 77 |
* @return the application context for the session object |
| 78 |
*/ |
| 79 |
PN_EXTERN void *pn_session_get_context(pn_session_t *session); |
| 80 |
|
| 81 |
/** |
| 82 |
* Set a new application context for a session object. |
| 83 |
* |
| 84 |
* The application context for a session object may be retrieved |
| 85 |
* using ::pn_session_get_context. |
| 86 |
* |
| 87 |
* @param[in] session the session object |
| 88 |
* @param[in] context the application context |
| 89 |
*/ |
| 90 |
PN_EXTERN void pn_session_set_context(pn_session_t *session, void *context); |
| 91 |
|
| 92 |
/** |
| 93 |
* Get the attachments that are associated with a session object. |
| 94 |
* |
| 95 |
* @param[in] session the session whose attachments are to be returned. |
| 96 |
* @return the attachments for the session object |
| 97 |
*/ |
| 98 |
PN_EXTERN pn_record_t *pn_session_attachments(pn_session_t *session); |
| 99 |
|
| 100 |
/** |
| 101 |
* Get the endpoint state flags for a session. |
| 102 |
* |
| 103 |
* @param[in] session the session object |
| 104 |
* @return the session's state flags |
| 105 |
*/ |
| 106 |
PN_EXTERN pn_state_t pn_session_state(pn_session_t *session); |
| 107 |
|
| 108 |
/** |
| 109 |
* **Deprecated** - Use ::pn_session_condition(). |
| 110 |
* |
| 111 |
* Get additional error information associated with the session. |
| 112 |
* |
| 113 |
* Whenever a session operation fails (i.e. returns an error code), |
| 114 |
* additional error details can be obtained using this function. The |
| 115 |
* error object that is returned may also be used to clear the error |
| 116 |
* condition. |
| 117 |
* |
| 118 |
* The pointer returned by this operation is valid until the |
| 119 |
* session object is freed. |
| 120 |
* |
| 121 |
* Deprecation notice: note that this will always return an empty |
| 122 |
* error object |
| 123 |
* |
| 124 |
* @param[in] session the session object |
| 125 |
* @return the session's error object |
| 126 |
*/ |
| 127 |
/* PN_DEPRECATED("Use pn_session_condition") */ |
| 128 |
PN_EXTERN pn_error_t *pn_session_error(pn_session_t *session); |
| 129 |
|
| 130 |
/** |
| 131 |
* Get the local condition associated with the session endpoint. |
| 132 |
* |
| 133 |
* The ::pn_condition_t object retrieved may be modified prior to |
| 134 |
* closing the session in order to indicate a particular condition |
| 135 |
* exists when the session closes. This is normally used to |
| 136 |
* communicate error conditions to the remote peer, however it may |
| 137 |
* also be used in non error cases. See ::pn_condition_t for more |
| 138 |
* details. |
| 139 |
* |
| 140 |
* The pointer returned by this operation is valid until the session |
| 141 |
* object is freed. |
| 142 |
* |
| 143 |
* @param[in] session the session object |
| 144 |
* @return the session's local condition object |
| 145 |
*/ |
| 146 |
PN_EXTERN pn_condition_t *pn_session_condition(pn_session_t *session); |
| 147 |
|
| 148 |
/** |
| 149 |
* Get the remote condition associated with the session endpoint. |
| 150 |
* |
| 151 |
* The ::pn_condition_t object retrieved may be examined in order to |
| 152 |
* determine whether the remote peer was indicating some sort of |
| 153 |
* exceptional condition when the remote session endpoint was |
| 154 |
* closed. The ::pn_condition_t object returned may not be modified. |
| 155 |
* |
| 156 |
* The pointer returned by this operation is valid until the |
| 157 |
* session object is freed. |
| 158 |
* |
| 159 |
* @param[in] session the session object |
| 160 |
* @return the session's remote condition object |
| 161 |
*/ |
| 162 |
PN_EXTERN pn_condition_t *pn_session_remote_condition(pn_session_t *session); |
| 163 |
|
| 164 |
/** |
| 165 |
* Get the parent connection for a session object. |
| 166 |
* |
| 167 |
* This operation retrieves the parent pn_connection_t object that |
| 168 |
* contains the given pn_session_t object. |
| 169 |
* |
| 170 |
* @param[in] session the session object |
| 171 |
* @return the parent connection object |
| 172 |
*/ |
| 173 |
PN_EXTERN pn_connection_t *pn_session_connection(pn_session_t *session); |
| 174 |
|
| 175 |
/** |
| 176 |
* Open a session. |
| 177 |
* |
| 178 |
* Once this operation has completed, the PN_LOCAL_ACTIVE state flag |
| 179 |
* will be set. |
| 180 |
* |
| 181 |
* @param[in] session the session object |
| 182 |
*/ |
| 183 |
PN_EXTERN void pn_session_open(pn_session_t *session); |
| 184 |
|
| 185 |
/** |
| 186 |
* Close a session. |
| 187 |
* |
| 188 |
* Once this operation has completed, the PN_LOCAL_CLOSED state flag |
| 189 |
* will be set. This may be called without calling |
| 190 |
* ::pn_session_open, in this case it is equivalent to calling |
| 191 |
* ::pn_session_open followed by ::pn_session_close. |
| 192 |
* |
| 193 |
* @param[in] session the session object |
| 194 |
*/ |
| 195 |
PN_EXTERN void pn_session_close(pn_session_t *session); |
| 196 |
|
| 197 |
/** |
| 198 |
* Get the incoming capacity of the session measured in bytes. |
| 199 |
* |
| 200 |
* The incoming capacity of a session determines how much incoming |
| 201 |
* message data the session can buffer. |
| 202 |
* |
| 203 |
* @param[in] session the session object |
| 204 |
* @return the incoming capacity of the session in bytes |
| 205 |
*/ |
| 206 |
PN_EXTERN size_t pn_session_get_incoming_capacity(pn_session_t *session); |
| 207 |
|
| 208 |
/** |
| 209 |
* Set the incoming capacity for a session object. |
| 210 |
* |
| 211 |
* The incoming capacity of a session determines how much incoming message |
| 212 |
* data the session can buffer, by governing the size of the session |
| 213 |
* incoming-window for transfer frames. This happens in concert with the |
| 214 |
* transport max frame size, and only when both values have been set. |
| 215 |
* |
| 216 |
* NOTE: If set, this value must be greater than or equal to the negotiated |
| 217 |
* frame size of the transport. The window is computed as a whole number of |
| 218 |
* frames when dividing remaining capacity at a given time by the connection |
| 219 |
* max frame size. As such, capacity and max frame size should be chosen so |
| 220 |
* as to ensure the frame window isn't unduly small and limiting performance. |
| 221 |
* |
| 222 |
* @param[in] session the session object |
| 223 |
* @param[in] capacity the incoming capacity for the session in bytes |
| 224 |
*/ |
| 225 |
PN_EXTERN void pn_session_set_incoming_capacity(pn_session_t *session, size_t capacity); |
| 226 |
|
| 227 |
/** |
| 228 |
* Get the outgoing window for a session object. |
| 229 |
* |
| 230 |
* @param[in] session the session object |
| 231 |
* @return the outgoing window for the session |
| 232 |
*/ |
| 233 |
PN_EXTERN size_t pn_session_get_outgoing_window(pn_session_t *session); |
| 234 |
|
| 235 |
/** |
| 236 |
* Set the outgoing window for a session object. |
| 237 |
* |
| 238 |
* @param[in] session the session object |
| 239 |
* @param[in] window the outgoing window for the session |
| 240 |
*/ |
| 241 |
PN_EXTERN void pn_session_set_outgoing_window(pn_session_t *session, size_t window); |
| 242 |
|
| 243 |
/** |
| 244 |
* Get the number of outgoing bytes currently buffered by a session. |
| 245 |
* |
| 246 |
* @param[in] session the session object |
| 247 |
* @return the number of outgoing bytes currently buffered |
| 248 |
*/ |
| 249 |
PN_EXTERN size_t pn_session_outgoing_bytes(pn_session_t *session); |
| 250 |
|
| 251 |
/** |
| 252 |
* Get the number of incoming bytes currently buffered by a session. |
| 253 |
* |
| 254 |
* @param[in] session the session object |
| 255 |
* @return the number of incoming bytes currently buffered |
| 256 |
*/ |
| 257 |
PN_EXTERN size_t pn_session_incoming_bytes(pn_session_t *session); |
| 258 |
|
| 259 |
/** |
| 260 |
* Retrieve the first session from a given connection that matches the |
| 261 |
* specified state mask. |
| 262 |
* |
| 263 |
* Examines the state of each session owned by the connection, and |
| 264 |
* returns the first session that matches the given state mask. If |
| 265 |
* state contains both local and remote flags, then an exact match |
| 266 |
* against those flags is performed. If state contains only local or |
| 267 |
* only remote flags, then a match occurs if any of the local or |
| 268 |
* remote flags are set respectively. |
| 269 |
* |
| 270 |
* @param[in] connection to be searched for matching sessions |
| 271 |
* @param[in] state mask to match |
| 272 |
* @return the first session owned by the connection that matches the |
| 273 |
* mask, else NULL if no sessions match |
| 274 |
*/ |
| 275 |
PN_EXTERN pn_session_t *pn_session_head(pn_connection_t *connection, pn_state_t state); |
| 276 |
|
| 277 |
/** |
| 278 |
* Retrieve the next session from a given connection that matches the |
| 279 |
* specified state mask. |
| 280 |
* |
| 281 |
* When used with ::pn_session_head, application can access all |
| 282 |
* sessions on the connection that match the given state. See |
| 283 |
* ::pn_session_head for description of match behavior. |
| 284 |
* |
| 285 |
* @param[in] session the previous session obtained from |
| 286 |
* ::pn_session_head or ::pn_session_next |
| 287 |
* @param[in] state mask to match. |
| 288 |
* @return the next session owned by the connection that matches the |
| 289 |
* mask, else NULL if no sessions match |
| 290 |
*/ |
| 291 |
PN_EXTERN pn_session_t *pn_session_next(pn_session_t *session, pn_state_t state); |
| 292 |
|
| 293 |
/** |
| 294 |
* @} |
| 295 |
*/ |
| 296 |
|
| 297 |
#ifdef __cplusplus |
| 298 |
} |
| 299 |
#endif |
| 300 |
|
| 301 |
#endif /* session.h */ |