support trace version 0.6
[lttv.git] / ltt / branches / poly / ltt / type.c
... / ...
CommitLineData
1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19#ifdef HAVE_CONFIG_H
20#include <config.h>
21#endif
22
23#include <stdio.h>
24#include <glib.h>
25
26#include "parser.h"
27#include <ltt/ltt.h>
28#include "ltt-private.h"
29#include <ltt/type.h>
30
31static unsigned intSizes[] = {
32 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
33 sizeof(short) };
34
35typedef enum _intSizesNames { SIZE_INT8, SIZE_INT16, SIZE_INT32,
36 SIZE_INT64, SIZE_SHORT, INT_SIZES_NUMBER }
37 intSizesNames;
38
39
40static unsigned floatSizes[] = {
41 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
42
43#define FLOAT_SIZES_NUMBER 7
44
45
46/*****************************************************************************
47 *Function name
48 * ltt_eventtype_name : get the name of the event type
49 *Input params
50 * et : an event type
51 *Return value
52 * GQuark : the name of the event type
53 ****************************************************************************/
54
55GQuark ltt_eventtype_name(LttEventType *et)
56{
57 return et->name;
58}
59
60/*****************************************************************************
61 *Function name
62 * ltt_eventtype_description : get the description of the event type
63 *Input params
64 * et : an event type
65 *Return value
66 * char * : the description of the event type
67 ****************************************************************************/
68
69gchar *ltt_eventtype_description(LttEventType *et)
70{
71 return et->description;
72}
73
74/*****************************************************************************
75 *Function name
76 * ltt_eventtype_facility : get the facility which contains the event type
77 *Input params
78 * et : an event type
79 *Return value
80 * LttFacility * : the facility
81 ****************************************************************************/
82
83LttFacility *ltt_eventtype_facility(LttEventType *et)
84{
85 return et->facility;
86}
87
88/*****************************************************************************
89 *Function name
90 * ltt_eventtype_id : get the id of the event type
91 *Input params
92 * et : an event type
93 *Return value
94 * unsigned : the id
95 ****************************************************************************/
96
97guint8 ltt_eventtype_id(LttEventType *et)
98{
99 return et->index;
100}
101
102/*****************************************************************************
103 *Function name
104 * ltt_field_name : get the name of the field
105 *Input params
106 * f : a field
107 *Return value
108 * char * : the name of the type
109 ****************************************************************************/
110
111GQuark ltt_field_name(LttField *f)
112{
113 return f->name;
114}
115/*****************************************************************************
116 *Function name
117 * ltt_type_class : get the type class of the type
118 *Input params
119 * t : a type
120 *Return value
121 * LttTypeEnum : the type class of the type
122 ****************************************************************************/
123
124LttTypeEnum ltt_type_class(LttType *t)
125{
126 return t->type_class;
127}
128
129/*****************************************************************************
130 *Function name
131 * ltt_type_size : obtain the type size. The size is the number of bytes
132 * for primitive types (INT, UINT, FLOAT, ENUM)
133 * or the size for the unsigned integer length count for
134 * sequences
135 *Input params
136 * tf : trace file
137 * t : a type
138 *Return value
139 * : the type size
140 * returns 0 if erroneous, and show a critical warning message.
141 ****************************************************************************/
142
143size_t ltt_type_size(LttTrace * trace, LttType *t)
144{
145 size_t size;
146
147 switch(t->type_class) {
148
149 case LTT_INT:
150 case LTT_UINT:
151 case LTT_SEQUENCE:
152 case LTT_ENUM:
153 if(likely(t->size < INT_SIZES_NUMBER))
154 size = intSizes[t->size];
155 else
156 goto error;
157 break;
158 case LTT_FLOAT:
159 if(likely(t->size < FLOAT_SIZES_NUMBER))
160 size = floatSizes[t->size];
161 else
162 goto error;
163 break;
164 case LTT_POINTER:
165 case LTT_LONG:
166 case LTT_ULONG:
167 case LTT_SIZE_T:
168 case LTT_SSIZE_T:
169 case LTT_OFF_T:
170 case LTT_STRING:
171 case LTT_ARRAY:
172 case LTT_STRUCT:
173 case LTT_UNION:
174 goto error;
175 break;
176 }
177
178 return size;
179
180
181error:
182 g_warning("no size known for the type");
183 return 0;
184}
185
186/*****************************************************************************
187 *Function name
188 * ltt_type_element_type : obtain the type of nested elements for arrays
189 * and sequences
190 *Input params
191 * t : a type
192 *Return value
193 * LttType : the type of nested element of array or sequence
194 ****************************************************************************/
195
196LttType *ltt_type_element_type(LttType *t)
197{
198 LttType *element_type;
199 LttField *field;
200
201 if(unlikely(t->type_class != LTT_ARRAY && t->type_class != LTT_SEQUENCE))
202 element_type = NULL;
203 else {
204 if(t->type_class == LTT_ARRAY)
205 field = &g_array_index(t->fields, LttField, 0);
206 else
207 field = &g_array_index(t->fields, LttField, 1);
208 element_type = ltt_field_type(field);
209 }
210
211 return element_type;
212}
213
214/*****************************************************************************
215 *Function name
216 * ltt_type_element_number : obtain the number of elements for arrays
217 *Input params
218 * t : a type
219 *Return value
220 * unsigned : the number of elements for arrays
221 ****************************************************************************/
222#if 0
223unsigned ltt_type_element_number(LttType *t)
224{
225 unsigned ret = 0;
226
227 if(likely(t->type_class == LTT_ARRAY))
228 ret = t->element_number;
229
230 return ret;
231}
232#endif //0
233/*****************************************************************************
234 *Function name
235 * ltt_type_member_number : obtain the number of data members for structure
236 *Input params
237 * t : a type
238 *Return value
239 * unsigned : the number of members for structure
240 ****************************************************************************/
241
242unsigned ltt_type_member_number(LttType *t)
243{
244 unsigned ret = 0;
245
246 if(likely(t->type_class == LTT_STRUCT || t->type_class == LTT_UNION))
247 ret = t->fields->len;
248
249 return ret;
250}
251
252
253/*****************************************************************************
254 *Function name
255 * ltt_enum_string_get : for enumerations, obtain the symbolic string
256 * associated with a value (0 to n - 1 for an
257 * enumeration of n elements)
258 *Input params
259 * t : a type
260 * i : index of the member
261 *Return value
262 * char * : symbolic string associated with a value
263 ****************************************************************************/
264
265GQuark ltt_enum_string_get(LttType *t, gulong i)
266{
267 if(likely(t->type_class == LTT_ENUM))
268 return (GQuark)g_hash_table_lookup(t->enum_map, (gpointer)i);
269 else
270 return 0;
271}
272#if 0
273/*****************************************************************************
274 *Function name
275 * ltt_field_element : obtain the field of nested elements for arrays and
276 * sequence
277 *Input params
278 * f : a field
279 *Return value
280 * LttField * : the field of the nested element
281 ****************************************************************************/
282
283LttField *ltt_field_element(LttField *f)
284{
285 LttField *nest = NULL;
286
287 if(likely(f->field_type->type_class == LTT_ARRAY ||
288 f->field_type->type_class == LTT_SEQUENCE))
289 nest = f->child[0];
290
291 return nest;
292}
293#endif//0
294
295/*****************************************************************************
296 *Function name
297 * ltt_field_member_by_name : obtain the field of data members for structure
298 *Input params
299 * f : a field
300 * name : name of the field
301 *Return value
302 * LttField * : the field of the nested element
303 ****************************************************************************/
304
305LttField *ltt_field_member_by_name(LttField *f, GQuark name)
306{
307 LttField *field_member;
308
309 g_assert(f->field_type.type_class == LTT_STRUCT ||
310 f->field_type.type_class == LTT_UNION);
311
312 field_member = g_datalist_id_get_data(&f->field_type.fields_by_name, name);
313
314 return field_member;
315}
316
317
318/*****************************************************************************
319 *Function name
320 * ltt_field_member : obtain the field of data members for structure
321 *Input params
322 * f : a field
323 * i : index of member field
324 *Return value
325 * LttField * : the field of the nested element
326 ****************************************************************************/
327
328LttField *ltt_field_member(LttField *f, guint i)
329{
330 LttField *field_member;
331
332 g_assert(f->field_type.type_class == LTT_STRUCT ||
333 f->field_type.type_class == LTT_UNION);
334 g_assert(i < f->field_type.fields->len);
335
336 field_member = &g_array_index(f->field_type.fields, LttField, i);
337
338 return field_member;
339}
340
341/*****************************************************************************
342 *Function name
343 * ltt_field_type : obtain the type of the field
344 *Input params
345 * f : a field
346 *Return value
347 * ltt_tyoe * : the type of field
348 ****************************************************************************/
349
350LttType *ltt_field_type(LttField *f)
351{
352 if(unlikely(!f))return NULL;
353 return &f->field_type;
354}
355
356int ltt_field_size(LttField * f)
357{
358 if(unlikely(!f))return 0;
359 return f->field_size;
360}
361
362
363/*****************************************************************************
364 *Function name
365 * ltt_eventtype_num_fields : get the number of fields of the event
366 *Input params
367 * e : an instance of an event type
368 *Return value
369 * guint : number of fields
370 ****************************************************************************/
371
372guint ltt_eventtype_num_fields(LttEventType *event_type)
373{
374 if(unlikely(!event_type)) return NULL;
375
376 return event_type->fields->len;
377
378}
379/*****************************************************************************
380 *Function name
381 * ltt_eventtype_field : get the i th field of the event
382 *Input params
383 * e : an instance of an event type
384 * i : field index
385 *Return value
386 * LttField * : The requested field, or NULL
387 ****************************************************************************/
388
389LttField *ltt_eventtype_field(LttEventType *event_type, guint i)
390{
391 if(unlikely(!event_type)) return NULL;
392
393 if(i >= event_type->fields->len) return NULL;
394
395 return &g_array_index(event_type->fields, LttField, i);
396
397}
398
399/*****************************************************************************
400 *Function name
401 * ltt_eventtype_field_by_name : get a field of the event
402 *Input params
403 * e : an instance of an event type
404 * name : field name
405 *Return value
406 * LttField * : The requested field, or NULL
407 ****************************************************************************/
408
409LttField *ltt_eventtype_field_by_name(LttEventType *event_type, GQuark name)
410{
411 if(unlikely(!event_type)) return NULL;
412
413 return (LttField*)g_datalist_id_get_data(&event_type->fields_by_name, name);
414
415}
416
417
This page took 0.023663 seconds and 4 git commands to generate.