X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fbt2%2Fbt2%2Fconnection.py;h=4c52a776b32d38c81f5429fd1198f09e9ba487a4;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=d430bc5b5ccf16f35010cac882db769ebf05a51e;hpb=6d137876393a3a8af5e4ad756c4ae849be0399c9;p=babeltrace.git diff --git a/bindings/python/bt2/bt2/connection.py b/bindings/python/bt2/bt2/connection.py index d430bc5b..4c52a776 100644 --- a/bindings/python/bt2/bt2/connection.py +++ b/bindings/python/bt2/bt2/connection.py @@ -20,83 +20,24 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from bt2 import native_bt, object, utils -import bt2.notification_iterator -import collections.abc +from bt2 import native_bt, utils +import bt2.message_iterator import bt2.port -import copy import bt2 -def _handle_status(status, gen_error_msg): - if status == native_bt.CONNECTION_STATUS_GRAPH_IS_CANCELED: - raise bt2.GraphCanceled - elif status == native_bt.CONNECTION_STATUS_IS_ENDED: - raise bt2.ConnectionEnded - elif status < 0: - raise bt2.Error(gen_error_msg) - - -def _create_private_from_ptr(ptr): - obj = _PrivateConnection._create_from_ptr(ptr) - obj._pub_ptr = native_bt.connection_from_private(ptr) - assert(obj._pub_ptr) - return obj - - -class _Connection(object._Object): - @staticmethod - def _downstream_port(ptr): - port_ptr = native_bt.connection_get_downstream_port(ptr) - utils._handle_ptr(port_ptr, "cannot get connection object's downstream port object") - return bt2.port._create_from_ptr(port_ptr) - - @staticmethod - def _upstream_port(ptr): - port_ptr = native_bt.connection_get_upstream_port(ptr) - utils._handle_ptr(port_ptr, "cannot get connection object's upstream port object") - return bt2.port._create_from_ptr(port_ptr) - - @property - def downstream_port(self): - return self._downstream_port(self._ptr) - - @property - def upstream_port(self): - return self._upstream_port(self._ptr) - - @staticmethod - def _is_ended(ptr): - return native_bt.connection_is_ended(ptr) == 1 - - @property - def is_ended(self): - return self._is_ended(self._ptr) - - def __eq__(self, other): - if type(other) not in (_Connection, _PrivateConnection): - return False - - return self.addr == other.addr - - -class _PrivateConnection(object._PrivateObject, _Connection): - def create_notification_iterator(self, notification_types=None): - notif_types = bt2.notification._notif_types_from_notif_classes(notification_types) - status, notif_iter_ptr = native_bt.py3_create_priv_conn_notif_iter(int(self._ptr), - notif_types) - _handle_status(status, 'cannot create notification iterator object') - assert(notif_iter_ptr) - return bt2.notification_iterator._PrivateConnectionNotificationIterator._create_from_ptr(notif_iter_ptr) - - @property - def is_ended(self): - return self._is_ended(self._pub_ptr) +class _Connection(bt2.object._SharedObject): + _get_ref = staticmethod(native_bt.connection_get_ref) + _put_ref = staticmethod(native_bt.connection_put_ref) @property def downstream_port(self): - return self._downstream_port(self._pub_ptr) + port_ptr = native_bt.connection_borrow_downstream_port_const(self._ptr) + utils._handle_ptr(port_ptr, "cannot get connection object's downstream port object") + return bt2.port._create_from_ptr_and_get_ref(port_ptr, native_bt.PORT_TYPE_INPUT) @property def upstream_port(self): - return self._upstream_port(self._pub_ptr) + port_ptr = native_bt.connection_borrow_upstream_port_const(self._ptr) + utils._handle_ptr(port_ptr, "cannot get connection object's upstream port object") + return bt2.port._create_from_ptr_and_get_ref(port_ptr, native_bt.PORT_TYPE_OUTPUT)