src.ctf.fs: move internal util to ctf/common/utils
[babeltrace.git] / plugins / ctf / common / utils / utils.c
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
30 struct bt_ctf_stream_class *ctf_utils_stream_class_from_packet_header(
31 struct bt_ctf_trace *trace,
32 struct bt_ctf_field *packet_header_field)
33 {
34 struct bt_ctf_field *stream_id_field = NULL;
35 struct bt_ctf_stream_class *stream_class = NULL;
36 uint64_t stream_id = -1ULL;
37 int ret;
38
39 if (!packet_header_field) {
40 goto single_stream_class;
41 }
42
43 stream_id_field = bt_ctf_field_structure_get_field_by_name(
44 packet_header_field, "stream_id");
45 if (!stream_id_field) {
46 goto single_stream_class;
47 }
48
49 ret = bt_ctf_field_unsigned_integer_get_value(stream_id_field,
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 */
58 if (bt_ctf_trace_get_stream_class_count(trace) == 0) {
59 goto end;
60 }
61
62 stream_class = bt_ctf_trace_get_stream_class_by_index(trace, 0);
63 } else {
64 stream_class = bt_ctf_trace_get_stream_class_by_id(trace,
65 stream_id);
66 }
67
68 end:
69 bt_put(stream_id_field);
70 return stream_class;
71 }
This page took 0.030191 seconds and 4 git commands to generate.