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