-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._SharedObject):
- @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)
+class _Connection(bt2.object._SharedObject):
+ _get_ref = staticmethod(native_bt.connection_get_ref)
+ _put_ref = staticmethod(native_bt.connection_put_ref)