Commit | Line | Data |
---|---|---|
a429c321 JG |
1 | /* |
2 | * Babeltrace - CTF Utils | |
3 | * | |
4 | * Copyright (c) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
7 | * of this software and associated documentation files (the "Software"), to deal | |
8 | * in the Software without restriction, including without limitation the rights | |
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
10 | * copies of the Software, and to permit persons to whom the Software is | |
11 | * furnished to do so, subject to the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice shall be included in | |
14 | * all copies or substantial portions of the Software. | |
15 | * | |
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
22 | * SOFTWARE. | |
23 | */ | |
24 | ||
25 | #define BT_LOG_TAG "PLUGIN-CTF-UTILS" | |
26 | #include "logging.h" | |
27 | ||
28 | #include "utils.h" | |
29 | ||
0b29603d | 30 | struct bt_stream_class *ctf_utils_borrow_stream_class_from_packet_header( |
50842bdc PP |
31 | struct bt_trace *trace, |
32 | struct bt_field *packet_header_field) | |
a429c321 | 33 | { |
50842bdc PP |
34 | struct bt_field *stream_id_field = NULL; |
35 | struct bt_stream_class *stream_class = NULL; | |
a429c321 JG |
36 | uint64_t stream_id = -1ULL; |
37 | int ret; | |
38 | ||
39 | if (!packet_header_field) { | |
40 | goto single_stream_class; | |
41 | } | |
42 | ||
0b29603d | 43 | stream_id_field = bt_field_structure_borrow_field_by_name( |
a429c321 JG |
44 | packet_header_field, "stream_id"); |
45 | if (!stream_id_field) { | |
46 | goto single_stream_class; | |
47 | } | |
48 | ||
3dca2276 | 49 | ret = bt_field_integer_unsigned_get_value(stream_id_field, |
a429c321 JG |
50 | &stream_id); |
51 | if (ret) { | |
52 | stream_id = -1ULL; | |
53 | } | |
54 | ||
55 | if (stream_id == -1ULL) { | |
56 | single_stream_class: | |
57 | /* Single stream class */ | |
50842bdc | 58 | if (bt_trace_get_stream_class_count(trace) == 0) { |
a429c321 JG |
59 | goto end; |
60 | } | |
61 | ||
0b29603d | 62 | stream_class = bt_trace_borrow_stream_class_by_index(trace, 0); |
a429c321 | 63 | } else { |
0b29603d | 64 | stream_class = bt_trace_borrow_stream_class_by_id(trace, |
a429c321 JG |
65 | stream_id); |
66 | } | |
67 | ||
68 | end: | |
a429c321 JG |
69 | return stream_class; |
70 | } |