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