Values API: split into private and public APIs
[babeltrace.git] / cli / babeltrace-cfg.c
CommitLineData
c42c79ea
PP
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
1670bffd 25#include <babeltrace/common-internal.h>
c42c79ea 26#include <babeltrace/values.h>
da91b29a 27#include <babeltrace/private-values.h>
c42c79ea
PP
28#include <glib.h>
29#include "babeltrace-cfg.h"
30
c42c79ea 31static
9009cc24 32void destroy_gstring(void *data)
1670bffd
PP
33{
34 g_string_free(data, TRUE);
35}
36
c42c79ea
PP
37/*
38 * Extracts the various paths from the string arg, delimited by ':',
5a3ee633 39 * and appends them to the array value object plugin_paths.
c42c79ea 40 */
5a3ee633 41enum bt_value_status bt_config_append_plugin_paths(
da91b29a 42 struct bt_private_value *plugin_paths, const char *arg)
c42c79ea 43{
1670bffd
PP
44 enum bt_value_status status = BT_VALUE_STATUS_OK;
45 GPtrArray *dirs = g_ptr_array_new_with_free_func(destroy_gstring);
46 int ret;
47 size_t i;
c42c79ea 48
1670bffd
PP
49 if (!dirs) {
50 status = BT_VALUE_STATUS_ERROR;
51 goto end;
52 }
c42c79ea 53
1670bffd
PP
54 ret = bt_common_append_plugin_path_dirs(arg, dirs);
55 if (ret) {
56 status = BT_VALUE_STATUS_ERROR;
57 goto end;
58 }
c42c79ea 59
1670bffd
PP
60 for (i = 0; i < dirs->len; i++) {
61 GString *dir = g_ptr_array_index(dirs, i);
c42c79ea 62
da91b29a
PP
63 status = bt_private_value_array_append_string_element(
64 plugin_paths, dir->str);
74aa915d
MD
65 if (status != BT_VALUE_STATUS_OK) {
66 break;
67 }
c42c79ea
PP
68 }
69
1670bffd
PP
70end:
71 g_ptr_array_free(dirs, TRUE);
72 return status;
c42c79ea
PP
73}
74
9009cc24 75void bt_config_connection_destroy(struct bt_config_connection *connection)
c42c79ea 76{
9009cc24
PP
77 if (!connection) {
78 return;
79 }
c42c79ea 80
9009cc24
PP
81 if (connection->upstream_comp_name) {
82 g_string_free(connection->upstream_comp_name, TRUE);
6e1bc0df 83 }
db0f160a 84
9009cc24
PP
85 if (connection->downstream_comp_name) {
86 g_string_free(connection->downstream_comp_name, TRUE);
c42c79ea
PP
87 }
88
9009cc24
PP
89 if (connection->upstream_port_glob) {
90 g_string_free(connection->upstream_port_glob, TRUE);
290725f7
PP
91 }
92
9009cc24
PP
93 if (connection->downstream_port_glob) {
94 g_string_free(connection->downstream_port_glob, TRUE);
290725f7
PP
95 }
96
9009cc24
PP
97 if (connection->arg) {
98 g_string_free(connection->arg, TRUE);
290725f7
PP
99 }
100
9009cc24 101 g_free(connection);
c42c79ea 102}
This page took 0.055966 seconds and 4 git commands to generate.