1 # The MIT License (MIT)
3 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 from bt2
import native_bt
, object, utils
30 def _create_from_ptr(ptr
):
31 notif_type
= native_bt
.notification_get_type(ptr
)
34 if notif_type
not in _NOTIF_TYPE_TO_CLS
:
35 raise bt2
.Error('unknown notification type: {}'.format(notif_type
))
37 return _NOTIF_TYPE_TO_CLS
[notif_type
]._create
_from
_ptr
(ptr
)
40 class _Notification(object._Object
):
44 class TraceEventNotification(_Notification
):
45 def __init__(self
, event
):
46 utils
._check
_type
(event
, bt2
.event
._Event
)
47 ptr
= native_bt
.notification_event_create(event
._ptr
)
50 raise bt2
.CreationError('cannot create trace event notification object')
56 event_ptr
= native_bt
.notification_event_get_event(self
._ptr
)
57 utils
._handle
_ptr
(event_ptr
, "cannot get trace event notification object's event object")
58 return bt2
.event
._create
_from
_ptr
(event_ptr
)
61 class BeginningOfPacketNotification(_Notification
):
62 def __init__(self
, packet
):
63 utils
._check
_type
(packet
, bt2
.packet
._Packet
)
64 ptr
= native_bt
.notification_packet_begin_create(packet
._ptr
)
67 raise bt2
.CreationError('cannot create beginning of packet notification object')
73 packet_ptr
= native_bt
.notification_packet_begin_get_packet(self
._ptr
)
74 utils
._handle
_ptr
(packet_ptr
, "cannot get beginning of packet notification object's packet object")
75 return bt2
.packet
._Packet
._create
_from
_ptr
(packet_ptr
)
78 class EndOfPacketNotification(_Notification
):
79 def __init__(self
, packet
):
80 utils
._check
_type
(packet
, bt2
.packet
._Packet
)
81 ptr
= native_bt
.notification_packet_end_create(packet
._ptr
)
84 raise bt2
.CreationError('cannot create end of packet notification object')
90 packet_ptr
= native_bt
.notification_packet_end_get_packet(self
._ptr
)
91 utils
._handle
_ptr
(packet_ptr
, "cannot get end of packet notification object's packet object")
92 return bt2
.packet
._Packet
._create
_from
_ptr
(packet_ptr
)
95 class EndOfStreamNotification(_Notification
):
96 def __init__(self
, stream
):
97 utils
._check
_type
(stream
, bt2
.stream
._Stream
)
98 ptr
= native_bt
.notification_stream_end_create(stream
._ptr
)
101 raise bt2
.CreationError('cannot create end of stream notification object')
103 super().__init
__(ptr
)
107 stream_ptr
= native_bt
.notification_stream_end_get_stream(self
._ptr
)
108 utils
._handle
_ptr
(stream_ptr
, "cannot get end of stream notification object's stream object")
109 return bt2
.stream
._create
_from
_ptr
(stream_ptr
)
112 class NewTraceNotification(_Notification
):
113 def __init__(self
, trace
):
114 utils
._check
_type
(trace
, bt2
.Trace
)
115 ptr
= native_bt
.notification_new_trace_create(trace
._ptr
)
118 raise bt2
.CreationError('cannot create new trace notification object')
120 super().__init
__(ptr
)
124 trace_ptr
= native_bt
.notification_new_trace_get_trace(self
._ptr
)
125 utils
._handle
_ptr
(trace_ptr
, "cannot get new trace notification object's trace object")
126 return bt2
.trace
._create
_from
_ptr
(trace_ptr
)
129 class NewStreamClassNotification(_Notification
):
130 def __init__(self
, stream_class
):
131 utils
._check
_type
(stream_class
, bt2
.StreamClass
)
132 ptr
= native_bt
.notification_new_stream_class_create(stream_class
._ptr
)
135 raise bt2
.CreationError('cannot create new stream class notification object')
137 super().__init
__(ptr
)
140 def stream_class(self
):
141 stream_class_ptr
= native_bt
.notification_new_stream_class_get_stream_class(self
._ptr
)
142 utils
._handle
_ptr
(stream_class_ptr
, "cannot get new stream class notification object's stream class object")
143 return bt2
.stream_class
.StreamClass
._create
_from
_ptr
(stream_class_ptr
)
146 _NOTIF_TYPE_TO_CLS
= {
147 native_bt
.NOTIFICATION_TYPE_EVENT
: TraceEventNotification
,
148 native_bt
.NOTIFICATION_TYPE_PACKET_BEGIN
: BeginningOfPacketNotification
,
149 native_bt
.NOTIFICATION_TYPE_PACKET_END
: EndOfPacketNotification
,
150 native_bt
.NOTIFICATION_TYPE_STREAM_END
: EndOfStreamNotification
,
151 native_bt
.NOTIFICATION_TYPE_NEW_TRACE
: NewTraceNotification
,
152 native_bt
.NOTIFICATION_TYPE_NEW_STREAM_CLASS
: NewStreamClassNotification
,