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 typedef enum _intSizesNames
{ SIZE_INT8
, SIZE_INT16
, SIZE_INT32
,
37 SIZE_INT64
, SIZE_SHORT
, INT_SIZES_NUMBER
}
41 static unsigned floatSizes
[] = {
42 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
44 #define FLOAT_SIZES_NUMBER 7
47 /*****************************************************************************
49 * ltt_eventtype_name : get the name of the event type
53 * GQuark : the name of the event type
54 ****************************************************************************/
56 GQuark
ltt_eventtype_name(LttEventType
*et
)
61 /*****************************************************************************
63 * ltt_eventtype_description : get the description of the event type
67 * char * : the description of the event type
68 ****************************************************************************/
70 gchar
*ltt_eventtype_description(LttEventType
*et
)
72 return et
->description
;
75 /*****************************************************************************
77 * ltt_eventtype_facility : get the facility which contains the event type
81 * LttFacility * : the facility
82 ****************************************************************************/
84 LttFacility
*ltt_eventtype_facility(LttEventType
*et
)
89 /*****************************************************************************
91 * ltt_eventtype_id : get the id of the event type
96 ****************************************************************************/
98 guint8
ltt_eventtype_id(LttEventType
*et
)
103 /*****************************************************************************
105 * ltt_field_name : get the name of the field
109 * char * : the name of the type
110 ****************************************************************************/
112 GQuark
ltt_field_name(LttField
*f
)
116 /*****************************************************************************
118 * ltt_type_class : get the type class of the type
122 * LttTypeEnum : the type class of the type
123 ****************************************************************************/
125 LttTypeEnum
ltt_type_class(LttType
*t
)
127 return t
->type_class
;
130 /*****************************************************************************
132 * ltt_type_size : obtain the type size. The size is the number of bytes
133 * for primitive types (INT, UINT, FLOAT, ENUM)
134 * or the size for the unsigned integer length count for
141 * returns 0 if erroneous, and show a critical warning message.
142 ****************************************************************************/
144 guint
ltt_type_size(LttTrace
* trace
, LttType
*t
)
148 switch(t
->type_class
) {
158 if(likely(t
->size
< INT_SIZES_NUMBER
))
159 size
= intSizes
[t
->size
];
164 if(likely(t
->size
< FLOAT_SIZES_NUMBER
))
165 size
= floatSizes
[t
->size
];
189 g_warning("no size known for the type");
193 /*****************************************************************************
195 * ltt_type_element_type : obtain the type of nested elements for arrays
200 * LttType : the type of nested element of array or sequence
201 ****************************************************************************/
203 LttType
*ltt_type_element_type(LttType
*t
)
205 LttType
*element_type
;
208 if(unlikely(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
))
211 if(t
->type_class
== LTT_ARRAY
)
212 field
= &g_array_index(t
->fields
, LttField
, 0);
214 field
= &g_array_index(t
->fields
, LttField
, 1);
215 element_type
= ltt_field_type(field
);
221 /*****************************************************************************
223 * ltt_type_element_number : obtain the number of elements for enums
227 * unsigned : the number of elements for arrays
228 ****************************************************************************/
229 unsigned ltt_type_element_number(LttType
*t
)
233 if(likely(t
->type_class
== LTT_ENUM
))
234 ret
= g_hash_table_size(t
->enum_map
);
239 /*****************************************************************************
241 * ltt_type_member_number : obtain the number of data members for structure
245 * unsigned : the number of members for structure
246 ****************************************************************************/
248 unsigned ltt_type_member_number(LttType
*t
)
252 if(likely(t
->type_class
== LTT_STRUCT
|| t
->type_class
== LTT_UNION
))
253 ret
= t
->fields
->len
;
259 /*****************************************************************************
261 * ltt_enum_string_get : for enumerations, obtain the symbolic string
262 * associated with a value (0 to n - 1 for an
263 * enumeration of n elements)
266 * i : index of the member
268 * char * : symbolic string associated with a value
269 ****************************************************************************/
271 GQuark
ltt_enum_string_get(LttType
*t
, gulong i
)
273 if(likely(t
->type_class
== LTT_ENUM
))
274 return (GQuark
)g_hash_table_lookup(t
->enum_map
, (gpointer
)i
);
279 /*****************************************************************************
281 * ltt_field_element : obtain the field of nested elements for arrays and
286 * LttField * : the field of the nested element
287 ****************************************************************************/
289 LttField
*ltt_field_element(LttField
*f
)
291 LttField
*nest
= NULL
;
293 if(likely(f
->field_type
->type_class
== LTT_ARRAY
||
294 f
->field_type
->type_class
== LTT_SEQUENCE
))
301 /*****************************************************************************
303 * ltt_field_member_by_name : obtain the field of data members for structure
306 * name : name of the field
308 * LttField * : the field of the nested element
309 ****************************************************************************/
311 LttField
*ltt_field_member_by_name(LttField
*f
, GQuark name
)
313 LttField
*field_member
;
315 g_assert(f
->field_type
.type_class
== LTT_STRUCT
||
316 f
->field_type
.type_class
== LTT_UNION
);
318 field_member
= g_datalist_id_get_data(&f
->field_type
.fields_by_name
, name
);
324 /*****************************************************************************
326 * ltt_field_member : obtain the field of data members for structure
329 * i : index of member field
331 * LttField * : the field of the nested element
332 ****************************************************************************/
334 LttField
*ltt_field_member(LttField
*f
, guint i
)
336 LttField
*field_member
;
338 g_assert(f
->field_type
.type_class
== LTT_STRUCT
||
339 f
->field_type
.type_class
== LTT_UNION
);
340 g_assert(i
< f
->field_type
.fields
->len
);
342 field_member
= &g_array_index(f
->field_type
.fields
, LttField
, i
);
347 /*****************************************************************************
349 * ltt_field_type : obtain the type of the field
353 * ltt_tyoe * : the type of field
354 ****************************************************************************/
356 LttType
*ltt_field_type(LttField
*f
)
358 if(unlikely(!f
))return NULL
;
359 return &f
->field_type
;
362 int ltt_field_size(LttField
* f
)
364 if(unlikely(!f
))return 0;
365 return f
->field_size
;
369 /*****************************************************************************
371 * ltt_eventtype_num_fields : get the number of fields of the event
373 * e : an instance of an event type
375 * guint : number of fields
376 ****************************************************************************/
378 guint
ltt_eventtype_num_fields(LttEventType
*event_type
)
380 if(unlikely(!event_type
)) return 0;
382 return event_type
->fields
->len
;
385 /*****************************************************************************
387 * ltt_eventtype_field : get the i th field of the event
389 * e : an instance of an event type
392 * LttField * : The requested field, or NULL
393 ****************************************************************************/
395 LttField
*ltt_eventtype_field(LttEventType
*event_type
, guint i
)
397 if(unlikely(!event_type
)) return NULL
;
399 if(i
>= event_type
->fields
->len
) return NULL
;
401 return &g_array_index(event_type
->fields
, LttField
, i
);
405 /*****************************************************************************
407 * ltt_eventtype_field_by_name : get a field of the event
409 * e : an instance of an event type
412 * LttField * : The requested field, or NULL
413 ****************************************************************************/
415 LttField
*ltt_eventtype_field_by_name(LttEventType
*event_type
, GQuark name
)
417 if(unlikely(!event_type
)) return NULL
;
419 return (LttField
*)g_datalist_id_get_data(&event_type
->fields_by_name
, name
);
This page took 0.038714 seconds and 4 git commands to generate.