| 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_types_and_fields(LttFacility * fac, type_descriptor_t * td, |
| 51 | LttField * fld); |
| 52 | |
| 53 | /* generate the facility according to the events belongin to it */ |
| 54 | void generateFacility(LttFacility * f, facility_t * fac, |
| 55 | guint32 checksum); |
| 56 | |
| 57 | /* functions to release the memory occupied by a facility */ |
| 58 | void freeFacility(LttFacility * facility); |
| 59 | void freeEventtype(LttEventType * evType); |
| 60 | void freeLttType(LttType ** type); |
| 61 | void freeLttField(LttField * fld); |
| 62 | void freeLttNamedType(LttType * type); |
| 63 | |
| 64 | |
| 65 | /***************************************************************************** |
| 66 | *Function name |
| 67 | * ltt_facility_open : open facilities |
| 68 | *Input params |
| 69 | * t : the trace containing the facilities |
| 70 | * pathname : the path name of the facility |
| 71 | * |
| 72 | *returns 0 on success, 1 on error. |
| 73 | ****************************************************************************/ |
| 74 | |
| 75 | int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname) |
| 76 | { |
| 77 | gchar *token; |
| 78 | parse_file_t in; |
| 79 | gsize length; |
| 80 | facility_t * fac; |
| 81 | unsigned long checksum; |
| 82 | GError * error = NULL; |
| 83 | gchar buffer[BUFFER_SIZE]; |
| 84 | |
| 85 | in.buffer = &(buffer[0]); |
| 86 | in.lineno = 0; |
| 87 | in.error = error_callback; |
| 88 | in.name = pathname; |
| 89 | |
| 90 | //in.fd = g_open(in.name, O_RDONLY, 0); |
| 91 | //if(in.fd < 0 ) { |
| 92 | in.fp = fopen(in.name, "r"); |
| 93 | if(in.fp == NULL) { |
| 94 | g_warning("cannot open facility description file %s", |
| 95 | in.name); |
| 96 | return 1; |
| 97 | } |
| 98 | |
| 99 | //in.channel = g_io_channel_unix_new(in.fd); |
| 100 | //in.pos = 0; |
| 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 | generateFacility(f, fac, checksum); |
| 125 | |
| 126 | g_free(fac->name); |
| 127 | g_free(fac->description); |
| 128 | freeEvents(&fac->events); |
| 129 | sequence_dispose(&fac->events); |
| 130 | freeNamedType(&fac->named_types); |
| 131 | table_dispose(&fac->named_types); |
| 132 | freeTypes(&fac->unnamed_types); |
| 133 | sequence_dispose(&fac->unnamed_types); |
| 134 | g_free(fac); |
| 135 | } |
| 136 | else { |
| 137 | g_warning("facility token was expected in file %s", in.name); |
| 138 | goto parse_error; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | parse_error: |
| 143 | //g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */ |
| 144 | //if(error != NULL) { |
| 145 | fclose(in.fp); |
| 146 | // g_warning("Can not close file: \n%s\n", error->message); |
| 147 | // g_error_free(error); |
| 148 | //} |
| 149 | |
| 150 | //g_close(in.fd); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | /***************************************************************************** |
| 155 | *Function name |
| 156 | * generateFacility : generate facility, internal function |
| 157 | *Input params |
| 158 | * facility : LttFacilty structure |
| 159 | * fac : facility structure |
| 160 | * checksum : checksum of the facility |
| 161 | ****************************************************************************/ |
| 162 | |
| 163 | void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum) |
| 164 | { |
| 165 | char * facilityName = fac->name; |
| 166 | sequence_t * events = &fac->events; |
| 167 | int i; |
| 168 | //LttEventType * evType; |
| 169 | LttEventType * event_type; |
| 170 | LttField * field; |
| 171 | LttType * type; |
| 172 | |
| 173 | g_assert(f->name == g_quark_from_string(facilityName)); |
| 174 | g_assert(f->checksum == checksum); |
| 175 | |
| 176 | //f->event_number = events->position; |
| 177 | |
| 178 | //initialize inner structures |
| 179 | f->events = g_array_sized_new (FALSE, TRUE, sizeof(LttEventType), |
| 180 | events->position); |
| 181 | //f->events = g_new(LttEventType*,f->event_number); |
| 182 | f->events = g_array_set_size(f->events, events->position); |
| 183 | |
| 184 | g_datalist_init(&f->events_by_name); |
| 185 | g_datalist_init(&f->named_types); |
| 186 | |
| 187 | //f->named_types_number = fac->named_types.keys.position; |
| 188 | //f->named_types = g_array_sized_new (FALSE, TRUE, sizeof(LttType), |
| 189 | // fac->named_types.keys.position); |
| 190 | //f->named_types = g_new(LttType*, fac->named_types.keys.position); |
| 191 | //f->named_types = g_array_set_size(f->named_types, |
| 192 | // fac->named_types.keys.position); |
| 193 | |
| 194 | //for each event, construct field tree and type graph |
| 195 | for(i=0;i<events->position;i++){ |
| 196 | event_type = &g_array_index(f->events, LttEventType, i); |
| 197 | //evType = g_new(LttEventType,1); |
| 198 | //f->events[i] = evType; |
| 199 | |
| 200 | event_type->name = |
| 201 | g_quark_from_string(((event_t*)(events->array[i]))->name); |
| 202 | |
| 203 | g_datalist_id_set_data(&f->events_by_name, event_type->name, |
| 204 | event_type); |
| 205 | |
| 206 | event_type->description = |
| 207 | g_strdup(((event_t*)(events->array[i]))->description); |
| 208 | |
| 209 | field = g_new(LttField, 1); |
| 210 | event_type->root_field = field; |
| 211 | event_type->facility = f; |
| 212 | event_type->index = i; |
| 213 | |
| 214 | if(((event_t*)(events->array[i]))->type != NULL){ |
| 215 | // field->field_pos = 0; |
| 216 | type = lookup_named_type(f,((event_t*)(events->array[i]))->type); |
| 217 | field->field_type = type; |
| 218 | field->offset_root = 0; |
| 219 | field->fixed_root = FIELD_UNKNOWN; |
| 220 | field->offset_parent = 0; |
| 221 | field->fixed_parent = FIELD_UNKNOWN; |
| 222 | // field->base_address = NULL; |
| 223 | field->field_size = 0; |
| 224 | field->fixed_size = FIELD_UNKNOWN; |
| 225 | field->parent = NULL; |
| 226 | field->child = NULL; |
| 227 | field->current_element = 0; |
| 228 | |
| 229 | //construct field tree and type graph |
| 230 | construct_types_and_fields(f,((event_t*)(events->array[i]))->type,field); |
| 231 | }else{ |
| 232 | event_type->root_field = NULL; |
| 233 | g_free(field); |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /***************************************************************************** |
| 240 | *Function name |
| 241 | * construct_types_and_fields : construct field tree and type graph, |
| 242 | * internal recursion function |
| 243 | *Input params |
| 244 | * fac : facility struct |
| 245 | * td : type descriptor |
| 246 | * root_field : root field of the event |
| 247 | ****************************************************************************/ |
| 248 | |
| 249 | |
| 250 | void construct_types_and_fields(LttFacility * fac, type_descriptor_t * td, |
| 251 | LttField * fld) |
| 252 | { |
| 253 | int i, flag; |
| 254 | type_descriptor_t * tmpTd; |
| 255 | |
| 256 | switch(td->type) { |
| 257 | case INT: |
| 258 | case UINT: |
| 259 | case FLOAT: |
| 260 | fld->field_type->size = td->size; |
| 261 | break; |
| 262 | case POINTER: |
| 263 | case LONG: |
| 264 | case ULONG: |
| 265 | case SIZE_T: |
| 266 | case SSIZE_T: |
| 267 | case OFF_T: |
| 268 | fld->field_type->size = 0; |
| 269 | break; |
| 270 | case STRING: |
| 271 | fld->field_type->size = 0; |
| 272 | break; |
| 273 | case ENUM: |
| 274 | fld->field_type->element_number = td->labels.position; |
| 275 | fld->field_type->enum_strings = g_new(GQuark,td->labels.position); |
| 276 | for(i=0;i<td->labels.position;i++){ |
| 277 | fld->field_type->enum_strings[i] |
| 278 | = g_quark_from_string(((char*)(td->labels.array[i]))); |
| 279 | } |
| 280 | fld->field_type->size = td->size; |
| 281 | break; |
| 282 | |
| 283 | case ARRAY: |
| 284 | fld->field_type->element_number = (unsigned)td->size; |
| 285 | case SEQUENCE: |
| 286 | fld->field_type->element_type = g_new(LttType*,1); |
| 287 | tmpTd = td->nested_type; |
| 288 | fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd); |
| 289 | fld->child = g_new(LttField*, 1); |
| 290 | fld->child[0] = g_new(LttField, 1); |
| 291 | |
| 292 | fld->child[0]->field_type = fld->field_type->element_type[0]; |
| 293 | fld->child[0]->offset_root = 0; |
| 294 | fld->child[0]->fixed_root = FIELD_UNKNOWN; |
| 295 | fld->child[0]->offset_parent = 0; |
| 296 | fld->child[0]->fixed_parent = FIELD_UNKNOWN; |
| 297 | fld->child[0]->field_size = 0; |
| 298 | fld->child[0]->fixed_size = FIELD_UNKNOWN; |
| 299 | fld->child[0]->parent = fld; |
| 300 | fld->child[0]->child = NULL; |
| 301 | fld->child[0]->current_element = 0; |
| 302 | construct_types_and_fields(fac, tmpTd, fld->child[0]); |
| 303 | break; |
| 304 | |
| 305 | case STRUCT: |
| 306 | case UNION: |
| 307 | fld->field_type->element_number = td->fields.position; |
| 308 | |
| 309 | g_assert(fld->field_type->element_type == NULL); |
| 310 | fld->field_type->element_type = g_new(LttType*, td->fields.position); |
| 311 | |
| 312 | fld->child = g_new(LttField*, td->fields.position); |
| 313 | for(i=0;i<td->fields.position;i++){ |
| 314 | tmpTd = ((field_t*)(td->fields.array[i]))->type; |
| 315 | |
| 316 | fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); |
| 317 | fld->child[i] = g_new(LttField,1); |
| 318 | |
| 319 | // fld->child[i]->field_pos = i; |
| 320 | fld->child[i]->field_type = fld->field_type->element_type[i]; |
| 321 | |
| 322 | fld->child[i]->field_type->element_name |
| 323 | = g_quark_from_string(((field_t*)(td->fields.array[i]))->name); |
| 324 | |
| 325 | fld->child[i]->offset_root = 0; |
| 326 | fld->child[i]->fixed_root = FIELD_UNKNOWN; |
| 327 | fld->child[i]->offset_parent = 0; |
| 328 | fld->child[i]->fixed_parent = FIELD_UNKNOWN; |
| 329 | fld->child[i]->field_size = 0; |
| 330 | fld->child[i]->fixed_size = FIELD_UNKNOWN; |
| 331 | fld->child[i]->parent = fld; |
| 332 | fld->child[i]->child = NULL; |
| 333 | fld->child[i]->current_element = 0; |
| 334 | construct_types_and_fields(fac, tmpTd, fld->child[i]); |
| 335 | } |
| 336 | break; |
| 337 | |
| 338 | default: |
| 339 | g_error("construct_types_and_fields : unknown type"); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | } |
| 344 | |
| 345 | |
| 346 | |
| 347 | #if 0 |
| 348 | void construct_types_and_fields(LttFacility * fac, type_descriptor * td, |
| 349 | LttField * fld) |
| 350 | { |
| 351 | int i, flag; |
| 352 | type_descriptor * tmpTd; |
| 353 | |
| 354 | // if(td->type == LTT_STRING || td->type == LTT_SEQUENCE) |
| 355 | // fld->field_size = 0; |
| 356 | // else fld->field_size = -1; |
| 357 | |
| 358 | if(td->type == LTT_ENUM){ |
| 359 | fld->field_type->element_number = td->labels.position; |
| 360 | fld->field_type->enum_strings = g_new(GQuark,td->labels.position); |
| 361 | for(i=0;i<td->labels.position;i++){ |
| 362 | fld->field_type->enum_strings[i] |
| 363 | = g_quark_from_string(((char*)(td->labels.array[i]))); |
| 364 | } |
| 365 | }else if(td->type == LTT_ARRAY || td->type == LTT_SEQUENCE){ |
| 366 | if(td->type == LTT_ARRAY) |
| 367 | fld->field_type->element_number = (unsigned)td->size; |
| 368 | fld->field_type->element_type = g_new(LttType*,1); |
| 369 | tmpTd = td->nested_type; |
| 370 | fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd); |
| 371 | fld->child = g_new(LttField*, 1); |
| 372 | fld->child[0] = g_new(LttField, 1); |
| 373 | |
| 374 | // fld->child[0]->field_pos = 0; |
| 375 | fld->child[0]->field_type = fld->field_type->element_type[0]; |
| 376 | fld->child[0]->offset_root = fld->offset_root; |
| 377 | fld->child[0]->fixed_root = fld->fixed_root; |
| 378 | fld->child[0]->offset_parent = 0; |
| 379 | fld->child[0]->fixed_parent = 1; |
| 380 | // fld->child[0]->base_address = NULL; |
| 381 | fld->child[0]->field_size = 0; |
| 382 | fld->child[0]->field_fixed = -1; |
| 383 | fld->child[0]->parent = fld; |
| 384 | fld->child[0]->child = NULL; |
| 385 | fld->child[0]->current_element = 0; |
| 386 | construct_types_and_fields(fac, tmpTd, fld->child[0]); |
| 387 | }else if(td->type == LTT_STRUCT){ |
| 388 | fld->field_type->element_number = td->fields.position; |
| 389 | |
| 390 | if(fld->field_type->element_type == NULL){ |
| 391 | fld->field_type->element_type = g_new(LttType*, td->fields.position); |
| 392 | flag = 1; |
| 393 | }else{ |
| 394 | flag = 0; |
| 395 | } |
| 396 | |
| 397 | fld->child = g_new(LttField*, td->fields.position); |
| 398 | for(i=0;i<td->fields.position;i++){ |
| 399 | tmpTd = ((type_fields*)(td->fields.array[i]))->type; |
| 400 | |
| 401 | if(flag) |
| 402 | fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); |
| 403 | fld->child[i] = g_new(LttField,1); |
| 404 | |
| 405 | fld->child[i]->field_pos = i; |
| 406 | fld->child[i]->field_type = fld->field_type->element_type[i]; |
| 407 | |
| 408 | if(flag){ |
| 409 | fld->child[i]->field_type->element_name |
| 410 | = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name); |
| 411 | } |
| 412 | |
| 413 | fld->child[i]->offset_root = -1; |
| 414 | fld->child[i]->fixed_root = -1; |
| 415 | fld->child[i]->offset_parent = -1; |
| 416 | fld->child[i]->fixed_parent = -1; |
| 417 | // fld->child[i]->base_address = NULL; |
| 418 | fld->child[i]->field_size = 0; |
| 419 | fld->child[i]->field_fixed = -1; |
| 420 | fld->child[i]->parent = fld; |
| 421 | fld->child[i]->child = NULL; |
| 422 | fld->child[i]->current_element = 0; |
| 423 | construct_types_and_fields(fac, tmpTd, fld->child[i]); |
| 424 | } |
| 425 | } |
| 426 | } |
| 427 | #endif //0 |
| 428 | |
| 429 | /***************************************************************************** |
| 430 | *Function name |
| 431 | * lookup_named_type: search named type in the table |
| 432 | * internal function |
| 433 | *Input params |
| 434 | * fac : facility struct |
| 435 | * td : type descriptor |
| 436 | *Return value |
| 437 | * : either find the named type, or create a new LttType |
| 438 | ****************************************************************************/ |
| 439 | |
| 440 | LttType * lookup_named_type(LttFacility *fac, type_descriptor_t * td) |
| 441 | { |
| 442 | LttType *type = NULL; |
| 443 | GQuark name = 0; |
| 444 | |
| 445 | if(td->type_name != NULL) { |
| 446 | /* Named type */ |
| 447 | name = g_quark_from_string(td->type_name); |
| 448 | |
| 449 | type = g_datalist_id_get_data(&fac->named_types, name); |
| 450 | } |
| 451 | |
| 452 | if(type == NULL){ |
| 453 | /* Create the type */ |
| 454 | type = g_new(LttType,1); |
| 455 | type->type_name = name; |
| 456 | type->type_class = td->type; |
| 457 | if(td->fmt) type->fmt = g_strdup(td->fmt); |
| 458 | else type->fmt = NULL; |
| 459 | type->size = td->size; |
| 460 | type->enum_strings = NULL; |
| 461 | type->element_type = NULL; |
| 462 | type->element_number = 0; |
| 463 | |
| 464 | if(td->type_name != NULL) |
| 465 | g_datalist_id_set_data_full(&fac->named_types, name, |
| 466 | type, (GDestroyNotify)freeLttNamedType); |
| 467 | } |
| 468 | return type; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | /***************************************************************************** |
| 473 | *Function name |
| 474 | * ltt_facility_close : close a facility, decrease its usage count, |
| 475 | * if usage count = 0, release the memory |
| 476 | *Input params |
| 477 | * f : facility that will be closed |
| 478 | ****************************************************************************/ |
| 479 | |
| 480 | void ltt_facility_close(LttFacility *f) |
| 481 | { |
| 482 | //release the memory it occupied |
| 483 | freeFacility(f); |
| 484 | } |
| 485 | |
| 486 | /***************************************************************************** |
| 487 | * Functions to release the memory occupied by the facility |
| 488 | ****************************************************************************/ |
| 489 | |
| 490 | void freeFacility(LttFacility * fac) |
| 491 | { |
| 492 | guint i; |
| 493 | LttEventType *et; |
| 494 | |
| 495 | for(i=0; i<fac->events->len; i++) { |
| 496 | et = &g_array_index (fac->events, LttEventType, i); |
| 497 | freeEventtype(et); |
| 498 | } |
| 499 | g_array_free(fac->events, TRUE); |
| 500 | |
| 501 | g_datalist_clear(&fac->named_types); |
| 502 | |
| 503 | } |
| 504 | |
| 505 | void freeEventtype(LttEventType * evType) |
| 506 | { |
| 507 | LttType * root_type; |
| 508 | if(evType->description) |
| 509 | g_free(evType->description); |
| 510 | if(evType->root_field){ |
| 511 | root_type = evType->root_field->field_type; |
| 512 | freeLttField(evType->root_field); |
| 513 | freeLttType(&root_type); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | void freeLttNamedType(LttType * type) |
| 518 | { |
| 519 | freeLttType(&type); |
| 520 | } |
| 521 | |
| 522 | void freeLttType(LttType ** type) |
| 523 | { |
| 524 | unsigned int i; |
| 525 | if(*type == NULL) return; |
| 526 | if((*type)->type_name != 0) return; //this is a named type. |
| 527 | //if((*type)->type_name){ |
| 528 | // return; //this is a named type |
| 529 | //} |
| 530 | if((*type)->fmt) |
| 531 | g_free((*type)->fmt); |
| 532 | if((*type)->enum_strings){ |
| 533 | g_free((*type)->enum_strings); |
| 534 | } |
| 535 | |
| 536 | if((*type)->element_type){ |
| 537 | for(i=0;i<(*type)->element_number;i++) |
| 538 | freeLttType(&((*type)->element_type[i])); |
| 539 | g_free((*type)->element_type); |
| 540 | } |
| 541 | g_free(*type); |
| 542 | *type = NULL; |
| 543 | } |
| 544 | |
| 545 | void freeLttField(LttField * fld) |
| 546 | { |
| 547 | int i; |
| 548 | int size = 0; |
| 549 | |
| 550 | if(fld->field_type){ |
| 551 | if(fld->field_type->type_class == LTT_ARRAY || |
| 552 | fld->field_type->type_class == LTT_SEQUENCE){ |
| 553 | size = 1; |
| 554 | }else if(fld->field_type->type_class == LTT_STRUCT){ |
| 555 | size = fld->field_type->element_number; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | if(fld->child){ |
| 560 | for(i=0; i<size; i++){ |
| 561 | if(fld->child[i])freeLttField(fld->child[i]); |
| 562 | } |
| 563 | g_free(fld->child); |
| 564 | } |
| 565 | g_free(fld); |
| 566 | } |
| 567 | |
| 568 | /***************************************************************************** |
| 569 | *Function name |
| 570 | * ltt_facility_name : obtain the facility's name |
| 571 | *Input params |
| 572 | * f : the facility |
| 573 | *Return value |
| 574 | * GQuark : the facility's name |
| 575 | ****************************************************************************/ |
| 576 | |
| 577 | GQuark ltt_facility_name(LttFacility *f) |
| 578 | { |
| 579 | return f->name; |
| 580 | } |
| 581 | |
| 582 | /***************************************************************************** |
| 583 | *Function name |
| 584 | * ltt_facility_checksum : obtain the facility's checksum |
| 585 | *Input params |
| 586 | * f : the facility |
| 587 | *Return value |
| 588 | * : the checksum of the facility |
| 589 | ****************************************************************************/ |
| 590 | |
| 591 | guint32 ltt_facility_checksum(LttFacility *f) |
| 592 | { |
| 593 | return f->checksum; |
| 594 | } |
| 595 | |
| 596 | /***************************************************************************** |
| 597 | *Function name |
| 598 | * ltt_facility_base_id : obtain the facility base id |
| 599 | *Input params |
| 600 | * f : the facility |
| 601 | *Return value |
| 602 | * : the base id of the facility |
| 603 | ****************************************************************************/ |
| 604 | |
| 605 | guint ltt_facility_id(LttFacility *f) |
| 606 | { |
| 607 | return f->id; |
| 608 | } |
| 609 | |
| 610 | /***************************************************************************** |
| 611 | *Function name |
| 612 | * ltt_facility_eventtype_number: obtain the number of the event types |
| 613 | *Input params |
| 614 | * f : the facility that will be closed |
| 615 | *Return value |
| 616 | * : the number of the event types |
| 617 | ****************************************************************************/ |
| 618 | |
| 619 | guint8 ltt_facility_eventtype_number(LttFacility *f) |
| 620 | { |
| 621 | return (f->events->len); |
| 622 | } |
| 623 | |
| 624 | /***************************************************************************** |
| 625 | *Function name |
| 626 | * ltt_facility_eventtype_get: obtain the event type according to event id |
| 627 | * from 0 to event_number - 1 |
| 628 | *Input params |
| 629 | * f : the facility that will be closed |
| 630 | *Return value |
| 631 | * LttEventType * : the event type required |
| 632 | ****************************************************************************/ |
| 633 | |
| 634 | LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i) |
| 635 | { |
| 636 | if(!f->exists) return NULL; |
| 637 | |
| 638 | g_assert(i < f->events->len); |
| 639 | return &g_array_index(f->events, LttEventType, i); |
| 640 | } |
| 641 | |
| 642 | /***************************************************************************** |
| 643 | *Function name |
| 644 | * ltt_facility_eventtype_get_by_name |
| 645 | * : obtain the event type according to event name |
| 646 | * event name is unique in the facility |
| 647 | *Input params |
| 648 | * f : the facility |
| 649 | * name : the name of the event |
| 650 | *Return value |
| 651 | * LttEventType * : the event type required |
| 652 | ****************************************************************************/ |
| 653 | |
| 654 | LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, GQuark name) |
| 655 | { |
| 656 | LttEventType *et = g_datalist_id_get_data(&f->events_by_name, name); |
| 657 | } |
| 658 | |