X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ffacility.c;h=1d9ed5f66fb807b35a848e986017f6889ab02b56;hb=eed2ef37f908daf7b3f884b5d8f91dad03f10526;hp=ad489cae211988fd0b4ce4a7e32502cbb17336c4;hpb=6cd62ccfe338056a2a7571addbb63e0e16354e86;p=lttv.git diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index ad489cae..1d9ed5f6 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -1,109 +1,150 @@ +/* This file is part of the Linux Trace Toolkit viewer + * Copyright (C) 2003-2004 Xiangxiu Yang + * 2005 Mathieu Desnoyers + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License Version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include +#include +#include +#include +#include + + -#include "LTTTypes.h" #include "parser.h" +#include +#include "ltt-private.h" #include +#ifndef g_open +#define g_open open +#endif + +#define g_close close + /* search for the (named) type in the table, if it does not exist create a new one */ -ltt_type * lookup_named_type(ltt_facility *fac, type_descriptor * td); +LttType * lookup_named_type(LttFacility *fac, type_descriptor * td); /* construct directed acyclic graph for types, and tree for fields */ -void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, - ltt_field * fld); +void construct_types_and_fields(LttFacility * fac,type_descriptor * td, + LttField * fld); /* generate the facility according to the events belongin to it */ -void generateFacility(ltt_facility * facility, char * pathname, - ltt_checksum checksum, sequence * events); +void generateFacility(LttFacility * f, facility_t * fac, + guint32 checksum); /* functions to release the memory occupied by a facility */ -void freeFacility(ltt_facility * facility); -void freeEventtype(ltt_eventtype * evType); -void freeAllNamedTypes(table * named_types); -void freeAllUnamedTypes(sequence * unnamed_types); -void freeAllFields(sequence * all_fields); -void freeLttType(ltt_type * type); -void freeLttField(ltt_field * fld); +void freeFacility(LttFacility * facility); +void freeEventtype(LttEventType * evType); +void freeLttType(LttType ** type); +void freeLttField(LttField * fld); +void freeLttNamedType(LttType * type); /***************************************************************************** *Function name - * ltt_facility_open : open a facility + * ltt_facility_open : open facilities *Input params + * t : the trace containing the facilities * pathname : the path name of the facility - * c : checksum of the facility registered in kernal - *Return value - * ltt_facility* : return a ltt_facility + * + *returns 0 on success, 1 on error. ****************************************************************************/ -ltt_facility * ltt_facility_open(char * pathname, ltt_checksum c) +int ltt_facility_open(LttFacility *f, LttTrace * t, gchar * pathname) { - char *token; + gchar *token; parse_file in; - char buffer[BUFFER_SIZE]; - ltt_checksum checksum; - event *ev; - sequence events; - table namedTypes; - sequence unnamedTypes; - ltt_facility * aFacility = NULL; - - sequence_init(&events); - table_init(&namedTypes); - sequence_init(&unnamedTypes); - - in.buffer = buffer; + gsize length; + facility_t * fac; + guint32 checksum; + GError * error = NULL; + gchar buffer[BUFFER_SIZE]; + + in.buffer = &(buffer[0]); in.lineno = 0; in.error = error_callback; - in.name = appendString(pathname,".event"); + in.name = pathname; + + in.fd = g_open(in.name, O_RDONLY, 0); + if(in.fd < 0 ) { + g_warning("cannot open facility description file %s", + in.name); + return 1; + } + + in.channel = g_io_channel_unix_new(in.fd); + in.pos = 0; - in.fp = fopen(in.name, "r"); - if(!in.fp )g_error("cannot open input file: %s\n", in.name); - while(1){ token = getToken(&in); if(in.type == ENDFILE) break; - if(strcmp("event",token) == 0) { - ev = g_new(event,1); - sequence_push(&events,ev); - parseEvent(&in,ev, &unnamedTypes, &namedTypes); + if(g_ascii_strcasecmp(token, "<")) in.error(&in,"not a facility file"); + token = getName(&in); + + if(g_ascii_strcasecmp("facility",token) == 0) { + fac = g_new(facility_t, 1); + fac->name = NULL; + fac->description = NULL; + sequence_init(&(fac->events)); + table_init(&(fac->named_types)); + sequence_init(&(fac->unnamed_types)); + + parseFacility(&in, fac); + + //check if any namedType is not defined + g_assert(checkNamedTypesImplemented(&fac->named_types) == 0); + + g_assert(generateChecksum(fac->name, &checksum, &fac->events) == 0); + + generateFacility(f, fac, checksum); + + g_free(fac->name); + g_free(fac->description); + freeEvents(&fac->events); + sequence_dispose(&fac->events); + freeNamedType(&fac->named_types); + table_dispose(&fac->named_types); + freeTypes(&fac->unnamed_types); + sequence_dispose(&fac->unnamed_types); + g_free(fac); } - else if(strcmp("type",token) == 0) { - parseTypeDefinition(&in, &unnamedTypes, &namedTypes); + else { + g_warning("facility token was expected in file %s", in.name); + goto parse_error; } - else g_error("event or type token expected\n"); } - - fclose(in.fp); - - checkNamedTypesImplemented(&namedTypes); - - generateChecksum(pathname, &checksum, &events); - //yxx disable during the test - aFacility = g_new(ltt_facility,1); - generateFacility(aFacility, pathname, checksum, &events); -/* - if(checksum == c){ - aFacility = g_new(ltt_facility,1); - generateFacility(aFacility, pathname, checksum, &events); - }else{ - g_error("local facility is different from the one registered in the kernel"); + parse_error: + g_io_channel_shutdown(in.channel, FALSE, &error); /* No flush */ + if(error != NULL) { + g_warning("Can not close file: \n%s\n", error->message); + g_error_free(error); } -*/ - free(in.name); - freeEvents(&events); - sequence_dispose(&events); - freeNamedType(&namedTypes); - table_dispose(&namedTypes); - freeTypes(&unnamedTypes); - sequence_dispose(&unnamedTypes); - - return aFacility; + g_close(in.fd); } @@ -111,74 +152,90 @@ ltt_facility * ltt_facility_open(char * pathname, ltt_checksum c) *Function name * generateFacility : generate facility, internal function *Input params - * facility : facilty structure - * facName : facility name + * facility : LttFacilty structure + * fac : facility structure * checksum : checksum of the facility - * events : sequence of events belonging to the facility ****************************************************************************/ -void generateFacility(ltt_facility * facility, char * pathname, - ltt_checksum checksum, sequence * events) +void generateFacility(LttFacility *f, facility_t *fac, guint32 checksum) { - char * facilityName; + char * facilityName = fac->name; + sequence * events = &fac->events; int i; - ltt_eventtype * evType; - ltt_field * field; - ltt_type * type; - - //get the facility name (strip any leading directory) - facilityName = strrchr(pathname,'/'); - if(facilityName) facilityName++; - else facilityName = pathname; + //LttEventType * evType; + LttEventType * event_type; + LttField * field; + LttType * type; - facility->name = g_strdup(facilityName); - facility->event_number = events->position; - facility->checksum = checksum; - facility->usage_count = 0; + g_assert(f->name == g_quark_from_string(facilityName)); + g_assert(f->checksum == checksum); + + //f->event_number = events->position; //initialize inner structures - facility->events = g_new(ltt_eventtype*,facility->event_number); - sequence_init(&(facility->all_fields)); - sequence_init(&(facility->all_unnamed_types)); - table_init(&(facility->all_named_types)); + f->events = g_array_sized_new (FALSE, TRUE, sizeof(LttEventType), + events->position); + //f->events = g_new(LttEventType*,f->event_number); + f->events = g_array_set_size(f->events, events->position); + + g_datalist_init(&f->events_by_name); + g_datalist_init(&f->named_types); + + //f->named_types_number = fac->named_types.keys.position; + //f->named_types = g_array_sized_new (FALSE, TRUE, sizeof(LttType), + // fac->named_types.keys.position); + //f->named_types = g_new(LttType*, fac->named_types.keys.position); + //f->named_types = g_array_set_size(f->named_types, + // fac->named_types.keys.position); //for each event, construct field tree and type graph for(i=0;iposition;i++){ - evType = g_new(ltt_eventtype,1); - facility->events[i] = evType; + event_type = &g_array_index(f->events, LttEventType, i); + //evType = g_new(LttEventType,1); + //f->events[i] = evType; - evType->name = g_strdup(((event*)(events->array[i]))->name); - evType->description=g_strdup(((event*)(events->array[i]))->description); + event_type->name = + g_quark_from_string(((event_t*)(events->array[i]))->name); - field = g_new(ltt_field, 1); - sequence_push(&(facility->all_fields), field); - evType->root_field = field; - evType->facility = facility; - evType->index = i; - - field->field_pos = 0; - type = lookup_named_type(facility,((event*)(events->array[i]))->type); - field->field_type = type; - field->offset_root = 0; - field->fixed_root = 1; - field->offset_parent = 0; - field->fixed_parent = 1; - // field->base_address = NULL; - field->field_size = 0; - field->field_fixed = -1; - field->parent = NULL; - field->child = NULL; - field->current_element = 0; - - //construct field tree and type graph - constructTypeAndFields(facility,((event*)(events->array[i]))->type,field); + g_datalist_id_set_data(&f->events_by_name, event_type->name, + event_type); + + event_type->description = + g_strdup(((event_t*)(events->array[i]))->description); + + field = g_new(LttField, 1); + event_type->root_field = field; + event_type->facility = f; + event_type->index = i; + + if(((event_t*)(events->array[i]))->type != NULL){ + // field->field_pos = 0; + type = lookup_named_type(f,((event_t*)(events->array[i]))->type); + field->field_type = type; + field->offset_root = 0; + field->fixed_root = FIELD_UNKNOWN; + field->offset_parent = 0; + field->fixed_parent = FIELD_UNKNOWN; + // field->base_address = NULL; + field->field_size = 0; + field->fixed_size = FIELD_UNKNOWN; + field->parent = NULL; + field->child = NULL; + field->current_element = 0; + + //construct field tree and type graph + construct_types_and_fields(f,((event_t*)(events->array[i]))->type,field); + }else{ + event_type->root_field = NULL; + g_free(field); + } } } /***************************************************************************** *Function name - * constructTypeAndFields : construct field tree and type graph, + * construct_types_and_fields : construct field tree and type graph, * internal recursion function *Input params * fac : facility struct @@ -186,10 +243,90 @@ void generateFacility(ltt_facility * facility, char * pathname, * root_field : root field of the event ****************************************************************************/ -void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, - ltt_field * fld) + +void construct_types_and_fields(LttFacility * fac, type_descriptor * td, + LttField * fld) { - int i; + int i, flag; + type_descriptor * tmpTd; + + switch(td->type) { + case LTT_ENUM: + fld->field_type->element_number = td->labels.position; + fld->field_type->enum_strings = g_new(GQuark,td->labels.position); + for(i=0;ilabels.position;i++){ + fld->field_type->enum_strings[i] + = g_quark_from_string(((char*)(td->labels.array[i]))); + } + break; + case LTT_ARRAY: + fld->field_type->element_number = (unsigned)td->size; + case LTT_SEQUENCE: + fld->field_type->element_type = g_new(LttType*,1); + tmpTd = td->nested_type; + fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd); + fld->child = g_new(LttField*, 1); + fld->child[0] = g_new(LttField, 1); + + fld->child[0]->field_type = fld->field_type->element_type[0]; + fld->child[0]->offset_root = 0; + fld->child[0]->fixed_root = FIELD_UNKNOWN; + fld->child[0]->offset_parent = 0; + fld->child[0]->fixed_parent = FIELD_UNKNOWN; + fld->child[0]->field_size = 0; + fld->child[0]->fixed_size = FIELD_UNKNOWN; + fld->child[0]->parent = fld; + fld->child[0]->child = NULL; + fld->child[0]->current_element = 0; + construct_types_and_fields(fac, tmpTd, fld->child[0]); + break; + case LTT_STRUCT: + case LTT_UNION: + fld->field_type->element_number = td->fields.position; + + g_assert(fld->field_type->element_type == NULL); + fld->field_type->element_type = g_new(LttType*, td->fields.position); + + fld->child = g_new(LttField*, td->fields.position); + for(i=0;ifields.position;i++){ + tmpTd = ((type_fields*)(td->fields.array[i]))->type; + + fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); + fld->child[i] = g_new(LttField,1); + + // fld->child[i]->field_pos = i; + fld->child[i]->field_type = fld->field_type->element_type[i]; + + fld->child[i]->field_type->element_name + = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name); + + fld->child[i]->offset_root = 0; + fld->child[i]->fixed_root = FIELD_UNKNOWN; + fld->child[i]->offset_parent = 0; + fld->child[i]->fixed_parent = FIELD_UNKNOWN; + fld->child[i]->field_size = 0; + fld->child[i]->fixed_size = FIELD_UNKNOWN; + fld->child[i]->parent = fld; + fld->child[i]->child = NULL; + fld->child[i]->current_element = 0; + construct_types_and_fields(fac, tmpTd, fld->child[i]); + } + + break; + default: + g_error("construct_types_and_fields : unknown type"); + } + + +} + + + +#if 0 +void construct_types_and_fields(LttFacility * fac, type_descriptor * td, + LttField * fld) +{ + int i, flag; type_descriptor * tmpTd; // if(td->type == LTT_STRING || td->type == LTT_SEQUENCE) @@ -198,22 +335,21 @@ void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, if(td->type == LTT_ENUM){ fld->field_type->element_number = td->labels.position; - fld->field_type->enum_strings = g_new(char*,td->labels.position); + fld->field_type->enum_strings = g_new(GQuark,td->labels.position); for(i=0;ilabels.position;i++){ fld->field_type->enum_strings[i] - = g_strdup(((char*)(td->labels.array[i]))); + = g_quark_from_string(((char*)(td->labels.array[i]))); } }else if(td->type == LTT_ARRAY || td->type == LTT_SEQUENCE){ if(td->type == LTT_ARRAY) fld->field_type->element_number = (unsigned)td->size; - fld->field_type->element_type = g_new(ltt_type*,1); + fld->field_type->element_type = g_new(LttType*,1); tmpTd = td->nested_type; fld->field_type->element_type[0] = lookup_named_type(fac, tmpTd); - fld->child = g_new(ltt_field*, 1); - fld->child[0] = g_new(ltt_field, 1); - sequence_push(&(fac->all_fields), fld->child[0]); + fld->child = g_new(LttField*, 1); + fld->child[0] = g_new(LttField, 1); - fld->child[0]->field_pos = 0; +// fld->child[0]->field_pos = 0; fld->child[0]->field_type = fld->field_type->element_type[0]; fld->child[0]->offset_root = fld->offset_root; fld->child[0]->fixed_root = fld->fixed_root; @@ -225,21 +361,33 @@ void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, fld->child[0]->parent = fld; fld->child[0]->child = NULL; fld->child[0]->current_element = 0; - constructTypeAndFields(fac, tmpTd, fld->child[0]); + construct_types_and_fields(fac, tmpTd, fld->child[0]); }else if(td->type == LTT_STRUCT){ fld->field_type->element_number = td->fields.position; - fld->field_type->element_type = g_new(ltt_type*, td->fields.position); - fld->child = g_new(ltt_field*, td->fields.position); + + if(fld->field_type->element_type == NULL){ + fld->field_type->element_type = g_new(LttType*, td->fields.position); + flag = 1; + }else{ + flag = 0; + } + + fld->child = g_new(LttField*, td->fields.position); for(i=0;ifields.position;i++){ - tmpTd = ((field*)(td->fields.array[i]))->type; - fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); - fld->child[i] = g_new(ltt_field,1); - sequence_push(&(fac->all_fields), fld->child[i]); + tmpTd = ((type_fields*)(td->fields.array[i]))->type; + + if(flag) + fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); + fld->child[i] = g_new(LttField,1); fld->child[i]->field_pos = i; fld->child[i]->field_type = fld->field_type->element_type[i]; - fld->child[i]->field_type->element_name - = g_strdup(((field*)(td->fields.array[i]))->name); + + if(flag){ + fld->child[i]->field_type->element_name + = g_quark_from_string(((type_fields*)(td->fields.array[i]))->name); + } + fld->child[i]->offset_root = -1; fld->child[i]->fixed_root = -1; fld->child[i]->offset_parent = -1; @@ -250,11 +398,11 @@ void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, fld->child[i]->parent = fld; fld->child[i]->child = NULL; fld->child[i]->current_element = 0; - constructTypeAndFields(fac, tmpTd, fld->child[i]); + construct_types_and_fields(fac, tmpTd, fld->child[i]); } } } - +#endif //0 /***************************************************************************** *Function name @@ -264,45 +412,30 @@ void constructTypeAndFields(ltt_facility * fac,type_descriptor * td, * fac : facility struct * td : type descriptor *Return value - * : either find the named type, or create a new ltt_type + * : either find the named type, or create a new LttType ****************************************************************************/ -ltt_type * lookup_named_type(ltt_facility *fac, type_descriptor * td) +LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) { - ltt_type * lttType = NULL; - int i; - char * name; - if(td->type_name){ - for(i=0;iall_named_types.keys.position;i++){ - name = (char *)(fac->all_named_types.keys.array[i]); - if(strcmp(name, td->type_name)==0){ - lttType = (ltt_type*)(fac->all_named_types.values.array[i]); - break; - } - } - } + GQuark name = g_quark_from_string(td->type_name); - if(!lttType){ - lttType = g_new(ltt_type,1); - lttType->type_class = td->type; - if(td->fmt) lttType->fmt = g_strdup(td->fmt); - else lttType->fmt = NULL; - lttType->size = td->size; - lttType->enum_strings = NULL; - lttType->element_type = NULL; - lttType->element_number = 0; - if(td->type_name){ - name = g_strdup(td->type_name); - table_insert(&(fac->all_named_types),name,lttType); - lttType->element_name = name; - } - else{ - sequence_push(&(fac->all_unnamed_types), lttType); - lttType->element_name = NULL; - } + LttType *type = g_datalist_id_get_data(&fac->named_types, name); + + if(type == NULL){ + type = g_new(LttType,1); + type->type_name = name; + g_datalist_id_set_data_full(&fac->named_types, name, + type, (GDestroyNotify)freeLttNamedType); + type->type_class = td->type; + if(td->fmt) type->fmt = g_strdup(td->fmt); + else type->fmt = NULL; + type->size = td->size; + type->enum_strings = NULL; + type->element_type = NULL; + type->element_number = 0; } - return lttType; + return type; } @@ -312,104 +445,92 @@ ltt_type * lookup_named_type(ltt_facility *fac, type_descriptor * td) * if usage count = 0, release the memory *Input params * f : facility that will be closed - *Return value - * int : usage count ?? status ****************************************************************************/ -int ltt_facility_close(ltt_facility *f) +void ltt_facility_close(LttFacility *f) { - // f->usage_count--; - if(f->usage_count > 0) return f->usage_count; - //release the memory it occupied freeFacility(f); - - return 0; } /***************************************************************************** * Functions to release the memory occupied by the facility ****************************************************************************/ -void freeFacility(ltt_facility * fac) +void freeFacility(LttFacility * fac) { - int i; - g_free(fac->name); //free facility name + guint i; + LttEventType *et; - //free event types - for(i=0;ievent_number;i++){ - freeEventtype(fac->events[i]); + for(i=0; ievents->len; i++) { + et = &g_array_index (fac->events, LttEventType, i); + freeEventtype(et); } + g_array_free(fac->events, TRUE); - //free all named types - freeAllNamedTypes(&(fac->all_named_types)); + g_datalist_clear(&fac->named_types); - //free all unnamed types - freeAllUnamedTypes(&(fac->all_unnamed_types)); - - //free all fields - freeAllFields(&(fac->all_fields)); - - //free the facility itself - g_free(fac); } -void freeEventtype(ltt_eventtype * evType) +void freeEventtype(LttEventType * evType) { - g_free(evType->name); + LttType * root_type; if(evType->description) g_free(evType->description); - g_free(evType); + if(evType->root_field){ + root_type = evType->root_field->field_type; + freeLttField(evType->root_field); + freeLttType(&root_type); + } } -void freeAllNamedTypes(table * named_types) +void freeLttNamedType(LttType * type) { - int i; - for(i=0;ikeys.position;i++){ - //free the name of the type - g_free((char*)(named_types->keys.array[i])); - - //free type - freeLttType((ltt_type*)(named_types->values.array[i])); - } - table_dispose(named_types); + freeLttType(&type); } -void freeAllUnamedTypes(sequence * unnamed_types) +void freeLttType(LttType ** type) { - int i; - for(i=0;iposition;i++){ - freeLttType((ltt_type*)(unnamed_types->array[i])); + unsigned int i; + if(*type == NULL) return; + //if((*type)->type_name){ + // return; //this is a named type + //} + if((*type)->fmt) + g_free((*type)->fmt); + if((*type)->enum_strings){ + g_free((*type)->enum_strings); } - sequence_dispose(unnamed_types); -} -void freeAllFields(sequence * all_fields) -{ - int i; - for(i=0;iposition;i++){ - freeLttField((ltt_field*)(all_fields->array[i])); + if((*type)->element_type){ + for(i=0;i<(*type)->element_number;i++) + freeLttType(&((*type)->element_type[i])); + g_free((*type)->element_type); } - sequence_dispose(all_fields); + g_free(*type); + *type = NULL; } -void freeLttType(ltt_type * type) -{ - if(type->element_name) - g_free(type->element_name); - if(type->fmt) - g_free(type->fmt); - if(type->enum_strings) - g_free(type->enum_strings); - if(type->element_type) - g_free(type->element_type); - g_free(type); -} +void freeLttField(LttField * fld) +{ + int i; + int size = 0; + + if(fld->field_type){ + if(fld->field_type->type_class == LTT_ARRAY || + fld->field_type->type_class == LTT_SEQUENCE){ + size = 1; + }else if(fld->field_type->type_class == LTT_STRUCT){ + size = fld->field_type->element_number; + } + } -void freeLttField(ltt_field * fld) -{ - if(fld->child) + if(fld->child){ + for(i=0; ichild[i])freeLttField(fld->child[i]); + } g_free(fld->child); + } g_free(fld); } @@ -417,12 +538,12 @@ void freeLttField(ltt_field * fld) *Function name * ltt_facility_name : obtain the facility's name *Input params - * f : the facility that will be closed + * f : the facility *Return value - * char * : the facility's name + * GQuark : the facility's name ****************************************************************************/ -char *ltt_facility_name(ltt_facility *f) +GQuark ltt_facility_name(LttFacility *f) { return f->name; } @@ -431,28 +552,42 @@ char *ltt_facility_name(ltt_facility *f) *Function name * ltt_facility_checksum : obtain the facility's checksum *Input params - * f : the facility that will be closed + * f : the facility *Return value - * ltt_checksum : the checksum of the facility + * : the checksum of the facility ****************************************************************************/ -ltt_checksum ltt_facility_checksum(ltt_facility *f) +guint32 ltt_facility_checksum(LttFacility *f) { return f->checksum; } +/***************************************************************************** + *Function name + * ltt_facility_base_id : obtain the facility base id + *Input params + * f : the facility + *Return value + * : the base id of the facility + ****************************************************************************/ + +guint ltt_facility_id(LttFacility *f) +{ + return f->id; +} + /***************************************************************************** *Function name * ltt_facility_eventtype_number: obtain the number of the event types *Input params * f : the facility that will be closed *Return value - * unsigned : the number of the event types + * : the number of the event types ****************************************************************************/ -unsigned ltt_facility_eventtype_number(ltt_facility *f) +guint8 ltt_facility_eventtype_number(LttFacility *f) { - return (unsigned)(f->event_number); + return (f->events->len); } /***************************************************************************** @@ -462,12 +597,13 @@ unsigned ltt_facility_eventtype_number(ltt_facility *f) *Input params * f : the facility that will be closed *Return value - * ltt_eventtype * : the event type required + * LttEventType * : the event type required ****************************************************************************/ -ltt_eventtype *ltt_facility_eventtype_get(ltt_facility *f, unsigned i) +LttEventType *ltt_facility_eventtype_get(LttFacility *f, guint8 i) { - return f->events[i]; + g_assert(i < f->events->len); + return &g_array_index(f->events, LttEventType, i); } /***************************************************************************** @@ -476,22 +612,14 @@ ltt_eventtype *ltt_facility_eventtype_get(ltt_facility *f, unsigned i) * : obtain the event type according to event name * event name is unique in the facility *Input params - * f : the facility that will be closed + * f : the facility * name : the name of the event *Return value - * ltt_eventtype * : the event type required + * LttEventType * : the event type required ****************************************************************************/ -ltt_eventtype *ltt_facility_eventtype_get_by_name(ltt_facility *f, char *name) +LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, GQuark name) { - int i; - ltt_eventtype * ev; - for(i=0;ievent_number;i++){ - ev = f->events[i]; - if(strcmp(ev->name, name) == 0)break; - } - - if(i==f->event_number) return NULL; - else return ev; + LttEventType *et = g_datalist_get_data(f->events_by_name, name); }