Unref: handle null pointers
[babeltrace.git] / include / babeltrace / ctf / metadata.h
... / ...
CommitLineData
1#ifndef _BABELTRACE_CTF_METADATA_H
2#define _BABELTRACE_CTF_METADATA_H
3
4/*
5 * BabelTrace
6 *
7 * CTF Metadata Header
8 *
9 * Copyright 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22#include <babeltrace/types.h>
23#include <babeltrace/ctf/types.h>
24#include <sys/types.h>
25#include <dirent.h>
26#include <uuid/uuid.h>
27#include <assert.h>
28#include <glib.h>
29
30struct ctf_trace;
31struct ctf_stream;
32struct ctf_event;
33
34struct ctf_stream_file {
35 /* Information about stream backing file */
36 int fd;
37 char *mmap; /* current stream mmap */
38 struct stream_pos pos; /* current stream position */
39};
40
41#define CTF_TRACE_SET_FIELD(ctf_trace, field) \
42 do { \
43 (ctf_trace)->field_mask |= CTF_TRACE_ ## field; \
44 } while (0)
45
46#define CTF_TRACE_FIELD_IS_SET(ctf_trace, field) \
47 ((ctf_trace)->field_mask & CTF_TRACE_ ## field)
48
49#define CTF_TRACE_GET_FIELD(ctf_trace, field) \
50 ({ \
51 assert(CTF_TRACE_FIELD_IS_SET(ctf_trace, field)); \
52 (ctf_trace)->(field); \
53 })
54
55
56struct ctf_trace {
57 /* root scope */
58 struct declaration_scope *root_declaration_scope;
59
60 struct declaration_scope *declaration_scope;
61 GPtrArray *streams; /* Array of struct ctf_stream pointers*/
62 struct ctf_stream_file metadata;
63
64 uint64_t major;
65 uint64_t minor;
66 uuid_t uuid;
67 int byte_order;
68
69 enum { /* Fields populated mask */
70 CTF_TRACE_major = (1U << 0),
71 CTF_TRACE_minor = (1U << 1),
72 CTF_TRACE_uuid = (1U << 2),
73 } field_mask;
74
75 /* Information about trace backing directory and files */
76 DIR *dir;
77 int dirfd;
78 int flags; /* open flags */
79};
80
81#define CTF_STREAM_SET_FIELD(ctf_stream, field) \
82 do { \
83 (ctf_stream)->field_mask |= CTF_STREAM_ ## field; \
84 } while (0)
85
86#define CTF_STREAM_FIELD_IS_SET(ctf_stream, field) \
87 ((ctf_stream)->field_mask & CTF_STREAM_ ## field)
88
89#define CTF_STREAM_GET_FIELD(ctf_stream, field) \
90 ({ \
91 assert(CTF_STREAM_FIELD_IS_SET(ctf_stream, field)); \
92 (ctf_stream)->(field); \
93 })
94
95struct ctf_stream {
96 struct ctf_trace *trace;
97 /* parent is lexical scope conaining the stream scope */
98 struct declaration_scope *declaration_scope;
99 /* innermost definition scope. to be used as parent of event. */
100 struct definition_scope *definition_scope;
101 GPtrArray *events_by_id; /* Array of struct ctf_event pointers indexed by id */
102 GHashTable *event_quark_to_id; /* GQuark to numeric id */
103
104 /* Declarations only used when parsing */
105 struct declaration_struct *packet_context_decl;
106 struct declaration_struct *event_header_decl;
107 struct declaration_struct *event_context_decl;
108
109 /* Definitions used afterward */
110 struct definition_struct *packet_context;
111 struct definition_struct *event_header;
112 struct definition_struct *event_context;
113
114 uint64_t stream_id;
115
116 enum { /* Fields populated mask */
117 CTF_STREAM_stream_id = (1 << 0),
118 } field_mask;
119
120 struct ctf_stream_file file; /* Backing file */
121};
122
123#define CTF_EVENT_SET_FIELD(ctf_event, field) \
124 do { \
125 (ctf_event)->field_mask |= CTF_EVENT_ ## field; \
126 } while (0)
127
128#define CTF_EVENT_FIELD_IS_SET(ctf_event, field) \
129 ((ctf_event)->field_mask & CTF_EVENT_ ## field)
130
131#define CTF_EVENT_GET_FIELD(ctf_event, field) \
132 ({ \
133 assert(CTF_EVENT_FIELD_IS_SET(ctf_event, field)); \
134 (ctf_event)->(field); \
135 })
136
137struct ctf_event {
138 /* stream mapped by stream_id */
139 struct ctf_stream *stream;
140 /* parent is lexical scope conaining the event scope */
141 struct declaration_scope *declaration_scope;
142
143 /* Declarations only used when parsing */
144 struct declaration_struct *context_decl;
145 struct declaration_struct *fields_decl;
146
147 /* Definitions used afterward */
148 struct definition_struct *context;
149 struct definition_struct *fields;
150
151 GQuark name;
152 uint64_t id; /* Numeric identifier within the stream */
153 uint64_t stream_id;
154
155 enum { /* Fields populated mask */
156 CTF_EVENT_name = (1 << 0),
157 CTF_EVENT_id = (1 << 1),
158 CTF_EVENT_stream_id = (1 << 2),
159 } field_mask;
160};
161
162#endif /* _BABELTRACE_CTF_METADATA_H */
This page took 0.022587 seconds and 4 git commands to generate.