X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=ltt%2Fbranches%2Fpoly%2Flttv%2Flttv%2Fattribute.c;h=a0d30704fd804a785575502233da8de28e6c92f7;hb=dbd243b1b5f764129ae8bcf95432df750bec4a8b;hp=a3f8ab9aecbdde8cd477428724cd971490d7719f;hpb=d8f124de0295aea546b6debf5945bfeea2bbeb2a;p=lttv.git diff --git a/ltt/branches/poly/lttv/lttv/attribute.c b/ltt/branches/poly/lttv/lttv/attribute.c index a3f8ab9a..a0d30704 100644 --- a/ltt/branches/poly/lttv/lttv/attribute.c +++ b/ltt/branches/poly/lttv/lttv/attribute.c @@ -16,6 +16,7 @@ * MA 02111-1307, USA. */ +#include #include #include @@ -55,6 +56,7 @@ LttvAttributeValue address_of_value(LttvAttributeType t, AttributeValue *v) case LTTV_POINTER: va.v_pointer = &v->dv_pointer; break; case LTTV_STRING: va.v_string = &v->dv_string; break; case LTTV_GOBJECT: va.v_gobject = &v->dv_gobject; break; + case LTTV_NONE: break; } return va; } @@ -75,6 +77,7 @@ AttributeValue init_value(LttvAttributeType t) case LTTV_POINTER: v.dv_pointer = NULL; break; case LTTV_STRING: v.dv_string = NULL; break; case LTTV_GOBJECT: v.dv_gobject = NULL; break; + case LTTV_NONE: break; } return v; } @@ -161,6 +164,10 @@ lttv_attribute_remove(LttvAttribute *self, unsigned i) a = &g_array_index(self->attributes, Attribute, i); + /* If the element is a gobject, unreference it. */ + if(a->type == LTTV_GOBJECT && a->value.dv_gobject != NULL) + g_object_unref(a->value.dv_gobject); + /* Remove the array element and its entry in the name index */ g_hash_table_remove(self->names, GUINT_TO_POINTER(a->name)); @@ -199,7 +206,7 @@ lttv_attribute_find_subdir(LttvAttribute *self, LttvAttributeName name) Attribute a; LttvAttribute *new; - + i = (unsigned)g_hash_table_lookup(self->names, GUINT_TO_POINTER(name)); if(i != 0) { a = g_array_index(self->attributes, Attribute, i - 1); @@ -234,7 +241,7 @@ lttv_attribute_find(LttvAttribute *self, LttvAttributeName name, } -void lttv_attribute_recursive_free(LttvAttribute *self) +/*void lttv_attribute_recursive_free(LttvAttribute *self) { int i, nb; @@ -249,7 +256,7 @@ void lttv_attribute_recursive_free(LttvAttribute *self) } } g_object_unref(self); -} +}*/ void lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src) @@ -272,7 +279,7 @@ void lttv_attribute_recursive_add(LttvAttribute *dest, LttvAttribute *src) else { g_assert(lttv_attribute_find(dest, a->name, a->type, &value)); switch(a->type) { - case LTTV_INT: + case LTTV_INT: *value.v_int += a->value.dv_int; break; case LTTV_UINT: @@ -329,7 +336,7 @@ lttv_attribute_write_xml(LttvAttribute *self, FILE *fp, int pos, int indent) for(i = 0 ; i < nb ; i++) { a = &g_array_index(self->attributes, Attribute, i); print_indent(fp, pos); - fprintf(fp, "name); + fprintf(fp, "name)); if(a->type == LTTV_GOBJECT && LTTV_IS_ATTRIBUTE(a->value.dv_gobject)) { fprintf(fp, "TYPE=ATTRS>"); lttv_attribute_write_xml((LttvAttribute *)(a->value.dv_gobject), fp, @@ -356,7 +363,7 @@ lttv_attribute_write_xml(LttvAttribute *self, FILE *fp, int pos, int indent) fprintf(fp, "TYPE=DOUBLE VALUE=%f/>\n", a->value.dv_double); break; case LTTV_TIME: - fprintf(fp, "TYPE=TIME SEC=%u NSEC=%u/>\n", a->value.dv_time.tv_sec, + fprintf(fp, "TYPE=TIME SEC=%lu NSEC=%lu/>\n", a->value.dv_time.tv_sec, a->value.dv_time.tv_nsec); break; case LTTV_POINTER: @@ -382,9 +389,7 @@ lttv_attribute_write_xml(LttvAttribute *self, FILE *fp, int pos, int indent) void lttv_attribute_read_xml(LttvAttribute *self, FILE *fp) { - int i, nb, res; - - Attribute *a; + int res; char buffer[256], type[10]; @@ -433,12 +438,12 @@ lttv_attribute_read_xml(LttvAttribute *self, FILE *fp) } else if(strcmp(type, "DOUBLE") == 0) { value = lttv_attribute_add(self, name, LTTV_DOUBLE); - res = fscanf(fp, " VALUE=%f/>", value.v_double); + res = fscanf(fp, " VALUE=%lf/>", value.v_double); g_assert(res == 1); } else if(strcmp(type, "TIME") == 0) { value = lttv_attribute_add(self, name, LTTV_TIME); - res = fscanf(fp, " SEC=%u NSEC=%u/>", &(value.v_time->tv_sec), + res = fscanf(fp, " SEC=%lu NSEC=%lu/>", &(value.v_time->tv_sec), &(value.v_time->tv_nsec)); g_assert(res == 2); } @@ -467,12 +472,21 @@ lttv_attribute_read_xml(LttvAttribute *self, FILE *fp) fscanf(fp,""); } +static LttvAttribute * +new_attribute (LttvAttribute *self) +{ + return g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); +} + static void attribute_interface_init (gpointer g_iface, gpointer iface_data) { LttvIAttributeClass *klass = (LttvIAttributeClass *)g_iface; + klass->new_attribute = (LttvIAttribute* (*) (LttvIAttribute *self)) + new_attribute; + klass->get_number = (unsigned int (*) (LttvIAttribute *self)) lttv_attribute_get_number; @@ -497,6 +511,7 @@ attribute_interface_init (gpointer g_iface, gpointer iface_data) klass->find_subdir = (LttvIAttribute* (*) (LttvIAttribute *self, LttvAttributeName name)) lttv_attribute_find_subdir; + } @@ -512,11 +527,15 @@ attribute_instance_init (GTypeInstance *instance, gpointer g_class) static void attribute_finalize (LttvAttribute *self) { - g_hash_table_destroy(self->names); + guint i; g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "attribute_finalize()"); + + for(i=0;iattributes->len;i++) { + lttv_attribute_remove(self, i); + } + + g_hash_table_destroy(self->names); g_array_free(self->attributes, TRUE); - G_OBJECT_CLASS(g_type_class_peek_parent( - g_type_class_peek(LTTV_ATTRIBUTE_TYPE)))->finalize(G_OBJECT(self)); } @@ -524,7 +543,7 @@ static void attribute_class_init (LttvAttributeClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - + gobject_class->finalize = (void (*)(GObject *self))attribute_finalize; } @@ -542,7 +561,8 @@ lttv_attribute_get_type (void) NULL, /* class_data */ sizeof (LttvAttribute), 0, /* n_preallocs */ - (GInstanceInitFunc) attribute_instance_init /* instance_init */ + (GInstanceInitFunc) attribute_instance_init, /* instance_init */ + NULL /* value handling */ }; static const GInterfaceInfo iattribute_info = {