update integer text output formatting
[babeltrace.git] / formats / ctf-text / ctf-text.c
CommitLineData
642ec66d
MD
1/*
2 * BabelTrace - Common Trace Format (CTF)
3 *
4 * CTF Text Format registration.
5 *
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 */
18
19#include <babeltrace/format.h>
20#include <babeltrace/ctf-text/types.h>
21#include <babeltrace/babeltrace.h>
22#include <inttypes.h>
23#include <uuid/uuid.h>
24#include <sys/mman.h>
25#include <errno.h>
26#include <sys/types.h>
27#include <sys/stat.h>
28#include <fcntl.h>
29#include <dirent.h>
30#include <glib.h>
31#include <unistd.h>
32#include <stdlib.h>
33
34struct trace_descriptor *ctf_text_open_trace(const char *path, int flags);
35void ctf_text_close_trace(struct trace_descriptor *descriptor);
36
37static
38rw_dispatch read_dispatch_table[] = {
39 /* All unimplemented */
40};
41
42static
43rw_dispatch write_dispatch_table[] = {
44 [ CTF_TYPE_INTEGER ] = ctf_text_integer_write,
45 [ CTF_TYPE_FLOAT ] = ctf_text_float_write,
46 [ CTF_TYPE_ENUM ] = ctf_text_enum_write,
47 [ CTF_TYPE_STRING ] = ctf_text_string_write,
48 [ CTF_TYPE_STRUCT ] = ctf_text_struct_write,
49 [ CTF_TYPE_VARIANT ] = ctf_text_variant_write,
50 [ CTF_TYPE_ARRAY ] = ctf_text_array_write,
51 [ CTF_TYPE_SEQUENCE ] = ctf_text_sequence_write,
52};
53
54static
55struct format ctf_text_format = {
56 .open_trace = ctf_text_open_trace,
57 .close_trace = ctf_text_close_trace,
58};
59
60struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
61{
62 struct ctf_text_stream_pos *pos;
63 FILE *fp;
64
65 pos = g_new0(struct ctf_text_stream_pos, 1);
66
67 switch (flags & O_ACCMODE) {
68 case O_WRONLY:
b61922b5
MD
69 if (!path)
70 path = "/dev/stdout";
642ec66d
MD
71 fp = fopen(path, "w");
72 if (!fp)
73 goto error;
74 pos->fp = fp;
75 pos->parent.rw_table = write_dispatch_table;
76 break;
77 case O_RDONLY:
78 default:
79 fprintf(stdout, "[error] Incorrect open flags.\n");
80 goto error;
81 }
82
83 return &pos->trace_descriptor;
84error:
85 g_free(pos);
86 return NULL;
87}
88
89void ctf_text_close_trace(struct trace_descriptor *td)
90{
91 struct ctf_text_stream_pos *pos =
92 container_of(td, struct ctf_text_stream_pos, trace_descriptor);
93 fclose(pos->fp);
94 g_free(pos);
95}
96
97void __attribute__((constructor)) ctf_text_init(void)
98{
99 int ret;
100
101 ctf_text_format.name = g_quark_from_static_string("text");
102 ret = bt_register_format(&ctf_text_format);
103 assert(!ret);
104}
105
106/* TODO: finalize */
This page took 0.026286 seconds and 4 git commands to generate.