network byte order + state multitraces fix
[lttv.git] / ltt / branches / poly / ltt / facility.c
CommitLineData
449cb9d7 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Xiangxiu Yang
3aee1200 3 * 2005 Mathieu Desnoyers
449cb9d7 4 *
1b44b0b5 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.
449cb9d7 8 *
1b44b0b5 9 * This library is distributed in the hope that it will be useful,
449cb9d7 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1b44b0b5 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
449cb9d7 13 *
1b44b0b5 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.
449cb9d7 18 */
19
4e4d11b3 20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
6cd62ccf 24#include <stdlib.h>
25#include <string.h>
26#include <stdio.h>
cdf90f40 27#include <glib.h>
45e14832 28#include <sys/types.h>
29#include <sys/stat.h>
30#include <fcntl.h>
31
32
6cd62ccf 33
6cd62ccf 34#include "parser.h"
a5dcde2f 35#include <ltt/ltt.h>
36#include "ltt-private.h"
6cd62ccf 37#include <ltt/facility.h>
38
86005ded 39#ifndef g_open
40#define g_open open
41#endif
42
45e14832 43#define g_close close
44
6cd62ccf 45/* search for the (named) type in the table, if it does not exist
46 create a new one */
90699b2b 47LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td);
6cd62ccf 48
49/* construct directed acyclic graph for types, and tree for fields */
2312de30 50void construct_fields(LttFacility *fac,
51 LttField *field,
52 field_t *fld);
6cd62ccf 53
54/* generate the facility according to the events belongin to it */
8d1e6362 55void generateFacility(LttFacility * f, facility_t * fac,
3aee1200 56 guint32 checksum);
6cd62ccf 57
58/* functions to release the memory occupied by a facility */
963b5f2d 59void freeFacility(LttFacility * facility);
60void freeEventtype(LttEventType * evType);
2312de30 61void freeLttType(LttType * type);
963b5f2d 62void freeLttField(LttField * fld);
908f42fa 63void freeLttNamedType(LttType * type);
6cd62ccf 64
65
66/*****************************************************************************
67 *Function name
963b5f2d 68 * ltt_facility_open : open facilities
6cd62ccf 69 *Input params
963b5f2d 70 * t : the trace containing the facilities
6cd62ccf 71 * pathname : the path name of the facility
3aee1200 72 *
29e7c5b3 73 * Open the facility corresponding to the right checksum.
74 *
3aee1200 75 *returns 0 on success, 1 on error.
6cd62ccf 76 ****************************************************************************/
77
3aee1200 78int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname)
6cd62ccf 79{
a0c1f622 80 int ret = 0;
45e14832 81 gchar *token;
90699b2b 82 parse_file_t in;
8d1e6362 83 facility_t * fac;
2312de30 84 unsigned int checksum;
45e14832 85 gchar buffer[BUFFER_SIZE];
29e7c5b3 86 gboolean generated = FALSE;
6cd62ccf 87
45e14832 88 in.buffer = &(buffer[0]);
6cd62ccf 89 in.lineno = 0;
90 in.error = error_callback;
963b5f2d 91 in.name = pathname;
ba8a51cd 92 in.unget = 0;
6cd62ccf 93
90699b2b 94 in.fp = fopen(in.name, "r");
cb03932a 95 if(in.fp == NULL) {
3aee1200 96 g_warning("cannot open facility description file %s",
97 in.name);
a0c1f622 98 ret = 1;
99 goto open_error;
3aee1200 100 }
45e14832 101
6cd62ccf 102 while(1){
103 token = getToken(&in);
104 if(in.type == ENDFILE) break;
105
45e14832 106 if(g_ascii_strcasecmp(token, "<")) in.error(&in,"not a facility file");
963b5f2d 107 token = getName(&in);
45e14832 108
109 if(g_ascii_strcasecmp("facility",token) == 0) {
8d1e6362 110 fac = g_new(facility_t, 1);
963b5f2d 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
90699b2b 120 checkNamedTypesImplemented(&fac->named_types);
963b5f2d 121
90699b2b 122 generateChecksum(fac->name, &checksum, &fac->events);
29e7c5b3 123
124 if(checksum == f->checksum) {
125 generateFacility(f, fac, checksum);
126 generated = TRUE;
127 }
963b5f2d 128
45e14832 129 g_free(fac->name);
d2ace3a9 130 free(fac->capname);
45e14832 131 g_free(fac->description);
963b5f2d 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);
cf1307af 138 g_free(fac);
129fd24a 139 if(generated) break; /* use the first good match */
6cd62ccf 140 }
3aee1200 141 else {
142 g_warning("facility token was expected in file %s", in.name);
a0c1f622 143 ret = 1;
3aee1200 144 goto parse_error;
145 }
6cd62ccf 146 }
29e7c5b3 147
3aee1200 148 parse_error:
90699b2b 149 fclose(in.fp);
a0c1f622 150open_error:
90699b2b 151
986e2a7c 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 }
29e7c5b3 157
a0c1f622 158 return ret;
6cd62ccf 159}
160
161
162/*****************************************************************************
163 *Function name
164 * generateFacility : generate facility, internal function
165 *Input params
963b5f2d 166 * facility : LttFacilty structure
167 * fac : facility structure
6cd62ccf 168 * checksum : checksum of the facility
6cd62ccf 169 ****************************************************************************/
170
3aee1200 171void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum)
6cd62ccf 172{
963b5f2d 173 char * facilityName = fac->name;
90699b2b 174 sequence_t * events = &fac->events;
f104d082 175 unsigned int i, j;
963b5f2d 176 LttType * type;
f104d082 177 table_t *named_types = &fac->named_types;
6cd62ccf 178
3aee1200 179 g_assert(f->name == g_quark_from_string(facilityName));
180 g_assert(f->checksum == checksum);
181
182 //f->event_number = events->position;
6cd62ccf 183
184 //initialize inner structures
3aee1200 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);
2312de30 191 // g_datalist_init(&f->named_types);
f104d082 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
6cd62ccf 219 for(i=0;i<events->position;i++){
2312de30 220 event_t *parser_event = (event_t*)events->array[i];
f104d082 221 LttEventType *event_type = &g_array_index(f->events, LttEventType, i);
6cd62ccf 222
3aee1200 223 event_type->name =
f104d082 224 g_quark_from_string(parser_event->name);
3aee1200 225
226 g_datalist_id_set_data(&f->events_by_name, event_type->name,
227 event_type);
228
229 event_type->description =
f104d082 230 g_strdup(parser_event->description);
6cd62ccf 231
3aee1200 232 event_type->index = i;
f104d082 233 event_type->facility = f;
6cd62ccf 234
f104d082 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
2312de30 245 construct_fields(f, field, parser_field);
f104d082 246 g_datalist_id_set_data(&event_type->fields_by_name,
247 field->name,
248 field);
8710c6c7 249 }
f104d082 250 }
251
252 /* What about 2 days weeks ? */
6cd62ccf 253}
254
255
256/*****************************************************************************
257 *Function name
3aee1200 258 * construct_types_and_fields : construct field tree and type graph,
6cd62ccf 259 * internal recursion function
260 *Input params
261 * fac : facility struct
f104d082 262 * field : destination lttv field
263 * fld : source parser field
6cd62ccf 264 ****************************************************************************/
265
f104d082 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
3aee1200 275
f104d082 276void construct_fields(LttFacility *fac,
277 LttField *field,
278 field_t *fld)
279{
280 guint len;
281 type_descriptor_t *td;
2312de30 282 LttType *type;
f104d082 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;
f0b795e0 297 type->network = td->network;
743e50fd 298
f104d082 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;
743e50fd 319 g_assert(type->size != 0);
f104d082 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;
743e50fd 336 g_assert(type->size != 0);
f104d082 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;
743e50fd 371 type->enum_map = g_hash_table_new(g_direct_hash, g_direct_equal);
f104d082 372 for(i=0; i<td->labels.position; i++) {
2312de30 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);
f104d082 376 }
377 }
743e50fd 378 g_assert(type->size != 0);
f104d082 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
90699b2b 479void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td,
3aee1200 480 LttField * fld)
481{
a0c1f622 482 int i;
90699b2b 483 type_descriptor_t * tmpTd;
3aee1200 484
485 switch(td->type) {
cb03932a 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:
3aee1200 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;
cb03932a 533
534 case STRUCT:
535 case UNION:
3aee1200 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++){
90699b2b 543 tmpTd = ((field_t*)(td->fields.array[i]))->type;
3aee1200 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
90699b2b 552 = g_quark_from_string(((field_t*)(td->fields.array[i]))->name);
3aee1200 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 }
3aee1200 565 break;
cb03932a 566
3aee1200 567 default:
568 g_error("construct_types_and_fields : unknown type");
569 }
570
571
572}
573
f104d082 574#endif //0
3aee1200 575
576#if 0
577void construct_types_and_fields(LttFacility * fac, type_descriptor * td,
963b5f2d 578 LttField * fld)
6cd62ccf 579{
908f42fa 580 int i, flag;
6cd62ccf 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;
3aee1200 589 fld->field_type->enum_strings = g_new(GQuark,td->labels.position);
6cd62ccf 590 for(i=0;i<td->labels.position;i++){
591 fld->field_type->enum_strings[i]
3aee1200 592 = g_quark_from_string(((char*)(td->labels.array[i])));
6cd62ccf 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;
963b5f2d 597 fld->field_type->element_type = g_new(LttType*,1);
6cd62ccf 598 tmpTd = td->nested_type;
599 fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd);
963b5f2d 600 fld->child = g_new(LttField*, 1);
601 fld->child[0] = g_new(LttField, 1);
6cd62ccf 602
3aee1200 603// fld->child[0]->field_pos = 0;
6cd62ccf 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;
3aee1200 615 construct_types_and_fields(fac, tmpTd, fld->child[0]);
6cd62ccf 616 }else if(td->type == LTT_STRUCT){
617 fld->field_type->element_number = td->fields.position;
908f42fa 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
963b5f2d 626 fld->child = g_new(LttField*, td->fields.position);
6cd62ccf 627 for(i=0;i<td->fields.position;i++){
8d1e6362 628 tmpTd = ((type_fields*)(td->fields.array[i]))->type;
908f42fa 629
630 if(flag)
631 fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd);
963b5f2d 632 fld->child[i] = g_new(LttField,1);
6cd62ccf 633
634 fld->child[i]->field_pos = i;
635 fld->child[i]->field_type = fld->field_type->element_type[i];
908f42fa 636
637 if(flag){
3aee1200 638 fld->child[i]->field_type->element_name
639 = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name);
908f42fa 640 }
641
6cd62ccf 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;
3aee1200 652 construct_types_and_fields(fac, tmpTd, fld->child[i]);
6cd62ccf 653 }
654 }
655}
3aee1200 656#endif //0
6cd62ccf 657
f104d082 658#if 0
6cd62ccf 659/*****************************************************************************
660 *Function name
661 * lookup_named_type: search named type in the table
662 * internal function
663 *Input params
664 * fac : facility struct
f104d082 665 * name : type name
6cd62ccf 666 *Return value
963b5f2d 667 * : either find the named type, or create a new LttType
6cd62ccf 668 ****************************************************************************/
669
f104d082 670LttType * lookup_named_type(LttFacility *fac, GQuark type_name)
6cd62ccf 671{
cb03932a 672 LttType *type = NULL;
6cd62ccf 673
f104d082 674 /* Named type */
675 type = g_datalist_id_get_data(&fac->named_types, name);
676
677 g_assert(type != NULL);
678#if 0
3aee1200 679 if(type == NULL){
cb03932a 680 /* Create the type */
3aee1200 681 type = g_new(LttType,1);
682 type->type_name = name;
3aee1200 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;
cb03932a 690
691 if(td->type_name != NULL)
692 g_datalist_id_set_data_full(&fac->named_types, name,
693 type, (GDestroyNotify)freeLttNamedType);
6cd62ccf 694 }
f104d082 695#endif //0
3aee1200 696 return type;
6cd62ccf 697}
f104d082 698#endif //0
6cd62ccf 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
6cd62ccf 706 ****************************************************************************/
707
3aee1200 708void ltt_facility_close(LttFacility *f)
6cd62ccf 709{
6cd62ccf 710 //release the memory it occupied
711 freeFacility(f);
6cd62ccf 712}
713
714/*****************************************************************************
715 * Functions to release the memory occupied by the facility
716 ****************************************************************************/
717
963b5f2d 718void freeFacility(LttFacility * fac)
6cd62ccf 719{
3aee1200 720 guint i;
721 LttEventType *et;
6cd62ccf 722
3aee1200 723 for(i=0; i<fac->events->len; i++) {
724 et = &g_array_index (fac->events, LttEventType, i);
725 freeEventtype(et);
6cd62ccf 726 }
3aee1200 727 g_array_free(fac->events, TRUE);
6cd62ccf 728
f104d082 729 g_datalist_clear(&fac->events_by_name);
6cd62ccf 730
f104d082 731 // g_datalist_clear(&fac->named_types);
6cd62ccf 732}
733
963b5f2d 734void freeEventtype(LttEventType * evType)
6cd62ccf 735{
f104d082 736 unsigned int i;
908f42fa 737 LttType * root_type;
6cd62ccf 738 if(evType->description)
f104d082 739 g_free(evType->description);
740
741 for(i=0; i<evType->fields->len;i++) {
2312de30 742 LttField *field = &g_array_index(evType->fields, LttField, i);
743 freeLttField(field);
1417d990 744 }
f104d082 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)
2312de30 757 g_hash_table_destroy(type->enum_map);
f104d082 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);
6cd62ccf 767}
768
908f42fa 769void freeLttNamedType(LttType * type)
770{
f104d082 771 freeLttType(type);
908f42fa 772}
773
f104d082 774void freeLttField(LttField * field)
1417d990 775{
f104d082 776 if(field->description)
777 g_free(field->description);
778 if(field->dynamic_offsets)
779 g_array_free(field->dynamic_offsets, TRUE);
2312de30 780 freeLttType(&field->field_type);
6cd62ccf 781}
782
783/*****************************************************************************
784 *Function name
785 * ltt_facility_name : obtain the facility's name
786 *Input params
3aee1200 787 * f : the facility
6cd62ccf 788 *Return value
3aee1200 789 * GQuark : the facility's name
6cd62ccf 790 ****************************************************************************/
791
3aee1200 792GQuark ltt_facility_name(LttFacility *f)
6cd62ccf 793{
794 return f->name;
795}
796
797/*****************************************************************************
798 *Function name
799 * ltt_facility_checksum : obtain the facility's checksum
800 *Input params
3aee1200 801 * f : the facility
6cd62ccf 802 *Return value
3aee1200 803 * : the checksum of the facility
6cd62ccf 804 ****************************************************************************/
805
3aee1200 806guint32 ltt_facility_checksum(LttFacility *f)
6cd62ccf 807{
808 return f->checksum;
809}
810
963b5f2d 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
3aee1200 820guint ltt_facility_id(LttFacility *f)
963b5f2d 821{
3aee1200 822 return f->id;
963b5f2d 823}
824
6cd62ccf 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
3aee1200 831 * : the number of the event types
6cd62ccf 832 ****************************************************************************/
833
3aee1200 834guint8 ltt_facility_eventtype_number(LttFacility *f)
6cd62ccf 835{
3aee1200 836 return (f->events->len);
6cd62ccf 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
963b5f2d 846 * LttEventType * : the event type required
6cd62ccf 847 ****************************************************************************/
848
3aee1200 849LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i)
6cd62ccf 850{
c4afd5d8 851 if(!f->exists) return NULL;
852
3aee1200 853 g_assert(i < f->events->len);
854 return &g_array_index(f->events, LttEventType, i);
6cd62ccf 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
cf74a6f1 863 * f : the facility
6cd62ccf 864 * name : the name of the event
865 *Return value
963b5f2d 866 * LttEventType * : the event type required
6cd62ccf 867 ****************************************************************************/
868
3aee1200 869LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, GQuark name)
6cd62ccf 870{
cb03932a 871 LttEventType *et = g_datalist_id_get_data(&f->events_by_name, name);
a0c1f622 872 return et;
6cd62ccf 873}
874
This page took 0.076241 seconds and 4 git commands to generate.