1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang, Mathieu Desnoyers
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;
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.
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,
28 #include "ltt-private.h"
31 static unsigned intSizes
[] = {
32 sizeof(int8_t), sizeof(int16_t), sizeof(int32_t), sizeof(int64_t),
35 typedef enum _intSizesNames
{ SIZE_INT8
, SIZE_INT16
, SIZE_INT32
,
36 SIZE_INT64
, SIZE_SHORT
, INT_SIZES_NUMBER
}
40 static unsigned floatSizes
[] = {
41 0, 0, sizeof(float), sizeof(double), 0, sizeof(float), sizeof(double) };
43 #define FLOAT_SIZES_NUMBER 7
46 /*****************************************************************************
48 * ltt_eventtype_name : get the name of the event type
52 * GQuark : the name of the event type
53 ****************************************************************************/
55 GQuark
ltt_eventtype_name(LttEventType
*et
)
60 /*****************************************************************************
62 * ltt_eventtype_description : get the description of the event type
66 * char * : the description of the event type
67 ****************************************************************************/
69 gchar
*ltt_eventtype_description(LttEventType
*et
)
71 return et
->description
;
74 /*****************************************************************************
76 * ltt_eventtype_facility : get the facility which contains the event type
80 * LttFacility * : the facility
81 ****************************************************************************/
83 LttFacility
*ltt_eventtype_facility(LttEventType
*et
)
88 /*****************************************************************************
90 * ltt_eventtype_id : get the id of the event type
95 ****************************************************************************/
97 guint8
ltt_eventtype_id(LttEventType
*et
)
102 /*****************************************************************************
104 * ltt_eventtype_type : get the type of the event type
108 * LttType * : the type of the event type
109 ****************************************************************************/
111 LttType
*ltt_eventtype_type(LttEventType
*et
)
113 if(unlikely(!et
->root_field
)) return NULL
;
114 else return et
->root_field
->field_type
;
117 /*****************************************************************************
119 * ltt_eventtype_field : get the root filed of the event type
123 * LttField * : the root filed of the event type
124 ****************************************************************************/
126 LttField
*ltt_eventtype_field(LttEventType
*et
)
128 return et
->root_field
;
131 /*****************************************************************************
133 * ltt_type_name : get the name of the type
137 * char * : the name of the type
138 ****************************************************************************/
140 GQuark
ltt_type_name(LttType
*t
)
142 return t
->element_name
;
145 /*****************************************************************************
147 * ltt_type_class : get the type class of the type
151 * LttTypeEnum : the type class of the type
152 ****************************************************************************/
154 LttTypeEnum
ltt_type_class(LttType
*t
)
156 return t
->type_class
;
159 /*****************************************************************************
161 * ltt_type_size : obtain the type size. The size is the number of bytes
162 * for primitive types (INT, UINT, FLOAT, ENUM)
163 * or the size for the unsigned integer length count for
170 * returns 0 if erroneous, and show a critical warning message.
171 ****************************************************************************/
173 size_t ltt_type_size(LttTrace
* trace
, LttType
*t
)
177 switch(t
->type_class
) {
183 if(likely(t
->size
< INT_SIZES_NUMBER
))
184 size
= intSizes
[t
->size
];
189 if(likely(t
->size
< FLOAT_SIZES_NUMBER
))
190 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
;
230 if(unlikely(t
->type_class
!= LTT_ARRAY
&& t
->type_class
!= LTT_SEQUENCE
))
233 element_type
= t
->element_type
[0];
238 /*****************************************************************************
240 * ltt_type_element_number : obtain the number of elements for arrays
244 * unsigned : the number of elements for arrays
245 ****************************************************************************/
247 unsigned ltt_type_element_number(LttType
*t
)
251 if(likely(t
->type_class
== LTT_ARRAY
))
252 ret
= t
->element_number
;
257 /*****************************************************************************
259 * ltt_type_member_number : obtain the number of data members for structure
263 * unsigned : the number of members for structure
264 ****************************************************************************/
266 unsigned ltt_type_member_number(LttType
*t
)
270 if(likely(t
->type_class
== LTT_STRUCT
|| t
->type_class
== LTT_UNION
))
271 ret
=t
->element_number
;
276 /*****************************************************************************
278 * ltt_type_member_type : obtain the type of a data member in a structure
282 * i : index of the member
284 * LttType * : the type of structure member
285 ****************************************************************************/
287 LttType
*ltt_type_member_type(LttType
*t
, unsigned i
, GQuark
*name
)
289 LttType
*member_type
= NULL
;
291 if(unlikely( (t
->type_class
!= LTT_STRUCT
292 && t
->type_class
!= LTT_UNION
)
294 (i
>= t
->element_number
)
298 *name
= t
->element_type
[i
]->element_name
;
299 member_type
= t
->element_type
[i
];
305 /*****************************************************************************
307 * ltt_enum_string_get : for enumerations, obtain the symbolic string
308 * associated with a value (0 to n - 1 for an
309 * enumeration of n elements)
312 * i : index of the member
314 * char * : symbolic string associated with a value
315 ****************************************************************************/
317 GQuark
ltt_enum_string_get(LttType
*t
, unsigned i
)
319 if(likely(t
->type_class
== LTT_ENUM
&& i
< t
->element_number
))
320 return t
->enum_strings
[i
];
325 /*****************************************************************************
327 * ltt_field_element : obtain the field of nested elements for arrays and
332 * LttField * : the field of the nested element
333 ****************************************************************************/
335 LttField
*ltt_field_element(LttField
*f
)
337 LttField
*nest
= NULL
;
339 if(likely(f
->field_type
->type_class
== LTT_ARRAY
||
340 f
->field_type
->type_class
== LTT_SEQUENCE
))
346 /*****************************************************************************
348 * ltt_field_member : obtain the field of data members for structure
351 * i : index of member field
353 * LttField * : the field of the nested element
354 ****************************************************************************/
356 LttField
*ltt_field_member(LttField
*f
, unsigned i
)
358 LttField
*field_member
;
360 g_assert(f
->field_type
->type_class
== LTT_STRUCT
||
361 f
->field_type
->type_class
== LTT_UNION
);
362 g_assert(i
< f
->field_type
->element_number
);
364 if(unlikely( f
->field_type
->type_class
!= LTT_STRUCT
365 && f
->field_type
->type_class
!= LTT_UNION
)
366 || i
>= f
->field_type
->element_number
)
370 field_member
= f
->child
[i
];
375 /*****************************************************************************
377 * ltt_field_type : obtain the type of the field
381 * ltt_tyoe * : the type of field
382 ****************************************************************************/
384 LttType
*ltt_field_type(LttField
*f
)
386 if(unlikely(!f
))return NULL
;
387 return f
->field_type
;
390 int ltt_field_size(LttField
* f
)
392 if(unlikely(!f
))return 0;
393 return f
->field_size
;
This page took 0.037194 seconds and 4 git commands to generate.