Rename `init` methods to `initialize`
[babeltrace.git] / src / plugins / text / pretty / pretty.c
CommitLineData
7a278c8e 1/*
2e339de1 2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
f504043c 3 * Copyright 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7a278c8e
JG
4 *
5 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
71c5da58 26#include <babeltrace2/babeltrace.h>
57952005
MJ
27#include "compat/compiler.h"
28#include "common/common.h"
bfd20a42 29#include <stdio.h>
39cfa40f 30#include <stdbool.h>
bac67f0f 31#include <glib.h>
8d81b92f 32#include <string.h>
57952005 33#include "common/assert.h"
6405967d 34
3228cc1d
PP
35#include "pretty.h"
36
6e1bc0df
MD
37static
38const char *plugin_options[] = {
ad96d936 39 "color",
a0ad501b 40 "path",
6e1bc0df
MD
41 "no-delta",
42 "clock-cycles",
43 "clock-seconds",
44 "clock-date",
45 "clock-gmt",
a263021c 46 "verbose",
6e1bc0df
MD
47 "name-default", /* show/hide */
48 "name-payload",
49 "name-context",
50 "name-scope",
51 "name-header",
52 "field-default", /* show/hide */
53 "field-trace",
54 "field-trace:hostname",
55 "field-trace:domain",
56 "field-trace:procname",
57 "field-trace:vpid",
58 "field-loglevel",
59 "field-emf",
60535549 60 "field-callsite",
6e1bc0df
MD
61};
62
1043fdea
PP
63static
64const char * const in_port_name = "in";
65
bfd20a42 66static
3228cc1d 67void destroy_pretty_data(struct pretty_component *pretty)
bac67f0f 68{
b09a5592 69 bt_self_component_port_input_message_iterator_put_ref(pretty->iterator);
5280f742
PP
70
71 if (pretty->string) {
72 (void) g_string_free(pretty->string, TRUE);
73 }
74
75 if (pretty->tmp_string) {
76 (void) g_string_free(pretty->tmp_string, TRUE);
77 }
78
3228cc1d 79 if (pretty->out != stdout) {
77986bad
JD
80 int ret;
81
3228cc1d 82 ret = fclose(pretty->out);
77986bad
JD
83 if (ret) {
84 perror("close output file");
85 }
86 }
3228cc1d 87 g_free(pretty->options.output_path);
3228cc1d 88 g_free(pretty);
bac67f0f
JG
89}
90
b25bd455 91static
3228cc1d 92struct pretty_component *create_pretty(void)
bac67f0f 93{
3228cc1d 94 struct pretty_component *pretty;
541b0a11 95
3228cc1d
PP
96 pretty = g_new0(struct pretty_component, 1);
97 if (!pretty) {
541b0a11
JG
98 goto end;
99 }
3228cc1d
PP
100 pretty->string = g_string_new("");
101 if (!pretty->string) {
6a18b281
MD
102 goto error;
103 }
5280f742
PP
104 pretty->tmp_string = g_string_new("");
105 if (!pretty->tmp_string) {
106 goto error;
107 }
541b0a11 108end:
3228cc1d 109 return pretty;
6a18b281
MD
110
111error:
3228cc1d 112 g_free(pretty);
6a18b281 113 return NULL;
bac67f0f
JG
114}
115
3228cc1d 116BT_HIDDEN
8eee8ea2 117void pretty_finalize(bt_self_component_sink *comp)
b25bd455 118{
834e9996
PP
119 destroy_pretty_data(
120 bt_self_component_get_data(
bb61965b 121 bt_self_component_sink_as_self_component(comp)));
b25bd455
JG
122}
123
bac67f0f 124static
fb25b9e3 125bt_component_class_message_iterator_next_method_status handle_message(
834e9996 126 struct pretty_component *pretty,
b09a5592 127 const bt_message *message)
4c1456f0 128{
fb25b9e3
PP
129 bt_component_class_message_iterator_next_method_status ret =
130 BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_OK;
541b0a11 131
8b45963b 132 BT_ASSERT(pretty);
541b0a11 133
b09a5592 134 switch (bt_message_get_type(message)) {
b09a5592
PP
135 case BT_MESSAGE_TYPE_EVENT:
136 if (pretty_print_event(pretty, message)) {
fb25b9e3 137 ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
834e9996 138 }
7cdc2bab 139 break;
22dfa677
PP
140 case BT_MESSAGE_TYPE_DISCARDED_EVENTS:
141 case BT_MESSAGE_TYPE_DISCARDED_PACKETS:
142 if (pretty_print_discarded_items(pretty, message)) {
fb25b9e3 143 ret = BT_COMPONENT_CLASS_MESSAGE_ITERATOR_NEXT_METHOD_STATUS_ERROR;
22dfa677
PP
144 }
145 break;
7cdc2bab 146 default:
6ff151ad 147 break;
78586d8a 148 }
b5e978f4 149
541b0a11 150 return ret;
4c1456f0 151}
bac67f0f 152
3228cc1d 153BT_HIDDEN
fb25b9e3
PP
154bt_component_class_sink_graph_is_configured_method_status
155pretty_graph_is_configured(bt_self_component_sink *comp)
75e1829b 156{
ab8b2b1b
SM
157 bt_component_class_sink_graph_is_configured_method_status status;
158 bt_self_component_port_input_message_iterator_create_from_sink_component_status
159 msg_iter_status;
3228cc1d 160 struct pretty_component *pretty;
75e1829b 161
834e9996 162 pretty = bt_self_component_get_data(
bb61965b 163 bt_self_component_sink_as_self_component(comp));
8b45963b 164 BT_ASSERT(pretty);
834e9996 165 BT_ASSERT(!pretty->iterator);
ab8b2b1b 166 msg_iter_status = bt_self_component_port_input_message_iterator_create_from_sink_component(
692f1a01 167 comp, bt_self_component_sink_borrow_input_port_by_name(comp,
ab8b2b1b
SM
168 in_port_name), &pretty->iterator);
169 if (msg_iter_status != BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_CREATE_FROM_SINK_COMPONENT_STATUS_OK) {
170 status = (int) msg_iter_status;
171 goto end;
75e1829b 172 }
72b913fb 173
ab8b2b1b
SM
174 status = BT_COMPONENT_CLASS_SINK_GRAPH_IS_CONFIGURED_METHOD_STATUS_OK;
175
176end:
634f394c 177 return status;
75e1829b
JG
178}
179
3228cc1d 180BT_HIDDEN
fb25b9e3 181bt_component_class_sink_consume_method_status pretty_consume(
8eee8ea2 182 bt_self_component_sink *comp)
fec2a9f2 183{
233c7608
JR
184 bt_component_class_sink_consume_method_status ret =
185 BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_OK;
b09a5592
PP
186 bt_message_array_const msgs;
187 bt_self_component_port_input_message_iterator *it;
834e9996 188 struct pretty_component *pretty = bt_self_component_get_data(
bb61965b 189 bt_self_component_sink_as_self_component(comp));
fb25b9e3 190 bt_message_iterator_next_status next_status;
3fd7b79d
PP
191 uint64_t count = 0;
192 uint64_t i = 0;
fec2a9f2 193
834e9996 194 it = pretty->iterator;
fb25b9e3 195 next_status = bt_self_component_port_input_message_iterator_next(it,
b09a5592 196 &msgs, &count);
0d8b4d8e 197
fb25b9e3
PP
198 switch (next_status) {
199 case BT_MESSAGE_ITERATOR_NEXT_STATUS_OK:
834e9996 200 break;
fb25b9e3
PP
201 case BT_MESSAGE_ITERATOR_NEXT_STATUS_MEMORY_ERROR:
202 case BT_MESSAGE_ITERATOR_NEXT_STATUS_AGAIN:
203 ret = (int) next_status;
834e9996 204 goto end;
fb25b9e3
PP
205 case BT_MESSAGE_ITERATOR_NEXT_STATUS_END:
206 ret = (int) next_status;
b09a5592 207 BT_SELF_COMPONENT_PORT_INPUT_MESSAGE_ITERATOR_PUT_REF_AND_RESET(
8c6884d9 208 pretty->iterator);
dfa6653c 209 goto end;
dfa6653c 210 default:
fb25b9e3 211 ret = BT_COMPONENT_CLASS_SINK_CONSUME_METHOD_STATUS_ERROR;
dfa6653c 212 goto end;
fec2a9f2
JG
213 }
214
fb25b9e3 215 BT_ASSERT(next_status == BT_MESSAGE_ITERATOR_NEXT_STATUS_OK);
3fd7b79d
PP
216
217 for (i = 0; i < count; i++) {
621b4e7e 218 ret = (int) handle_message(pretty, msgs[i]);
3fd7b79d
PP
219 if (ret) {
220 goto end;
221 }
222
b09a5592 223 bt_message_put_ref(msgs[i]);
3fd7b79d 224 }
dfa6653c 225
fec2a9f2 226end:
3fd7b79d 227 for (; i < count; i++) {
b09a5592 228 bt_message_put_ref(msgs[i]);
3fd7b79d
PP
229 }
230
fec2a9f2
JG
231 return ret;
232}
233
6e1bc0df 234static
8eee8ea2 235int add_params_to_map(bt_value *plugin_opt_map)
6e1bc0df 236{
834e9996 237 int ret = 0;
6e1bc0df
MD
238 unsigned int i;
239
240 for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) {
241 const char *key = plugin_options[i];
fb25b9e3
PP
242
243 if (bt_value_map_insert_entry(plugin_opt_map, key,
244 bt_value_null) < 0) {
834e9996 245 ret = -1;
6e1bc0df
MD
246 goto end;
247 }
248 }
fb25b9e3 249
6e1bc0df
MD
250end:
251 return ret;
252}
253
254static
8eee8ea2 255bt_bool check_param_exists(const char *key, const bt_value *object,
ce141536 256 void *data)
6e1bc0df 257{
3228cc1d 258 struct pretty_component *pretty = data;
6e1bc0df 259
ce141536
PP
260 if (!bt_value_map_has_entry(pretty->plugin_opt_map,
261 key)) {
3228cc1d
PP
262 fprintf(pretty->err,
263 "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key);
6e1bc0df 264 }
c55a9f58 265 return BT_TRUE;
6e1bc0df
MD
266}
267
268static
8eee8ea2 269void apply_one_string(const char *key, const bt_value *params, char **option)
6e1bc0df 270{
8eee8ea2 271 const bt_value *value = NULL;
6e1bc0df
MD
272 const char *str;
273
ce141536 274 value = bt_value_map_borrow_entry_value_const(params, key);
6e1bc0df
MD
275 if (!value) {
276 goto end;
277 }
278 if (bt_value_is_null(value)) {
279 goto end;
280 }
b5cdc106 281 str = bt_value_string_get(value);
6e1bc0df 282 *option = g_strdup(str);
b5cdc106 283
6e1bc0df 284end:
834e9996 285 return;
6e1bc0df
MD
286}
287
288static
8eee8ea2 289void apply_one_bool(const char *key, const bt_value *params, bool *option,
6e1bc0df
MD
290 bool *found)
291{
8eee8ea2 292 const bt_value *value = NULL;
c55a9f58 293 bt_bool bool_val;
6e1bc0df 294
ce141536 295 value = bt_value_map_borrow_entry_value_const(params, key);
6e1bc0df
MD
296 if (!value) {
297 goto end;
298 }
b5cdc106 299 bool_val = bt_value_bool_get(value);
c55a9f58 300 *option = (bool) bool_val;
6e1bc0df
MD
301 if (found) {
302 *found = true;
303 }
f78d5dd1 304
6e1bc0df 305end:
834e9996 306 return;
6e1bc0df
MD
307}
308
ad96d936 309static
3228cc1d 310void warn_wrong_color_param(struct pretty_component *pretty)
ad96d936 311{
3228cc1d 312 fprintf(pretty->err,
ad96d936
PP
313 "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n");
314}
315
77986bad 316static
834e9996 317int open_output_file(struct pretty_component *pretty)
77986bad 318{
834e9996 319 int ret = 0;
77986bad 320
3228cc1d 321 if (!pretty->options.output_path) {
77986bad
JD
322 goto end;
323 }
324
3228cc1d
PP
325 pretty->out = fopen(pretty->options.output_path, "w");
326 if (!pretty->out) {
77986bad
JD
327 goto error;
328 }
329
330 goto end;
331
332error:
834e9996
PP
333 ret = -1;
334
77986bad
JD
335end:
336 return ret;
337}
338
6e1bc0df 339static
8eee8ea2 340int apply_params(struct pretty_component *pretty, const bt_value *params)
6e1bc0df 341{
834e9996 342 int ret = 0;
6e1bc0df
MD
343 bool value, found;
344 char *str = NULL;
345
ce141536 346 pretty->plugin_opt_map = bt_value_map_create();
3228cc1d 347 if (!pretty->plugin_opt_map) {
834e9996 348 ret = -1;
6e1bc0df
MD
349 goto end;
350 }
3228cc1d 351 ret = add_params_to_map(pretty->plugin_opt_map);
834e9996 352 if (ret) {
6e1bc0df
MD
353 goto end;
354 }
355 /* Report unknown parameters. */
fb25b9e3
PP
356 if (bt_value_map_foreach_entry_const(params,
357 check_param_exists, pretty) < 0) {
834e9996 358 ret = -1;
6e1bc0df
MD
359 goto end;
360 }
fb25b9e3 361
6e1bc0df 362 /* Known parameters. */
3228cc1d 363 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
44514773 364 if (bt_value_map_has_entry(params, "color")) {
8eee8ea2 365 const bt_value *color_value;
ad96d936
PP
366 const char *color;
367
ce141536
PP
368 color_value = bt_value_map_borrow_entry_value_const(params,
369 "color");
ad96d936
PP
370 if (!color_value) {
371 goto end;
372 }
373
b5cdc106
PP
374 color = bt_value_string_get(color_value);
375
376 if (strcmp(color, "never") == 0) {
377 pretty->options.color = PRETTY_COLOR_OPT_NEVER;
378 } else if (strcmp(color, "auto") == 0) {
379 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
380 } else if (strcmp(color, "always") == 0) {
381 pretty->options.color = PRETTY_COLOR_OPT_ALWAYS;
ad96d936 382 } else {
b5cdc106 383 warn_wrong_color_param(pretty);
ad96d936 384 }
ad96d936
PP
385 }
386
834e9996 387 apply_one_string("path", params, &pretty->options.output_path);
3228cc1d 388 ret = open_output_file(pretty);
834e9996 389 if (ret) {
77986bad
JD
390 goto end;
391 }
6e1bc0df 392
6e1bc0df 393 value = false; /* Default. */
834e9996 394 apply_one_bool("no-delta", params, &value, NULL);
3228cc1d 395 pretty->options.print_delta_field = !value; /* Reverse logic. */
6e1bc0df
MD
396
397 value = false; /* Default. */
834e9996 398 apply_one_bool("clock-cycles", params, &value, NULL);
3228cc1d 399 pretty->options.print_timestamp_cycles = value;
6e1bc0df
MD
400
401 value = false; /* Default. */
834e9996 402 apply_one_bool("clock-seconds", params, &value, NULL);
3228cc1d 403 pretty->options.clock_seconds = value;
6e1bc0df
MD
404
405 value = false; /* Default. */
834e9996 406 apply_one_bool("clock-date", params, &value, NULL);
3228cc1d 407 pretty->options.clock_date = value;
6e1bc0df
MD
408
409 value = false; /* Default. */
834e9996 410 apply_one_bool("clock-gmt", params, &value, NULL);
3228cc1d 411 pretty->options.clock_gmt = value;
6e1bc0df 412
a263021c 413 value = false; /* Default. */
834e9996 414 apply_one_bool("verbose", params, &value, NULL);
3228cc1d 415 pretty->options.verbose = value;
a263021c 416
6e1bc0df 417 /* Names. */
834e9996 418 apply_one_string("name-default", params, &str);
6e1bc0df 419 if (!str) {
3228cc1d 420 pretty->options.name_default = PRETTY_DEFAULT_UNSET;
acfa8112 421 } else if (strcmp(str, "show") == 0) {
3228cc1d 422 pretty->options.name_default = PRETTY_DEFAULT_SHOW;
acfa8112 423 } else if (strcmp(str, "hide") == 0) {
3228cc1d 424 pretty->options.name_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 425 } else {
834e9996 426 ret = -1;
6e1bc0df
MD
427 goto end;
428 }
429 g_free(str);
430 str = NULL;
431
3228cc1d
PP
432 switch (pretty->options.name_default) {
433 case PRETTY_DEFAULT_UNSET:
434 pretty->options.print_payload_field_names = true;
435 pretty->options.print_context_field_names = true;
436 pretty->options.print_header_field_names = false;
437 pretty->options.print_scope_field_names = false;
6e1bc0df 438 break;
3228cc1d
PP
439 case PRETTY_DEFAULT_SHOW:
440 pretty->options.print_payload_field_names = true;
441 pretty->options.print_context_field_names = true;
442 pretty->options.print_header_field_names = true;
443 pretty->options.print_scope_field_names = true;
6e1bc0df 444 break;
3228cc1d
PP
445 case PRETTY_DEFAULT_HIDE:
446 pretty->options.print_payload_field_names = false;
447 pretty->options.print_context_field_names = false;
448 pretty->options.print_header_field_names = false;
449 pretty->options.print_scope_field_names = false;
6e1bc0df
MD
450 break;
451 default:
834e9996 452 ret = -1;
6e1bc0df
MD
453 goto end;
454 }
455
456 value = false;
457 found = false;
834e9996 458 apply_one_bool("name-payload", params, &value, &found);
6e1bc0df 459 if (found) {
3228cc1d 460 pretty->options.print_payload_field_names = value;
6e1bc0df
MD
461 }
462
463 value = false;
464 found = false;
834e9996 465 apply_one_bool("name-context", params, &value, &found);
6e1bc0df 466 if (found) {
3228cc1d 467 pretty->options.print_context_field_names = value;
6e1bc0df
MD
468 }
469
470 value = false;
471 found = false;
834e9996 472 apply_one_bool("name-header", params, &value, &found);
6e1bc0df 473 if (found) {
3228cc1d 474 pretty->options.print_header_field_names = value;
6e1bc0df
MD
475 }
476
477 value = false;
478 found = false;
834e9996 479 apply_one_bool("name-scope", params, &value, &found);
6e1bc0df 480 if (found) {
3228cc1d 481 pretty->options.print_scope_field_names = value;
6e1bc0df
MD
482 }
483
484 /* Fields. */
834e9996 485 apply_one_string("field-default", params, &str);
6e1bc0df 486 if (!str) {
3228cc1d 487 pretty->options.field_default = PRETTY_DEFAULT_UNSET;
acfa8112 488 } else if (strcmp(str, "show") == 0) {
3228cc1d 489 pretty->options.field_default = PRETTY_DEFAULT_SHOW;
acfa8112 490 } else if (strcmp(str, "hide") == 0) {
3228cc1d 491 pretty->options.field_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 492 } else {
834e9996 493 ret = -1;
6e1bc0df
MD
494 goto end;
495 }
496 g_free(str);
497 str = NULL;
498
3228cc1d
PP
499 switch (pretty->options.field_default) {
500 case PRETTY_DEFAULT_UNSET:
501 pretty->options.print_trace_field = false;
502 pretty->options.print_trace_hostname_field = true;
503 pretty->options.print_trace_domain_field = false;
504 pretty->options.print_trace_procname_field = true;
505 pretty->options.print_trace_vpid_field = true;
506 pretty->options.print_loglevel_field = false;
507 pretty->options.print_emf_field = false;
508 pretty->options.print_callsite_field = false;
6e1bc0df 509 break;
3228cc1d
PP
510 case PRETTY_DEFAULT_SHOW:
511 pretty->options.print_trace_field = true;
512 pretty->options.print_trace_hostname_field = true;
513 pretty->options.print_trace_domain_field = true;
514 pretty->options.print_trace_procname_field = true;
515 pretty->options.print_trace_vpid_field = true;
516 pretty->options.print_loglevel_field = true;
517 pretty->options.print_emf_field = true;
518 pretty->options.print_callsite_field = true;
6e1bc0df 519 break;
3228cc1d
PP
520 case PRETTY_DEFAULT_HIDE:
521 pretty->options.print_trace_field = false;
522 pretty->options.print_trace_hostname_field = false;
523 pretty->options.print_trace_domain_field = false;
524 pretty->options.print_trace_procname_field = false;
525 pretty->options.print_trace_vpid_field = false;
526 pretty->options.print_loglevel_field = false;
527 pretty->options.print_emf_field = false;
528 pretty->options.print_callsite_field = false;
6e1bc0df
MD
529 break;
530 default:
834e9996 531 ret = -1;
6e1bc0df
MD
532 goto end;
533 }
534
535 value = false;
536 found = false;
834e9996 537 apply_one_bool("field-trace", params, &value, &found);
6e1bc0df 538 if (found) {
3228cc1d 539 pretty->options.print_trace_field = value;
6e1bc0df
MD
540 }
541
542 value = false;
543 found = false;
834e9996 544 apply_one_bool("field-trace:hostname", params, &value, &found);
6e1bc0df 545 if (found) {
3228cc1d 546 pretty->options.print_trace_hostname_field = value;
6e1bc0df
MD
547 }
548
549 value = false;
550 found = false;
834e9996 551 apply_one_bool("field-trace:domain", params, &value, &found);
6e1bc0df 552 if (found) {
3228cc1d 553 pretty->options.print_trace_domain_field = value;
6e1bc0df
MD
554 }
555
556 value = false;
557 found = false;
834e9996 558 apply_one_bool("field-trace:procname", params, &value, &found);
6e1bc0df 559 if (found) {
3228cc1d 560 pretty->options.print_trace_procname_field = value;
6e1bc0df
MD
561 }
562
563 value = false;
564 found = false;
834e9996 565 apply_one_bool("field-trace:vpid", params, &value, &found);
6e1bc0df 566 if (found) {
3228cc1d 567 pretty->options.print_trace_vpid_field = value;
6e1bc0df
MD
568 }
569
570 value = false;
571 found = false;
834e9996 572 apply_one_bool("field-loglevel", params, &value, &found);
6e1bc0df 573 if (found) {
3228cc1d 574 pretty->options.print_loglevel_field = value;
6e1bc0df
MD
575 }
576
577 value = false;
578 found = false;
834e9996 579 apply_one_bool("field-emf", params, &value, &found);
6e1bc0df 580 if (found) {
3228cc1d 581 pretty->options.print_emf_field = value;
6e1bc0df
MD
582 }
583
584 value = false;
585 found = false;
834e9996 586 apply_one_bool("field-callsite", params, &value, &found);
6e1bc0df 587 if (found) {
3228cc1d 588 pretty->options.print_callsite_field = value;
6e1bc0df
MD
589 }
590
6e1bc0df 591end:
8c6884d9 592 bt_value_put_ref(pretty->plugin_opt_map);
3228cc1d 593 pretty->plugin_opt_map = NULL;
6e1bc0df
MD
594 g_free(str);
595 return ret;
596}
597
ad96d936 598static
3228cc1d 599void set_use_colors(struct pretty_component *pretty)
ad96d936 600{
3228cc1d
PP
601 switch (pretty->options.color) {
602 case PRETTY_COLOR_OPT_ALWAYS:
603 pretty->use_colors = true;
ad96d936 604 break;
3228cc1d
PP
605 case PRETTY_COLOR_OPT_AUTO:
606 pretty->use_colors = pretty->out == stdout &&
ad96d936
PP
607 bt_common_colors_supported();
608 break;
3228cc1d
PP
609 case PRETTY_COLOR_OPT_NEVER:
610 pretty->use_colors = false;
ad96d936
PP
611 break;
612 }
613}
614
3228cc1d 615BT_HIDDEN
4175c1d5 616bt_component_class_initialize_method_status pretty_init(
e3250e61
SM
617 bt_self_component_sink *comp,
618 bt_self_component_sink_configuration *config,
619 const bt_value *params,
f807570c 620 __attribute__((unused)) void *init_method_data)
bac67f0f 621{
4175c1d5
FD
622 bt_component_class_initialize_method_status ret =
623 BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_OK;
3228cc1d 624 struct pretty_component *pretty = create_pretty();
bac67f0f 625
3228cc1d 626 if (!pretty) {
4175c1d5 627 ret = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
bac67f0f
JG
628 goto end;
629 }
630
fb25b9e3
PP
631 if (bt_self_component_sink_add_input_port(comp,
632 in_port_name, NULL, NULL) < 0) {
4175c1d5 633 ret = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
fb25b9e3 634 goto error;
b9d103be
PP
635 }
636
3228cc1d
PP
637 pretty->out = stdout;
638 pretty->err = stderr;
6e1bc0df 639
3228cc1d
PP
640 pretty->delta_cycles = -1ULL;
641 pretty->last_cycles_timestamp = -1ULL;
3af83b5a 642
3228cc1d
PP
643 pretty->delta_real_timestamp = -1ULL;
644 pretty->last_real_timestamp = -1ULL;
3af83b5a 645
834e9996 646 if (apply_params(pretty, params)) {
4175c1d5 647 ret = BT_COMPONENT_CLASS_INITIALIZE_METHOD_STATUS_ERROR;
6e1bc0df
MD
648 goto error;
649 }
650
3228cc1d 651 set_use_colors(pretty);
834e9996 652 bt_self_component_set_data(
bb61965b 653 bt_self_component_sink_as_self_component(comp), pretty);
2b4c4a7c 654
bac67f0f
JG
655end:
656 return ret;
834e9996 657
bac67f0f 658error:
3228cc1d 659 destroy_pretty_data(pretty);
bac67f0f
JG
660 return ret;
661}
This page took 0.090798 seconds and 4 git commands to generate.