network byte order + state multitraces fix
[lttv.git] / ltt / branches / poly / ltt / facility.c
... / ...
CommitLineData
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 */
47LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td);
48
49/* construct directed acyclic graph for types, and tree for fields */
50void construct_fields(LttFacility *fac,
51 LttField *field,
52 field_t *fld);
53
54/* generate the facility according to the events belongin to it */
55void generateFacility(LttFacility * f, facility_t * fac,
56 guint32 checksum);
57
58/* functions to release the memory occupied by a facility */
59void freeFacility(LttFacility * facility);
60void freeEventtype(LttEventType * evType);
61void freeLttType(LttType * type);
62void freeLttField(LttField * fld);
63void 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
78int 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);
150open_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
171void 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
276void 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 field->name = g_quark_from_string(fld->name);
285 if(fld->description) {
286 len = strlen(fld->description);
287 field->description = g_new(gchar, len+1);
288 strcpy(field->description, fld->description);
289 }
290 field->dynamic_offsets = NULL;
291 type = &field->field_type;
292 td = fld->type;
293
294 type->enum_map = NULL;
295 type->fields = NULL;
296 type->fields_by_name = NULL;
297 type->network = td->network;
298
299 switch(td->type) {
300 case INT_FIXED:
301 type->type_class = LTT_INT_FIXED;
302 type->size = td->size;
303 break;
304 case UINT_FIXED:
305 type->type_class = LTT_UINT_FIXED;
306 type->size = td->size;
307 break;
308 case POINTER:
309 type->type_class = LTT_POINTER;
310 type->size = fac->pointer_size;
311 break;
312 case CHAR:
313 type->type_class = LTT_CHAR;
314 type->size = td->size;
315 break;
316 case UCHAR:
317 type->type_class = LTT_UCHAR;
318 type->size = td->size;
319 g_assert(type->size != 0);
320 break;
321 case SHORT:
322 type->type_class = LTT_SHORT;
323 type->size = td->size;
324 break;
325 case USHORT:
326 type->type_class = LTT_USHORT;
327 type->size = td->size;
328 break;
329 case INT:
330 type->type_class = LTT_INT;
331 type->size = fac->int_size;
332 break;
333 case UINT:
334 type->type_class = LTT_UINT;
335 type->size = fac->int_size;
336 g_assert(type->size != 0);
337 break;
338 case LONG:
339 type->type_class = LTT_LONG;
340 type->size = fac->long_size;
341 break;
342 case ULONG:
343 type->type_class = LTT_ULONG;
344 type->size = fac->long_size;
345 break;
346 case SIZE_T:
347 type->type_class = LTT_SIZE_T;
348 type->size = fac->size_t_size;
349 break;
350 case SSIZE_T:
351 type->type_class = LTT_SSIZE_T;
352 type->size = fac->size_t_size;
353 break;
354 case OFF_T:
355 type->type_class = LTT_OFF_T;
356 type->size = fac->size_t_size;
357 break;
358 case FLOAT:
359 type->type_class = LTT_FLOAT;
360 type->size = td->size;
361 break;
362 case STRING:
363 type->type_class = LTT_STRING;
364 type->size = 0;
365 break;
366 case ENUM:
367 type->type_class = LTT_ENUM;
368 type->size = fac->int_size;
369 {
370 guint i;
371 type->enum_map = g_hash_table_new(g_direct_hash, g_direct_equal);
372 for(i=0; i<td->labels.position; i++) {
373 GQuark value = g_quark_from_string((char*)td->labels.array[i]);
374 gint key = *(int*)td->labels_values.array[i];
375 g_hash_table_insert(type->enum_map, (gpointer)key, (gpointer)value);
376 }
377 }
378 g_assert(type->size != 0);
379 break;
380 case ARRAY:
381 type->type_class = LTT_ARRAY;
382 type->size = td->size;
383 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
384 td->fields.position);
385 type->fields = g_array_set_size(type->fields, td->fields.position);
386 {
387 guint i;
388
389 for(i=0; i<td->fields.position; i++) {
390 field_t *schild = (field_t*)td->fields.array[i];
391 LttField *dchild = &g_array_index(type->fields, LttField, i);
392
393 construct_fields(fac, dchild, schild);
394 }
395 }
396 break;
397 case SEQUENCE:
398 type->type_class = LTT_SEQUENCE;
399 type->size = 0;
400 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
401 td->fields.position);
402 type->fields = g_array_set_size(type->fields, td->fields.position);
403 {
404 guint i;
405
406 for(i=0; i<td->fields.position; i++) {
407 field_t *schild = (field_t*)td->fields.array[i];
408 LttField *dchild = &g_array_index(type->fields, LttField, i);
409
410 construct_fields(fac, dchild, schild);
411 }
412 }
413 break;
414 case STRUCT:
415 type->type_class = LTT_STRUCT;
416 type->size = 0; // Size not calculated by the parser.
417 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
418 td->fields.position);
419 type->fields = g_array_set_size(type->fields, td->fields.position);
420 g_datalist_init(&type->fields_by_name);
421 {
422 guint i;
423
424 for(i=0; i<td->fields.position; i++) {
425 field_t *schild = (field_t*)td->fields.array[i];
426 LttField *dchild = &g_array_index(type->fields, LttField, i);
427
428 construct_fields(fac, dchild, schild);
429 g_datalist_id_set_data(&type->fields_by_name,
430 dchild->name,
431 dchild);
432 }
433 }
434 break;
435 case UNION:
436 type->type_class = LTT_UNION;
437 type->size = 0; // Size not calculated by the parser.
438 type->fields = g_array_sized_new(FALSE, TRUE, sizeof(LttField),
439 td->fields.position);
440 type->fields = g_array_set_size(type->fields, td->fields.position);
441 g_datalist_init(&type->fields_by_name);
442 {
443 guint i;
444
445 for(i=0; i<td->fields.position; i++) {
446 field_t *schild = (field_t*)td->fields.array[i];
447 LttField *dchild = &g_array_index(type->fields, LttField, i);
448
449 construct_fields(fac, dchild, schild);
450 g_datalist_id_set_data(&type->fields_by_name,
451 dchild->name,
452 dchild);
453 }
454 }
455 break;
456 case NONE:
457 default:
458 g_error("construct_fields : unknown type");
459 }
460
461 field->field_size = type->size;
462
463 /* Put the fields as "variable" offset to root first. Then,
464 * the offset precomputation will only have to set the FIELD_FIXED until
465 * it reaches the first variable length field, then stop.
466 */
467 field->fixed_root = FIELD_VARIABLE;
468
469 if(td->fmt) {
470 len = strlen(td->fmt);
471 type->fmt = g_new(gchar, len+1);
472 strcpy(type->fmt, td->fmt);
473 }
474}
475
476
477
478#if 0
479void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td,
480 LttField * fld)
481{
482 int i;
483 type_descriptor_t * tmpTd;
484
485 switch(td->type) {
486 case INT:
487 case UINT:
488 case FLOAT:
489 fld->field_type->size = td->size;
490 break;
491 case POINTER:
492 case LONG:
493 case ULONG:
494 case SIZE_T:
495 case SSIZE_T:
496 case OFF_T:
497 fld->field_type->size = 0;
498 break;
499 case STRING:
500 fld->field_type->size = 0;
501 break;
502 case ENUM:
503 fld->field_type->element_number = td->labels.position;
504 fld->field_type->enum_strings = g_new(GQuark,td->labels.position);
505 for(i=0;i<td->labels.position;i++){
506 fld->field_type->enum_strings[i]
507 = g_quark_from_string(((char*)(td->labels.array[i])));
508 }
509 fld->field_type->size = td->size;
510 break;
511
512 case ARRAY:
513 fld->field_type->element_number = (unsigned)td->size;
514 case SEQUENCE:
515 fld->field_type->element_type = g_new(LttType*,1);
516 tmpTd = td->nested_type;
517 fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd);
518 fld->child = g_new(LttField*, 1);
519 fld->child[0] = g_new(LttField, 1);
520
521 fld->child[0]->field_type = fld->field_type->element_type[0];
522 fld->child[0]->offset_root = 0;
523 fld->child[0]->fixed_root = FIELD_UNKNOWN;
524 fld->child[0]->offset_parent = 0;
525 fld->child[0]->fixed_parent = FIELD_UNKNOWN;
526 fld->child[0]->field_size = 0;
527 fld->child[0]->fixed_size = FIELD_UNKNOWN;
528 fld->child[0]->parent = fld;
529 fld->child[0]->child = NULL;
530 fld->child[0]->current_element = 0;
531 construct_types_and_fields(fac, tmpTd, fld->child[0]);
532 break;
533
534 case STRUCT:
535 case UNION:
536 fld->field_type->element_number = td->fields.position;
537
538 g_assert(fld->field_type->element_type == NULL);
539 fld->field_type->element_type = g_new(LttType*, td->fields.position);
540
541 fld->child = g_new(LttField*, td->fields.position);
542 for(i=0;i<td->fields.position;i++){
543 tmpTd = ((field_t*)(td->fields.array[i]))->type;
544
545 fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
546 fld->child[i] = g_new(LttField,1);
547
548 // fld->child[i]->field_pos = i;
549 fld->child[i]->field_type = fld->field_type->element_type[i];
550
551 fld->child[i]->field_type->element_name
552 = g_quark_from_string(((field_t*)(td->fields.array[i]))->name);
553
554 fld->child[i]->offset_root = 0;
555 fld->child[i]->fixed_root = FIELD_UNKNOWN;
556 fld->child[i]->offset_parent = 0;
557 fld->child[i]->fixed_parent = FIELD_UNKNOWN;
558 fld->child[i]->field_size = 0;
559 fld->child[i]->fixed_size = FIELD_UNKNOWN;
560 fld->child[i]->parent = fld;
561 fld->child[i]->child = NULL;
562 fld->child[i]->current_element = 0;
563 construct_types_and_fields(fac, tmpTd, fld->child[i]);
564 }
565 break;
566
567 default:
568 g_error("construct_types_and_fields : unknown type");
569 }
570
571
572}
573
574#endif //0
575
576#if 0
577void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
578 LttField * fld)
579{
580 int i, flag;
581 type_descriptor * tmpTd;
582
583 // if(td->type == LTT_STRING || td->type == LTT_SEQUENCE)
584 // fld->field_size = 0;
585 // else fld->field_size = -1;
586
587 if(td->type == LTT_ENUM){
588 fld->field_type->element_number = td->labels.position;
589 fld->field_type->enum_strings = g_new(GQuark,td->labels.position);
590 for(i=0;i<td->labels.position;i++){
591 fld->field_type->enum_strings[i]
592 = g_quark_from_string(((char*)(td->labels.array[i])));
593 }
594 }else if(td->type == LTT_ARRAY || td->type == LTT_SEQUENCE){
595 if(td->type == LTT_ARRAY)
596 fld->field_type->element_number = (unsigned)td->size;
597 fld->field_type->element_type = g_new(LttType*,1);
598 tmpTd = td->nested_type;
599 fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd);
600 fld->child = g_new(LttField*, 1);
601 fld->child[0] = g_new(LttField, 1);
602
603// fld->child[0]->field_pos = 0;
604 fld->child[0]->field_type = fld->field_type->element_type[0];
605 fld->child[0]->offset_root = fld->offset_root;
606 fld->child[0]->fixed_root = fld->fixed_root;
607 fld->child[0]->offset_parent = 0;
608 fld->child[0]->fixed_parent = 1;
609 // fld->child[0]->base_address = NULL;
610 fld->child[0]->field_size = 0;
611 fld->child[0]->field_fixed = -1;
612 fld->child[0]->parent = fld;
613 fld->child[0]->child = NULL;
614 fld->child[0]->current_element = 0;
615 construct_types_and_fields(fac, tmpTd, fld->child[0]);
616 }else if(td->type == LTT_STRUCT){
617 fld->field_type->element_number = td->fields.position;
618
619 if(fld->field_type->element_type == NULL){
620 fld->field_type->element_type = g_new(LttType*, td->fields.position);
621 flag = 1;
622 }else{
623 flag = 0;
624 }
625
626 fld->child = g_new(LttField*, td->fields.position);
627 for(i=0;i<td->fields.position;i++){
628 tmpTd = ((type_fields*)(td->fields.array[i]))->type;
629
630 if(flag)
631 fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
632 fld->child[i] = g_new(LttField,1);
633
634 fld->child[i]->field_pos = i;
635 fld->child[i]->field_type = fld->field_type->element_type[i];
636
637 if(flag){
638 fld->child[i]->field_type->element_name
639 = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name);
640 }
641
642 fld->child[i]->offset_root = -1;
643 fld->child[i]->fixed_root = -1;
644 fld->child[i]->offset_parent = -1;
645 fld->child[i]->fixed_parent = -1;
646 // fld->child[i]->base_address = NULL;
647 fld->child[i]->field_size = 0;
648 fld->child[i]->field_fixed = -1;
649 fld->child[i]->parent = fld;
650 fld->child[i]->child = NULL;
651 fld->child[i]->current_element = 0;
652 construct_types_and_fields(fac, tmpTd, fld->child[i]);
653 }
654 }
655}
656#endif //0
657
658#if 0
659/*****************************************************************************
660 *Function name
661 * lookup_named_type: search named type in the table
662 * internal function
663 *Input params
664 * fac : facility struct
665 * name : type name
666 *Return value
667 * : either find the named type, or create a new LttType
668 ****************************************************************************/
669
670LttType * lookup_named_type(LttFacility *fac, GQuark type_name)
671{
672 LttType *type = NULL;
673
674 /* Named type */
675 type = g_datalist_id_get_data(&fac->named_types, name);
676
677 g_assert(type != NULL);
678#if 0
679 if(type == NULL){
680 /* Create the type */
681 type = g_new(LttType,1);
682 type->type_name = name;
683 type->type_class = td->type;
684 if(td->fmt) type->fmt = g_strdup(td->fmt);
685 else type->fmt = NULL;
686 type->size = td->size;
687 type->enum_strings = NULL;
688 type->element_type = NULL;
689 type->element_number = 0;
690
691 if(td->type_name != NULL)
692 g_datalist_id_set_data_full(&fac->named_types, name,
693 type, (GDestroyNotify)freeLttNamedType);
694 }
695#endif //0
696 return type;
697}
698#endif //0
699
700/*****************************************************************************
701 *Function name
702 * ltt_facility_close : close a facility, decrease its usage count,
703 * if usage count = 0, release the memory
704 *Input params
705 * f : facility that will be closed
706 ****************************************************************************/
707
708void ltt_facility_close(LttFacility *f)
709{
710 //release the memory it occupied
711 freeFacility(f);
712}
713
714/*****************************************************************************
715 * Functions to release the memory occupied by the facility
716 ****************************************************************************/
717
718void freeFacility(LttFacility * fac)
719{
720 guint i;
721 LttEventType *et;
722
723 for(i=0; i<fac->events->len; i++) {
724 et = &g_array_index (fac->events, LttEventType, i);
725 freeEventtype(et);
726 }
727 g_array_free(fac->events, TRUE);
728
729 g_datalist_clear(&fac->events_by_name);
730
731 // g_datalist_clear(&fac->named_types);
732}
733
734void freeEventtype(LttEventType * evType)
735{
736 unsigned int i;
737 LttType * root_type;
738 if(evType->description)
739 g_free(evType->description);
740
741 for(i=0; i<evType->fields->len;i++) {
742 LttField *field = &g_array_index(evType->fields, LttField, i);
743 freeLttField(field);
744 }
745 g_array_free(evType->fields, TRUE);
746 g_datalist_clear(&evType->fields_by_name);
747}
748
749void freeLttType(LttType * type)
750{
751 unsigned int i;
752
753 if(type->fmt)
754 g_free(type->fmt);
755
756 if(type->enum_map)
757 g_hash_table_destroy(type->enum_map);
758
759 if(type->fields) {
760 for(i=0; i<type->fields->len; i++) {
761 freeLttField(&g_array_index(type->fields, LttField, i));
762 }
763 g_array_free(type->fields, TRUE);
764 }
765 if(type->fields_by_name)
766 g_datalist_clear(&type->fields_by_name);
767}
768
769void freeLttNamedType(LttType * type)
770{
771 freeLttType(type);
772}
773
774void freeLttField(LttField * field)
775{
776 if(field->description)
777 g_free(field->description);
778 if(field->dynamic_offsets)
779 g_array_free(field->dynamic_offsets, TRUE);
780 freeLttType(&field->field_type);
781}
782
783/*****************************************************************************
784 *Function name
785 * ltt_facility_name : obtain the facility's name
786 *Input params
787 * f : the facility
788 *Return value
789 * GQuark : the facility's name
790 ****************************************************************************/
791
792GQuark ltt_facility_name(LttFacility *f)
793{
794 return f->name;
795}
796
797/*****************************************************************************
798 *Function name
799 * ltt_facility_checksum : obtain the facility's checksum
800 *Input params
801 * f : the facility
802 *Return value
803 * : the checksum of the facility
804 ****************************************************************************/
805
806guint32 ltt_facility_checksum(LttFacility *f)
807{
808 return f->checksum;
809}
810
811/*****************************************************************************
812 *Function name
813 * ltt_facility_base_id : obtain the facility base id
814 *Input params
815 * f : the facility
816 *Return value
817 * : the base id of the facility
818 ****************************************************************************/
819
820guint ltt_facility_id(LttFacility *f)
821{
822 return f->id;
823}
824
825/*****************************************************************************
826 *Function name
827 * ltt_facility_eventtype_number: obtain the number of the event types
828 *Input params
829 * f : the facility that will be closed
830 *Return value
831 * : the number of the event types
832 ****************************************************************************/
833
834guint8 ltt_facility_eventtype_number(LttFacility *f)
835{
836 return (f->events->len);
837}
838
839/*****************************************************************************
840 *Function name
841 * ltt_facility_eventtype_get: obtain the event type according to event id
842 * from 0 to event_number - 1
843 *Input params
844 * f : the facility that will be closed
845 *Return value
846 * LttEventType * : the event type required
847 ****************************************************************************/
848
849LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i)
850{
851 if(!f->exists) return NULL;
852
853 g_assert(i < f->events->len);
854 return &g_array_index(f->events, LttEventType, i);
855}
856
857/*****************************************************************************
858 *Function name
859 * ltt_facility_eventtype_get_by_name
860 * : obtain the event type according to event name
861 * event name is unique in the facility
862 *Input params
863 * f : the facility
864 * name : the name of the event
865 *Return value
866 * LttEventType * : the event type required
867 ****************************************************************************/
868
869LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, GQuark name)
870{
871 LttEventType *et = g_datalist_id_get_data(&f->events_by_name, name);
872 return et;
873}
874
This page took 0.024479 seconds and 4 git commands to generate.