772cd5a5a9f58083502517162db6ede76f7b80b1
[babeltrace.git] / cli / babeltrace-cfg.c
1 /*
2 * Babeltrace trace converter - parameter parsing
3 *
4 * Copyright 2016 Philippe Proulx <pproulx@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 #include <babeltrace/common-internal.h>
26 #include <babeltrace/values.h>
27 #include <glib.h>
28 #include "babeltrace-cfg.h"
29
30 static
31 void destroy_gstring(void *data)
32 {
33 g_string_free(data, TRUE);
34 }
35
36 /*
37 * Extracts the various paths from the string arg, delimited by ':',
38 * and appends them to the array value object plugin_paths.
39 */
40 enum bt_value_status bt_config_append_plugin_paths(
41 struct bt_value *plugin_paths, const char *arg)
42 {
43 enum bt_value_status status = BT_VALUE_STATUS_OK;
44 GPtrArray *dirs = g_ptr_array_new_with_free_func(destroy_gstring);
45 int ret;
46 size_t i;
47
48 if (!dirs) {
49 status = BT_VALUE_STATUS_ERROR;
50 goto end;
51 }
52
53 ret = bt_common_append_plugin_path_dirs(arg, dirs);
54 if (ret) {
55 status = BT_VALUE_STATUS_ERROR;
56 goto end;
57 }
58
59 for (i = 0; i < dirs->len; i++) {
60 GString *dir = g_ptr_array_index(dirs, i);
61
62 status = bt_value_array_append_string(plugin_paths, dir->str);
63 if (status != BT_VALUE_STATUS_OK) {
64 break;
65 }
66 }
67
68 end:
69 g_ptr_array_free(dirs, TRUE);
70 return status;
71 }
72
73 void bt_config_connection_destroy(struct bt_config_connection *connection)
74 {
75 if (!connection) {
76 return;
77 }
78
79 if (connection->upstream_comp_name) {
80 g_string_free(connection->upstream_comp_name, TRUE);
81 }
82
83 if (connection->downstream_comp_name) {
84 g_string_free(connection->downstream_comp_name, TRUE);
85 }
86
87 if (connection->upstream_port_glob) {
88 g_string_free(connection->upstream_port_glob, TRUE);
89 }
90
91 if (connection->downstream_port_glob) {
92 g_string_free(connection->downstream_port_glob, TRUE);
93 }
94
95 if (connection->arg) {
96 g_string_free(connection->arg, TRUE);
97 }
98
99 g_free(connection);
100 }
This page took 0.035393 seconds and 4 git commands to generate.