X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bindings%2Fpython%2Fbt2%2Fbt2%2Fstream.py;h=3798ec6a87c92c88cc7b622e46d2f7171a9c13dd;hb=0fd756a43bce605875565a14c1ed1b070fa3ad94;hp=32fb9a5fb0de8c44e9daa5e1d8e05593d72f48a8;hpb=1b8fb86234d51aff255b8e97435d4dbb3316eaec;p=babeltrace.git diff --git a/bindings/python/bt2/bt2/stream.py b/bindings/python/bt2/bt2/stream.py index 32fb9a5f..3798ec6a 100644 --- a/bindings/python/bt2/bt2/stream.py +++ b/bindings/python/bt2/bt2/stream.py @@ -20,69 +20,41 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -from bt2 import native_bt, object, utils +from bt2 import native_bt, utils import bt2.packet import bt2.event -import abc import bt2 -def _create_from_ptr(stream_ptr): - if native_bt.ctf_stream_is_writer(stream_ptr): - import ctf_writer +class _Stream(bt2.object._SharedObject): + _get_ref = staticmethod(native_bt.stream_get_ref) + _put_ref = staticmethod(native_bt.stream_put_ref) - cls = ctf_writer._CtfWriterStream - else: - cls = _Stream - - return cls._create_from_ptr(stream_ptr) - - -class _StreamBase(object._Object): @property def stream_class(self): - stream_class_ptr = native_bt.ctf_stream_get_class(self._ptr) - assert(stream_class_ptr) - return bt2.StreamClass._create_from_ptr(stream_class_ptr) + stream_class_ptr = native_bt.stream_borrow_class(self._ptr) + assert stream_class_ptr is not None + return bt2.stream_class.StreamClass._create_from_ptr_and_get_ref(stream_class_ptr) @property def name(self): - return native_bt.ctf_stream_get_name(self._ptr) + return native_bt.stream_get_name(self._ptr) + + def _name(self, name): + utils._check_str(name) + native_bt.stream_set_name(self._ptr, name) + + _name = property(fset=_name) @property def id(self): - id = native_bt.ctf_stream_get_id(self._ptr) + id = native_bt.stream_get_id(self._ptr) return id if id >= 0 else None - def __eq__(self, other): - if self.addr == other.addr: - return True - - return (self.name, self.id) == (other.name, other.id) - - -class _Stream(_StreamBase): def create_packet(self): - packet_ptr = native_bt.ctf_packet_create(self._ptr) + packet_ptr = native_bt.packet_create(self._ptr) if packet_ptr is None: raise bt2.CreationError('cannot create packet object') return bt2.packet._Packet._create_from_ptr(packet_ptr) - - def __eq__(self, other): - if type(other) is not type(self): - return False - - return _StreamBase.__eq__(self, other) - - def _copy(self): - return self.stream_class(self.name, self.id) - - def __copy__(self): - return self._copy() - - def __deepcopy__(self, memo): - cpy = self._copy() - memo[id(self)] = cpy - return cpy