C AMQP Protocol Engine API  0.5
proton/engine.h
Go to the documentation of this file.
00001 #ifndef PROTON_ENGINE_H
00002 #define PROTON_ENGINE_H 1
00003 
00004 /*
00005  *
00006  * Licensed to the Apache Software Foundation (ASF) under one
00007  * or more contributor license agreements.  See the NOTICE file
00008  * distributed with this work for additional information
00009  * regarding copyright ownership.  The ASF licenses this file
00010  * to you under the Apache License, Version 2.0 (the
00011  * "License"); you may not use this file except in compliance
00012  * with the License.  You may obtain a copy of the License at
00013  *
00014  *   http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing,
00017  * software distributed under the License is distributed on an
00018  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00019  * KIND, either express or implied.  See the License for the
00020  * specific language governing permissions and limitations
00021  * under the License.
00022  *
00023  */
00024 
00025 #include <proton/import_export.h>
00026 #ifndef __cplusplus
00027 #include <stdbool.h>
00028 #endif
00029 #include <stddef.h>
00030 #include <sys/types.h>
00031 #include <proton/codec.h>
00032 #include <proton/error.h>
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037 
00044 typedef struct pn_transport_t pn_transport_t;
00045 typedef struct pn_connection_t pn_connection_t; 
00046 typedef struct pn_session_t pn_session_t;       
00047 typedef struct pn_link_t pn_link_t;             
00048 typedef struct pn_terminus_t pn_terminus_t;
00049 typedef struct pn_condition_t pn_condition_t;
00050 
00051 typedef enum {
00052   PN_UNSPECIFIED = 0,
00053   PN_SOURCE = 1,
00054   PN_TARGET = 2,
00055   PN_COORDINATOR = 3
00056 } pn_terminus_type_t;
00057 typedef enum {
00058   PN_NONDURABLE = 0,
00059   PN_CONFIGURATION = 1,
00060   PN_DELIVERIES = 2
00061 } pn_durability_t;
00062 typedef enum {
00063   PN_LINK_CLOSE,
00064   PN_SESSION_CLOSE,
00065   PN_CONNECTION_CLOSE,
00066   PN_NEVER
00067 } pn_expiry_policy_t;
00068 typedef enum {
00069   PN_DIST_MODE_UNSPECIFIED,
00070   PN_DIST_MODE_COPY,
00071   PN_DIST_MODE_MOVE
00072 } pn_distribution_mode_t;
00073 typedef enum {
00074   PN_SND_UNSETTLED = 0,
00075   PN_SND_SETTLED = 1,
00076   PN_SND_MIXED = 2
00077 } pn_snd_settle_mode_t;
00078 typedef enum {
00079   PN_RCV_FIRST = 0,  
00080   PN_RCV_SECOND = 1  
00081 } pn_rcv_settle_mode_t;
00082 
00083 typedef struct pn_disposition_t pn_disposition_t;
00084 typedef struct pn_delivery_t pn_delivery_t;
00085 
00086 typedef struct pn_delivery_tag_t {
00087   size_t size;
00088   const char *bytes;
00089 } pn_delivery_tag_t;
00090 
00091 #ifndef SWIG  // older versions of SWIG choke on this:
00092 static inline pn_delivery_tag_t pn_dtag(const char *bytes, size_t size) {
00093   pn_delivery_tag_t dtag = {size, bytes};
00094   return dtag;
00095 }
00096 #endif
00097 
00098 typedef int pn_state_t;     
00100 #define PN_LOCAL_UNINIT (1)    
00101 #define PN_LOCAL_ACTIVE (2)    
00102 #define PN_LOCAL_CLOSED (4)    
00103 #define PN_REMOTE_UNINIT (8)   
00104 #define PN_REMOTE_ACTIVE (16)  
00105 #define PN_REMOTE_CLOSED (32)  
00107 #define PN_LOCAL_MASK (PN_LOCAL_UNINIT | PN_LOCAL_ACTIVE | PN_LOCAL_CLOSED)
00108 #define PN_REMOTE_MASK (PN_REMOTE_UNINIT | PN_REMOTE_ACTIVE | PN_REMOTE_CLOSED)
00109 
00116 #define PN_RECEIVED (0x0000000000000023)
00117 #define PN_ACCEPTED (0x0000000000000024)
00118 #define PN_REJECTED (0x0000000000000025)
00119 #define PN_RELEASED (0x0000000000000026)
00120 #define PN_MODIFIED (0x0000000000000027)
00121 
00122 typedef int pn_trace_t;
00123 
00124 #define PN_TRACE_OFF (0)
00125 #define PN_TRACE_RAW (1)
00126 #define PN_TRACE_FRM (2)
00127 #define PN_TRACE_DRV (4)
00128 
00129 // connection
00130 
00135 PN_EXTERN pn_connection_t *pn_connection(void);
00136 
00142 PN_EXTERN pn_state_t pn_connection_state(pn_connection_t *connection);
00144 PN_EXTERN pn_error_t *pn_connection_error(pn_connection_t *connection);
00146 PN_EXTERN const char *pn_connection_get_container(pn_connection_t *connection);
00148 PN_EXTERN void pn_connection_set_container(pn_connection_t *connection, const char *container);
00150 PN_EXTERN const char *pn_connection_get_hostname(pn_connection_t *connection);
00152 PN_EXTERN void pn_connection_set_hostname(pn_connection_t *connection, const char *hostname);
00153 PN_EXTERN const char *pn_connection_remote_container(pn_connection_t *connection);
00154 PN_EXTERN const char *pn_connection_remote_hostname(pn_connection_t *connection);
00155 PN_EXTERN pn_data_t *pn_connection_offered_capabilities(pn_connection_t *connection);
00156 PN_EXTERN pn_data_t *pn_connection_desired_capabilities(pn_connection_t *connection);
00157 PN_EXTERN pn_data_t *pn_connection_properties(pn_connection_t *connection);
00158 PN_EXTERN pn_data_t *pn_connection_remote_offered_capabilities(pn_connection_t *connection);
00159 PN_EXTERN pn_data_t *pn_connection_remote_desired_capabilities(pn_connection_t *connection);
00160 PN_EXTERN pn_data_t *pn_connection_remote_properties(pn_connection_t *connection);
00161 
00162 
00178 PN_EXTERN pn_delivery_t *pn_work_head(pn_connection_t *connection);
00179 
00188 PN_EXTERN pn_delivery_t *pn_work_next(pn_delivery_t *delivery);
00189 
00198 PN_EXTERN pn_session_t *pn_session(pn_connection_t *connection);
00199 
00200 PN_EXTERN size_t pn_session_get_incoming_capacity(pn_session_t *ssn);
00201 PN_EXTERN void pn_session_set_incoming_capacity(pn_session_t *ssn, size_t capacity);
00202 
00203 PN_EXTERN size_t pn_session_outgoing_bytes(pn_session_t *ssn);
00204 PN_EXTERN size_t pn_session_incoming_bytes(pn_session_t *ssn);
00205 
00214 PN_EXTERN pn_transport_t *pn_transport(void);
00215 
00221 PN_EXTERN int pn_transport_bind(pn_transport_t *transport, pn_connection_t *connection);
00222 
00223 PN_EXTERN int pn_transport_unbind(pn_transport_t *transport);
00224 
00239 PN_EXTERN pn_session_t *pn_session_head(pn_connection_t *connection, pn_state_t state);
00240 
00253 PN_EXTERN pn_session_t *pn_session_next(pn_session_t *session, pn_state_t state);
00254 
00269 PN_EXTERN pn_link_t *pn_link_head(pn_connection_t *connection, pn_state_t state);
00270 
00283 PN_EXTERN pn_link_t *pn_link_next(pn_link_t *link, pn_state_t state);
00284 
00285 PN_EXTERN void pn_connection_reset(pn_connection_t *connection);
00286 PN_EXTERN void pn_connection_open(pn_connection_t *connection);
00287 PN_EXTERN void pn_connection_close(pn_connection_t *connection);
00288 PN_EXTERN void pn_connection_free(pn_connection_t *connection);
00289 
00297 PN_EXTERN void *pn_connection_get_context(pn_connection_t *connection);
00298 
00305 PN_EXTERN void pn_connection_set_context(pn_connection_t *connection, void *context);
00306 
00307 
00308 // transport
00309 PN_EXTERN pn_error_t *pn_transport_error(pn_transport_t *transport);
00310 /* deprecated */
00311 PN_EXTERN ssize_t pn_transport_input(pn_transport_t *transport, const char *bytes, size_t available);
00312 /* deprecated */
00313 PN_EXTERN ssize_t pn_transport_output(pn_transport_t *transport, char *bytes, size_t size);
00314 
00327 PN_EXTERN ssize_t pn_transport_capacity(pn_transport_t *transport);
00328 
00337 PN_EXTERN char *pn_transport_tail(pn_transport_t *transport);
00338 
00348 PN_EXTERN int pn_transport_push(pn_transport_t *transport, const char *src, size_t size);
00349 
00360 PN_EXTERN int pn_transport_process(pn_transport_t *transport, size_t size);
00361 
00368 PN_EXTERN int pn_transport_close_tail(pn_transport_t *transport);
00369 
00382 PN_EXTERN ssize_t pn_transport_pending(pn_transport_t *transport);
00383 
00393 PN_EXTERN const char *pn_transport_head(pn_transport_t *transport);
00394 
00402 PN_EXTERN int pn_transport_peek(pn_transport_t *transport, char *dst, size_t size);
00403 
00412 PN_EXTERN void pn_transport_pop(pn_transport_t *transport, size_t size);
00413 
00420 PN_EXTERN int pn_transport_close_head(pn_transport_t *transport);
00421 
00422 
00436 PN_EXTERN pn_timestamp_t pn_transport_tick(pn_transport_t *transport, pn_timestamp_t now);
00437 PN_EXTERN void pn_transport_trace(pn_transport_t *transport, pn_trace_t trace);
00438 // max frame of zero means "unlimited"
00439 PN_EXTERN uint32_t pn_transport_get_max_frame(pn_transport_t *transport);
00440 PN_EXTERN void pn_transport_set_max_frame(pn_transport_t *transport, uint32_t size);
00441 PN_EXTERN uint32_t pn_transport_get_remote_max_frame(pn_transport_t *transport);
00442 /* timeout of zero means "no timeout" */
00443 PN_EXTERN pn_millis_t pn_transport_get_idle_timeout(pn_transport_t *transport);
00444 PN_EXTERN void pn_transport_set_idle_timeout(pn_transport_t *transport, pn_millis_t timeout);
00445 PN_EXTERN pn_millis_t pn_transport_get_remote_idle_timeout(pn_transport_t *transport);
00446 PN_EXTERN uint64_t pn_transport_get_frames_output(const pn_transport_t *transport);
00447 PN_EXTERN uint64_t pn_transport_get_frames_input(const pn_transport_t *transport);
00448 PN_EXTERN bool pn_transport_quiesced(pn_transport_t *transport);
00449 PN_EXTERN void pn_transport_free(pn_transport_t *transport);
00450 
00451 // session
00452 PN_EXTERN pn_state_t pn_session_state(pn_session_t *session);
00453 PN_EXTERN pn_error_t *pn_session_error(pn_session_t *session);
00454 PN_EXTERN pn_connection_t *pn_session_connection(pn_session_t *session);
00455 PN_EXTERN void pn_session_open(pn_session_t *session);
00456 PN_EXTERN void pn_session_close(pn_session_t *session);
00457 PN_EXTERN void pn_session_free(pn_session_t *session);
00458 PN_EXTERN void *pn_session_get_context(pn_session_t *session);
00459 PN_EXTERN void pn_session_set_context(pn_session_t *session, void *context);
00460 
00461 // link
00462 PN_EXTERN pn_link_t *pn_sender(pn_session_t *session, const char *name);
00463 PN_EXTERN pn_link_t *pn_receiver(pn_session_t *session, const char *name);
00464 PN_EXTERN const char *pn_link_name(pn_link_t *link);
00465 PN_EXTERN bool pn_link_is_sender(pn_link_t *link);
00466 PN_EXTERN bool pn_link_is_receiver(pn_link_t *link);
00467 PN_EXTERN pn_state_t pn_link_state(pn_link_t *link);
00468 PN_EXTERN pn_error_t *pn_link_error(pn_link_t *link);
00469 PN_EXTERN pn_session_t *pn_link_session(pn_link_t *link);
00470 PN_EXTERN pn_terminus_t *pn_link_source(pn_link_t *link);
00471 PN_EXTERN pn_terminus_t *pn_link_target(pn_link_t *link);
00472 PN_EXTERN pn_terminus_t *pn_link_remote_source(pn_link_t *link);
00473 PN_EXTERN pn_terminus_t *pn_link_remote_target(pn_link_t *link);
00474 PN_EXTERN pn_delivery_t *pn_link_current(pn_link_t *link);
00475 PN_EXTERN bool pn_link_advance(pn_link_t *link);
00476 PN_EXTERN int pn_link_credit(pn_link_t *link);
00477 PN_EXTERN int pn_link_queued(pn_link_t *link);
00478 PN_EXTERN int pn_link_available(pn_link_t *link);
00479 PN_EXTERN pn_snd_settle_mode_t pn_link_snd_settle_mode(pn_link_t *link);
00480 PN_EXTERN pn_rcv_settle_mode_t pn_link_rcv_settle_mode(pn_link_t *link);
00481 PN_EXTERN pn_snd_settle_mode_t pn_link_remote_snd_settle_mode(pn_link_t *link);
00482 PN_EXTERN pn_rcv_settle_mode_t pn_link_remote_rcv_settle_mode(pn_link_t *link);
00483 PN_EXTERN void pn_link_set_snd_settle_mode(pn_link_t *link, pn_snd_settle_mode_t);
00484 PN_EXTERN void pn_link_set_rcv_settle_mode(pn_link_t *link, pn_rcv_settle_mode_t);
00485 
00486 PN_EXTERN int pn_link_unsettled(pn_link_t *link);
00487 PN_EXTERN pn_delivery_t *pn_unsettled_head(pn_link_t *link);
00488 PN_EXTERN pn_delivery_t *pn_unsettled_next(pn_delivery_t *delivery);
00489 
00490 PN_EXTERN void pn_link_open(pn_link_t *sender);
00491 PN_EXTERN void pn_link_close(pn_link_t *sender);
00492 PN_EXTERN void pn_link_free(pn_link_t *sender);
00493 PN_EXTERN void *pn_link_get_context(pn_link_t *link);
00494 PN_EXTERN void pn_link_set_context(pn_link_t *link, void *context);
00495 
00496 // sender
00497 PN_EXTERN void pn_link_offered(pn_link_t *sender, int credit);
00498 PN_EXTERN ssize_t pn_link_send(pn_link_t *sender, const char *bytes, size_t n);
00499 PN_EXTERN void pn_link_drained(pn_link_t *sender);
00500 //void pn_link_abort(pn_sender_t *sender);
00501 
00502 // receiver
00503 PN_EXTERN void pn_link_flow(pn_link_t *receiver, int credit);
00504 PN_EXTERN void pn_link_drain(pn_link_t *receiver, int credit);
00505 PN_EXTERN ssize_t pn_link_recv(pn_link_t *receiver, char *bytes, size_t n);
00506 
00507 // terminus
00508 PN_EXTERN pn_terminus_type_t pn_terminus_get_type(pn_terminus_t *terminus);
00509 PN_EXTERN int pn_terminus_set_type(pn_terminus_t *terminus, pn_terminus_type_t type);
00510 
00511 PN_EXTERN const char *pn_terminus_get_address(pn_terminus_t *terminus);
00512 PN_EXTERN int pn_terminus_set_address(pn_terminus_t *terminus, const char *address);
00513 PN_EXTERN pn_durability_t pn_terminus_get_durability(pn_terminus_t *terminus);
00514 PN_EXTERN int pn_terminus_set_durability(pn_terminus_t *terminus,
00515                                pn_durability_t durability);
00516 PN_EXTERN pn_expiry_policy_t pn_terminus_get_expiry_policy(pn_terminus_t *terminus);
00517 PN_EXTERN int pn_terminus_set_expiry_policy(pn_terminus_t *terminus, pn_expiry_policy_t policy);
00518 PN_EXTERN pn_seconds_t pn_terminus_get_timeout(pn_terminus_t *terminus);
00519 PN_EXTERN int pn_terminus_set_timeout(pn_terminus_t *terminus, pn_seconds_t);
00520 PN_EXTERN bool pn_terminus_is_dynamic(pn_terminus_t *terminus);
00521 PN_EXTERN int pn_terminus_set_dynamic(pn_terminus_t *terminus, bool dynamic);
00522 PN_EXTERN pn_data_t *pn_terminus_properties(pn_terminus_t *terminus);
00523 PN_EXTERN pn_data_t *pn_terminus_capabilities(pn_terminus_t *terminus);
00524 PN_EXTERN pn_data_t *pn_terminus_outcomes(pn_terminus_t *terminus);
00525 PN_EXTERN pn_data_t *pn_terminus_filter(pn_terminus_t *terminus);
00526 PN_EXTERN pn_distribution_mode_t pn_terminus_get_distribution_mode(const pn_terminus_t *terminus);
00527 PN_EXTERN int pn_terminus_set_distribution_mode(pn_terminus_t *terminus, pn_distribution_mode_t m);
00528 PN_EXTERN int pn_terminus_copy(pn_terminus_t *terminus, pn_terminus_t *src);
00529 
00530 // delivery
00531 PN_EXTERN pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag);
00532 PN_EXTERN pn_delivery_tag_t pn_delivery_tag(pn_delivery_t *delivery);
00533 PN_EXTERN pn_link_t *pn_delivery_link(pn_delivery_t *delivery);
00534 // how do we do delivery state?
00535 PN_EXTERN pn_disposition_t *pn_delivery_local(pn_delivery_t *delivery);
00536 PN_EXTERN uint64_t pn_delivery_local_state(pn_delivery_t *delivery);
00537 PN_EXTERN pn_disposition_t *pn_delivery_remote(pn_delivery_t *delivery);
00538 PN_EXTERN uint64_t pn_delivery_remote_state(pn_delivery_t *delivery);
00539 PN_EXTERN bool pn_delivery_settled(pn_delivery_t *delivery);
00540 PN_EXTERN size_t pn_delivery_pending(pn_delivery_t *delivery);
00541 PN_EXTERN bool pn_delivery_partial(pn_delivery_t *delivery);
00542 PN_EXTERN bool pn_delivery_writable(pn_delivery_t *delivery);
00543 PN_EXTERN bool pn_delivery_readable(pn_delivery_t *delivery);
00544 PN_EXTERN bool pn_delivery_updated(pn_delivery_t *delivery);
00545 PN_EXTERN void pn_delivery_update(pn_delivery_t *delivery, uint64_t state);
00546 PN_EXTERN void pn_delivery_clear(pn_delivery_t *delivery);
00547 //int pn_delivery_format(pn_delivery_t *delivery);
00548 PN_EXTERN void pn_delivery_settle(pn_delivery_t *delivery);
00549 PN_EXTERN void pn_delivery_dump(pn_delivery_t *delivery);
00550 PN_EXTERN void *pn_delivery_get_context(pn_delivery_t *delivery);
00551 PN_EXTERN void pn_delivery_set_context(pn_delivery_t *delivery, void *context);
00552 
00553 // disposition
00554 PN_EXTERN uint64_t pn_disposition_type(pn_disposition_t *disposition);
00555 PN_EXTERN pn_data_t *pn_disposition_data(pn_disposition_t *disposition);
00556 PN_EXTERN uint32_t pn_disposition_get_section_number(pn_disposition_t *disposition);
00557 PN_EXTERN void pn_disposition_set_section_number(pn_disposition_t *disposition, uint32_t section_number);
00558 PN_EXTERN uint64_t pn_disposition_get_section_offset(pn_disposition_t *disposition);
00559 PN_EXTERN void pn_disposition_set_section_offset(pn_disposition_t *disposition, uint64_t section_offset);
00560 PN_EXTERN bool pn_disposition_is_failed(pn_disposition_t *disposition);
00561 PN_EXTERN void pn_disposition_set_failed(pn_disposition_t *disposition, bool failed);
00562 PN_EXTERN bool pn_disposition_is_undeliverable(pn_disposition_t *disposition);
00563 PN_EXTERN void pn_disposition_set_undeliverable(pn_disposition_t *disposition, bool undeliverable);
00564 PN_EXTERN pn_data_t *pn_disposition_annotations(pn_disposition_t *disposition);
00565 
00566 // conditions
00567 PN_EXTERN pn_condition_t *pn_connection_condition(pn_connection_t *connection);
00568 PN_EXTERN pn_condition_t *pn_connection_remote_condition(pn_connection_t *connection);
00569 
00570 PN_EXTERN pn_condition_t *pn_session_condition(pn_session_t *session);
00571 PN_EXTERN pn_condition_t *pn_session_remote_condition(pn_session_t *session);
00572 
00573 PN_EXTERN pn_condition_t *pn_link_condition(pn_link_t *link);
00574 PN_EXTERN pn_condition_t *pn_link_remote_condition(pn_link_t *link);
00575 
00576 PN_EXTERN pn_condition_t *pn_disposition_condition(pn_disposition_t *disposition);
00577 
00578 PN_EXTERN bool pn_condition_is_set(pn_condition_t *condition);
00579 PN_EXTERN void pn_condition_clear(pn_condition_t *condition);
00580 
00581 PN_EXTERN const char *pn_condition_get_name(pn_condition_t *condition);
00582 PN_EXTERN int pn_condition_set_name(pn_condition_t *condition, const char *name);
00583 
00584 PN_EXTERN const char *pn_condition_get_description(pn_condition_t *condition);
00585 PN_EXTERN int pn_condition_set_description(pn_condition_t *condition, const char *description);
00586 
00587 PN_EXTERN pn_data_t *pn_condition_info(pn_condition_t *condition);
00588 
00589 PN_EXTERN bool pn_condition_is_redirect(pn_condition_t *condition);
00590 PN_EXTERN const char *pn_condition_redirect_host(pn_condition_t *condition);
00591 PN_EXTERN int pn_condition_redirect_port(pn_condition_t *condition);
00592 
00593 #ifdef __cplusplus
00594 }
00595 #endif
00596 
00597 #endif /* engine.h */