1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
3 * 2005 Mathieu Desnoyers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License Version 2.1 as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
29 #include "ltt-private.h"
32 static unsigned intSizes
[] = {
33 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
36 static unsigned floatSizes
[] = {
37 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
40 typedef enum _intSizesNames
{ SIZE_INT8
, SIZE_INT16
, SIZE_INT32
,
41 SIZE_INT64
, SIZE_SHORT
, INT_SIZES_NUMBER
}
44 static char * typeNames
[] = {
45 "int_fixed", "uint_fixed", "pointer", "char", "uchar", "short", "ushort",
46 "int", "uint", "long", "ulong", "size_t", "ssize_t", "off_t", "float",
47 "string", "enum", "array", "sequence", "struct", "union", "none" };
50 #define FLOAT_SIZES_NUMBER 7
53 /*****************************************************************************
55 * ltt_eventtype_name : get the name of the event type
59 * GQuark : the name of the event type
60 ****************************************************************************/
62 GQuark
ltt_eventtype_name(LttEventType
*et
)
67 /*****************************************************************************
69 * ltt_eventtype_description : get the description of the event type
73 * char * : the description of the event type
74 ****************************************************************************/
76 gchar
*ltt_eventtype_description(LttEventType
*et
)
78 return et
->description
;
81 /*****************************************************************************
83 * ltt_eventtype_facility : get the facility which contains the event type
87 * LttFacility * : the facility
88 ****************************************************************************/
90 LttFacility
*ltt_eventtype_facility(LttEventType
*et
)
95 /*****************************************************************************
97 * ltt_eventtype_id : get the id of the event type
102 ****************************************************************************/
104 guint8
ltt_eventtype_id(LttEventType
*et
)
109 /*****************************************************************************
111 * ltt_type_name : get the name of the type
115 * GQuark : the name of the type
116 ****************************************************************************/
118 GQuark
ltt_type_name(LttType
*t
)
120 return g_quark_from_static_string(typeNames
[t
->type_class
]);
123 /*****************************************************************************
125 * ltt_field_name : get the name of the field
129 * char * : the name of the type
130 ****************************************************************************/
132 GQuark
ltt_field_name(LttField
*f
)
139 /*****************************************************************************
141 * ltt_type_class : get the type class of the type
145 * LttTypeEnum : the type class of the type
146 ****************************************************************************/
148 LttTypeEnum
ltt_type_class(LttType
*t
)
150 return t
->type_class
;
153 /*****************************************************************************
155 * ltt_type_size : obtain the type size. The size is the number of bytes
156 * for primitive types (INT, UINT, FLOAT, ENUM)
157 * or the size for the unsigned integer length count for
164 * returns 0 if erroneous, and show a critical warning message.
165 ****************************************************************************/
167 guint
ltt_type_size(LttTrace
* trace
, LttType
*t
)
171 switch(t
->type_class
) {
181 if(likely(t
->size
< INT_SIZES_NUMBER
))
182 size
= intSizes
[t
->size
];
187 if(likely(t
->size
< FLOAT_SIZES_NUMBER
))
188 size
= floatSizes
[t
->size
];
212 g_warning("no size known for the type");
216 /*****************************************************************************
218 * ltt_type_element_type : obtain the type of nested elements for arrays
223 * LttType : the type of nested element of array or sequence
224 ****************************************************************************/
226 LttType
*ltt_type_element_type(LttType
*t
)
228 LttType
*element_type
;
231 if(unlikely(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
))
234 if(t
->type_class
== LTT_ARRAY
)
235 field
= &g_array_index(t
->fields
, LttField
, 0);
237 field
= &g_array_index(t
->fields
, LttField
, 1);
238 element_type
= ltt_field_type(field
);
244 /*****************************************************************************
246 * ltt_type_element_number : obtain the number of elements for enums
250 * unsigned : the number of elements for arrays
251 ****************************************************************************/
252 unsigned ltt_type_element_number(LttType
*t
)
256 if(likely(t
->type_class
== LTT_ENUM
))
257 // Permits non full enums ret = g_hash_table_size(t->enum_map);
258 ret
= (unsigned)(t
->highest_value
- t
->lowest_value
);
263 /*****************************************************************************
265 * ltt_type_member_number : obtain the number of data members for structure
269 * unsigned : the number of members for structure
270 ****************************************************************************/
272 unsigned ltt_type_member_number(LttType
*t
)
276 if(likely(t
->type_class
== LTT_STRUCT
|| t
->type_class
== LTT_UNION
))
277 ret
= t
->fields
->len
;
283 /*****************************************************************************
285 * ltt_enum_string_get : for enumerations, obtain the symbolic string
286 * associated with a value (0 to n - 1 for an
287 * enumeration of n elements)
290 * i : index of the member
292 * char * : symbolic string associated with a value
293 ****************************************************************************/
295 GQuark
ltt_enum_string_get(LttType
*t
, gulong i
)
297 if(likely(t
->type_class
== LTT_ENUM
))
298 return (GQuark
)g_hash_table_lookup(t
->enum_map
, (gpointer
)i
);
303 /*****************************************************************************
305 * ltt_field_element : obtain the field of nested elements for arrays and
310 * LttField * : the field of the nested element
311 ****************************************************************************/
313 LttField
*ltt_field_element(LttField
*f
)
315 LttField
*nest
= NULL
;
317 if(likely(f
->field_type
->type_class
== LTT_ARRAY
||
318 f
->field_type
->type_class
== LTT_SEQUENCE
))
325 /*****************************************************************************
327 * ltt_field_member_by_name : obtain the field of data members for structure
330 * name : name of the field
332 * LttField * : the field of the nested element
333 ****************************************************************************/
335 LttField
*ltt_field_member_by_name(LttField
*f
, GQuark name
)
337 LttField
*field_member
;
339 g_assert(f
->field_type
.type_class
== LTT_STRUCT
||
340 f
->field_type
.type_class
== LTT_UNION
);
342 field_member
= g_datalist_id_get_data(&f
->field_type
.fields_by_name
, name
);
348 /*****************************************************************************
350 * ltt_field_member : obtain the field of data members for structure
353 * i : index of member field
355 * LttField * : the field of the nested element
356 ****************************************************************************/
358 LttField
*ltt_field_member(LttField
*f
, guint i
)
360 LttField
*field_member
;
362 g_assert(f
->field_type
.type_class
== LTT_STRUCT
||
363 f
->field_type
.type_class
== LTT_UNION
);
364 g_assert(i
< f
->field_type
.fields
->len
);
366 field_member
= &g_array_index(f
->field_type
.fields
, LttField
, i
);
371 /*****************************************************************************
373 * ltt_field_type : obtain the type of the field
377 * ltt_tyoe * : the type of field
378 ****************************************************************************/
380 LttType
*ltt_field_type(LttField
*f
)
382 if(unlikely(!f
))return NULL
;
383 return &f
->field_type
;
386 int ltt_field_size(LttField
* f
)
388 if(unlikely(!f
))return 0;
389 return f
->field_size
;
393 /*****************************************************************************
395 * ltt_eventtype_num_fields : get the number of fields of the event
397 * e : an instance of an event type
399 * guint : number of fields
400 ****************************************************************************/
402 guint
ltt_eventtype_num_fields(LttEventType
*event_type
)
404 if(unlikely(!event_type
)) return 0;
406 return event_type
->fields
->len
;
409 /*****************************************************************************
411 * ltt_eventtype_field : get the i th field of the event
413 * e : an instance of an event type
416 * LttField * : The requested field, or NULL
417 ****************************************************************************/
419 LttField
*ltt_eventtype_field(LttEventType
*event_type
, guint i
)
421 if(unlikely(!event_type
)) return NULL
;
423 if(i
>= event_type
->fields
->len
) return NULL
;
425 return &g_array_index(event_type
->fields
, LttField
, i
);
429 /*****************************************************************************
431 * ltt_eventtype_field_by_name : get a field of the event
433 * e : an instance of an event type
436 * LttField * : The requested field, or NULL
437 ****************************************************************************/
439 LttField
*ltt_eventtype_field_by_name(LttEventType
*event_type
, GQuark name
)
441 if(unlikely(!event_type
)) return NULL
;
443 return (LttField
*)g_datalist_id_get_data(&event_type
->fields_by_name
, name
);
This page took 0.040037 seconds and 5 git commands to generate.