qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject qpid-proton git commit: made handlers overridable from python
Date Thu, 22 Jan 2015 22:30:28 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master 15e0ae96a -> f354584c7


made handlers overridable from python


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

Branch: refs/heads/master
Commit: f354584c7a9b693fed26ff7b2055147e1e593f81
Parents: 15e0ae9
Author: Rafael Schloming <rhs@alum.mit.edu>
Authored: Thu Jan 22 17:30:17 2015 -0500
Committer: Rafael Schloming <rhs@alum.mit.edu>
Committed: Thu Jan 22 17:30:17 2015 -0500

----------------------------------------------------------------------
 proton-c/bindings/python/proton/__init__.py | 30 ++++++++++++++++++++----
 proton-c/include/proton/reactor.h           |  3 +++
 proton-c/src/reactor/acceptor.c             |  4 ++--
 proton-c/src/reactor/connection.c           |  2 +-
 proton-c/src/reactor/reactor.c              | 16 +++++++------
 proton-c/src/reactor/reactor.h              |  2 --
 6 files changed, 41 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f354584c/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index 03bff98..b9bee7d 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -2207,6 +2207,18 @@ class Endpoint(object):
   def _get_remote_cond_impl(self):
       assert False, "Subclass must override this!"
 
+  def _get_handler(self):
+    record = self._get_attachments()
+    return WrappedHandler(pn_record_get_handler(record))
+
+  def _set_handler(self, handler):
+    record = self._get_attachments()
+    impl = _chandler(handler)
+    pn_record_set_handler(record, impl)
+    pn_decref(impl)
+
+  handler = property(_get_handler, _set_handler)
+
   @property
   def transport(self):
     return self.connection.transport
@@ -2284,6 +2296,9 @@ class Connection(Wrapper, Endpoint):
     self.desired_capabilities = None
     self.properties = None
 
+  def _get_attachments(self):
+    return pn_connection_attachments(self._impl)
+
   @property
   def connection(self):
     return self
@@ -2397,6 +2412,9 @@ class Session(Wrapper, Endpoint):
   def __init__(self, impl):
     Wrapper.__init__(self, impl, pn_session_attachments)
 
+  def _get_attachments(self):
+    return pn_session_attachments(self._impl)
+
   def _get_cond_impl(self):
     return pn_session_condition(self._impl)
 
@@ -2469,6 +2487,9 @@ class Link(Wrapper, Endpoint):
   def __init__(self, impl):
     Wrapper.__init__(self, impl, pn_link_attachments)
 
+  def _get_attachments(self):
+    return pn_link_attachments(self._impl)
+
   def _check(self, err):
     if err < 0:
       exc = EXCEPTIONS.get(err, LinkException)
@@ -3400,7 +3421,11 @@ class Event(Wrapper, EventBase):
     if isinstance(handler, WrappedHandler):
       pn_handler_dispatch(handler._impl, self._impl)
     else:
-      return dispatch(handler, self.type.method, self)
+      dispatch(handler, self.type.method, self)
+      if hasattr(handler, "handlers"):
+        for h in handler.handlers:
+          self.dispatch(h)
+
 
   @property
   def reactor(self):
@@ -3460,9 +3485,6 @@ class _cadapter:
     ev = Event.wrap(cevent)
     try:
       ev.dispatch(self.handler)
-      if hasattr(self.handler, "handlers"):
-        for h in self.handler.handlers:
-          ev.dispatch(h)
     except:
       if self.errors is None:
         raise

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f354584c/proton-c/include/proton/reactor.h
----------------------------------------------------------------------
diff --git a/proton-c/include/proton/reactor.h b/proton-c/include/proton/reactor.h
index 8447355..b1689ee 100644
--- a/proton-c/include/proton/reactor.h
+++ b/proton-c/include/proton/reactor.h
@@ -90,6 +90,9 @@ PN_EXTERN pn_record_t *pn_task_attachments(pn_task_t *task);
 
 PN_EXTERN pn_reactor_t *pn_event_reactor(pn_event_t *event);
 
