Add missing ctf-text.c to repo
[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:
69 fp = fopen(path, "w");
70 if (!fp)
71 goto error;
72 pos->fp = fp;
73 pos->parent.rw_table = write_dispatch_table;
74 break;
75 case O_RDONLY:
76 default:
77 fprintf(stdout, "[error] Incorrect open flags.\n");
78 goto error;
79 }
80
81 return &pos->trace_descriptor;
82error:
83 g_free(pos);
84 return NULL;
85}
86
87void ctf_text_close_trace(struct trace_descriptor *td)
88{
89 struct ctf_text_stream_pos *pos =
90 container_of(td, struct ctf_text_stream_pos, trace_descriptor);
91 fclose(pos->fp);
92 g_free(pos);
93}
94
95void __attribute__((constructor)) ctf_text_init(void)
96{
97 int ret;
98
99 ctf_text_format.name = g_quark_from_static_string("text");
100 ret = bt_register_format(&ctf_text_format);
101 assert(!ret);
102}
103
104/* TODO: finalize */
This page took 0.037947 seconds and 4 git commands to generate.