add usertrace support
[lttv.git] / ltt / branches / poly / ltt / facility.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
3 * 2005 Mathieu Desnoyers
4 *
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.
8 *
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.
13 *
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.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
27 #include <glib.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31
32
33
34 #include "parser.h"
35 #include <ltt/ltt.h>
36 #include "ltt-private.h"
37 #include <ltt/facility.h>
38
39 #ifndef g_open
40 #define g_open open
41 #endif
42
43 #define g_close close
44
45 /* search for the (named) type in the table, if it does not exist
46 create a new one */
47 LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td);
48
49 /* construct directed acyclic graph for types, and tree for fields */
50 void construct_fields(LttFacility *fac,
51 LttField *field,
52 field_t *fld);
53
54 /* generate the facility according to the events belongin to it */
55 void generateFacility(LttFacility * f, facility_t * fac,
56 guint32 checksum);
57
58 /* functions to release the memory occupied by a facility */
59 void freeFacility(LttFacility * facility);
60 void freeEventtype(LttEventType * evType);
61 void freeLttType(LttType * type);
62 void freeLttField(LttField * fld);
63 void freeLttNamedType(LttType * type);
64
65
66 /*****************************************************************************
67 *Function name
68 * ltt_facility_open : open facilities
69 *Input params
70 * t : the trace containing the facilities
71 * pathname : the path name of the facility
72 *
73 * Open the facility corresponding to the right checksum.
74 *
75 *returns 0 on success, 1 on error.
76 ****************************************************************************/
77
78 int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
79 {
80 int ret = 0;
81 gchar *token;
82 parse_file_t in;
83 facility_t * fac;
84 unsigned int checksum;
85 gchar buffer[BUFFER_SIZE];
86 gboolean generated = FALSE;
87
88 in.buffer = &(buffer[0]);
89 in.lineno = 0;
90 in.error = error_callback;
91 in.name = pathname;
92 in.unget = 0;
93
94 in.fp = fopen(in.name, "r");
95 if(in.fp == NULL) {
96 g_warning("cannot open facility description file %s",
97 in.name);
98 ret = 1;
99 goto open_error;
100 }
101
102 while(1){
103 token = getToken(&in);
104 if(in.type == ENDFILE) break;
105
106 if(g_ascii_strcasecmp(token, "<")) in.error(&in,"not a facility file");
107 token = getName(&in);
108
109 if(g_ascii_strcasecmp("facility",token) == 0) {
110 fac = g_new(facility_t, 1);
111 fac->name = NULL;
112 fac->description = NULL;
113 sequence_init(&(fac->events));
114 table_init(&(fac->named_types));
115 sequence_init(&(fac->unnamed_types));
116
117 parseFacility(&in, fac);
118
119 //check if any namedType is not defined
120 checkNamedTypesImplemented(&fac->named_types);
121
122 generateChecksum(fac->name, &checksum, &fac->events);
123
124 if(checksum == f->checksum) {
125 generateFacility(f, fac, checksum);
126 generated = TRUE;
127 }
128
129 g_free(fac->name);
130 free(fac->capname);
131 g_free(fac->description);
132 freeEvents(&fac->events);
133 sequence_dispose(&fac->events);
134 freeNamedType(&fac->named_types);
135 table_dispose(&fac->named_types);
136 freeTypes(&fac->unnamed_types);
137 sequence_dispose(&fac->unnamed_types);
138 g_free(fac);
139 if(generated) break; /* use the first good match */
140 }
141 else {
142 g_warning("facility token was expected in file %s", in.name);
143 ret = 1;
144 goto parse_error;
145 }
146 }
147
148 parse_error:
149 fclose(in.fp);
150 open_error:
151
152 if(!generated) {
153 g_warning("Cannot find facility %s, checksum 0x%X",
154 g_quark_to_string(f->name), f->checksum);
155 ret = 1;
156 }
157
158 return ret;
159 }
160
161
162 /*****************************************************************************
163 *Function name
164 * generateFacility : generate facility, internal function
165 *Input params
166 * facility : LttFacilty structure
167 * fac : facility structure
168 * checksum : checksum of the facility
169 ****************************************************************************/
170
171 void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
172 {
173 char * facilityName = fac->name;
174 sequence_t * events = &fac->events;
175 unsigned int i, j;
176 LttType * type;
177 table_t *named_types = &fac->named_types;
178
179 g_assert(f->name == g_quark_from_string(facilityName));
180 g_assert(f->checksum == checksum);
181
182 //f->event_number = events->position;
183
184 //initialize inner structures
185 f->events = g_array_sized_new (FALSE, TRUE, sizeof(LttEventType),
186 events->position);
187 //f->events = g_new(LttEventType*,f->event_number);
188 f->events = g_array_set_size(f->events, events->position);
189
190 g_datalist_init(&f->events_by_name);
191 // g_datalist_init(&f->named_types);
192 #if 0
193 /* The first day, he created the named types */
194
195 for(i=0; i<named_types->keys.position; i++) {
196 GQuark name = g_quark_from_string((char*)named_types->keys.array[i]);
197 type_descriptor_t *td = (type_descriptor_t*)named_types->values.array[i];
198
199 /* Create the type */
200 type = g_new(LttType,1);
201 type->type_name = name;
202 type->type_class = td->type;
203 if(td->fmt) type->fmt = g_strdup(td->fmt);
204 else type->fmt = NULL;
205 type->size = td->size;
206 type->enum_strings = NULL;
207 type->element_type = NULL;
208 type->element_number = 0;
209
210 construct_types_and_fields(type, td, NULL, NULL, ...);
211
212 g_datalist_id_set_data_full(&fac->named_types, name,
213 type, (GDestroyNotify)freeLttNamedType);
214
215 }
216 #endif //0
217 /* The second day, he created the event fields and types */
218 //for each event, construct field and type acyclic graph
219 for(i=0;i<events->position;i++){
220 event_t *parser_event = (event_t*)events->array[i];
221 LttEventType *event_type = &g_array_index(f->events, LttEventType, i);
222
223 event_type->name =
224 g_quark_from_string(parser_event->name);
225
226 g_datalist_id_set_data(&f->events_by_name, event_type->name,
227 event_type);
228
229 event_type->description =
230 g_strdup(parser_event->description);
231
232 event_type->index = i;
233 event_type->facility = f;
234
235 event_type->fields = g_array_sized_new(FALSE, TRUE,
236 sizeof(LttField), parser_event->fields.position);
237 event_type->fields =
238 g_array_set_size(event_type->fields, parser_event->fields.position);
239 g_datalist_init(&event_type->fields_by_name);
240
241 for(j=0; j<parser_event->fields.position; j++) {
242 LttField *field = &g_array_index(event_type->fields, LttField, j);
243 field_t *parser_field = (field_t*)parser_event->fields.array[j];
244
245 construct_fields(f, field, parser_field);
246 g_datalist_id_set_data(&event_type->fields_by_name,
247 field->name,
248 field);
249 }
250 }
251
252 /* What about 2 days weeks ? */
253 }
254
255
256 /*****************************************************************************
257 *Function name
258 * construct_types_and_fields : construct field tree and type graph,
259 * internal recursion function
260 *Input params
261 * fac : facility struct
262 * field : destination lttv field
263 * fld : source parser field
264 ****************************************************************************/
265
266 //DONE
267 //make the change for arrays and sequences
268 //no more root field. -> change this for an array of fields.
269 // Compute the field size here.
270 // Flag fields as "VARIABLE OFFSET" or "FIXED OFFSET" : as soon as
271 // a field with a variable size is found, all the following fields must
272 // be flagged with "VARIABLE OFFSET", this will be done by the offset
273 // precomputation.
274
275
276 void construct_fields(LttFacility *fac,
277 LttField *field,
278 field_t *fld)
279 {
280 guint len;
281 type_descriptor_t *td;
282 LttType *type;
283
284 if(fld->name)
285 field->name = g_quark_from_string(fld->name);
286 else
287 fld->name = 0;
288
289 if(fld->description) {
290 len = strlen(fld->description);
291 field->description = g_new(gchar, len+1);
292 strcpy(field->description, fld->description);
293 }
294 field->dynamic_offsets = NULL;
295 type = &field->field_type;
296 td = fld->type;
297
298 type->enum_map = NULL;
299 type->fields = NULL;
300 type->fields_by_name = NULL;
301 type->network = td->network;
302
303 switch(td->type) {
304 case INT_FIXED:
305 type->type_class = LTT_INT_FIXED;
306 type->size = td->size;
307 break;
308 case UINT_FIXED:
309 type->type_class = LTT_UINT_FIXED;
310 type->size = td->size;
311 break;
312 case POINTER:
313 type->type_class = LTT_POINTER;
314 type->size = fac->pointer_size;
315 break;
316 case CHAR:
317 type->type_class = LTT_CHAR;
318 type->size = td->size;
319 break;
320 case UCHAR:
321 type->type_class = LTT_UCHAR;
322 type->size = td->size;
323 g_assert(type->size != 0);
324 break;
325 case SHORT:
326 type->type_class = LTT_SHORT;
327 type->size = td->size;
328 break;
329 case USHORT:
330 type->type_class = LTT_USHORT;
331 type->size = td->size;
332 break;
333 case INT:
334 type->type_class = LTT_INT;
335 type->size = fac->int_size;
336 break;
337 case UINT:
338 type->type_class = LTT_UINT;
339 type->size = fac->int_size;
340 g_assert(type->size != 0);
341 break;
342 case LONG:
343 type->type_class = LTT_LONG;
344 type->size = fac->long_size;
345 break;
346 case ULONG:
347 type->type_class = LTT_ULONG;
348 type->size = fac->long_size;
349 break;
350 case SIZE_T:
351 type->type_class = LTT_SIZE_T;
352 type->size = fac->size_t_size;
353 break;
354 case SSIZE_T:
355 type->type_class = LTT_SSIZE_T;
356 type->size = fac->size_t_size;
357 break;
358 case OFF_T:
359 type->type_class = LTT_OFF_T;
360 type->size = fac->size_t_size;
361 break;
362 case FLOAT:
363 type->type_class = LTT_FLOAT;
364 type->size = td->size;
365 break;
366 case STRING:
367 type->type_class = LTT_STRING;
368 type->size = 0;
369 break;
370 case ENUM:
371 type->type_class = LTT_ENUM;
372 type->size = fac->int_size;
373 {
374 guint i;
375 type->enum_map = g_hash_table_new(g_direct_hash, g_direct_equal);
376 for(i=0; i<td->labels.position; i++) {
377 GQuark value = g_quark_from_string((char*)td->labels.array[i]);
378 gint key = *(int*)td->labels_values.array[i];
379 g_hash_table_insert(type->enum_map, (gpointer)key, (gpointer)value);
380 }
381 }
382 g_assert(type->size != 0);
383 break;
384 case ARRAY:
385 type->type_class = LTT_ARRAY;
386 type->size = td->size;
387 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
388 td->fields.position);
389 type->fields = g_array_set_size(type->fields, td->fields.position);
390 {
391 guint i;
392
393 for(i=0; i<td->fields.position; i++) {
394 field_t *schild = (field_t*)td->fields.array[i];
395 LttField *dchild = &g_array_index(type->fields, LttField, i);
396
397 construct_fields(fac, dchild, schild);
398 }
399 }
400 break;
401 case SEQUENCE:
402 type->type_class = LTT_SEQUENCE;
403 type->size = 0;
404 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
405 td->fields.position);
406 type->fields = g_array_set_size(type->fields, td->fields.position);
407 {
408 guint i;
409
410 for(i=0; i<td->fields.position; i++) {
411 field_t *schild = (field_t*)td->fields.array[i];
412 LttField *dchild = &g_array_index(type->fields, LttField, i);
413
414 construct_fields(fac, dchild, schild);
415 }
416 }
417 break;
418 case STRUCT:
419 type->type_class = LTT_STRUCT;
420 type->size = 0; // Size not calculated by the parser.
421 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
422 td->fields.position);
423 type->fields = g_array_set_size(type->fields, td->fields.position);
424 g_datalist_init(&type->fields_by_name);
425 {
426 guint i;
427
428 for(i=0; i<td->fields.position; i++) {
429 field_t *schild = (field_t*)td->fields.array[i];
430 LttField *dchild = &g_array_index(type->fields, LttField, i);
431
432 construct_fields(fac, dchild, schild);
433 g_datalist_id_set_data(&type->fields_by_name,
434 dchild->name,
435 dchild);
436 }
437 }
438 break;
439 case UNION:
440 type->type_class = LTT_UNION;
441 type->size = 0; // Size not calculated by the parser.
442 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
443 td->fields.position);
444 type->fields = g_array_set_size(type->fields, td->fields.position);
445 g_datalist_init(&type->fields_by_name);
446 {
447 guint i;
448
449 for(i=0; i<td->fields.position; i++) {
450 field_t *schild = (field_t*)td->fields.array[i];
451 LttField *dchild = &g_array_index(type->fields, LttField, i);
452
453 construct_fields(fac, dchild, schild);
454 g_datalist_id_set_data(&type->fields_by_name,
455 dchild->name,
456 dchild);
457 }
458 }
459 break;
460 case NONE:
461 default:
462 g_error("construct_fields : unknown type");
463 }
464
465 field->field_size = type->size;
466
467 /* Put the fields as "variable" offset to root first. Then,
468 * the offset precomputation will only have to set the FIELD_FIXED until
469 * it reaches the first variable length field, then stop.
470 */
471 field->fixed_root = FIELD_VARIABLE;
472
473 if(td->fmt) {
474 len = strlen(td->fmt);
475 type->fmt = g_new(gchar, len+1);
476 strcpy(type->fmt, td->fmt);
477 }
478 }
479
480
481
482 #if 0
483 void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td,
484 LttField * fld)
485 {
486 int i;
487 type_descriptor_t * tmpTd;
488
489 switch(td->type) {
490 case INT:
491 case UINT:
492 case FLOAT:
493 fld->field_type->size = td->size;
494 break;
495 case POINTER:
496 case LONG:
497 case ULONG:
498 case SIZE_T:
499 case SSIZE_T:
500 case OFF_T:
501 fld->field_type->size = 0;
502 break;
503 case STRING:
504 fld->field_type->size = 0;
505 break;
506 case ENUM:
507 fld->field_type->element_number = td->labels.position;
508 fld->field_type->enum_strings = g_new(GQuark,td->labels.position);
509 for(i=0;i<td->labels.position;i++){
510 fld->field_type->enum_strings[i]
511 = g_quark_from_string(((char*)(td->labels.array[i])));
512 }
513 fld->field_type->size = td->size;
514 break;
515
516 case ARRAY:
517 fld->field_type->element_number = (unsigned)td->size;
518 case SEQUENCE:
519 fld->field_type->element_type = g_new(LttType*,1);
520 tmpTd = td->nested_type;
521 fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd);
522 fld->child = g_new(LttField*, 1);
523 fld->child[0] = g_new(LttField, 1);
524
525 fld->child[0]->field_type = fld->field_type->element_type[0];
526 fld->child[0]->offset_root = 0;
527 fld->child[0]->fixed_root = FIELD_UNKNOWN;
528 fld->child[0]->offset_parent = 0;
529 fld->child[0]->fixed_parent = FIELD_UNKNOWN;
530 fld->child[0]->field_size = 0;
531 fld->child[0]->fixed_size = FIELD_UNKNOWN;
532 fld->child[0]->parent = fld;
533 fld->child[0]->child = NULL;
534 fld->child[0]->current_element = 0;
535 construct_types_and_fields(fac, tmpTd, fld->child[0]);
536 break;
537
538 case STRUCT:
539 case UNION:
540 fld->field_type->element_number = td->fields.position;
541
542 g_assert(fld->field_type->element_type == NULL);
543 fld->field_type->element_type = g_new(LttType*, td->fields.position);
544
545 fld->child = g_new(LttField*, td->fields.position);
546 for(i=0;i<td->fields.position;i++){
547 tmpTd = ((field_t*)(td->fields.array[i]))->type;
548
549 fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
550 fld->child[i] = g_new(LttField,1);
551
552 // fld->child[i]->field_pos = i;
553 fld->child[i]->field_type = fld->field_type->element_type[i];
554
555 fld->child[i]->field_type->element_name
556 = g_quark_from_string(((field_t*)(td->fields.array[i]))->name);
557
558 fld->child[i]->offset_root = 0;
559 fld->child[i]->fixed_root = FIELD_UNKNOWN;
560 fld->child[i]->offset_parent = 0;
561 fld->child[i]->fixed_parent = FIELD_UNKNOWN;
562 fld->child[i]->field_size = 0;
563 fld->child[i]->fixed_size = FIELD_UNKNOWN;
564 fld->child[i]->parent = fld;
565 fld->child[i]->child = NULL;
566 fld->child[i]->current_element = 0;
567 construct_types_and_fields(fac, tmpTd, fld->child[i]);
568 }
569 break;
570
571 default:
572 g_error("construct_types_and_fields : unknown type");
573 }
574
575
576 }
577
578 #endif //0
579
580 #if 0
581 void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
582 LttField * fld)
583 {
584 int i, flag;
585 type_descriptor * tmpTd;
586
587 // if(td->type == LTT_STRING || td->type == LTT_SEQUENCE)
588 // fld->field_size = 0;
589 // else fld->field_size = -1;
590
591 if(td->type == LTT_ENUM){
592 fld->field_type->element_number = td->labels.position;
593 fld->field_type->enum_strings = g_new(GQuark,td->labels.position);
594 for(i=0;i<td->labels.position;i++){
595 fld->field_type->enum_strings[i]
596 = g_quark_from_string(((char*)(td->labels.array[i])));
597 }
598 }else if(td->type == LTT_ARRAY || td->type == LTT_SEQUENCE){
599 if(td->type == LTT_ARRAY)
600 fld->field_type->element_number = (unsigned)td->size;
601 fld->field_type->element_type = g_new(LttType*,1);
602 tmpTd = td->nested_type;
603 fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd);
604 fld->child = g_new(LttField*, 1);
605 fld->child[0] = g_new(LttField, 1);
606
607 // fld->child[0]->field_pos = 0;
608 fld->child[0]->field_type = fld->field_type->element_type[0];
609 fld->child[0]->offset_root = fld->offset_root;
610 fld->child[0]->fixed_root = fld->fixed_root;
611 fld->child[0]->offset_parent = 0;
612 fld->child[0]->fixed_parent = 1;
613 // fld->child[0]->base_address = NULL;
614 fld->child[0]->field_size = 0;
615 fld->child[0]->field_fixed = -1;
616 fld->child[0]->parent = fld;
617 fld->child[0]->child = NULL;
618 fld->child[0]->current_element = 0;
619 construct_types_and_fields(fac, tmpTd, fld->child[0]);
620 }else if(td->type == LTT_STRUCT){
621 fld->field_type->element_number = td->fields.position;
622
623 if(fld->field_type->element_type == NULL){
624 fld->field_type->element_type = g_new(LttType*, td->fields.position);
625 flag = 1;
626 }else{
627 flag = 0;
628 }
629
630 fld->child = g_new(LttField*, td->fields.position);
631 for(i=0;i<td->fields.position;i++){
632 tmpTd = ((type_fields*)(td->fields.array[i]))->type;
633
634 if(flag)
635 fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
636 fld->child[i] = g_new(LttField,1);
637
638 fld->child[i]->field_pos = i;
639 fld->child[i]->field_type = fld->field_type->element_type[i];
640
641 if(flag){
642 fld->child[i]->field_type->element_name
643 = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name);
644 }
645
646 fld->child[i]->offset_root = -1;
647 fld->child[i]->fixed_root = -1;
648 fld->child[i]->offset_parent = -1;
649 fld->child[i]->fixed_parent = -1;
650 // fld->child[i]->base_address = NULL;
651 fld->child[i]->field_size = 0;
652 fld->child[i]->field_fixed = -1;
653 fld->child[i]->parent = fld;
654 fld->child[i]->child = NULL;
655 fld->child[i]->current_element = 0;
656 construct_types_and_fields(fac, tmpTd, fld->child[i]);
657 }
658 }
659 }
660 #endif //0
661
662 #if 0
663 /*****************************************************************************
664 *Function name
665 * lookup_named_type: search named type in the table
666 * internal function
667 *Input params
668 * fac : facility struct
669 * name : type name
670 *Return value
671 * : either find the named type, or create a new LttType
672 ****************************************************************************/
673
674 LttType * lookup_named_type(LttFacility *fac, GQuark type_name)
675 {
676 LttType *type = NULL;
677
678 /* Named type */
679 type = g_datalist_id_get_data(&fac->named_types, name);
680
681 g_assert(type != NULL);
682 #if 0
683 if(type == NULL){
684 /* Create the type */
685 type = g_new(LttType,1);
686 type->type_name = name;
687 type->type_class = td->type;
688 if(td->fmt) type->fmt = g_strdup(td->fmt);
689 else type->fmt = NULL;
690 type->size = td->size;
691 type->enum_strings = NULL;
692 type->element_type = NULL;
693 type->element_number = 0;
694
695 if(td->type_name != NULL)
696 g_datalist_id_set_data_full(&fac->named_types, name,
697 type, (GDestroyNotify)freeLttNamedType);
698 }
699 #endif //0
700 return type;
701 }
702 #endif //0
703
704 /*****************************************************************************
705 *Function name
706 * ltt_facility_close : close a facility, decrease its usage count,
707 * if usage count = 0, release the memory
708 *Input params
709 * f : facility that will be closed
710 ****************************************************************************/
711
712 void ltt_facility_close(LttFacility *f)
713 {
714 //release the memory it occupied
715 freeFacility(f);
716 }
717
718 /*****************************************************************************
719 * Functions to release the memory occupied by the facility
720 ****************************************************************************/
721
722 void freeFacility(LttFacility * fac)
723 {
724 guint i;
725 LttEventType *et;
726
727 for(i=0; i<fac->events->len; i++) {
728 et = &g_array_index (fac->events, LttEventType, i);
729 freeEventtype(et);
730 }
731 g_array_free(fac->events, TRUE);
732
733 g_datalist_clear(&fac->events_by_name);
734
735 // g_datalist_clear(&fac->named_types);
736 }
737
738 void freeEventtype(LttEventType * evType)
739 {
740 unsigned int i;
741 LttType * root_type;
742 if(evType->description)
743 g_free(evType->description);
744
745 for(i=0; i<evType->fields->len;i++) {
746 LttField *field = &g_array_index(evType->fields, LttField, i);
747 freeLttField(field);
748 }
749 g_array_free(evType->fields, TRUE);
750 g_datalist_clear(&evType->fields_by_name);
751 }
752
753 void freeLttType(LttType * type)
754 {
755 unsigned int i;
756
757 if(type->fmt)
758 g_free(type->fmt);
759
760 if(type->enum_map)
761 g_hash_table_destroy(type->enum_map);
762
763 if(type->fields) {
764 for(i=0; i<type->fields->len; i++) {
765 freeLttField(&g_array_index(type->fields, LttField, i));
766 }
767 g_array_free(type->fields, TRUE);
768 }
769 if(type->fields_by_name)
770 g_datalist_clear(&type->fields_by_name);
771 }
772
773 void freeLttNamedType(LttType * type)
774 {
775 freeLttType(type);
776 }
777
778 void freeLttField(LttField * field)
779 {
780 if(field->description)
781 g_free(field->description);
782 if(field->dynamic_offsets)
783 g_array_free(field->dynamic_offsets, TRUE);
784 freeLttType(&field->field_type);
785 }
786
787 /*****************************************************************************
788 *Function name
789 * ltt_facility_name : obtain the facility's name
790 *Input params
791 * f : the facility
792 *Return value
793 * GQuark : the facility's name
794 ****************************************************************************/
795
796 GQuark ltt_facility_name(LttFacility *f)
797 {
798 return f->name;
799 }
800
801 /*****************************************************************************
802 *Function name
803 * ltt_facility_checksum : obtain the facility's checksum
804 *Input params
805 * f : the facility
806 *Return value
807 * : the checksum of the facility
808 ****************************************************************************/
809
810 guint32 ltt_facility_checksum(LttFacility *f)
811 {
812 return f->checksum;
813 }
814
815 /*****************************************************************************
816 *Function name
817 * ltt_facility_base_id : obtain the facility base id
818 *Input params
819 * f : the facility
820 *Return value
821 * : the base id of the facility
822 ****************************************************************************/
823
824 guint ltt_facility_id(LttFacility *f)
825 {
826 return f->id;
827 }
828
829 /*****************************************************************************
830 *Function name
831 * ltt_facility_eventtype_number: obtain the number of the event types
832 *Input params
833 * f : the facility that will be closed
834 *Return value
835 * : the number of the event types
836 ****************************************************************************/
837
838 guint8 ltt_facility_eventtype_number(LttFacility *f)
839 {
840 return (f->events->len);
841 }
842
843 /*****************************************************************************
844 *Function name
845 * ltt_facility_eventtype_get: obtain the event type according to event id
846 * from 0 to event_number - 1
847 *Input params
848 * f : the facility that will be closed
849 *Return value
850 * LttEventType * : the event type required
851 ****************************************************************************/
852
853 LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i)
854 {
855 if(!f->exists) return NULL;
856
857 g_assert(i < f->events->len);
858 return &g_array_index(f->events, LttEventType, i);
859 }
860
861 /*****************************************************************************
862 *Function name
863 * ltt_facility_eventtype_get_by_name
864 * : obtain the event type according to event name
865 * event name is unique in the facility
866 *Input params
867 * f : the facility
868 * name : the name of the event
869 *Return value
870 * LttEventType * : the event type required
871 ****************************************************************************/
872
873 LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, GQuark name)
874 {
875 LttEventType *et = g_datalist_id_get_data(&f->events_by_name, name);
876 return et;
877 }
878
This page took 0.048559 seconds and 4 git commands to generate.