+PN_EXTERN pn_handler_t *pn_record_get_handler(pn_record_t *record);
+PN_EXTERN void pn_record_set_handler(pn_record_t *record, pn_handler_t *handler);
+
 /** @}
  */
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f354584c/proton-c/src/reactor/acceptor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/acceptor.c b/proton-c/src/reactor/acceptor.c
index 405d372..8800048 100644
--- a/proton-c/src/reactor/acceptor.c
+++ b/proton-c/src/reactor/acceptor.c
@@ -32,7 +32,7 @@ void pni_acceptor_readable(pn_selectable_t *sel) {
   pn_reactor_t *reactor = (pn_reactor_t *) pni_selectable_get_context(sel);
   char name[1024];
   pn_socket_t sock = pn_accept(pn_reactor_io(reactor), pn_selectable_get_fd(sel), name, 1024);
-  pn_handler_t *handler = pni_record_get_handler(pn_selectable_attachments(sel));
+  pn_handler_t *handler = pn_record_get_handler(pn_selectable_attachments(sel));
   if (!handler) { handler = pn_reactor_handler(reactor); }
   pn_connection_t *conn = pn_reactor_connection(reactor, handler);
   pn_transport_t *trans = pn_transport();
@@ -63,7 +63,7 @@ pn_acceptor_t *pn_reactor_acceptor(pn_reactor_t *reactor, const char *host,
cons
   pn_selectable_on_readable(sel, pni_acceptor_readable);
   pn_selectable_on_finalize(sel, pni_acceptor_finalize);
   pni_record_init_reactor(pn_selectable_attachments(sel), reactor);
-  pni_record_init_handler(pn_selectable_attachments(sel), handler);
+  pn_record_set_handler(pn_selectable_attachments(sel), handler);
   pn_selectable_set_reading(sel, true);
   pn_reactor_update(reactor, sel);
   return (pn_acceptor_t *) sel;

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f354584c/proton-c/src/reactor/connection.c
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/connection.c b/proton-c/src/reactor/connection.c
index e5233fc..b427675 100644
--- a/proton-c/src/reactor/connection.c
+++ b/proton-c/src/reactor/connection.c
@@ -213,7 +213,7 @@ pn_selectable_t *pn_reactor_selectable_transport(pn_reactor_t *reactor,
pn_socke
 pn_connection_t *pn_reactor_connection(pn_reactor_t *reactor, pn_handler_t *handler) {
   assert(reactor);
   pn_connection_t *connection = pn_connection();
-  pni_record_init_handler(pn_connection_attachments(connection), handler);
+  pn_record_set_handler(pn_connection_attachments(connection), handler);
   pn_connection_collect(connection, pn_reactor_collector(reactor));
   pn_list_add(pn_reactor_children(reactor), connection);
   pn_decref(connection);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f354584c/proton-c/src/reactor/reactor.c
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/reactor.c b/proton-c/src/reactor/reactor.c
index 80b5762..d576ca4 100644
--- a/proton-c/src/reactor/reactor.c
+++ b/proton-c/src/reactor/reactor.c
@@ -207,11 +207,13 @@ static void pni_reactor_dispatch_post(pn_reactor_t *reactor, pn_event_t
*event)
 static void *pni_handler = NULL;
 #define PN_HANDLER ((pn_handle_t) &pni_handler)
 
-pn_handler_t *pni_record_get_handler(pn_record_t *record) {
+pn_handler_t *pn_record_get_handler(pn_record_t *record) {
+  assert(record);
   return (pn_handler_t *) pn_record_get(record, PN_HANDLER);
 }
 
-void pni_record_init_handler(pn_record_t *record, pn_handler_t *handler) {
+void pn_record_set_handler(pn_record_t *record, pn_handler_t *handler) {
+  assert(record);
   pn_record_def(record, PN_HANDLER, PN_OBJECT);
   pn_record_set(record, PN_HANDLER, handler);
 }
@@ -282,21 +284,21 @@ pn_handler_t *pn_event_handler(pn_event_t *event, pn_handler_t *default_handler)
   pn_handler_t *handler = NULL;
   pn_link_t *link = pn_event_link(event);
   if (link) {
-    handler = pni_record_get_handler(pn_link_attachments(link));
+    handler = pn_record_get_handler(pn_link_attachments(link));
     if (handler) { return handler; }
   }
   pn_session_t *session = pn_event_session(event);
   if (session) {
-    handler = pni_record_get_handler(pn_session_attachments(session));
+    handler = pn_record_get_handler(pn_session_attachments(session));
     if (handler) { return handler; }
   }
   pn_connection_t *connection = pn_event_connection(event);
   if (connection) {
-    handler = pni_record_get_handler(pn_connection_attachments(connection));
+    handler = pn_record_get_handler(pn_connection_attachments(connection));
     if (handler) { return handler; }
   }
   if (pn_class_id(pn_event_class(event)) == CID_pn_task) {
-    handler = pni_record_get_handler(pn_task_attachments((pn_task_t *) pn_event_context(event)));
+    handler = pn_record_get_handler(pn_task_attachments((pn_task_t *) pn_event_context(event)));
     if (handler) { return handler; }
   }
   return default_handler;
@@ -306,7 +308,7 @@ pn_task_t *pn_reactor_schedule(pn_reactor_t *reactor, int delay, pn_handler_t
*h
   pn_task_t *task = pn_timer_schedule(reactor->timer, reactor->now + delay);
   pn_record_t *record = pn_task_attachments(task);
   pni_record_init_reactor(record, reactor);
-  pni_record_init_handler(record, handler);
+  pn_record_set_handler(record, handler);
   if (reactor->selectable) {
     pn_selectable_set_deadline(reactor->selectable, pn_timer_deadline(reactor->timer));
     pn_reactor_update(reactor, reactor->selectable);

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f354584c/proton-c/src/reactor/reactor.h
----------------------------------------------------------------------
diff --git a/proton-c/src/reactor/reactor.h b/proton-c/src/reactor/reactor.h
index 398eb8b..689df81 100644
--- a/proton-c/src/reactor/reactor.h
+++ b/proton-c/src/reactor/reactor.h
@@ -24,8 +24,6 @@
 
 #include <proton/reactor.h>
 
-pn_handler_t *pni_record_get_handler(pn_record_t *record);
-void pni_record_init_handler(pn_record_t *record, pn_handler_t *handler);
 void pni_record_init_reactor(pn_record_t *record, pn_reactor_t *reactor);
 
 


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


Mime
View raw message