lib: make graph API const-correct
[babeltrace.git] / 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
9d408fca 26#include <babeltrace/babeltrace.h>
3d9990ac 27#include <babeltrace/compiler-internal.h>
ad96d936 28#include <babeltrace/common-internal.h>
7d61fa8e 29#include <plugins-common.h>
bfd20a42 30#include <stdio.h>
39cfa40f 31#include <stdbool.h>
bac67f0f 32#include <glib.h>
f6ccaed9 33#include <babeltrace/assert-internal.h>
6405967d 34
3228cc1d
PP
35#include "pretty.h"
36
61d6f9b1
MJ
37GQuark stream_packet_context_quarks[STREAM_PACKET_CONTEXT_QUARKS_LEN];
38
6e1bc0df
MD
39static
40const char *plugin_options[] = {
ad96d936 41 "color",
a0ad501b 42 "path",
6e1bc0df
MD
43 "no-delta",
44 "clock-cycles",
45 "clock-seconds",
46 "clock-date",
47 "clock-gmt",
a263021c 48 "verbose",
6e1bc0df
MD
49 "name-default", /* show/hide */
50 "name-payload",
51 "name-context",
52 "name-scope",
53 "name-header",
54 "field-default", /* show/hide */
55 "field-trace",
56 "field-trace:hostname",
57 "field-trace:domain",
58 "field-trace:procname",
59 "field-trace:vpid",
60 "field-loglevel",
61 "field-emf",
60535549 62 "field-callsite",
6e1bc0df
MD
63};
64
bfd20a42 65static
3228cc1d 66void destroy_pretty_data(struct pretty_component *pretty)
bac67f0f 67{
d94d92ac 68 bt_object_put_ref(pretty->iterator);
5280f742
PP
69
70 if (pretty->string) {
71 (void) g_string_free(pretty->string, TRUE);
72 }
73
74 if (pretty->tmp_string) {
75 (void) g_string_free(pretty->tmp_string, TRUE);
76 }
77
3228cc1d 78 if (pretty->out != stdout) {
77986bad
JD
79 int ret;
80
3228cc1d 81 ret = fclose(pretty->out);
77986bad
JD
82 if (ret) {
83 perror("close output file");
84 }
85 }
3228cc1d 86 g_free(pretty->options.output_path);
3228cc1d 87 g_free(pretty);
bac67f0f
JG
88}
89
b25bd455 90static
3228cc1d 91struct pretty_component *create_pretty(void)
bac67f0f 92{
3228cc1d 93 struct pretty_component *pretty;
541b0a11 94
3228cc1d
PP
95 pretty = g_new0(struct pretty_component, 1);
96 if (!pretty) {
541b0a11
JG
97 goto end;
98 }
3228cc1d
PP
99 pretty->string = g_string_new("");
100 if (!pretty->string) {
6a18b281
MD
101 goto error;
102 }
5280f742
PP
103 pretty->tmp_string = g_string_new("");
104 if (!pretty->tmp_string) {
105 goto error;
106 }
541b0a11 107end:
3228cc1d 108 return pretty;
6a18b281
MD
109
110error:
3228cc1d 111 g_free(pretty);
6a18b281 112 return NULL;
bac67f0f
JG
113}
114
3228cc1d 115BT_HIDDEN
d94d92ac 116void pretty_finalize(struct bt_self_component_sink *comp)
b25bd455 117{
d94d92ac
PP
118 destroy_pretty_data(
119 bt_self_component_get_data(
707b7d35 120 bt_self_component_sink_as_self_component(comp)));
b25bd455
JG
121}
122
bac67f0f 123static
d94d92ac
PP
124enum bt_self_component_status handle_notification(
125 struct pretty_component *pretty,
0d72b8c3 126 const struct bt_notification *notification)
4c1456f0 127{
d94d92ac 128 enum bt_self_component_status ret = BT_SELF_COMPONENT_STATUS_OK;
541b0a11 129
f6ccaed9 130 BT_ASSERT(pretty);
541b0a11 131
7cdc2bab 132 switch (bt_notification_get_type(notification)) {
0f6bea4e 133 case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
d94d92ac
PP
134 if (pretty_print_packet(pretty, notification)) {
135 ret = BT_SELF_COMPONENT_STATUS_ERROR;
136 }
0f6bea4e 137 break;
7cdc2bab 138 case BT_NOTIFICATION_TYPE_EVENT:
d94d92ac
PP
139 if (pretty_print_event(pretty, notification)) {
140 ret = BT_SELF_COMPONENT_STATUS_ERROR;
141 }
7cdc2bab
MD
142 break;
143 case BT_NOTIFICATION_TYPE_INACTIVITY:
144 fprintf(stderr, "Inactivity notification\n");
145 break;
7cdc2bab 146 default:
f42867e2 147 break;
78586d8a 148 }
b5e978f4 149
541b0a11 150 return ret;
4c1456f0 151}
bac67f0f 152
3228cc1d 153BT_HIDDEN
d94d92ac
PP
154enum bt_self_component_status pretty_port_connected(
155 struct bt_self_component_sink *comp,
156 struct bt_self_component_port_input *self_port,
0d72b8c3 157 const struct bt_port_output *other_port)
75e1829b 158{
d94d92ac 159 enum bt_self_component_status status = BT_SELF_COMPONENT_STATUS_OK;
3228cc1d 160 struct pretty_component *pretty;
75e1829b 161
d94d92ac 162 pretty = bt_self_component_get_data(
707b7d35 163 bt_self_component_sink_as_self_component(comp));
f6ccaed9 164 BT_ASSERT(pretty);
d94d92ac
PP
165 BT_ASSERT(!pretty->iterator);
166 pretty->iterator = bt_self_component_port_input_notification_iterator_create(
167 self_port);
168 if (!pretty->iterator) {
169 status = BT_SELF_COMPONENT_STATUS_NOMEM;
75e1829b 170 }
72b913fb 171
bf55043c 172 return status;
75e1829b
JG
173}
174
3228cc1d 175BT_HIDDEN
d94d92ac
PP
176enum bt_self_component_status pretty_consume(
177 struct bt_self_component_sink *comp)
fec2a9f2 178{
d94d92ac 179 enum bt_self_component_status ret;
0d72b8c3 180 bt_notification_array_const notifs;
d94d92ac
PP
181 struct bt_self_component_port_input_notification_iterator *it;
182 struct pretty_component *pretty = bt_self_component_get_data(
707b7d35 183 bt_self_component_sink_as_self_component(comp));
41a2b7ae 184 enum bt_notification_iterator_status it_ret;
d4393e08
PP
185 uint64_t count = 0;
186 uint64_t i = 0;
fec2a9f2 187
d94d92ac
PP
188 it = pretty->iterator;
189 it_ret = bt_self_component_port_input_notification_iterator_next(it,
190 &notifs, &count);
0d8b4d8e 191
41a2b7ae 192 switch (it_ret) {
d94d92ac
PP
193 case BT_NOTIFICATION_ITERATOR_STATUS_OK:
194 break;
195 case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM:
196 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
41a2b7ae 197 goto end;
dfa6653c 198 case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
d94d92ac
PP
199 ret = BT_SELF_COMPONENT_STATUS_AGAIN;
200 goto end;
201 case BT_NOTIFICATION_ITERATOR_STATUS_END:
202 ret = BT_SELF_COMPONENT_STATUS_END;
203 BT_OBJECT_PUT_REF_AND_RESET(pretty->iterator);
dfa6653c 204 goto end;
dfa6653c 205 default:
d94d92ac 206 ret = BT_SELF_COMPONENT_STATUS_ERROR;
dfa6653c 207 goto end;
fec2a9f2
JG
208 }
209
d4393e08
PP
210 BT_ASSERT(it_ret == BT_NOTIFICATION_ITERATOR_STATUS_OK);
211
212 for (i = 0; i < count; i++) {
213 ret = handle_notification(pretty, notifs[i]);
214 if (ret) {
215 goto end;
216 }
217
65300d60 218 bt_object_put_ref(notifs[i]);
d4393e08 219 }
dfa6653c 220
fec2a9f2 221end:
d4393e08 222 for (; i < count; i++) {
65300d60 223 bt_object_put_ref(notifs[i]);
d4393e08
PP
224 }
225
fec2a9f2
JG
226 return ret;
227}
228
6e1bc0df 229static
05e21286 230int add_params_to_map(struct bt_value *plugin_opt_map)
6e1bc0df 231{
d94d92ac 232 int ret = 0;
6e1bc0df
MD
233 unsigned int i;
234
235 for (i = 0; i < BT_ARRAY_SIZE(plugin_options); i++) {
236 const char *key = plugin_options[i];
237 enum bt_value_status status;
238
05e21286 239 status = bt_value_map_insert_entry(plugin_opt_map, key,
da91b29a 240 bt_value_null);
6e1bc0df
MD
241 switch (status) {
242 case BT_VALUE_STATUS_OK:
243 break;
244 default:
d94d92ac 245 ret = -1;
6e1bc0df
MD
246 goto end;
247 }
248 }
249end:
250 return ret;
251}
252
253static
05e21286
PP
254bt_bool check_param_exists(const char *key, const struct bt_value *object,
255 void *data)
6e1bc0df 256{
3228cc1d 257 struct pretty_component *pretty = data;
6e1bc0df 258
05e21286
PP
259 if (!bt_value_map_has_entry(pretty->plugin_opt_map,
260 key)) {
3228cc1d
PP
261 fprintf(pretty->err,
262 "[warning] Parameter \"%s\" unknown to \"text.pretty\" sink component\n", key);
6e1bc0df 263 }
c55a9f58 264 return BT_TRUE;
6e1bc0df
MD
265}
266
267static
05e21286 268void apply_one_string(const char *key, const struct bt_value *params, char **option)
6e1bc0df 269{
05e21286 270 const struct bt_value *value = NULL;
6e1bc0df
MD
271 const char *str;
272
05e21286 273 value = bt_value_map_borrow_entry_value_const(params, key);
6e1bc0df
MD
274 if (!value) {
275 goto end;
276 }
277 if (bt_value_is_null(value)) {
278 goto end;
279 }
601b0d3c 280 str = bt_value_string_get(value);
6e1bc0df 281 *option = g_strdup(str);
601b0d3c 282
6e1bc0df 283end:
d94d92ac 284 return;
6e1bc0df
MD
285}
286
287static
05e21286 288void apply_one_bool(const char *key, const struct bt_value *params, bool *option,
6e1bc0df
MD
289 bool *found)
290{
05e21286 291 const struct bt_value *value = NULL;
c55a9f58 292 bt_bool bool_val;
6e1bc0df 293
05e21286 294 value = bt_value_map_borrow_entry_value_const(params, key);
6e1bc0df
MD
295 if (!value) {
296 goto end;
297 }
601b0d3c 298 bool_val = bt_value_bool_get(value);
c55a9f58 299 *option = (bool) bool_val;
6e1bc0df
MD
300 if (found) {
301 *found = true;
302 }
a82e90e8 303
6e1bc0df 304end:
d94d92ac 305 return;
6e1bc0df
MD
306}
307
ad96d936 308static
3228cc1d 309void warn_wrong_color_param(struct pretty_component *pretty)
ad96d936 310{
3228cc1d 311 fprintf(pretty->err,
ad96d936
PP
312 "[warning] Accepted values for the \"color\" parameter are:\n \"always\", \"auto\", \"never\"\n");
313}
314
77986bad 315static
d94d92ac 316int open_output_file(struct pretty_component *pretty)
77986bad 317{
d94d92ac 318 int ret = 0;
77986bad 319
3228cc1d 320 if (!pretty->options.output_path) {
77986bad
JD
321 goto end;
322 }
323
3228cc1d
PP
324 pretty->out = fopen(pretty->options.output_path, "w");
325 if (!pretty->out) {
77986bad
JD
326 goto error;
327 }
328
329 goto end;
330
331error:
d94d92ac
PP
332 ret = -1;
333
77986bad
JD
334end:
335 return ret;
336}
337
6e1bc0df 338static
05e21286 339int apply_params(struct pretty_component *pretty, const struct bt_value *params)
6e1bc0df 340{
d94d92ac 341 int ret = 0;
6e1bc0df
MD
342 enum bt_value_status status;
343 bool value, found;
344 char *str = NULL;
345
05e21286 346 pretty->plugin_opt_map = bt_value_map_create();
3228cc1d 347 if (!pretty->plugin_opt_map) {
d94d92ac 348 ret = -1;
6e1bc0df
MD
349 goto end;
350 }
3228cc1d 351 ret = add_params_to_map(pretty->plugin_opt_map);
d94d92ac 352 if (ret) {
6e1bc0df
MD
353 goto end;
354 }
355 /* Report unknown parameters. */
05e21286
PP
356 status = bt_value_map_foreach_entry_const(params,
357 check_param_exists, pretty);
6e1bc0df
MD
358 switch (status) {
359 case BT_VALUE_STATUS_OK:
360 break;
361 default:
d94d92ac 362 ret = -1;
6e1bc0df
MD
363 goto end;
364 }
365 /* Known parameters. */
3228cc1d 366 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
07208d85 367 if (bt_value_map_has_entry(params, "color")) {
05e21286 368 const struct bt_value *color_value;
ad96d936
PP
369 const char *color;
370
05e21286
PP
371 color_value = bt_value_map_borrow_entry_value_const(params,
372 "color");
ad96d936
PP
373 if (!color_value) {
374 goto end;
375 }
376
601b0d3c
PP
377 color = bt_value_string_get(color_value);
378
379 if (strcmp(color, "never") == 0) {
380 pretty->options.color = PRETTY_COLOR_OPT_NEVER;
381 } else if (strcmp(color, "auto") == 0) {
382 pretty->options.color = PRETTY_COLOR_OPT_AUTO;
383 } else if (strcmp(color, "always") == 0) {
384 pretty->options.color = PRETTY_COLOR_OPT_ALWAYS;
ad96d936 385 } else {
601b0d3c 386 warn_wrong_color_param(pretty);
ad96d936 387 }
ad96d936
PP
388 }
389
d94d92ac 390 apply_one_string("path", params, &pretty->options.output_path);
3228cc1d 391 ret = open_output_file(pretty);
d94d92ac 392 if (ret) {
77986bad
JD
393 goto end;
394 }
6e1bc0df 395
6e1bc0df 396 value = false; /* Default. */
d94d92ac 397 apply_one_bool("no-delta", params, &value, NULL);
3228cc1d 398 pretty->options.print_delta_field = !value; /* Reverse logic. */
6e1bc0df
MD
399
400 value = false; /* Default. */
d94d92ac 401 apply_one_bool("clock-cycles", params, &value, NULL);
3228cc1d 402 pretty->options.print_timestamp_cycles = value;
6e1bc0df
MD
403
404 value = false; /* Default. */
d94d92ac 405 apply_one_bool("clock-seconds", params, &value, NULL);
3228cc1d 406 pretty->options.clock_seconds = value;
6e1bc0df
MD
407
408 value = false; /* Default. */
d94d92ac 409 apply_one_bool("clock-date", params, &value, NULL);
3228cc1d 410 pretty->options.clock_date = value;
6e1bc0df
MD
411
412 value = false; /* Default. */
d94d92ac 413 apply_one_bool("clock-gmt", params, &value, NULL);
3228cc1d 414 pretty->options.clock_gmt = value;
6e1bc0df 415
a263021c 416 value = false; /* Default. */
d94d92ac 417 apply_one_bool("verbose", params, &value, NULL);
3228cc1d 418 pretty->options.verbose = value;
a263021c 419
6e1bc0df 420 /* Names. */
d94d92ac 421 apply_one_string("name-default", params, &str);
6e1bc0df 422 if (!str) {
3228cc1d 423 pretty->options.name_default = PRETTY_DEFAULT_UNSET;
6e1bc0df 424 } else if (!strcmp(str, "show")) {
3228cc1d 425 pretty->options.name_default = PRETTY_DEFAULT_SHOW;
6e1bc0df 426 } else if (!strcmp(str, "hide")) {
3228cc1d 427 pretty->options.name_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 428 } else {
d94d92ac 429 ret = -1;
6e1bc0df
MD
430 goto end;
431 }
432 g_free(str);
433 str = NULL;
434
3228cc1d
PP
435 switch (pretty->options.name_default) {
436 case PRETTY_DEFAULT_UNSET:
437 pretty->options.print_payload_field_names = true;
438 pretty->options.print_context_field_names = true;
439 pretty->options.print_header_field_names = false;
440 pretty->options.print_scope_field_names = false;
6e1bc0df 441 break;
3228cc1d
PP
442 case PRETTY_DEFAULT_SHOW:
443 pretty->options.print_payload_field_names = true;
444 pretty->options.print_context_field_names = true;
445 pretty->options.print_header_field_names = true;
446 pretty->options.print_scope_field_names = true;
6e1bc0df 447 break;
3228cc1d
PP
448 case PRETTY_DEFAULT_HIDE:
449 pretty->options.print_payload_field_names = false;
450 pretty->options.print_context_field_names = false;
451 pretty->options.print_header_field_names = false;
452 pretty->options.print_scope_field_names = false;
6e1bc0df
MD
453 break;
454 default:
d94d92ac 455 ret = -1;
6e1bc0df
MD
456 goto end;
457 }
458
459 value = false;
460 found = false;
d94d92ac 461 apply_one_bool("name-payload", params, &value, &found);
6e1bc0df 462 if (found) {
3228cc1d 463 pretty->options.print_payload_field_names = value;
6e1bc0df
MD
464 }
465
466 value = false;
467 found = false;
d94d92ac 468 apply_one_bool("name-context", params, &value, &found);
6e1bc0df 469 if (found) {
3228cc1d 470 pretty->options.print_context_field_names = value;
6e1bc0df
MD
471 }
472
473 value = false;
474 found = false;
d94d92ac 475 apply_one_bool("name-header", params, &value, &found);
6e1bc0df 476 if (found) {
3228cc1d 477 pretty->options.print_header_field_names = value;
6e1bc0df
MD
478 }
479
480 value = false;
481 found = false;
d94d92ac 482 apply_one_bool("name-scope", params, &value, &found);
6e1bc0df 483 if (found) {
3228cc1d 484 pretty->options.print_scope_field_names = value;
6e1bc0df
MD
485 }
486
487 /* Fields. */
d94d92ac 488 apply_one_string("field-default", params, &str);
6e1bc0df 489 if (!str) {
3228cc1d 490 pretty->options.field_default = PRETTY_DEFAULT_UNSET;
6e1bc0df 491 } else if (!strcmp(str, "show")) {
3228cc1d 492 pretty->options.field_default = PRETTY_DEFAULT_SHOW;
6e1bc0df 493 } else if (!strcmp(str, "hide")) {
3228cc1d 494 pretty->options.field_default = PRETTY_DEFAULT_HIDE;
6e1bc0df 495 } else {
d94d92ac 496 ret = -1;
6e1bc0df
MD
497 goto end;
498 }
499 g_free(str);
500 str = NULL;
501
3228cc1d
PP
502 switch (pretty->options.field_default) {
503 case PRETTY_DEFAULT_UNSET:
504 pretty->options.print_trace_field = false;
505 pretty->options.print_trace_hostname_field = true;
506 pretty->options.print_trace_domain_field = false;
507 pretty->options.print_trace_procname_field = true;
508 pretty->options.print_trace_vpid_field = true;
509 pretty->options.print_loglevel_field = false;
510 pretty->options.print_emf_field = false;
511 pretty->options.print_callsite_field = false;
6e1bc0df 512 break;
3228cc1d
PP
513 case PRETTY_DEFAULT_SHOW:
514 pretty->options.print_trace_field = true;
515 pretty->options.print_trace_hostname_field = true;
516 pretty->options.print_trace_domain_field = true;
517 pretty->options.print_trace_procname_field = true;
518 pretty->options.print_trace_vpid_field = true;
519 pretty->options.print_loglevel_field = true;
520 pretty->options.print_emf_field = true;
521 pretty->options.print_callsite_field = true;
6e1bc0df 522 break;
3228cc1d
PP
523 case PRETTY_DEFAULT_HIDE:
524 pretty->options.print_trace_field = false;
525 pretty->options.print_trace_hostname_field = false;
526 pretty->options.print_trace_domain_field = false;
527 pretty->options.print_trace_procname_field = false;
528 pretty->options.print_trace_vpid_field = false;
529 pretty->options.print_loglevel_field = false;
530 pretty->options.print_emf_field = false;
531 pretty->options.print_callsite_field = false;
6e1bc0df
MD
532 break;
533 default:
d94d92ac 534 ret = -1;
6e1bc0df
MD
535 goto end;
536 }
537
538 value = false;
539 found = false;
d94d92ac 540 apply_one_bool("field-trace", params, &value, &found);
6e1bc0df 541 if (found) {
3228cc1d 542 pretty->options.print_trace_field = value;
6e1bc0df
MD
543 }
544
545 value = false;
546 found = false;
d94d92ac 547 apply_one_bool("field-trace:hostname", params, &value, &found);
6e1bc0df 548 if (found) {
3228cc1d 549 pretty->options.print_trace_hostname_field = value;
6e1bc0df
MD
550 }
551
552 value = false;
553 found = false;
d94d92ac 554 apply_one_bool("field-trace:domain", params, &value, &found);
6e1bc0df 555 if (found) {
3228cc1d 556 pretty->options.print_trace_domain_field = value;
6e1bc0df
MD
557 }
558
559 value = false;
560 found = false;
d94d92ac 561 apply_one_bool("field-trace:procname", params, &value, &found);
6e1bc0df 562 if (found) {
3228cc1d 563 pretty->options.print_trace_procname_field = value;
6e1bc0df
MD
564 }
565
566 value = false;
567 found = false;
d94d92ac 568 apply_one_bool("field-trace:vpid", params, &value, &found);
6e1bc0df 569 if (found) {
3228cc1d 570 pretty->options.print_trace_vpid_field = value;
6e1bc0df
MD
571 }
572
573 value = false;
574 found = false;
d94d92ac 575 apply_one_bool("field-loglevel", params, &value, &found);
6e1bc0df 576 if (found) {
3228cc1d 577 pretty->options.print_loglevel_field = value;
6e1bc0df
MD
578 }
579
580 value = false;
581 found = false;
d94d92ac 582 apply_one_bool("field-emf", params, &value, &found);
6e1bc0df 583 if (found) {
3228cc1d 584 pretty->options.print_emf_field = value;
6e1bc0df
MD
585 }
586
587 value = false;
588 found = false;
d94d92ac 589 apply_one_bool("field-callsite", params, &value, &found);
6e1bc0df 590 if (found) {
3228cc1d 591 pretty->options.print_callsite_field = value;
6e1bc0df
MD
592 }
593
6e1bc0df 594end:
65300d60 595 bt_object_put_ref(pretty->plugin_opt_map);
3228cc1d 596 pretty->plugin_opt_map = NULL;
6e1bc0df
MD
597 g_free(str);
598 return ret;
599}
600
ad96d936 601static
3228cc1d 602void set_use_colors(struct pretty_component *pretty)
ad96d936 603{
3228cc1d
PP
604 switch (pretty->options.color) {
605 case PRETTY_COLOR_OPT_ALWAYS:
606 pretty->use_colors = true;
ad96d936 607 break;
3228cc1d
PP
608 case PRETTY_COLOR_OPT_AUTO:
609 pretty->use_colors = pretty->out == stdout &&
ad96d936
PP
610 bt_common_colors_supported();
611 break;
3228cc1d
PP
612 case PRETTY_COLOR_OPT_NEVER:
613 pretty->use_colors = false;
ad96d936
PP
614 break;
615 }
616}
617
2b4c4a7c
JD
618static
619void init_stream_packet_context_quarks(void)
620{
621 stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] =
622 g_quark_from_string("timestamp_begin");
623 stream_packet_context_quarks[Q_TIMESTAMP_BEGIN] =
624 g_quark_from_string("timestamp_begin");
625 stream_packet_context_quarks[Q_TIMESTAMP_END] =
626 g_quark_from_string("timestamp_end");
627 stream_packet_context_quarks[Q_EVENTS_DISCARDED] =
628 g_quark_from_string("events_discarded");
629 stream_packet_context_quarks[Q_CONTENT_SIZE] =
630 g_quark_from_string("content_size");
631 stream_packet_context_quarks[Q_PACKET_SIZE] =
632 g_quark_from_string("packet_size");
633 stream_packet_context_quarks[Q_PACKET_SEQ_NUM] =
634 g_quark_from_string("packet_seq_num");
635}
636
3228cc1d 637BT_HIDDEN
d94d92ac
PP
638enum bt_self_component_status pretty_init(
639 struct bt_self_component_sink *comp,
05e21286 640 const struct bt_value *params,
7d61fa8e 641 UNUSED_VAR void *init_method_data)
bac67f0f 642{
d94d92ac 643 enum bt_self_component_status ret;
3228cc1d 644 struct pretty_component *pretty = create_pretty();
bac67f0f 645
3228cc1d 646 if (!pretty) {
d94d92ac 647 ret = BT_SELF_COMPONENT_STATUS_NOMEM;
bac67f0f
JG
648 goto end;
649 }
650
d94d92ac
PP
651 ret = bt_self_component_sink_add_input_port(comp, "in", NULL, NULL);
652 if (ret != BT_SELF_COMPONENT_STATUS_OK) {
b9d103be
PP
653 goto end;
654 }
655
3228cc1d
PP
656 pretty->out = stdout;
657 pretty->err = stderr;
6e1bc0df 658
3228cc1d
PP
659 pretty->delta_cycles = -1ULL;
660 pretty->last_cycles_timestamp = -1ULL;
3af83b5a 661
3228cc1d
PP
662 pretty->delta_real_timestamp = -1ULL;
663 pretty->last_real_timestamp = -1ULL;
3af83b5a 664
d94d92ac
PP
665 if (apply_params(pretty, params)) {
666 ret = BT_SELF_COMPONENT_STATUS_ERROR;
6e1bc0df
MD
667 goto error;
668 }
669
3228cc1d 670 set_use_colors(pretty);
d94d92ac 671 bt_self_component_set_data(
707b7d35 672 bt_self_component_sink_as_self_component(comp), pretty);
2b4c4a7c
JD
673 init_stream_packet_context_quarks();
674
bac67f0f
JG
675end:
676 return ret;
d94d92ac 677
bac67f0f 678error:
3228cc1d 679 destroy_pretty_data(pretty);
bac67f0f
JG
680 return ret;
681}
This page took 0.075538 seconds and 4 git commands to generate.