You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by fa...@apache.org on 2014/03/14 12:20:49 UTC
svn commit: r1577483 [3/5] - in
/qpid/proton/branches/fadams-javascript-binding/proton-c: ./ bindings/
bindings/perl/ bindings/perl/lib/ bindings/perl/lib/qpid/proton/
bindings/php/ bindings/python/ bindings/ruby/ docs/api/ include/proton/
src/ src/cod...
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/object.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/object.h?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/object.h (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/object.h Fri Mar 14 11:20:47 2014
@@ -44,6 +44,8 @@ typedef struct pn_list_t pn_list_t;
typedef struct pn_map_t pn_map_t;
typedef struct pn_hash_t pn_hash_t;
typedef struct pn_string_t pn_string_t;
+typedef void *(*pn_iterator_next_t)(void *state);
+typedef struct pn_iterator_t pn_iterator_t;
typedef struct {
void (*initialize)(void *);
@@ -84,6 +86,8 @@ PN_EXTERN int pn_list_add(pn_list_t *lis
PN_EXTERN ssize_t pn_list_index(pn_list_t *list, void *value);
PN_EXTERN bool pn_list_remove(pn_list_t *list, void *value);
PN_EXTERN void pn_list_del(pn_list_t *list, int index, int n);
+PN_EXTERN void pn_list_clear(pn_list_t *list);
+PN_EXTERN void pn_list_iterator(pn_list_t *list, pn_iterator_t *iter);
#define PN_REFCOUNT_KEY (0x2)
#define PN_REFCOUNT_VALUE (0x4)
@@ -134,6 +138,10 @@ PN_EXTERN size_t pn_string_capacity(pn_s
PN_EXTERN int pn_string_resize(pn_string_t *string, size_t size);
PN_EXTERN int pn_string_copy(pn_string_t *string, pn_string_t *src);
+PN_EXTERN pn_iterator_t *pn_iterator(void);
+PN_EXTERN void *pn_iterator_start(pn_iterator_t *iterator,
+ pn_iterator_next_t next, size_t size);
+PN_EXTERN void *pn_iterator_next(pn_iterator_t *iterator);
#ifdef __cplusplus
}
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/sasl.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/sasl.h?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/sasl.h (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/sasl.h Fri Mar 14 11:20:47 2014
@@ -41,6 +41,10 @@ extern "C" {
* peers. The peer acting as the SASL Client must provide
* authentication credentials. The peer acting as the SASL Server must
* provide authentication against the received credentials.
+ *
+ * @defgroup sasl SASL
+ * @ingroup transport
+ * @{
*/
typedef struct pn_sasl_t pn_sasl_t;
@@ -167,6 +171,8 @@ PN_EXTERN void pn_sasl_done(pn_sasl_t *s
*/
PN_EXTERN pn_sasl_outcome_t pn_sasl_outcome(pn_sasl_t *sasl);
+/** @} */
+
#ifdef __cplusplus
}
#endif
Added: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selectable.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selectable.h?rev=1577483&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selectable.h (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selectable.h Fri Mar 14 11:20:47 2014
@@ -0,0 +1,59 @@
+#ifndef PROTON_SELECTABLE_H
+#define PROTON_SELECTABLE_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <proton/import_export.h>
+#include <proton/object.h>
+#include <proton/io.h>
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef pn_iterator_t pn_selectables_t;
+typedef struct pn_selectable_t pn_selectable_t;
+
+PN_EXTERN pn_selectables_t *pn_selectables(void);
+PN_EXTERN pn_selectable_t *pn_selectables_next(pn_selectables_t *selectables);
+PN_EXTERN void pn_selectables_free(pn_selectables_t *selectables);
+
+PN_EXTERN pn_socket_t pn_selectable_fd(pn_selectable_t *selectable);
+PN_EXTERN ssize_t pn_selectable_capacity(pn_selectable_t *selectable);
+PN_EXTERN ssize_t pn_selectable_pending(pn_selectable_t *selectable);
+PN_EXTERN pn_timestamp_t pn_selectable_deadline(pn_selectable_t *selectable);
+PN_EXTERN void pn_selectable_readable(pn_selectable_t *selectable);
+PN_EXTERN void pn_selectable_writable(pn_selectable_t *selectable);
+PN_EXTERN void pn_selectable_expired(pn_selectable_t *selectable);
+PN_EXTERN bool pn_selectable_is_registered(pn_selectable_t *selectable);
+PN_EXTERN void pn_selectable_set_registered(pn_selectable_t *selectable, bool registered);
+PN_EXTERN bool pn_selectable_is_terminal(pn_selectable_t *selectable);
+PN_EXTERN void pn_selectable_free(pn_selectable_t *selectable);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* selectable.h */
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selectable.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selectable.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selector.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selector.h?rev=1577483&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selector.h (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selector.h Fri Mar 14 11:20:47 2014
@@ -0,0 +1,53 @@
+#ifndef PROTON_SELECTOR_H
+#define PROTON_SELECTOR_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <proton/import_export.h>
+#include <proton/selectable.h>
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define PN_READABLE (1)
+#define PN_WRITABLE (2)
+#define PN_EXPIRED (4)
+
+typedef struct pn_selector_t pn_selector_t;
+
+PN_EXTERN pn_selector_t *pn_selector(void);
+PN_EXTERN void pn_selector_free(pn_selector_t *selector);
+PN_EXTERN void pn_selector_add(pn_selector_t *selector, pn_selectable_t *selectable);
+PN_EXTERN void pn_selector_update(pn_selector_t *selector, pn_selectable_t *selectable);
+PN_EXTERN void pn_selector_remove(pn_selector_t *selector, pn_selectable_t *selectable);
+PN_EXTERN int pn_selector_select(pn_selector_t *select, int timeout);
+PN_EXTERN pn_selectable_t *pn_selector_next(pn_selector_t *select, int *events);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* selector.h */
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selector.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/selector.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/session.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/session.h?rev=1577483&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/session.h (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/session.h Fri Mar 14 11:20:47 2014
@@ -0,0 +1,263 @@
+#ifndef PROTON_SESSION_H
+#define PROTON_SESSION_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <proton/import_export.h>
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+#include <stddef.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @file
+ * Session API for the proton Engine.
+ *
+ * @defgroup session Session
+ * @ingroup engine
+ * @{
+ */
+
+/**
+ * Factory for creating a new session on a given connection object.
+ *
+ * Creates a new session object and adds it to the set of sessions
+ * maintained by the connection object.
+ *
+ * @param[in] connection the connection object
+ * @return a pointer to the new session
+ */
+PN_EXTERN pn_session_t *pn_session(pn_connection_t *connection);
+
+/**
+ * Free a session object.
+ *
+ * When a session object is freed, all ::pn_link_t, and
+ * ::pn_delivery_t objects associated with the session are also
+ * freed.
+ *
+ * @param[in] session a session object to free (or NULL)
+ */
+PN_EXTERN void pn_session_free(pn_session_t *session);
+
+/**
+ * Get the application context that is associated with a session
+ * object.
+ *
+ * The application context for a session may be set using
+ * ::pn_session_set_context.
+ *
+ * @param[in] session the session whose context is to be returned.
+ * @return the application context for the session object
+ */
+PN_EXTERN void *pn_session_get_context(pn_session_t *session);
+
+/**
+ * Set a new application context for a session object.
+ *
+ * The application context for a session object may be retrieved
+ * using ::pn_session_get_context.
+ *
+ * @param[in] session the session object
+ * @param[in] context the application context
+ */
+PN_EXTERN void pn_session_set_context(pn_session_t *session, void *context);
+
+/**
+ * Get the endpoint state flags for a session.
+ *
+ * @param[in] session the session
+ * @return the session's state flags
+ */
+PN_EXTERN pn_state_t pn_session_state(pn_session_t *session);
+
+/**
+ * Get additional error information associated with the session.
+ *
+ * Whenever a session operation fails (i.e. returns an error code),
+ * additional error details can be obtained using this function. The
+ * error object that is returned may also be used to clear the error
+ * condition.
+ *
+ * The pointer returned by this operation is valid until the
+ * session object is freed.
+ *
+ * @param[in] session the sesion object
+ * @return the session's error object
+ */
+PN_EXTERN pn_error_t *pn_session_error(pn_session_t *session);
+
+/**
+ * Get the local condition associated with the session endpoint.
+ *
+ * The ::pn_condition_t object retrieved may be modified prior to
+ * closing the session in order to indicate a particular condition
+ * exists when the session closes. This is normally used to
+ * communicate error conditions to the remote peer, however it may
+ * also be used in non error cases. See ::pn_condition_t for more
+ * details.
+ *
+ * The pointer returned by this operation is valid until the session
+ * object is freed.
+ *
+ * @param[in] session the session object
+ * @return the session's local condition object
+ */
+PN_EXTERN pn_condition_t *pn_session_condition(pn_session_t *session);
+
+/**
+ * Get the remote condition associated with the session endpoint.
+ *
+ * The ::pn_condition_t object retrieved may be examined in order to
+ * determine whether the remote peer was indicating some sort of
+ * exceptional condition when the remote session endpoint was
+ * closed. The ::pn_condition_t object returned may not be modified.
+ *
+ * The pointer returned by this operation is valid until the
+ * session object is freed.
+ *
+ * @param[in] session the session object
+ * @return the session's remote condition object
+ */
+PN_EXTERN pn_condition_t *pn_session_remote_condition(pn_session_t *session);
+
+/**
+ * Get the parent connection for a session object.
+ *
+ * This operation retrieves the parent pn_connection_t object that
+ * contains the given pn_session_t object.
+ *
+ * @param[in] session the session object
+ * @return the parent connection object
+ */
+PN_EXTERN pn_connection_t *pn_session_connection(pn_session_t *session);
+
+/**
+ * Open a session.
+ *
+ * Once this operation has completed, the PN_LOCAL_ACTIVE state flag
+ * will be set.
+ *
+ * @param[in] session a session object
+ */
+PN_EXTERN void pn_session_open(pn_session_t *session);
+
+/**
+ * Close a session.
+ *
+ * Once this operation has completed, the PN_LOCAL_CLOSED state flag
+ * will be set. This may be called without calling
+ * ::pn_session_open, in this case it is equivalent to calling
+ * ::pn_session_open followed by ::pn_session_close.
+ *
+ * @param[in] session a session object
+ */
+PN_EXTERN void pn_session_close(pn_session_t *session);
+
+/**
+ * Get the incoming capacity of the session measured in bytes.
+ *
+ * The incoming capacity of a session determines how much incoming
+ * message data the session will buffer. Note that if this value is
+ * less than the negotiated frame size of the transport, it will be
+ * rounded up to one full frame.
+ *
+ * @param[in] session the session object
+ * @return the incoming capacity of the session in bytes
+ */
+PN_EXTERN size_t pn_session_get_incoming_capacity(pn_session_t *session);
+
+/**
+ * Set the incoming capacity for a session object.
+ *
+ * The incoming capacity of a session determines how much incoming
+ * message data the session will buffer. Note that if this value is
+ * less than the negotiated frame size of the transport, it will be
+ * rounded up to one full frame.
+ *
+ * @param[in] session the session object
+ * @param[in] capacity the incoming capacity for the session
+ */
+PN_EXTERN void pn_session_set_incoming_capacity(pn_session_t *session, size_t capacity);
+
+/**
+ * Get the number of outgoing bytes currently buffered by a session.
+ *
+ * @param[in] session a session object
+ * @return the number of outgoing bytes currently buffered
+ */
+PN_EXTERN size_t pn_session_outgoing_bytes(pn_session_t *session);
+
+/**
+ * Get the number of incoming bytes currently buffered by a session.
+ *
+ * @param[in] session a session object
+ * @return the number of incoming bytes currently buffered
+ */
+PN_EXTERN size_t pn_session_incoming_bytes(pn_session_t *session);
+
+/**
+ * Retrieve the first session from a given connection that matches the
+ * specified state mask.
+ *
+ * Examines the state of each session owned by the connection, and
+ * returns the first session that matches the given state mask. If
+ * state contains both local and remote flags, then an exact match
+ * against those flags is performed. If state contains only local or
+ * only remote flags, then a match occurs if any of the local or
+ * remote flags are set respectively.
+ *
+ * @param[in] connection to be searched for matching sessions
+ * @param[in] state mask to match
+ * @return the first session owned by the connection that matches the
+ * mask, else NULL if no sessions match
+ */
+PN_EXTERN pn_session_t *pn_session_head(pn_connection_t *connection, pn_state_t state);
+
+/**
+ * Retrieve the next session from a given connection that matches the
+ * specified state mask.
+ *
+ * When used with ::pn_session_head, application can access all
+ * sessions on the connection that match the given state. See
+ * ::pn_session_head for description of match behavior.
+ *
+ * @param[in] session the previous session obtained from
+ * ::pn_session_head or ::pn_session_next
+ * @param[in] state mask to match.
+ * @return the next session owned by the connection that matches the
+ * mask, else NULL if no sessions match
+ */
+PN_EXTERN pn_session_t *pn_session_next(pn_session_t *session, pn_state_t state);
+
+/** @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* session.h */
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/session.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/session.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/ssl.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/ssl.h?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/ssl.h (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/ssl.h Fri Mar 14 11:20:47 2014
@@ -56,9 +56,6 @@ extern "C" {
* sessions constructed from this domain will perform the corresponding role (either
* client or server).
*
- * Some per-session attributes - such as peer verification mode - may be overridden on a
- * per-session basis from the default provided by the parent pn_ssl_domain_t.
- *
* If either an SSL server or client needs to identify itself with the remote node, it
* must have its SSL certificate configured (see ::pn_ssl_domain_set_credentials()).
*
@@ -66,14 +63,17 @@ extern "C" {
* must have its database of trusted CAs configured (see ::pn_ssl_domain_set_trusted_ca_db()).
*
* An SSL server connection may allow the remote client to connect without SSL (eg. "in
- * the clear"), see ::pn_ssl_allow_unsecured_client().
+ * the clear"), see ::pn_ssl_domain_allow_unsecured_client().
*
* The level of verification required of the remote may be configured (see
- * ::pn_ssl_domain_set_default_peer_authentication ::pn_ssl_set_peer_authentication,
- * ::pn_ssl_get_peer_authentication).
+ * ::pn_ssl_domain_set_peer_authentication)
+ *
+ * Support for SSL Client Session resume is provided (see ::pn_ssl_init,
+ * ::pn_ssl_resume_status).
*
- * Support for SSL Client Session resume is provided (see ::pn_ssl_get_state,
- * ::pn_ssl_resume_state).
+ * @defgroup ssl SSL
+ * @ingroup transport
+ * @{
*/
typedef struct pn_ssl_domain_t pn_ssl_domain_t;
@@ -132,9 +132,9 @@ PN_EXTERN void pn_ssl_domain_free( pn_ss
* @return 0 on success
*/
PN_EXTERN int pn_ssl_domain_set_credentials( pn_ssl_domain_t *domain,
- const char *certificate_file,
- const char *private_key_file,
- const char *password);
+ const char *certificate_file,
+ const char *private_key_file,
+ const char *password);
/** Configure the set of trusted CA certificates used by this domain to verify peers.
*
@@ -180,10 +180,10 @@ typedef enum {
* Once certificates and trusted CAs are configured, peer verification can be enabled.
*
* @note In order to verify a peer, a trusted CA must be configured. See
- * ::pn_ssl_set_trusted_ca_db().
+ * ::pn_ssl_domain_set_trusted_ca_db().
*
* @note Servers must provide their own certificate when verifying a peer. See
- * ::pn_ssl_set_credentials().
+ * ::pn_ssl_domain_set_credentials().
*
* @note This setting effects only those pn_ssl_t objects created after this call
* returns. pn_ssl_t objects created before invoking this method will use the domain's
@@ -228,9 +228,10 @@ PN_EXTERN pn_ssl_t *pn_ssl(pn_transport_
*
* @param[in] ssl the ssl session to configured.
* @param[in] domain the ssl domain used to configure the SSL session.
- * @param[in] session_id if supplied, attempt to resume a previous SSL session that used
- * the same session_id. The resulting session will be identified by the given session_id
- * and stored for future session restore.
+ * @param[in] session_id if supplied, attempt to resume a previous SSL
+ * session that used the same session_id. If no previous SSL session
+ * is available, a new session will be created using the session_id
+ * and stored for future session restore (see ::::pn_ssl_resume_status).
* @return 0 on success, else an error code.
*/
PN_EXTERN int pn_ssl_init( pn_ssl_t *ssl,
@@ -287,7 +288,7 @@ PN_EXTERN pn_ssl_resume_status_t pn_ssl_
* (potential imposter), and the SSL connection is aborted.
*
* @note Verification of the hostname is only done if PN_SSL_VERIFY_PEER_NAME is enabled.
- * See ::pn_ssl_set_peer_authentication.
+ * See ::pn_ssl_domain_set_peer_authentication.
*
* @param[in] ssl the ssl session.
* @param[in] hostname the expected identity of the remote. Must conform to the syntax as
@@ -311,6 +312,8 @@ PN_EXTERN int pn_ssl_set_peer_hostname(
*/
PN_EXTERN int pn_ssl_get_peer_hostname( pn_ssl_t *ssl, char *hostname, size_t *bufsize );
+/** @} */
+
#ifdef __cplusplus
}
#endif
Added: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/terminus.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/terminus.h?rev=1577483&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/terminus.h (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/terminus.h Fri Mar 14 11:20:47 2014
@@ -0,0 +1,310 @@
+#ifndef PROTON_TERMINUS_H
+#define PROTON_TERMINUS_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <proton/import_export.h>
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+#include <stddef.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** @file
+ *
+ * Terminus API for the proton Engine.
+ *
+ * @defgroup terminus Terminus
+ * @ingroup link
+ * @{
+ */
+
+/**
+ * Encapsulates the endpoint state associated with an AMQP Terminus.
+ *
+ * An AMQP Terminus acts as either a source or target for messages,
+ * but never both. Every AMQP link is associated with both a source
+ * terminus and a target terminus that is negotiated during link
+ * establishment. A terminus consists of an AMQP address, along with a
+ * number of other properties defining the quality of service and
+ * behaviour of the link.
+ */
+typedef struct pn_terminus_t pn_terminus_t;
+
+/**
+ * Type of an AMQP terminus.
+ */
+typedef enum {
+ PN_UNSPECIFIED = 0, /**< indicates a nonexistent terminus, may used
+ as a source or target */
+ PN_SOURCE = 1, /**< indicates a source of messages */
+ PN_TARGET = 2, /**< indicates a target for messages */
+ PN_COORDINATOR = 3 /**< a special target identifying a transaction
+ coordinator */
+} pn_terminus_type_t;
+
+/**
+ * Durability mode of an AMQP terminus.
+ *
+ * An AMQP terminus may provide durable storage for its state, thereby
+ * permitting link recovery in the event of endpoint failures. This
+ * durability may be applied to the configuration of the terminus
+ * only, or to all delivery state as well.
+ */
+typedef enum {
+ PN_NONDURABLE = 0, /**< indicates a non durable terminus */
+ PN_CONFIGURATION = 1, /**< indicates a terminus with durably held
+ configuration, but not delivery state */
+ PN_DELIVERIES = 2 /**< indicates a terminus with both durably held
+ configuration and durably held delivery
+ state. */
+} pn_durability_t;
+
+/**
+ * Expiry policy of an AMQP terminus.
+ *
+ * An orphaned terminus can only exist for the timeout configured by
+ * ::pn_terminus_set_timeout. The expiry policy determins when a
+ * terminus is considered orphaned, i.e. when the expiry timer starts
+ * counting down.
+ */
+typedef enum {
+ PN_LINK_CLOSE, /**< the terminus is orphaned when the parent link is closed */
+ PN_SESSION_CLOSE, /**< the terminus is orphaned when the parent session is closed */
+ PN_CONNECTION_CLOSE, /**< the terminus is orphaned when the parent connection is closed */
+ PN_NEVER /**< the terminus is never considered orphaned */
+} pn_expiry_policy_t;
+
+/**
+ * Distribution mode of an AMQP terminus.
+ *
+ * The distribution mode of a source terminus defines the behaviour
+ * when multiple receiving links provide addresses that resolve to the
+ * same node.
+ */
+typedef enum {
+ PN_DIST_MODE_UNSPECIFIED = 0, /**< the behaviour is defined by the node */
+ PN_DIST_MODE_COPY = 1, /**< the receiver gets all messages */
+ PN_DIST_MODE_MOVE = 2 /**< the receiver competes for messages */
+} pn_distribution_mode_t;
+
+/**
+ * Get the type of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @return the terminus type
+ */
+PN_EXTERN pn_terminus_type_t pn_terminus_get_type(pn_terminus_t *terminus);
+
+/**
+ * Set the type of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @param[in] type the terminus type
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_set_type(pn_terminus_t *terminus, pn_terminus_type_t type);
+
+/**
+ * Get the address of a terminus object.
+ *
+ * The pointer returned by this operation is valid until
+ * ::pn_terminus_set_address is called or until the terminus is freed
+ * due to its parent link being freed.
+ *
+ * @param[in] terminus a terminus object
+ * @return a pointer to the address
+ */
+PN_EXTERN const char *pn_terminus_get_address(pn_terminus_t *terminus);
+
+/**
+ * Set the address of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @param[in] address an AMQP address string
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_set_address(pn_terminus_t *terminus, const char *address);
+
+/**
+ * Get the distribution mode of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @return the distribution mode of the terminus
+ */
+PN_EXTERN pn_distribution_mode_t pn_terminus_get_distribution_mode(const pn_terminus_t *terminus);
+
+/**
+ * Set the distribution mode of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @param[in] mode the distribution mode for the terminus
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_set_distribution_mode(pn_terminus_t *terminus, pn_distribution_mode_t mode);
+
+/**
+ * Get the durability mode of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @return the terminus durability mode
+ */
+PN_EXTERN pn_durability_t pn_terminus_get_durability(pn_terminus_t *terminus);
+
+/**
+ * Set the durability mode of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @param[in] durability the terminus durability mode
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_set_durability(pn_terminus_t *terminus,
+ pn_durability_t durability);
+
+/**
+ * Get the expiry policy of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @return the expiry policy of the terminus
+ */
+PN_EXTERN pn_expiry_policy_t pn_terminus_get_expiry_policy(pn_terminus_t *terminus);
+
+/**
+ * Set the expiry policy of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @param[in] policy the expiry policy for the terminus
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_set_expiry_policy(pn_terminus_t *terminus, pn_expiry_policy_t policy);
+
+/**
+ * Get the timeout of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @return the timeout of the terminus
+ */
+PN_EXTERN pn_seconds_t pn_terminus_get_timeout(pn_terminus_t *terminus);
+
+/**
+ * Set the timeout of a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @param[in] timeout the timeout for the terminus
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_set_timeout(pn_terminus_t *terminus, pn_seconds_t timeout);
+
+/**
+ * Get the dynamic flag for a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @return true if the dynamic flag is set for the terminus, false otherwise
+ */
+PN_EXTERN bool pn_terminus_is_dynamic(pn_terminus_t *terminus);
+
+/**
+ * Set the dynamic flag for a terminus object.
+ *
+ * @param[in] terminus a terminus object
+ * @param[in] dynamic the dynamic flag for the terminus
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_set_dynamic(pn_terminus_t *terminus, bool dynamic);
+
+/**
+ * Access/modify the AMQP properties data for a terminus object.
+ *
+ * This operation will return a pointer to a ::pn_data_t object that
+ * is valid until the terminus object is freed due to its parent link
+ * being freed. Any data contained by the ::pn_data_t object will be
+ * sent as the AMQP properties for the parent terminus object. Note
+ * that this MUST take the form of a symbol keyed map to be valid.
+ *
+ * @param[in] terminus a terminus object
+ * @return a pointer to a pn_data_t representing the terminus properties
+ */
+PN_EXTERN pn_data_t *pn_terminus_properties(pn_terminus_t *terminus);
+
+/**
+ * Access/modify the AMQP capabilities data for a terminus object.
+ *
+ * This operation will return a pointer to a ::pn_data_t object that
+ * is valid until the terminus object is freed due to its parent link
+ * being freed. Any data contained by the ::pn_data_t object will be
+ * sent as the AMQP capabilities for the parent terminus object. Note
+ * that this MUST take the form of an array of symbols to be valid.
+ *
+ * @param[in] terminus a terminus object
+ * @return a pointer to a pn_data_t representing the terminus capabilities
+ */
+PN_EXTERN pn_data_t *pn_terminus_capabilities(pn_terminus_t *terminus);
+
+/**
+ * Access/modify the AMQP outcomes for a terminus object.
+ *
+ * This operation will return a pointer to a ::pn_data_t object that
+ * is valid until the terminus object is freed due to its parent link
+ * being freed. Any data contained by the ::pn_data_t object will be
+ * sent as the AMQP outcomes for the parent terminus object. Note
+ * that this MUST take the form of an array of symbols to be valid.
+ *
+ * @param[in] terminus a terminus object
+ * @return a pointer to a pn_data_t representing the terminus outcomes
+ */
+PN_EXTERN pn_data_t *pn_terminus_outcomes(pn_terminus_t *terminus);
+
+/**
+ * Access/modify the AMQP filter set for a terminus object.
+ *
+ * This operation will return a pointer to a ::pn_data_t object that
+ * is valid until the terminus object is freed due to its parent link
+ * being freed. Any data contained by the ::pn_data_t object will be
+ * sent as the AMQP filter set for the parent terminus object. Note
+ * that this MUST take the form of a symbol keyed map to be valid.
+ *
+ * @param[in] terminus a source terminus object
+ * @return a pointer to a pn_data_t representing the terminus filter set
+ */
+PN_EXTERN pn_data_t *pn_terminus_filter(pn_terminus_t *terminus);
+
+/**
+ * Copy a terminus object.
+ *
+ * @param[in] terminus the terminus object to be copied into
+ * @param[in] src the terminus to be copied from
+ * @return 0 on success or an error code on failure
+ */
+PN_EXTERN int pn_terminus_copy(pn_terminus_t *terminus, pn_terminus_t *src);
+
+/** @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* terminus.h */
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/terminus.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/terminus.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/transport.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/transport.h?rev=1577483&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/transport.h (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/transport.h Fri Mar 14 11:20:47 2014
@@ -0,0 +1,496 @@
+#ifndef PROTON_TRANSPORT_H
+#define PROTON_TRANSPORT_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <proton/import_export.h>
+#ifndef __cplusplus
+#include <stdbool.h>
+#endif
+#include <stddef.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file
+ *
+ * Transport API for the proton Engine.
+ *
+ * @defgroup transport Transport
+ * @ingroup engine
+ * @{
+ */
+
+/**
+ * Holds the trace flags for an AMQP transport.
+ *
+ * The trace flags for an AMQP transport control what sort of
+ * information is logged by an AMQP transport. The following bits can
+ * be set:
+ *
+ * - ::PN_TRACE_OFF
+ * - ::PN_TRACE_RAW
+ * - ::PN_TRACE_FRM
+ * - ::PN_TRACE_DRV
+ *
+ */
+typedef int pn_trace_t;
+
+/**
+ * Callback for customizing logging behaviour.
+ */
+typedef void (*pn_tracer_t)(pn_transport_t *transport, const char *message);
+
+/**
+ * Turn logging off entirely.
+ */
+#define PN_TRACE_OFF (0)
+
+/**
+ * Log raw binary data into/out of the transport.
+ */
+#define PN_TRACE_RAW (1)
+
+/**
+ * Log frames into/out of the transport.
+ */
+#define PN_TRACE_FRM (2)
+
+/**
+ * Log driver related events, e.g. initialization, end of stream, etc.
+ */
+#define PN_TRACE_DRV (4)
+
+/**
+ * Factory for creating a transport.
+ *
+ * A transport is used by a connection to interface with the network.
+ * There can only be one connection associated with a transport. See
+ * pn_transport_bind().
+ *
+ * @return pointer to new transport
+ */
+PN_EXTERN pn_transport_t *pn_transport(void);
+
+/**
+ * Free a transport object.
+ *
+ * When a transport is freed, it is automatically unbound from its
+ * associated connection.
+ *
+ * @param[in] transport a transport object or NULL
+ */
+PN_EXTERN void pn_transport_free(pn_transport_t *transport);
+
+/**
+ * Get additional error information associated with the transport.
+ *
+ * Whenever a transport operation fails (i.e. returns an error code),
+ * additional error details can be obtained using this function. The
+ * error object that is returned may also be used to clear the error
+ * condition.
+ *
+ * The pointer returned by this operation is valid until the
+ * transport object is freed.
+ *
+ * @param[in] transport the transport object
+ * @return the transport's error object
+ */
+PN_EXTERN pn_error_t *pn_transport_error(pn_transport_t *transport);
+
+/**
+ * Binds the transport to an AMQP connection.
+ *
+ * @return an error code, or 0 on success
+ */
+PN_EXTERN int pn_transport_bind(pn_transport_t *transport, pn_connection_t *connection);
+
+/**
+ * Unbinds a transport from its AMQP connection.
+ *
+ * @return an error code, or 0 on success
+ */
+PN_EXTERN int pn_transport_unbind(pn_transport_t *transport);
+
+/**
+ * Update a transports trace flags.
+ *
+ * The trace flags for a transport control what sort of information is
+ * logged. See ::pn_trace_t for more details.
+ *
+ * @param[in] transport a transport object
+ * @param[in] trace the trace flags
+ */
+PN_EXTERN void pn_transport_trace(pn_transport_t *transport, pn_trace_t trace);
+
+/**
+ * Set the tracing function used by a transport.
+ *
+ * The tracing function is called to perform logging. Overriding this
+ * function allows embedding applications to divert the engine's
+ * logging to a place of their choice.
+ *
+ * @param[in] transport a transport object
+ * @param[in] tracer the tracing function
+ */
+PN_EXTERN void pn_transport_set_tracer(pn_transport_t *transport, pn_tracer_t tracer);
+
+/**
+ * Get the tracning function used by a transport.
+ *
+ * @param[in] transport a transport object
+ * @return the tracing function used by a transport
+ */
+PN_EXTERN pn_tracer_t pn_transport_get_tracer(pn_transport_t *transport);
+
+/**
+ * Get the application context that is associated with a transport object.
+ *
+ * The application context for a transport may be set using
+ * ::pn_transport_set_context.
+ *
+ * @param[in] transport the transport whose context is to be returned.
+ * @return the application context for the transport object
+ */
+PN_EXTERN void *pn_transport_get_context(pn_transport_t *transport);
+
+/**
+ * Set a new application context for a transport object.
+ *
+ * The application context for a transport object may be retrieved using
+ * ::pn_transport_get_context.
+ *
+ * @param[in] transport the transport object
+ * @param[in] context the application context
+ */
+PN_EXTERN void pn_transport_set_context(pn_transport_t *transport, void *context);
+
+/**
+ * Log a message using a transport's logging mechanism.
+ *
+ * This can be useful in a debugging context as the log message will
+ * be prefixed with the transport's identifier.
+ *
+ * @param[in] transport a transport object
+ * @param[in] message the message to be logged
+ */
+PN_EXTERN void pn_transport_log(pn_transport_t *transport, const char *message);
+
+/**
+ * Log a printf formatted message using a transport's logging
+ * mechanism.
+ *
+ * This can be useful in a debugging context as the log message will
+ * be prefixed with the transport's identifier.
+ *
+ * @param[in] transport a transport object
+ * @param[in] fmt the printf formatted message to be logged
+ */
+PN_EXTERN void pn_transport_logf(pn_transport_t *transport, const char *fmt, ...);
+
+/**
+ * Get the maximum allowed channel for a transport.
+ *
+ * @param[in] transport a transport object
+ * @return the maximum allowed channel
+ */
+PN_EXTERN uint16_t pn_transport_get_channel_max(pn_transport_t *transport);
+
+/**
+ * Set the maximum allowed channel for a transport.
+ *
+ * @param[in] transport a transport object
+ * @param[in] channel_max the maximum allowed channel
+ */
+PN_EXTERN void pn_transport_set_channel_max(pn_transport_t *transport, uint16_t channel_max);
+
+/**
+ * Get the maximum allowed channel of a transport's remote peer.
+ *
+ * @param[in] transport a transport object
+ * @return the maximum allowed channel of the transport's remote peer
+ */
+PN_EXTERN uint16_t pn_transport_remote_channel_max(pn_transport_t *transport);
+
+/**
+ * Get the maximum frame size of a transport.
+ *
+ * @param[in] transport a transport object
+ * @return the maximum frame size of the transport object
+ */
+PN_EXTERN uint32_t pn_transport_get_max_frame(pn_transport_t *transport);
+
+/**
+ * Set the maximum frame size of a transport.
+ *
+ * @param[in] transport a transport object
+ * @param[in] size the maximum frame size for the transport object
+ */
+PN_EXTERN void pn_transport_set_max_frame(pn_transport_t *transport, uint32_t size);
+
+/**
+ * Get the maximum frame size of a transport's remote peer.
+ *
+ * @param[in] transport a transport object
+ * @return the maximum frame size of the transport's remote peer
+ */
+PN_EXTERN uint32_t pn_transport_get_remote_max_frame(pn_transport_t *transport);
+
+/**
+ * Get the idle timeout for a transport.
+ *
+ * A zero idle timeout means heartbeats are disabled.
+ *
+ * @param[in] transport a transport object
+ * @return the transport's idle timeout
+ */
+PN_EXTERN pn_millis_t pn_transport_get_idle_timeout(pn_transport_t *transport);
+
+/**
+ * Set the idle timeout for a transport.
+ *
+ * A zero idle timeout means heartbeats are disabled.
+ *
+ * @param[in] transport a transport object
+ * @param[in] timeout the idle timeout for the transport object
+ */
+PN_EXTERN void pn_transport_set_idle_timeout(pn_transport_t *transport, pn_millis_t timeout);
+
+/**
+ * Get the idle timeout for a transport's remote peer.
+ *
+ * A zero idle timeout means heartbeats are disabled.
+ *
+ * @param[in] transport a transport object
+ * @return the idle timeout for the transport's remote peer
+ */
+PN_EXTERN pn_millis_t pn_transport_get_remote_idle_timeout(pn_transport_t *transport);
+
+/**
+ * @deprecated
+ */
+PN_EXTERN ssize_t pn_transport_input(pn_transport_t *transport, const char *bytes, size_t available);
+/**
+ * @deprecated
+ */
+PN_EXTERN ssize_t pn_transport_output(pn_transport_t *transport, char *bytes, size_t size);
+
+/**
+ * Get the amount of free space for input following the transport's
+ * tail pointer.
+ *
+ * If the engine is in an exceptional state such as encountering an
+ * error condition or reaching the end of stream state, a negative
+ * value will be returned indicating the condition. If an error is
+ * indicated, futher details can be obtained from
+ * ::pn_transport_error. Calls to ::pn_transport_process may alter the
+ * value of this pointer. See ::pn_transport_process for details.
+ *
+ * @param[in] transport the transport
+ * @return the free space in the transport, PN_EOS or error code if < 0
+ */
+PN_EXTERN ssize_t pn_transport_capacity(pn_transport_t *transport);
+
+/**
+ * Get the transport's tail pointer.
+ *
+ * The amount of free space following this pointer is reported by
+ * ::pn_transport_capacity. Calls to ::pn_transport_process may alther
+ * the value of this pointer. See ::pn_transport_process for details.
+ *
+ * @param[in] transport the transport
+ * @return a pointer to the transport's input buffer, NULL if no capacity available.
+ */
+PN_EXTERN char *pn_transport_tail(pn_transport_t *transport);
+
+/**
+ * Pushes the supplied bytes into the tail of the transport.
+ *
+ * This is equivalent to copying @c size bytes afther the tail pointer
+ * and then calling ::pn_transport_process with an argument of @c
+ * size. It is an error to call this with a @c size larger than the
+ * capacity reported by ::pn_transport_capacity.
+ *
+ * @param[in] transport the transport
+ * @param[in] src the start of the data to push into the transport
+ * @param[in] size the amount of data to push into the transport
+ *
+ * @return 0 on success, or error code if < 0
+ */
+PN_EXTERN int pn_transport_push(pn_transport_t *transport, const char *src, size_t size);
+
+/**
+ * Process input data following the tail pointer.
+ *
+ * Calling this function will cause the transport to consume @c size
+ * bytes of input occupying the free space following the tail pointer.
+ * Calls to this function may change the value of ::pn_transport_tail,
+ * as well as the amount of free space reported by
+ * ::pn_transport_capacity.
+ *
+ * @param[in] transport the transport
+ * @param[in] size the amount of data written to the transport's input buffer
+ * @return 0 on success, or error code if < 0
+ */
+PN_EXTERN int pn_transport_process(pn_transport_t *transport, size_t size);
+
+/**
+ * Indicate that the input has reached End Of Stream (EOS).
+ *
+ * This tells the transport that no more input will be forthcoming.
+ *
+ * @param[in] transport the transport
+ * @return 0 on success, or error code if < 0
+ */
+PN_EXTERN int pn_transport_close_tail(pn_transport_t *transport);
+
+/**
+ * Get the number of pending output bytes following the transport's
+ * head pointer.
+ *
+ * If the engine is in an exceptional state such as encountering an
+ * error condition or reaching the end of stream state, a negative
+ * value will be returned indicating the condition. If an error is
+ * indicated, further details can be obtained from
+ * ::pn_transport_error. Calls to ::pn_transport_pop may alter the
+ * value of this pointer. See ::pn_transport_pop for details.
+ *
+ * @param[in] transport the transport
+ * @return the number of pending output bytes, or an error code
+ */
+PN_EXTERN ssize_t pn_transport_pending(pn_transport_t *transport);
+
+/**
+ * Get the transport's head pointer.
+ *
+ * This pointer references queued output data. The
+ * ::pn_transport_pending function reports how many bytes of output
+ * data follow this pointer. Calls to ::pn_transport_pop may alter
+ * this pointer and any data it references. See ::pn_transport_pop for
+ * details.
+ *
+ * @param[in] transport the transport
+ * @return a pointer to the transport's output buffer, or NULL if no pending output.
+ */
+PN_EXTERN const char *pn_transport_head(pn_transport_t *transport);
+
+/**
+ * Copies @c size bytes from the head of the transport to the @c dst
+ * pointer.
+ *
+ * It is an error to call this with a value of @c size that is greater
+ * than the value reported by ::pn_transport_pending.
+ *
+ * @param[in] transport the transport
+ * @param[out] dst the destination buffer
+ * @param[in] size the capacity of the destination buffer
+ * @return 0 on success, or error code if < 0
+ */
+PN_EXTERN int pn_transport_peek(pn_transport_t *transport, char *dst, size_t size);
+
+/**
+ * Removes @c size bytes of output from the pending output queue
+ * following the transport's head pointer.
+ *
+ * Calls to this function may alter the transport's head pointer as
+ * well as the number of pending bytes reported by
+ * ::pn_transport_pending.
+ *
+ * @param[in] transport the transport
+ * @param[in] size the number of bytes to remove
+ */
+PN_EXTERN void pn_transport_pop(pn_transport_t *transport, size_t size);
+
+/**
+ * Indicate that the output has closed.
+ *
+ * This tells the transport that no more output will be popped.
+ *
+ * @param[in] transport the transport
+ * @return 0 on success, or error code if < 0
+ */
+PN_EXTERN int pn_transport_close_head(pn_transport_t *transport);
+
+/**
+ * Check if a transport has buffered data.
+ *
+ * @param[in] transport a transport object
+ * @return true if the transport has buffered data, false otherwise
+ */
+PN_EXTERN bool pn_transport_quiesced(pn_transport_t *transport);
+
+/**
+ * Check if a transport is closed.
+ *
+ * A transport is defined to be closed when both the tail and the head
+ * are closed. In other words, when both ::pn_transport_capacity() < 0
+ * and ::pn_transport_pending() < 0.
+ *
+ * @param[in] transport a transport object
+ * @return true if the transport is closed, false otherwise
+ */
+PN_EXTERN bool pn_transport_closed(pn_transport_t *transport);
+
+/**
+ * Process any pending transport timer events.
+ *
+ * This method should be called after all pending input has been
+ * processed by the transport (see ::pn_transport_input), and before
+ * generating output (see ::pn_transport_output). It returns the
+ * deadline for the next pending timer event, if any are present.
+ *
+ * @param[in] transport the transport to process.
+ * @param[in] now the current time
+ *
+ * @return if non-zero, then the expiration time of the next pending timer event for the
+ * transport. The caller must invoke pn_transport_tick again at least once at or before
+ * this deadline occurs.
+ */
+PN_EXTERN pn_timestamp_t pn_transport_tick(pn_transport_t *transport, pn_timestamp_t now);
+
+/**
+ * Get the number of frames output by a transport.
+ *
+ * @param[in] transport a transport object
+ * @return the number of frames output by the transport
+ */
+PN_EXTERN uint64_t pn_transport_get_frames_output(const pn_transport_t *transport);
+
+/**
+ * Get the number of frames input by a transport.
+ *
+ * @param[in] transport a transport object
+ * @return the number of frames input by the transport
+ */
+PN_EXTERN uint64_t pn_transport_get_frames_input(const pn_transport_t *transport);
+
+#ifdef __cplusplus
+}
+#endif
+
+/** @}
+ */
+
+#endif /* transport.h */
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/transport.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/transport.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/types.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/types.h?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/types.h (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/types.h Fri Mar 14 11:20:47 2014
@@ -30,11 +30,22 @@
#include <proton/type_compat.h>
#endif
+/**
+ * @file
+ *
+ * @defgroup types Types
+ * @{
+ */
#ifdef __cplusplus
extern "C" {
#endif
+/**
+ * @defgroup primitives Primitive Types
+ * @{
+ */
+
typedef int32_t pn_sequence_t;
typedef uint32_t pn_millis_t;
typedef uint32_t pn_seconds_t;
@@ -57,8 +68,125 @@ typedef struct {
PN_EXTERN pn_bytes_t pn_bytes(size_t size, char *start);
PN_EXTERN pn_bytes_t pn_bytes_dup(size_t size, const char *start);
+/** @}
+ */
+
+/**
+ * @defgroup abstract Abstract Types
+ * @{
+ */
+
+/**
+ * Holds the state flags for an AMQP endpoint.
+ *
+ * A pn_state_t is an integral value with flags that encode both the
+ * local and remote state of an AMQP Endpoint (@link pn_connection_t
+ * Connection @endlink, @link pn_session_t Session @endlink, or @link
+ * pn_link_t Link @endlink). The local portion of the state may be
+ * accessed using ::PN_LOCAL_MASK, and the remote portion may be
+ * accessed using ::PN_REMOTE_MASK. Individual bits may be accessed
+ * using ::PN_LOCAL_UNINIT, ::PN_LOCAL_ACTIVE, ::PN_LOCAL_CLOSED, and
+ * ::PN_REMOTE_UNINIT, ::PN_REMOTE_ACTIVE, ::PN_REMOTE_CLOSED.
+ *
+ * Every AMQP endpoint (@link pn_connection_t Connection @endlink,
+ * @link pn_session_t Session @endlink, or @link pn_link_t Link
+ * @endlink) starts out in an uninitialized state and then proceeds
+ * linearly to an active and then closed state. This lifecycle occurs
+ * at both endpoints involved, and so the state model for an endpoint
+ * includes not only the known local state, but also the last known
+ * state of the remote endpoint.
+ *
+ * @ingroup connection
+ */
+typedef int pn_state_t;
+
+/**
+ * An AMQP Connection object.
+ *
+ * A pn_connection_t object encapsulates all of the endpoint state
+ * associated with an AMQP Connection. A pn_connection_t object
+ * contains zero or more ::pn_session_t objects, which in turn contain
+ * zero or more ::pn_link_t objects. Each ::pn_link_t object contains
+ * an ordered sequence of ::pn_delivery_t objects. A link is either a
+ * @link sender Sender @endlink, or a @link receiver Receiver
+ * @endlink, but never both.
+ *
+ * @ingroup connection
+ */
+typedef struct pn_connection_t pn_connection_t;
+
+/**
+ * An AMQP Session object.
+ *
+ * A pn_session_t object encapsulates all of the endpoint state
+ * associated with an AMQP Session. A pn_session_t object contains
+ * zero or more ::pn_link_t objects.
+ *
+ * @ingroup session
+ */
+typedef struct pn_session_t pn_session_t;
+
+/**
+ * An AMQP Link object.
+ *
+ * A pn_link_t object encapsulates all of the endpoint state
+ * associated with an AMQP Link. A pn_link_t object contains an
+ * ordered sequence of ::pn_delivery_t objects representing in-flight
+ * deliveries. A pn_link_t may be either a @link sender Sender
+ * @endlink, or a @link receiver Receiver @endlink, but never both.
+ *
+ * A pn_link_t object maintains a pointer to the *current* delivery
+ * within the ordered sequence of deliveries contained by the link
+ * (See ::pn_link_current). The *current* delivery is the target of a
+ * number of operations associated with the link, such as sending
+ * (::pn_link_send) and receiving (::pn_link_recv) message data.
+ *
+ * @ingroup link
+ */
+typedef struct pn_link_t pn_link_t;
+
+/**
+ * An AMQP Delivery object.
+ *
+ * A pn_delivery_t object encapsulates all of the endpoint state
+ * associated with an AMQP Delivery. Every delivery exists within the
+ * context of a ::pn_link_t object.
+ *
+ * @ingroup delivery
+ */
+typedef struct pn_delivery_t pn_delivery_t;
+
+/**
+ * An event collector.
+ *
+ * A pn_collector_t may be used to register interest in being notified
+ * of high level events that can occur to the various objects
+ * representing AMQP endpoint state. See ::pn_event_t for more
+ * details.
+ *
+ * @ingroup event
+ */
+typedef struct pn_collector_t pn_collector_t;
+
+/**
+ * An AMQP Transport object.
+ *
+ * A pn_transport_t encapsulates the transport related state of all
+ * AMQP endpoint objects associated with a physical network connection
+ * at a given point in time.
+ *
+ * @ingroup transport
+ */
+
+typedef struct pn_transport_t pn_transport_t;
+
+/** @}
+ */
#ifdef __cplusplus
}
#endif
+/** @}
+ */
+
#endif /* types.h */
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/util.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/util.h?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/util.h (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/include/proton/util.h Fri Mar 14 11:20:47 2014
@@ -29,7 +29,7 @@
extern "C" {
#endif
-PN_EXTERN void parse_url(char *url, char **scheme, char **user, char **pass, char **host, char **port, char **path);
+PN_EXTERN void pni_parse_url(char *url, char **scheme, char **user, char **pass, char **host, char **port, char **path);
PN_EXTERN void pn_fatal(const char *fmt, ...);
PN_EXTERN void pn_vfatal(const char *fmt, va_list ap);
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/src/codec/codec.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/src/codec/codec.c?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/src/codec/codec.c (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/src/codec/codec.c Fri Mar 14 11:20:47 2014
@@ -513,6 +513,7 @@ int pn_data_vfill(pn_data_t *data, const
break;
case 'z':
{
+ // For maximum portability, caller must pass these as two separate args, not a single struct
size_t size = va_arg(ap, size_t);
char *start = va_arg(ap, char *);
if (start) {
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/src/dispatcher/dispatcher.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/src/dispatcher/dispatcher.c?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/src/dispatcher/dispatcher.c (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/src/dispatcher/dispatcher.c Fri Mar 14 11:20:47 2014
@@ -36,7 +36,9 @@ pn_dispatcher_t *pn_dispatcher(uint8_t f
disp->frame_type = frame_type;
disp->transport = transport;
- disp->trace = PN_TRACE_OFF;
+ disp->trace = (pn_env_bool("PN_TRACE_RAW") ? PN_TRACE_RAW : PN_TRACE_OFF) |
+ (pn_env_bool("PN_TRACE_FRM") ? PN_TRACE_FRM : PN_TRACE_OFF) |
+ (pn_env_bool("PN_TRACE_DRV") ? PN_TRACE_DRV : PN_TRACE_OFF);
disp->input = pn_buffer(1024);
disp->fragment = 0;
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine-internal.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine-internal.h?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine-internal.h (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine-internal.h Fri Mar 14 11:20:47 2014
@@ -50,6 +50,7 @@ struct pn_endpoint_t {
pn_endpoint_t *transport_next;
pn_endpoint_t *transport_prev;
bool modified;
+ bool freed;
};
typedef struct {
@@ -110,11 +111,12 @@ typedef struct pn_io_layer_t {
} pn_io_layer_t;
struct pn_transport_t {
- pn_tracer_t *tracer;
+ bool freed;
+ pn_tracer_t tracer;
size_t header_count;
pn_sasl_t *sasl;
pn_ssl_t *ssl;
- pn_connection_t *connection;
+ pn_connection_t *connection; // reference counted
pn_dispatcher_t *disp;
bool open_sent;
bool open_rcvd;
@@ -122,6 +124,8 @@ struct pn_transport_t {
bool close_rcvd;
char *remote_container;
char *remote_hostname;
+ uint16_t channel_max;
+ uint16_t remote_channel_max;
pn_data_t *remote_offered_capabilities;
pn_data_t *remote_desired_capabilities;
pn_data_t *remote_properties;
@@ -167,6 +171,7 @@ struct pn_transport_t {
size_t input_pending;
char *input_buf;
bool tail_closed; // input stream closed by driver
+ bool head_closed;
void *context;
};
@@ -175,13 +180,13 @@ struct pn_connection_t {
pn_endpoint_t endpoint;
pn_endpoint_t *endpoint_head;
pn_endpoint_t *endpoint_tail;
- pn_endpoint_t *transport_head;
+ pn_endpoint_t *transport_head; // reference counted
pn_endpoint_t *transport_tail;
pn_list_t *sessions;
pn_transport_t *transport;
pn_delivery_t *work_head;
pn_delivery_t *work_tail;
- pn_delivery_t *tpwork_head;
+ pn_delivery_t *tpwork_head; // reference counted
pn_delivery_t *tpwork_tail;
pn_string_t *container;
pn_string_t *hostname;
@@ -189,11 +194,12 @@ struct pn_connection_t {
pn_data_t *desired_capabilities;
pn_data_t *properties;
void *context;
+ pn_collector_t *collector;
};
struct pn_session_t {
pn_endpoint_t endpoint;
- pn_connection_t *connection;
+ pn_connection_t *connection; // reference counted
pn_list_t *links;
void *context;
size_t incoming_capacity;
@@ -221,7 +227,7 @@ struct pn_terminus_t {
struct pn_link_t {
pn_endpoint_t endpoint;
pn_string_t *name;
- pn_session_t *session;
+ pn_session_t *session; // reference counted
pn_terminus_t source;
pn_terminus_t target;
pn_terminus_t remote_source;
@@ -259,7 +265,7 @@ struct pn_disposition_t {
};
struct pn_delivery_t {
- pn_link_t *link;
+ pn_link_t *link; // reference counted
pn_buffer_t *tag;
pn_disposition_t local;
pn_disposition_t remote;
@@ -298,10 +304,11 @@ pn_timestamp_t pn_io_layer_tick_passthru
void pn_condition_init(pn_condition_t *condition);
void pn_condition_tini(pn_condition_t *condition);
-void pn_modified(pn_connection_t *connection, pn_endpoint_t *endpoint);
-void pn_real_settle(pn_delivery_t *delivery);
+void pn_modified(pn_connection_t *connection, pn_endpoint_t *endpoint, bool emit);
+void pn_real_settle(pn_delivery_t *delivery); // will free delivery if link is freed
void pn_clear_tpwork(pn_delivery_t *delivery);
void pn_work_update(pn_connection_t *connection, pn_delivery_t *delivery);
void pn_clear_modified(pn_connection_t *connection, pn_endpoint_t *endpoint);
+void pn_connection_unbound(pn_connection_t *conn);
#endif /* engine-internal.h */
Modified: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine.c?rev=1577483&r1=1577482&r2=1577483&view=diff
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine.c (original)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/engine.c Fri Mar 14 11:20:47 2014
@@ -51,20 +51,18 @@ pn_connection_t *pn_ep_get_connection(pn
return NULL;
}
-void pn_modified(pn_connection_t *connection, pn_endpoint_t *endpoint);
-
-void pn_open(pn_endpoint_t *endpoint)
+static void pn_endpoint_open(pn_endpoint_t *endpoint)
{
// TODO: do we care about the current state?
PN_SET_LOCAL(endpoint->state, PN_LOCAL_ACTIVE);
- pn_modified(pn_ep_get_connection(endpoint), endpoint);
+ pn_modified(pn_ep_get_connection(endpoint), endpoint, true);
}
-void pn_close(pn_endpoint_t *endpoint)
+void pn_endpoint_close(pn_endpoint_t *endpoint)
{
// TODO: do we care about the current state?
PN_SET_LOCAL(endpoint->state, PN_LOCAL_CLOSED);
- pn_modified(pn_ep_get_connection(endpoint), endpoint);
+ pn_modified(pn_ep_get_connection(endpoint), endpoint, true);
}
void pn_connection_reset(pn_connection_t *connection)
@@ -76,19 +74,63 @@ void pn_connection_reset(pn_connection_t
void pn_connection_open(pn_connection_t *connection)
{
- if (connection) pn_open((pn_endpoint_t *) connection);
+ if (connection) pn_endpoint_open((pn_endpoint_t *) connection);
}
void pn_connection_close(pn_connection_t *connection)
{
- if (connection) pn_close((pn_endpoint_t *) connection);
+ if (connection) pn_endpoint_close((pn_endpoint_t *) connection);
}
void pn_endpoint_tini(pn_endpoint_t *endpoint);
void pn_connection_free(pn_connection_t *connection)
{
- pn_free(connection);
+ assert(!connection->endpoint.freed);
+ if (pn_connection_state(connection) & PN_LOCAL_ACTIVE)
+ pn_connection_close(connection);
+ // free those endpoints that haven't been freed by the application
+ LL_REMOVE(connection, endpoint, &connection->endpoint);
+ while (connection->endpoint_head) {
+ pn_endpoint_t *ep = connection->endpoint_head;
+ switch (ep->type) {
+ case SESSION:
+ // note: this will free all child links:
+ pn_session_free((pn_session_t *)ep);
+ break;
+ case SENDER:
+ case RECEIVER:
+ pn_link_free((pn_link_t *)ep);
+ break;
+ default:
+ assert(false);
+ }
+ }
+ connection->endpoint.freed = true;
+ if (!connection->transport) {
+ // no transport available to consume transport work items,
+ // so manually clear them:
+ pn_connection_unbound(connection);
+ }
+ pn_decref(connection);
+}
+
+// invoked when transport has been removed:
+void pn_connection_unbound(pn_connection_t *connection)
+{
+ connection->transport = NULL;
+ if (connection->endpoint.freed) {
+ // connection has been freed prior to unbinding, thus it
+ // cannot be re-assigned to a new transport. Clear the
+ // transport work lists to allow the connection to be freed.
+ while (connection->transport_head) {
+ pn_clear_modified(connection, connection->transport_head);
+ }
+ while (connection->tpwork_head) {
+ pn_real_settle(connection->tpwork_head);
+ pn_clear_tpwork(connection->tpwork_head);
+ }
+ }
}
void *pn_connection_get_context(pn_connection_t *conn)
@@ -102,6 +144,12 @@ void pn_connection_set_context(pn_connec
conn->context = context;
}
+pn_transport_t *pn_connection_transport(pn_connection_t *connection)
+{
+ assert(connection);
+ return connection->transport;
+}
+
void pn_condition_init(pn_condition_t *condition)
{
condition->name = pn_string(NULL);
@@ -120,33 +168,45 @@ void pn_add_session(pn_connection_t *con
{
pn_list_add(conn->sessions, ssn);
ssn->connection = conn;
+ pn_incref(conn); // keep around until finalized
}
void pn_remove_session(pn_connection_t *conn, pn_session_t *ssn)
{
- ssn->connection = NULL;
pn_list_remove(conn->sessions, ssn);
}
pn_connection_t *pn_session_connection(pn_session_t *session)
{
- return session ? session->connection : NULL;
+ if (!session) return NULL;
+ return session->connection->endpoint.freed
+ ? NULL : session->connection;
}
void pn_session_open(pn_session_t *session)
{
- if (session) pn_open((pn_endpoint_t *) session);
+ if (session) pn_endpoint_open((pn_endpoint_t *) session);
}
void pn_session_close(pn_session_t *session)
{
- if (session) pn_close((pn_endpoint_t *) session);
+ if (session) pn_endpoint_close((pn_endpoint_t *) session);
}
void pn_session_free(pn_session_t *session)
{
- if (session && session->connection)
- pn_remove_session(session->connection, session);
+ assert(!session->endpoint.freed);
+ while(pn_list_size(session->links)) {
+ pn_link_t *link = (pn_link_t *)pn_list_get(session->links, 0);
+ pn_link_free(link);
+ }
+ if (pn_session_state(session) & PN_LOCAL_ACTIVE)
+ pn_session_close(session);
+ pn_remove_session(session->connection, session);
+ pn_endpoint_t *endpoint = (pn_endpoint_t *) session;
+ LL_REMOVE(pn_ep_get_connection(endpoint), endpoint, endpoint);
+ session->endpoint.freed = true;
+ pn_decref(session);
}
void *pn_session_get_context(pn_session_t *session)
@@ -174,12 +234,12 @@ void pn_remove_link(pn_session_t *ssn, p
void pn_link_open(pn_link_t *link)
{
- if (link) pn_open((pn_endpoint_t *) link);
+ if (link) pn_endpoint_open((pn_endpoint_t *) link);
}
void pn_link_close(pn_link_t *link)
{
- if (link) pn_close((pn_endpoint_t *) link);
+ if (link) pn_endpoint_close((pn_endpoint_t *) link);
}
void pn_terminus_free(pn_terminus_t *terminus)
@@ -193,11 +253,25 @@ void pn_terminus_free(pn_terminus_t *ter
void pn_link_free(pn_link_t *link)
{
- if (link && link->session) {
- pn_remove_link(link->session, link);
- pn_endpoint_t *endpoint = (pn_endpoint_t *) link;
- LL_REMOVE(pn_ep_get_connection(endpoint), endpoint, endpoint);
+ assert(!link->endpoint.freed);
+ if (pn_link_state(link) & PN_LOCAL_ACTIVE)
+ pn_link_close(link);
+ pn_remove_link(link->session, link);
+ pn_endpoint_t *endpoint = (pn_endpoint_t *) link;
+ LL_REMOVE(pn_ep_get_connection(endpoint), endpoint, endpoint);
+ pn_delivery_t *delivery = link->unsettled_head;
+ while (delivery) {
+ pn_delivery_t *next = delivery->unsettled_next;
+ pn_delivery_settle(delivery);
+ delivery = next;
}
+ while (link->settled_head) {
+ delivery = link->settled_head;
+ LL_POP(link, settled, pn_delivery_t);
+ pn_decref(delivery);
+ }
+ link->endpoint.freed = true;
+ pn_decref(link);
}
void *pn_link_get_context(pn_link_t *link)
@@ -223,6 +297,7 @@ void pn_endpoint_init(pn_endpoint_t *end
endpoint->transport_next = NULL;
endpoint->transport_prev = NULL;
endpoint->modified = false;
+ endpoint->freed = false;
LL_ADD(conn, endpoint, endpoint);
}
@@ -251,6 +326,8 @@ static void pn_connection_finalize(void
#define pn_connection_compare NULL
#define pn_connection_inspect NULL
+#include "event.h"
+
pn_connection_t *pn_connection()
{
static pn_class_t clazz = PN_CLASS(pn_connection);
@@ -263,7 +340,7 @@ pn_connection_t *pn_connection()
pn_endpoint_init(&conn->endpoint, CONNECTION, conn);
conn->transport_head = NULL;
conn->transport_tail = NULL;
- conn->sessions = pn_list(0, PN_REFCOUNT);
+ conn->sessions = pn_list(0, 0);
conn->transport = NULL;
conn->work_head = NULL;
conn->work_tail = NULL;
@@ -274,10 +351,16 @@ pn_connection_t *pn_connection()
conn->offered_capabilities = pn_data(16);
conn->desired_capabilities = pn_data(16);
conn->properties = pn_data(16);
+ conn->collector = NULL;
return conn;
}
+void pn_connection_collect(pn_connection_t *connection, pn_collector_t *collector)
+{
+ connection->collector = collector;
+}
+
pn_state_t pn_connection_state(pn_connection_t *connection)
{
return connection ? connection->endpoint.state : 0;
@@ -380,6 +463,7 @@ void pn_add_work(pn_connection_t *connec
{
if (!delivery->work)
{
+ assert(!delivery->local.settled); // never allow settled deliveries
LL_ADD(connection, work, delivery);
delivery->work = true;
}
@@ -422,8 +506,9 @@ void pn_add_tpwork(pn_delivery_t *delive
{
LL_ADD(connection, tpwork, delivery);
delivery->tpwork = true;
+ pn_incref(delivery);
}
- pn_modified(connection, &connection->endpoint);
+ pn_modified(connection, &connection->endpoint, true);
}
void pn_clear_tpwork(pn_delivery_t *delivery)
@@ -433,6 +518,7 @@ void pn_clear_tpwork(pn_delivery_t *deli
{
LL_REMOVE(connection, tpwork, delivery);
delivery->tpwork = false;
+ pn_decref(delivery); // may free delivery!
}
}
@@ -449,11 +535,19 @@ void pn_dump(pn_connection_t *conn)
printf("\n");
}
-void pn_modified(pn_connection_t *connection, pn_endpoint_t *endpoint)
+void pn_modified(pn_connection_t *connection, pn_endpoint_t *endpoint, bool emit)
{
if (!endpoint->modified) {
LL_ADD(connection, transport, endpoint);
endpoint->modified = true;
+ pn_incref(endpoint);
+ }
+
+ if (emit) {
+ pn_event_t *event = pn_collector_put(connection->collector, PN_TRANSPORT);
+ if (event) {
+ pn_event_init_connection(event, connection);
+ }
}
}
@@ -464,6 +558,7 @@ void pn_clear_modified(pn_connection_t *
endpoint->transport_next = NULL;
endpoint->transport_prev = NULL;
endpoint->modified = false;
+ pn_decref(endpoint); // may free endpoint!
}
}
@@ -542,13 +637,21 @@ pn_link_t *pn_link_next(pn_link_t *link,
static void pn_session_finalize(void *object)
{
pn_session_t *session = (pn_session_t *) object;
+ //pn_transport_t *transport = session->connection->transport;
+ //if (transport) {
+ /* if ((int16_t)session->state.local_channel >= 0) // END not sent */
+ /* pn_hash_del(transport->local_channels, session->state.local_channel); */
+ /* if ((int16_t)session->state.remote_channel >= 0) // END not received */
+ /* pn_unmap_channel(transport, session); */
+ /* } */
+
pn_free(session->links);
pn_endpoint_tini(&session->endpoint);
-
pn_delivery_map_free(&session->state.incoming);
pn_delivery_map_free(&session->state.outgoing);
pn_free(session->state.local_handles);
pn_free(session->state.remote_handles);
+ pn_decref(session->connection);
}
#define pn_session_initialize NULL
@@ -565,8 +668,7 @@ pn_session_t *pn_session(pn_connection_t
pn_endpoint_init(&ssn->endpoint, SESSION, conn);
pn_add_session(conn, ssn);
- pn_decref(ssn);
- ssn->links = pn_list(0, PN_REFCOUNT);
+ ssn->links = pn_list(0, 0);
ssn->context = 0;
ssn->incoming_capacity = 1024*1024;
ssn->incoming_bytes = 0;
@@ -641,22 +743,17 @@ static void pn_link_finalize(void *objec
{
pn_link_t *link = (pn_link_t *) object;
+ // assumptions: all deliveries freed
+ assert(link->settled_head == NULL);
+ assert(link->unsettled_head == NULL);
+
pn_terminus_free(&link->source);
pn_terminus_free(&link->target);
pn_terminus_free(&link->remote_source);
pn_terminus_free(&link->remote_target);
- while (link->settled_head) {
- pn_delivery_t *d = link->settled_head;
- LL_POP(link, settled, pn_delivery_t);
- pn_free(d);
- }
- while (link->unsettled_head) {
- pn_delivery_t *d = link->unsettled_head;
- LL_POP(link, unsettled, pn_delivery_t);
- pn_free(d);
- }
pn_free(link->name);
pn_endpoint_tini(&link->endpoint);
+ pn_decref(link->session);
}
#define pn_link_initialize NULL
@@ -671,7 +768,7 @@ pn_link_t *pn_link_new(int type, pn_sess
pn_endpoint_init(&link->endpoint, type, session->connection);
pn_add_link(session, link);
- pn_decref(link);
+ pn_incref(session); // keep session until link finalized
link->name = pn_string(name);
pn_terminus_init(&link->source, PN_SOURCE);
pn_terminus_init(&link->target, PN_TARGET);
@@ -889,7 +986,9 @@ bool pn_link_is_receiver(pn_link_t *link
pn_session_t *pn_link_session(pn_link_t *link)
{
- return link->session;
+ assert(link);
+ return link->session->endpoint.freed
+ ? NULL : link->session;
}
static void pn_disposition_finalize(pn_disposition_t *ds)
@@ -902,10 +1001,13 @@ static void pn_disposition_finalize(pn_d
static void pn_delivery_finalize(void *object)
{
pn_delivery_t *delivery = (pn_delivery_t *) object;
+ assert(delivery->settled);
+ assert(!delivery->state.init); // no longer in session delivery map
pn_buffer_free(delivery->tag);
pn_buffer_free(delivery->bytes);
pn_disposition_finalize(&delivery->local);
pn_disposition_finalize(&delivery->remote);
+ pn_decref(delivery->link);
}
static void pn_disposition_init(pn_disposition_t *ds)
@@ -942,6 +1044,8 @@ pn_delivery_t *pn_delivery(pn_link_t *li
static pn_class_t clazz = PN_CLASS(pn_delivery);
delivery = (pn_delivery_t *) pn_new(sizeof(pn_delivery_t), &clazz);
if (!delivery) return NULL;
+ delivery->link = link;
+ pn_incref(delivery->link); // keep link until finalized
delivery->tag = pn_buffer(16);
delivery->bytes = pn_buffer(64);
pn_disposition_init(&delivery->local);
@@ -949,7 +1053,6 @@ pn_delivery_t *pn_delivery(pn_link_t *li
} else {
assert(!delivery->tpwork);
}
- delivery->link = link;
pn_buffer_clear(delivery->tag);
pn_buffer_append(delivery->tag, tag.bytes, tag.size);
pn_disposition_clear(&delivery->local);
@@ -1250,25 +1353,34 @@ void pn_real_settle(pn_delivery_t *deliv
{
pn_link_t *link = delivery->link;
LL_REMOVE(link, unsettled, delivery);
- LL_ADD(link, settled, delivery);
+ pn_delivery_map_del(pn_link_is_sender(link)
+ ? &link->session->state.outgoing
+ : &link->session->state.incoming,
+ delivery);
pn_buffer_clear(delivery->tag);
pn_buffer_clear(delivery->bytes);
delivery->settled = true;
+ if (link->endpoint.freed) {
+ pn_decref(delivery);
+ } else {
+ LL_ADD(link, settled, delivery);
+ }
}
void pn_delivery_settle(pn_delivery_t *delivery)
{
assert(delivery);
+ if (!delivery->local.settled) {
+ pn_link_t *link = delivery->link;
+ if (pn_is_current(delivery)) {
+ pn_link_advance(link);
+ }
- pn_link_t *link = delivery->link;
- if (pn_is_current(delivery)) {
- pn_link_advance(link);
+ link->unsettled_count--;
+ delivery->local.settled = true;
+ pn_add_tpwork(delivery);
+ pn_work_update(delivery->link->session->connection, delivery);
}
-
- link->unsettled_count--;
- delivery->local.settled = true;
- pn_add_tpwork(delivery);
- pn_work_update(delivery->link->session->connection, delivery);
}
void pn_link_offered(pn_link_t *sender, int credit)
@@ -1295,7 +1407,7 @@ int pn_link_drained(pn_link_t *link)
if (link->drain && link->credit > 0) {
link->drained = link->credit;
link->credit = 0;
- pn_modified(link->session->connection, &link->endpoint);
+ pn_modified(link->session->connection, &link->endpoint, true);
drained = link->drained;
}
} else {
@@ -1333,7 +1445,7 @@ void pn_link_flow(pn_link_t *receiver, i
assert(receiver);
assert(pn_link_is_receiver(receiver));
receiver->credit += credit;
- pn_modified(receiver->session->connection, &receiver->endpoint);
+ pn_modified(receiver->session->connection, &receiver->endpoint, true);
if (!receiver->drain_flag_mode) {
pn_link_set_drain(receiver, false);
receiver->drain_flag_mode = false;
@@ -1354,7 +1466,7 @@ void pn_link_set_drain(pn_link_t *receiv
assert(receiver);
assert(pn_link_is_receiver(receiver));
receiver->drain = drain;
- pn_modified(receiver->session->connection, &receiver->endpoint);
+ pn_modified(receiver->session->connection, &receiver->endpoint, true);
receiver->drain_flag_mode = true;
}
@@ -1367,8 +1479,9 @@ bool pn_link_draining(pn_link_t *receive
pn_link_t *pn_delivery_link(pn_delivery_t *delivery)
{
- if (!delivery) return NULL;
- return delivery->link;
+ assert(delivery);
+ return delivery->link->endpoint.freed
+ ? NULL : delivery->link;
}
pn_disposition_t *pn_delivery_local(pn_delivery_t *delivery)
Added: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.c
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.c?rev=1577483&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.c (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.c Fri Mar 14 11:20:47 2014
@@ -0,0 +1,290 @@
+#include <proton/engine.h>
+#include <assert.h>
+#include "engine-internal.h"
+
+struct pn_collector_t {
+ pn_event_t *head;
+ pn_event_t *tail;
+ pn_event_t *free_head;
+};
+
+struct pn_event_t {
+ pn_event_type_t type;
+ pn_connection_t *connection;
+ pn_session_t *session;
+ pn_link_t *link;
+ pn_delivery_t *delivery;
+ pn_transport_t *transport;
+ pn_event_t *next;
+};
+
+static void pn_collector_initialize(void *obj)
+{
+ pn_collector_t *collector = (pn_collector_t *) obj;
+ collector->head = NULL;
+ collector->tail = NULL;
+ collector->free_head = NULL;
+}
+
+static void pn_collector_finalize(void *obj)
+{
+ pn_collector_t *collector = (pn_collector_t *) obj;
+
+ while (pn_collector_peek(collector)) {
+ pn_collector_pop(collector);
+ }
+
+ assert(!collector->head);
+ assert(!collector->tail);
+
+ pn_event_t *event = collector->free_head;
+ while (event) {
+ pn_event_t *next = event->next;
+ pn_free(event);
+ event = next;
+ }
+}
+
+static int pn_collector_inspect(void *obj, pn_string_t *dst)
+{
+ assert(obj);
+ pn_collector_t *collector = (pn_collector_t *) obj;
+ int err = pn_string_addf(dst, "EVENTS[");
+ if (err) return err;
+ pn_event_t *event = collector->head;
+ bool first = true;
+ while (event) {
+ if (first) {
+ first = false;
+ } else {
+ err = pn_string_addf(dst, ", ");
+ if (err) return err;
+ }
+ err = pn_inspect(event, dst);
+ if (err) return err;
+ event = event->next;
+ }
+ return pn_string_addf(dst, "]");
+}
+
+#define pn_collector_hashcode NULL
+#define pn_collector_compare NULL
+
+pn_collector_t *pn_collector(void)
+{
+ static pn_class_t clazz = PN_CLASS(pn_collector);
+ pn_collector_t *collector = (pn_collector_t *) pn_new(sizeof(pn_collector_t), &clazz);
+ return collector;
+}
+
+void pn_collector_free(pn_collector_t *collector)
+{
+ pn_free(collector);
+}
+
+pn_event_t *pn_event(void);
+static void pn_event_initialize(void *obj);
+
+pn_event_t *pn_collector_put(pn_collector_t *collector, pn_event_type_t type)
+{
+ if (!collector) {
+ return NULL;
+ }
+
+ pn_event_t *event;
+
+ if (collector->free_head) {
+ event = collector->free_head;
+ collector->free_head = collector->free_head->next;
+ pn_event_initialize(event);
+ } else {
+ event = pn_event();
+ }
+
+ pn_event_t *tail = collector->tail;
+
+ if (tail) {
+ tail->next = event;
+ collector->tail = event;
+ } else {
+ collector->tail = event;
+ collector->head = event;
+ }
+
+ event->type = type;
+
+ return event;
+}
+
+pn_event_t *pn_collector_peek(pn_collector_t *collector)
+{
+ // discard any events for objects that no longer exist
+ pn_event_t *event = collector->head;
+ while (event && ((event->delivery && event->delivery->local.settled)
+ ||
+ (event->link && event->link->endpoint.freed)
+ ||
+ (event->session && event->session->endpoint.freed)
+ ||
+ (event->connection && event->connection->endpoint.freed)
+ ||
+ (event->transport && event->transport->freed))) {
+ pn_collector_pop(collector);
+ event = collector->head;
+ }
+ return collector->head;
+}
+
+bool pn_collector_pop(pn_collector_t *collector)
+{
+ pn_event_t *event = collector->head;
+ if (event) {
+ collector->head = event->next;
+ } else {
+ return false;
+ }
+
+ if (!collector->head) {
+ collector->tail = NULL;
+ }
+
+ event->next = collector->free_head;
+ collector->free_head = event;
+
+ if (event->connection) pn_decref(event->connection);
+ if (event->session) pn_decref(event->session);
+ if (event->link) pn_decref(event->link);
+ if (event->delivery) pn_decref(event->delivery);
+ if (event->transport) pn_decref(event->transport);
+
+ return true;
+}
+
+static void pn_event_initialize(void *obj)
+{
+ pn_event_t *event = (pn_event_t *) obj;
+ event->type = PN_EVENT_NONE;
+ event->connection = NULL;
+ event->session = NULL;
+ event->link = NULL;
+ event->delivery = NULL;
+ event->transport = NULL;
+ event->next = NULL;
+}
+
+static void pn_event_finalize(void *obj) {}
+
+static int pn_event_inspect(void *obj, pn_string_t *dst)
+{
+ assert(obj);
+ pn_event_t *event = (pn_event_t *) obj;
+ int err = pn_string_addf(dst, "(%d", event->type);
+ void *objects[] = {event->connection, event->session, event->link,
+ event->delivery, event->transport};
+ for (int i = 0; i < 5; i++) {
+ if (objects[i]) {
+ err = pn_string_addf(dst, ", ");
+ if (err) return err;
+ err = pn_inspect(objects[i], dst);
+ if (err) return err;
+ }
+ }
+
+ return pn_string_addf(dst, ")");
+}
+
+#define pn_event_hashcode NULL
+#define pn_event_compare NULL
+
+pn_event_t *pn_event(void)
+{
+ static pn_class_t clazz = PN_CLASS(pn_event);
+ pn_event_t *event = (pn_event_t *) pn_new(sizeof(pn_event_t), &clazz);
+ return event;
+}
+
+void pn_event_init_transport(pn_event_t *event, pn_transport_t *transport)
+{
+ event->transport = transport;
+ pn_incref(event->transport);
+}
+
+void pn_event_init_connection(pn_event_t *event, pn_connection_t *connection)
+{
+ event->connection = connection;
+ pn_event_init_transport(event, event->connection->transport);
+ pn_incref(event->connection);
+}
+
+void pn_event_init_session(pn_event_t *event, pn_session_t *session)
+{
+ event->session = session;
+ pn_event_init_connection(event, pn_session_connection(event->session));
+ pn_incref(event->session);
+}
+
+void pn_event_init_link(pn_event_t *event, pn_link_t *link)
+{
+ event->link = link;
+ pn_event_init_session(event, pn_link_session(event->link));
+ pn_incref(event->link);
+}
+
+void pn_event_init_delivery(pn_event_t *event, pn_delivery_t *delivery)
+{
+ event->delivery = delivery;
+ pn_event_init_link(event, pn_delivery_link(delivery));
+ pn_incref(event->delivery);
+}
+
+pn_event_type_t pn_event_type(pn_event_t *event)
+{
+ return event->type;
+}
+
+pn_connection_t *pn_event_connection(pn_event_t *event)
+{
+ return event->connection;
+}
+
+pn_session_t *pn_event_session(pn_event_t *event)
+{
+ return event->session;
+}
+
+pn_link_t *pn_event_link(pn_event_t *event)
+{
+ return event->link;
+}
+
+pn_delivery_t *pn_event_delivery(pn_event_t *event)
+{
+ return event->delivery;
+}
+
+pn_transport_t *pn_event_transport(pn_event_t *event)
+{
+ return event->transport;
+}
+
+const char *pn_event_type_name(pn_event_type_t type)
+{
+ switch (type) {
+ case PN_EVENT_NONE:
+ return "PN_EVENT_NONE";
+ case PN_CONNECTION_STATE:
+ return "PN_CONNECTION_STATE";
+ case PN_SESSION_STATE:
+ return "PN_SESSION_STATE";
+ case PN_LINK_STATE:
+ return "PN_LINK_STATE";
+ case PN_LINK_FLOW:
+ return "PN_LINK_FLOW";
+ case PN_DELIVERY:
+ return "PN_DELIVERY";
+ case PN_TRANSPORT:
+ return "PN_TRANSPORT";
+ }
+
+ return "<unrecognized>";
+}
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.c
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.h
URL: http://svn.apache.org/viewvc/qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.h?rev=1577483&view=auto
==============================================================================
--- qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.h (added)
+++ qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.h Fri Mar 14 11:20:47 2014
@@ -0,0 +1,33 @@
+#ifndef _PROTON_EVENT_H
+#define _PROTON_EVENT_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+pn_event_t *pn_collector_put(pn_collector_t *collector, pn_event_type_t type);
+
+void pn_event_init_transport(pn_event_t *event, pn_transport_t *transport);
+void pn_event_init_connection(pn_event_t *event, pn_connection_t *connection);
+void pn_event_init_session(pn_event_t *event, pn_session_t *session);
+void pn_event_init_link(pn_event_t *event, pn_link_t *link);
+void pn_event_init_delivery(pn_event_t *event, pn_delivery_t *delivery);
+
+#endif /* event.h */
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.h
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: qpid/proton/branches/fadams-javascript-binding/proton-c/src/engine/event.h
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org