You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2014/11/27 12:31:19 UTC

[2/3] qpid-proton git commit: use records to provide more flexible contexts

use records to provide more flexible contexts


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/fb3ecd4f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/fb3ecd4f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/fb3ecd4f

Branch: refs/heads/master
Commit: fb3ecd4fb7dc49e963a62f6d7fe5b3bf2a41b65a
Parents: 901e147
Author: Rafael Schloming <rh...@alum.mit.edu>
Authored: Sun Nov 23 05:22:55 2014 -0500
Committer: Rafael Schloming <rh...@alum.mit.edu>
Committed: Thu Nov 27 06:14:50 2014 -0500

----------------------------------------------------------------------
 proton-c/include/proton/connection.h  | 10 +++++
 proton-c/include/proton/delivery.h    | 10 +++++
 proton-c/include/proton/link.h        | 10 +++++
 proton-c/include/proton/session.h     | 10 +++++
 proton-c/include/proton/transport.h   |  9 +++++
 proton-c/src/engine/engine-internal.h | 10 ++---
 proton-c/src/engine/engine.c          | 65 ++++++++++++++++++++++--------
 proton-c/src/transport/transport.c    | 10 ++++-
 8 files changed, 112 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/include/proton/connection.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/connection.h b/proton-c/include/proton/connection.h
