X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Fltt%2Ffacility.c;h=55077aa3d1d713b529d8f561791bcfdd68e2827a;hb=d6fef8908a155b21de130fc4dc2b6b050080d153;hp=6d70d5728af3a1d7e0de8553433a80c1ff2f95b8;hpb=cbd41522fece37839f38aaf3372b8a11fac9b267;p=lttv.git diff --git a/ltt/branches/poly/ltt/facility.c b/ltt/branches/poly/ltt/facility.c index 6d70d572..55077aa3 100644 --- a/ltt/branches/poly/ltt/facility.c +++ b/ltt/branches/poly/ltt/facility.c @@ -1,8 +1,28 @@ +/* This file is part of the Linux Trace Toolkit viewer + * Copyright (C) 2003-2004 Xiangxiu Yang + * + * 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. + */ + #include #include #include #include "parser.h" +#include +#include "ltt-private.h" #include /* search for the (named) type in the table, if it does not exist @@ -14,7 +34,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, LttField * fld); /* generate the facility according to the events belongin to it */ -void generateFacility(LttFacility * f, facility * fac, +void generateFacility(LttFacility * f, facility_t * fac, LttChecksum checksum); /* functions to release the memory occupied by a facility */ @@ -38,7 +58,7 @@ void ltt_facility_open(LttTrace * t, char * pathname) char *token; parse_file in; char buffer[BUFFER_SIZE]; - facility * fac; + facility_t * fac; LttFacility * f; LttChecksum checksum; @@ -58,7 +78,7 @@ void ltt_facility_open(LttTrace * t, char * pathname) token = getName(&in); if(strcmp("facility",token) == 0) { - fac = g_new(facility, 1); + fac = g_new(facility_t, 1); fac->name = NULL; fac->description = NULL; sequence_init(&(fac->events)); @@ -68,9 +88,9 @@ void ltt_facility_open(LttTrace * t, char * pathname) parseFacility(&in, fac); //check if any namedType is not defined - checkNamedTypesImplemented(&fac->named_types); + g_assert(checkNamedTypesImplemented(&fac->named_types) == 0); - generateChecksum(fac->name, &checksum, &fac->events); + g_assert(generateChecksum(fac->name, &checksum, &fac->events) == 0); f = g_new(LttFacility,1); f->base_id = 0; @@ -104,7 +124,7 @@ void ltt_facility_open(LttTrace * t, char * pathname) * checksum : checksum of the facility ****************************************************************************/ -void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) +void generateFacility(LttFacility *f, facility_t *fac,LttChecksum checksum) { char * facilityName = fac->name; sequence * events = &fac->events; @@ -128,17 +148,17 @@ void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) 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); + evType->name = g_strdup(((event_t*)(events->array[i]))->name); + evType->description=g_strdup(((event_t*)(events->array[i]))->description); field = g_new(LttField, 1); evType->root_field = field; evType->facility = f; evType->index = i; - if(((event*)(events->array[i]))->type != NULL){ + if(((event_t*)(events->array[i]))->type != NULL){ field->field_pos = 0; - type = lookup_named_type(f,((event*)(events->array[i]))->type); + type = lookup_named_type(f,((event_t*)(events->array[i]))->type); field->field_type = type; field->offset_root = 0; field->fixed_root = 1; @@ -152,7 +172,7 @@ void generateFacility(LttFacility *f, facility *fac,LttChecksum checksum) field->current_element = 0; //construct field tree and type graph - constructTypeAndFields(f,((event*)(events->array[i]))->type,field); + constructTypeAndFields(f,((event_t*)(events->array[i]))->type,field); }else{ evType->root_field = NULL; g_free(field); @@ -222,7 +242,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, fld->child = g_new(LttField*, td->fields.position); for(i=0;ifields.position;i++){ - tmpTd = ((field*)(td->fields.array[i]))->type; + tmpTd = ((type_fields*)(td->fields.array[i]))->type; if(flag) fld->field_type->element_type[i] = lookup_named_type(fac, tmpTd); @@ -233,7 +253,7 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, if(flag){ fld->child[i]->field_type->element_name - = g_strdup(((field*)(td->fields.array[i]))->name); + = g_strdup(((type_fields*)(td->fields.array[i]))->name); } fld->child[i]->offset_root = -1; @@ -266,17 +286,18 @@ void constructTypeAndFields(LttFacility * fac,type_descriptor * td, LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) { LttType * lttType = NULL; - int i; + unsigned int i=0; char * name; + if(td->type_name){ for(i=0;inamed_types_number; i++){ if(fac->named_types[i] == NULL) break; name = fac->named_types[i]->type_name; if(strcmp(name, td->type_name)==0){ - lttType = fac->named_types[i]; + lttType = fac->named_types[i]; // if(lttType->element_name) g_free(lttType->element_name); // lttType->element_name = NULL; - break; + break; } } } @@ -293,7 +314,7 @@ LttType * lookup_named_type(LttFacility *fac, type_descriptor * td) lttType->element_name = NULL; if(td->type_name){ lttType->type_name = g_strdup(td->type_name); - fac->named_types[i] = lttType; + fac->named_types[i] = lttType; /* i is initialized, checked. */ } else{ lttType->type_name = NULL; @@ -328,7 +349,7 @@ int ltt_facility_close(LttFacility *f) void freeFacility(LttFacility * fac) { - int i; + unsigned int i; g_free(fac->name); //free facility name //free event types @@ -365,7 +386,6 @@ void freeEventtype(LttEventType * evType) void freeLttNamedType(LttType * type) { - int i; g_free(type->type_name); type->type_name = NULL; freeLttType(&type); @@ -373,7 +393,7 @@ void freeLttNamedType(LttType * type) void freeLttType(LttType ** type) { - int i; + unsigned int i; if(*type == NULL) return; if((*type)->type_name){ return; //this is a named type @@ -473,7 +493,7 @@ unsigned ltt_facility_base_id(LttFacility *f) unsigned ltt_facility_eventtype_number(LttFacility *f) { - return (unsigned)(f->event_number); + return (f->event_number); } /***************************************************************************** @@ -497,7 +517,7 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *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 * LttEventType * : the event type required @@ -505,14 +525,16 @@ LttEventType *ltt_facility_eventtype_get(LttFacility *f, unsigned i) LttEventType *ltt_facility_eventtype_get_by_name(LttFacility *f, char *name) { - int i; - LttEventType * ev; + unsigned int i; + LttEventType * ev = NULL; + for(i=0;ievent_number;i++){ - ev = f->events[i]; - if(strcmp(ev->name, name) == 0)break; + LttEventType *iter_ev = f->events[i]; + if(strcmp(iter_ev->name, name) == 0) { + ev = iter_ev; + break; + } } - - if(i==f->event_number) return NULL; - else return ev; + return ev; }