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
24 import bt2
.field_types
25 import collections
.abc
32 class EventClassLogLevel
:
33 UNKNOWN
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_UNKNOWN
34 UNSPECIFIED
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED
35 EMERGENCY
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_EMERGENCY
36 ALERT
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_ALERT
37 CRITICAL
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_CRITICAL
38 ERROR
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_ERROR
39 WARNING
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_WARNING
40 NOTICE
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_NOTICE
41 INFO
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_INFO
42 DEBUG_SYSTEM
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_SYSTEM
43 DEBUG_PROGRAM
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROGRAM
44 DEBUG_PROCESS
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_PROCESS
45 DEBUG_MODULE
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_MODULE
46 DEBUG_UNIT
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_UNIT
47 DEBUG_FUNCTION
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_FUNCTION
48 DEBUG_LINE
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG_LINE
49 DEBUG
= native_bt
.CTF_EVENT_CLASS_LOG_LEVEL_DEBUG
52 class EventClass(object._Object
):
53 def __init__(self
, name
, id=None, log_level
=None, emf_uri
=None,
54 context_field_type
=None, payload_field_type
=None):
55 utils
._check
_str
(name
)
56 ptr
= native_bt
.ctf_event_class_create(name
)
59 raise bt2
.CreationError('cannot create event class object')
66 if log_level
is not None:
67 self
.log_level
= log_level
69 if emf_uri
is not None:
70 self
.emf_uri
= emf_uri
72 if context_field_type
is not None:
73 self
.context_field_type
= context_field_type
75 if payload_field_type
is not None:
76 self
.payload_field_type
= payload_field_type
79 def stream_class(self
):
80 sc_ptr
= native_bt
.ctf_event_class_get_stream_class(self
._ptr
)
82 if sc_ptr
is not None:
83 return bt2
.StreamClass
._create
_from
_ptr
(sc_ptr
)
87 return native_bt
.ctf_event_class_get_name(self
._ptr
)
91 id = native_bt
.ctf_event_class_get_id(self
._ptr
)
92 return id if id >= 0 else None
96 utils
._check
_int
64(id)
97 ret
= native_bt
.ctf_event_class_set_id(self
._ptr
, id)
98 utils
._handle
_ret
(ret
, "cannot set event class object's ID")
102 log_level
= native_bt
.ctf_event_class_get_log_level(self
._ptr
)
103 return log_level
if log_level
>= 0 else None
106 def log_level(self
, log_level
):
108 EventClassLogLevel
.UNSPECIFIED
,
109 EventClassLogLevel
.EMERGENCY
,
110 EventClassLogLevel
.ALERT
,
111 EventClassLogLevel
.CRITICAL
,
112 EventClassLogLevel
.ERROR
,
113 EventClassLogLevel
.WARNING
,
114 EventClassLogLevel
.NOTICE
,
115 EventClassLogLevel
.INFO
,
116 EventClassLogLevel
.DEBUG_SYSTEM
,
117 EventClassLogLevel
.DEBUG_PROGRAM
,
118 EventClassLogLevel
.DEBUG_PROCESS
,
119 EventClassLogLevel
.DEBUG_MODULE
,
120 EventClassLogLevel
.DEBUG_UNIT
,
121 EventClassLogLevel
.DEBUG_FUNCTION
,
122 EventClassLogLevel
.DEBUG_LINE
,
123 EventClassLogLevel
.DEBUG
,
126 if log_level
not in log_levels
:
127 raise ValueError("'{}' is not a valid log level".format(log_level
))
129 ret
= native_bt
.ctf_event_class_set_log_level(self
._ptr
, log_level
)
130 utils
._handle
_ret
(ret
, "cannot set event class object's log level")
134 return native_bt
.ctf_event_class_get_emf_uri(self
._ptr
)
137 def emf_uri(self
, emf_uri
):
138 utils
._check
_str
(emf_uri
)
139 ret
= native_bt
.ctf_event_class_set_emf_uri(self
._ptr
, emf_uri
)
140 utils
._handle
_ret
(ret
, "cannot set event class object's EMF URI")
143 def context_field_type(self
):
144 ft_ptr
= native_bt
.ctf_event_class_get_context_type(self
._ptr
)
149 return bt2
.field_types
._create
_from
_ptr
(ft_ptr
)
151 @context_field_type.setter
152 def context_field_type(self
, context_field_type
):
153 context_field_type_ptr
= None
155 if context_field_type
is not None:
156 utils
._check
_type
(context_field_type
, bt2
.field_types
._FieldType
)
157 context_field_type_ptr
= context_field_type
._ptr
159 ret
= native_bt
.ctf_event_class_set_context_type(self
._ptr
, context_field_type_ptr
)
160 utils
._handle
_ret
(ret
, "cannot set event class object's context field type")
163 def payload_field_type(self
):
164 ft_ptr
= native_bt
.ctf_event_class_get_payload_type(self
._ptr
)
169 return bt2
.field_types
._create
_from
_ptr
(ft_ptr
)
171 @payload_field_type.setter
172 def payload_field_type(self
, payload_field_type
):
173 payload_field_type_ptr
= None
175 if payload_field_type
is not None:
176 utils
._check
_type
(payload_field_type
, bt2
.field_types
._FieldType
)
177 payload_field_type_ptr
= payload_field_type
._ptr
179 ret
= native_bt
.ctf_event_class_set_payload_type(self
._ptr
, payload_field_type_ptr
)
180 utils
._handle
_ret
(ret
, "cannot set event class object's payload field type")
183 event_ptr
= native_bt
.ctf_event_create(self
._ptr
)
185 if event_ptr
is None:
186 raise bt2
.CreationError('cannot create event field object')
188 return bt2
.event
._create
_from
_ptr
(event_ptr
)
190 def __eq__(self
, other
):
191 if type(other
) is not type(self
):
194 if self
.addr
== other
.addr
:
202 self
.context_field_type
,
203 self
.payload_field_type
210 other
.context_field_type
,
211 other
.payload_field_type
213 return self_props
== other_props
215 def _copy(self
, ft_copy_func
):
216 cpy
= EventClass(self
.name
)
219 if self
.log_level
is not None:
220 cpy
.log_level
= self
.log_level
222 if self
.emf_uri
is not None:
223 cpy
.emf_uri
= self
.emf_uri
225 cpy
.context_field_type
= ft_copy_func(self
.context_field_type
)
226 cpy
.payload_field_type
= ft_copy_func(self
.payload_field_type
)
230 return self
._copy
(lambda ft
: ft
)
232 def __deepcopy__(self
, memo
):
233 cpy
= self
._copy
(copy
.deepcopy
)