index e476689..b7e525c 100644
--- a/proton-c/include/proton/connection.h
+++ b/proton-c/include/proton/connection.h
@@ -138,6 +138,7 @@ PN_EXTERN pn_error_t *pn_connection_error(pn_connection_t *connection);
 PN_EXTERN void pn_connection_collect(pn_connection_t *connection, pn_collector_t *collector);
 
 /**
+ * @deprecated
  * Get the application context that is associated with a connection
  * object.
  *
@@ -150,6 +151,7 @@ PN_EXTERN void pn_connection_collect(pn_connection_t *connection, pn_collector_t
 PN_EXTERN void *pn_connection_get_context(pn_connection_t *connection);
 
 /**
+ * @deprecated
  * Set a new application context for a connection object.
  *
  * The application context for a connection object may be retrieved
@@ -161,6 +163,14 @@ PN_EXTERN void *pn_connection_get_context(pn_connection_t *connection);
 PN_EXTERN void pn_connection_set_context(pn_connection_t *connection, void *context);
 
 /**
+ * Get the attachments that are associated with a connection object.
+ *
+ * @param[in] connection the connection whose attachments are to be returned.
+ * @return the attachments for the connection object
+ */
+PN_EXTERN pn_record_t *pn_connection_attachments(pn_connection_t *connection);
+
+/**
  * Get the endpoint state flags for a connection.
  *
  * @param[in] connection the connection

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/include/proton/delivery.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/delivery.h b/proton-c/include/proton/delivery.h
index 527eaed..be75653 100644
--- a/proton-c/include/proton/delivery.h
+++ b/proton-c/include/proton/delivery.h
@@ -78,6 +78,7 @@ static inline pn_delivery_tag_t pn_dtag(const char *bytes, size_t size) {
 PN_EXTERN pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag);
 
 /**
+ * @deprecated
  * Get the application context that is associated with a delivery object.
  *
  * The application context for a delivery may be set using
@@ -89,6 +90,7 @@ PN_EXTERN pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag);
 PN_EXTERN void *pn_delivery_get_context(pn_delivery_t *delivery);
 
 /**
+ * @deprecated
  * Set a new application context for a delivery object.
  *
  * The application context for a delivery object may be retrieved using
@@ -100,6 +102,14 @@ PN_EXTERN void *pn_delivery_get_context(pn_delivery_t *delivery);
 PN_EXTERN void pn_delivery_set_context(pn_delivery_t *delivery, void *context);
 
 /**
+ * Get the attachments that are associated with a delivery object.
+ *
+ * @param[in] delivery the delivery whose attachments are to be returned.
+ * @return the attachments for the delivery object
+ */
+PN_EXTERN pn_record_t *pn_delivery_attachments(pn_delivery_t *delivery);
+
+/**
  * Get the tag for a delivery object.
  *
  * @param[in] delivery a delivery object

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/include/proton/link.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/link.h b/proton-c/include/proton/link.h
index b2fa4b9..863fe16 100644
--- a/proton-c/include/proton/link.h
+++ b/proton-c/include/proton/link.h
@@ -80,6 +80,7 @@ PN_EXTERN pn_link_t *pn_receiver(pn_session_t *session, const char *name);
 PN_EXTERN void pn_link_free(pn_link_t *link);
 
 /**
+ * @deprecated
  * Get the application context that is associated with a link object.
  *
  * The application context for a link may be set using
@@ -91,6 +92,7 @@ PN_EXTERN void pn_link_free(pn_link_t *link);
 PN_EXTERN void *pn_link_get_context(pn_link_t *link);
 
 /**
+ * @deprecated
  * Set a new application context for a link object.
  *
  * The application context for a link object may be retrieved using
@@ -102,6 +104,14 @@ PN_EXTERN void *pn_link_get_context(pn_link_t *link);
 PN_EXTERN void pn_link_set_context(pn_link_t *link, void *context);
 
 /**
+ * Get the attachments that are associated with a link object.
+ *
+ * @param[in] link the link whose attachments are to be returned.
+ * @return the attachments for the link object
+ */
+PN_EXTERN pn_record_t *pn_link_attachments(pn_link_t *link);
+
+/**
  * Get the name of a link.
  *
  * @param[in] link a link object

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/include/proton/session.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/session.h b/proton-c/include/proton/session.h
index 678b141..8b6e9fa 100644
--- a/proton-c/include/proton/session.h
+++ b/proton-c/include/proton/session.h
@@ -62,6 +62,7 @@ PN_EXTERN pn_session_t *pn_session(pn_connection_t *connection);
 PN_EXTERN void pn_session_free(pn_session_t *session);
 
 /**
+ * @deprecated
  * Get the application context that is associated with a session
  * object.
  *
@@ -74,6 +75,7 @@ PN_EXTERN void pn_session_free(pn_session_t *session);
 PN_EXTERN void *pn_session_get_context(pn_session_t *session);
 
 /**
+ * @deprecated
  * Set a new application context for a session object.
  *
  * The application context for a session object may be retrieved
@@ -85,6 +87,14 @@ PN_EXTERN void *pn_session_get_context(pn_session_t *session);
 PN_EXTERN void pn_session_set_context(pn_session_t *session, void *context);
 
 /**
+ * Get the attachments that are associated with a session object.
+ *
+ * @param[in] session the session whose attachments are to be returned.
+ * @return the attachments for the session object
+ */
+PN_EXTERN pn_record_t *pn_session_attachments(pn_session_t *session);
+
+/**
  * Get the endpoint state flags for a session.
  *
  * @param[in] session the session

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/include/proton/transport.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/transport.h b/proton-c/include/proton/transport.h
index 537e27d..690952b 100644
--- a/proton-c/include/proton/transport.h
+++ b/proton-c/include/proton/transport.h
@@ -197,6 +197,7 @@ PN_EXTERN pn_tracer_t pn_transport_get_tracer(pn_transport_t *transport);
 PN_EXTERN void *pn_transport_get_context(pn_transport_t *transport);
 
 /**
+ * @deprecated
  * Set a new application context for a transport object.
  *
  * The application context for a transport object may be retrieved using
@@ -208,6 +209,14 @@ PN_EXTERN void *pn_transport_get_context(pn_transport_t *transport);
 PN_EXTERN void pn_transport_set_context(pn_transport_t *transport, void *context);
 
 /**
+ * Get the attachments that are associated with a transport object.
+ *
+ * @param[in] transport the transport whose attachments are to be returned.
+ * @return the attachments for the transport object
+ */
+PN_EXTERN pn_record_t *pn_transport_attachments(pn_transport_t *transport);
+
+/**
  * Log a message using a transport's logging mechanism.
  *
  * This can be useful in a debugging context as the log message will

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/src/engine/engine-internal.h
----------------------------------------------------------------------
diff --git a/proton-c/src/engine/engine-internal.h b/proton-c/src/engine/engine-internal.h
index f53e88b..fbeb79b 100644
--- a/proton-c/src/engine/engine-internal.h
+++ b/proton-c/src/engine/engine-internal.h
@@ -160,7 +160,7 @@ struct pn_transport_t {
   size_t output_pending;
   char *output_buf;
 
-  void *context;
+  pn_record_t *context;
 
   /* input from peer */
   size_t input_size;
@@ -198,15 +198,15 @@ struct pn_connection_t {
   pn_data_t *offered_capabilities;
   pn_data_t *desired_capabilities;
   pn_data_t *properties;
-  void *context;
   pn_collector_t *collector;
+  pn_record_t *context;
 };
 
 struct pn_session_t {
   pn_endpoint_t endpoint;
   pn_connection_t *connection;  // reference counted
   pn_list_t *links;
-  void *context;
+  pn_record_t *context;
   size_t incoming_capacity;
   pn_sequence_t incoming_bytes;
   pn_sequence_t outgoing_bytes;
@@ -243,7 +243,7 @@ struct pn_link_t {
   pn_delivery_t *current;
   pn_delivery_t *settled_head;
   pn_delivery_t *settled_tail;
-  void *context;
+  pn_record_t *context;
   size_t unsettled_count;
   pn_sequence_t available;
   pn_sequence_t credit;
@@ -285,7 +285,7 @@ struct pn_delivery_t {
   pn_delivery_t *tpwork_prev;
   pn_delivery_state_t state;
   pn_buffer_t *bytes;
-  void *context;
+  pn_record_t *context;
   bool updated;
   bool settled; // tracks whether we're in the unsettled list or not
   bool work;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/src/engine/engine.c
----------------------------------------------------------------------
diff --git a/proton-c/src/engine/engine.c b/proton-c/src/engine/engine.c
index 1855f55..79da48c 100644
--- a/proton-c/src/engine/engine.c
+++ b/proton-c/src/engine/engine.c
@@ -152,15 +152,23 @@ void pn_connection_unbound(pn_connection_t *connection)
   }
 }
 
+pn_record_t *pn_connection_attachments(pn_connection_t *connection)
+{
+  assert(connection);
+  return connection->context;
+}
+
 void *pn_connection_get_context(pn_connection_t *conn)
 {
-    return conn ? conn->context : 0;
+  // XXX: we should really assert on conn here, but this causes
+  // messenger tests to fail
+  return conn ? pn_record_get(conn->context, PN_LEGCTX) : NULL;
 }
 
 void pn_connection_set_context(pn_connection_t *conn, void *context)
 {
-    if (conn)
-        conn->context = context;
+  assert(conn);
+  pn_record_set(conn->context, PN_LEGCTX, context);
 }
 
 pn_transport_t *pn_connection_transport(pn_connection_t *connection)
@@ -227,15 +235,21 @@ void pn_session_free(pn_session_t *session)
   pn_decref(session);
 }
 
+pn_record_t *pn_session_attachments(pn_session_t *session)
+{
+  assert(session);
+  return session->context;
+}
+
 void *pn_session_get_context(pn_session_t *session)
 {
-    return session ? session->context : 0;
+  return session ? pn_record_get(session->context, PN_LEGCTX) : 0;
 }
 
 void pn_session_set_context(pn_session_t *session, void *context)
 {
-    if (session)
-        session->context = context;
+  assert(context);
+  pn_record_set(session->context, PN_LEGCTX, context);
 }
 
 
@@ -303,13 +317,20 @@ void pn_link_free(pn_link_t *link)
 
 void *pn_link_get_context(pn_link_t *link)
 {
-    return link ? link->context : 0;
+  assert(link);
+  return pn_record_get(link->context, PN_LEGCTX);
 }
 
 void pn_link_set_context(pn_link_t *link, void *context)
 {
-    if (link)
-        link->context = context;
+  assert(link);
+  pn_record_set(link->context, PN_LEGCTX, context);
+}
+
+pn_record_t *pn_link_attachments(pn_link_t *link)
+{
+  assert(link);
+  return link->context;
 }
 
 void pn_endpoint_init(pn_endpoint_t *endpoint, int type, pn_connection_t *conn)
@@ -359,6 +380,7 @@ static void pn_connection_finalize(void *object)
     return;
   }
 
+  pn_free(conn->context);
   pn_decref(conn->collector);
   pn_free(conn->sessions);
   pn_free(conn->container);
@@ -374,13 +396,12 @@ static void pn_connection_finalize(void *object)
 #define pn_connection_compare NULL
 #define pn_connection_inspect NULL
 
-pn_connection_t *pn_connection()
+pn_connection_t *pn_connection(void)
 {
   static const pn_class_t clazz = PN_CLASS(pn_connection);
   pn_connection_t *conn = (pn_connection_t *) pn_class_new(&clazz, sizeof(pn_connection_t));
   if (!conn) return NULL;
 
-  conn->context = NULL;
   conn->endpoint_head = NULL;
   conn->endpoint_tail = NULL;
   pn_endpoint_init(&conn->endpoint, CONNECTION, conn);
@@ -398,6 +419,7 @@ pn_connection_t *pn_connection()
   conn->desired_capabilities = pn_data(0);
   conn->properties = pn_data(0);
   conn->collector = NULL;
+  conn->context = pn_record();
 
   return conn;
 }
@@ -707,6 +729,7 @@ static void pn_session_finalize(void *object)
     return;
   }
 
+  pn_free(session->context);
   pn_free(session->links);
   pn_endpoint_tini(endpoint);
   pn_delivery_map_free(&session->state.incoming);
@@ -731,7 +754,7 @@ pn_session_t *pn_session(pn_connection_t *conn)
   pn_endpoint_init(&ssn->endpoint, SESSION, conn);
   pn_add_session(conn, ssn);
   ssn->links = pn_list(PN_WEAKREF, 0);
-  ssn->context = 0;
+  ssn->context = pn_record();
   ssn->incoming_capacity = 1024*1024;
   ssn->incoming_bytes = 0;
   ssn->outgoing_bytes = 0;
@@ -826,6 +849,7 @@ static void pn_link_finalize(void *object)
     return;
   }
 
+  pn_free(link->context);
   pn_terminus_free(&link->source);
   pn_terminus_free(&link->target);
   pn_terminus_free(&link->remote_source);
@@ -862,7 +886,7 @@ pn_link_t *pn_link_new(int type, pn_session_t *session, const char *name)
   link->drain = false;
   link->drain_flag_mode = true;
   link->drained = 0;
-  link->context = 0;
+  link->context = pn_record();
   link->snd_settle_mode = PN_SND_MIXED;
   link->rcv_settle_mode = PN_RCV_FIRST;
   link->remote_snd_settle_mode = PN_SND_MIXED;
@@ -1092,6 +1116,7 @@ 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_free(delivery->context);
   pn_buffer_free(delivery->tag);
   pn_buffer_free(delivery->bytes);
   pn_disposition_finalize(&delivery->local);
@@ -1139,6 +1164,7 @@ pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag)
     delivery->bytes = pn_buffer(64);
     pn_disposition_init(&delivery->local);
     pn_disposition_init(&delivery->remote);
+    delivery->context = pn_record();
   } else {
     assert(!delivery->tpwork);
   }
@@ -1157,7 +1183,7 @@ pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag)
   delivery->tpwork = false;
   pn_buffer_clear(delivery->bytes);
   delivery->done = false;
-  delivery->context = NULL;
+  pn_record_clear(delivery->context);
 
   // begin delivery state
   delivery->state.init = false;
@@ -1235,13 +1261,19 @@ void pn_delivery_dump(pn_delivery_t *d)
 void *pn_delivery_get_context(pn_delivery_t *delivery)
 {
   assert(delivery);
-  return delivery->context;
+  return pn_record_get(delivery->context, PN_LEGCTX);
 }
 
 void pn_delivery_set_context(pn_delivery_t *delivery, void *context)
 {
   assert(delivery);
-  delivery->context = context;
+  pn_record_set(delivery->context, PN_LEGCTX, context);
+}
+
+pn_record_t *pn_delivery_attachments(pn_delivery_t *delivery)
+{
+  assert(delivery);
+  return delivery->context;
 }
 
 uint64_t pn_disposition_type(pn_disposition_t *disposition)
@@ -1448,6 +1480,7 @@ void pn_real_settle(pn_delivery_t *delivery)
                       delivery);
   pn_buffer_clear(delivery->tag);
   pn_buffer_clear(delivery->bytes);
+  pn_record_clear(delivery->context);
   delivery->settled = true;
   if (link->endpoint.freed) {
     pn_decref(delivery);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/fb3ecd4f/proton-c/src/transport/transport.c
----------------------------------------------------------------------
diff --git a/proton-c/src/transport/transport.c b/proton-c/src/transport/transport.c
index 67fd3ab..08072fe 100644
--- a/proton-c/src/transport/transport.c
+++ b/proton-c/src/transport/transport.c
@@ -309,6 +309,7 @@ static void pn_transport_initialize(void *object)
   transport->scratch = pn_string(NULL);
   transport->disp = pn_dispatcher(0, transport);
   transport->connection = NULL;
+  transport->context = pn_record();
 
   for (int layer=0; layer<PN_IO_LAYER_CT; ++layer) {
     transport->io_layers[layer] = NULL;
@@ -431,6 +432,7 @@ static void pn_transport_finalize(void *object)
 {
   pn_transport_t *transport = (pn_transport_t *) object;
 
+  pn_free(transport->context);
   pn_ssl_free(transport);
   pn_sasl_free(transport);
   pn_dispatcher_free(transport->disp);
@@ -2134,12 +2136,18 @@ pn_tracer_t pn_transport_get_tracer(pn_transport_t *transport)
 void pn_transport_set_context(pn_transport_t *transport, void *context)
 {
   assert(transport);
-  transport->context = context;
+  pn_record_set(transport->context, PN_LEGCTX, context);
 }
 
 void *pn_transport_get_context(pn_transport_t *transport)
 {
   assert(transport);
+  return pn_record_get(transport->context, PN_LEGCTX);
+}
+
+pn_record_t *pn_transport_attachments(pn_transport_t *transport)
+{
+  assert(transport);
   return transport->context;
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org