X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=types%2Fstring.c;h=bff569db93bb11118b0904d48fcc5f1454623863;hp=3b3cb07416cce808e4f5c299d92b5c4220b1fcb3;hb=98b6832656447ab0f8024f9086aa67625e391ac7;hpb=e19c3d69b39d2fa422ab54b5ec7192799f536680 diff --git a/types/string.c b/types/string.c index 3b3cb074..bff569db 100644 --- a/types/string.c +++ b/types/string.c @@ -3,7 +3,9 @@ * * BabelTrace - String Type Converter * - * Copyright 2010, 2011 - Mathieu Desnoyers + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation + * + * Author: Mathieu Desnoyers * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,85 +23,89 @@ #include static -struct declaration *_string_declaration_new(struct type *type, - struct declaration_scope *parent_scope); +struct definition *_string_definition_new(struct declaration *declaration, + struct definition_scope *parent_scope, + GQuark field_name, int index, + const char *root_name); static -void _string_declaration_free(struct declaration *declaration); - -void string_copy(struct stream_pos *dest, const struct format *fdest, - struct stream_pos *src, const struct format *fsrc, - struct declaration *declaration) -{ - struct declaration_string *string = - container_of(declaration, struct declaration_string, p); - struct type_string *string_type = string->type; - - if (fsrc->string_copy == fdest->string_copy) { - fsrc->string_copy(dest, src, string_type); - } else { - char *tmp = NULL; - - fsrc->string_read(&tmp, src, string_type); - fdest->string_write(dest, tmp, string_type); - fsrc->string_free_temp(tmp); - } -} +void _string_definition_free(struct definition *definition); static -void _string_type_free(struct type *type) +void _string_declaration_free(struct declaration *declaration) { - struct type_string *string_type = - container_of(type, struct type_string, p); - g_free(string_type); + struct declaration_string *string_declaration = + container_of(declaration, struct declaration_string, p); + g_free(string_declaration); } -struct type_string *string_type_new(const char *name) +struct declaration_string * + string_declaration_new(enum ctf_string_encoding encoding) { - struct type_string *string_type; - int ret; + struct declaration_string *string_declaration; - string_type = g_new(struct type_string, 1); - string_type->p.name = g_quark_from_string(name); - string_type->p.alignment = CHAR_BIT; - string_type->p.copy = string_copy; - string_type->p.type_free = _string_type_free; - string_type->p.declaration_new = _string_declaration_new; - string_type->p.declaration_free = _strin_declaration_free; - string_type->p.ref = 1; - if (string_type->p.name) { - ret = register_type(&string_type->p); - if (ret) { - g_free(string_type); - return NULL; - } - } - return string_type; + string_declaration = g_new(struct declaration_string, 1); + string_declaration->p.id = CTF_TYPE_STRING; + string_declaration->p.alignment = CHAR_BIT; + string_declaration->p.declaration_free = _string_declaration_free; + string_declaration->p.definition_new = _string_definition_new; + string_declaration->p.definition_free = _string_definition_free; + string_declaration->p.ref = 1; + string_declaration->encoding = encoding; + return string_declaration; } static -struct declaration * - _string_declaration_new(struct type *type, - struct declaration_scope *parent_scope) +struct definition * + _string_definition_new(struct declaration *declaration, + struct definition_scope *parent_scope, + GQuark field_name, int index, + const char *root_name) { - struct type_string *string_type = - container_of(type, struct type_string, p); - struct declaration_string *string; + struct declaration_string *string_declaration = + container_of(declaration, struct declaration_string, p); + struct definition_string *string; + int ret; - string = g_new(struct declaration_string, 1); - type_ref(&string_type->p); - string->p.type = string_type; + string = g_new(struct definition_string, 1); + declaration_ref(&string_declaration->p); + string->p.declaration = declaration; + string->declaration = string_declaration; string->p.ref = 1; + /* + * Use INT_MAX order to ensure that all fields of the parent + * scope are seen as being prior to this scope. + */ + string->p.index = root_name ? INT_MAX : index; + string->p.name = field_name; + string->p.path = new_definition_path(parent_scope, field_name, + root_name); + string->p.scope = NULL; string->value = NULL; + string->len = 0; + string->alloc_len = 0; + ret = register_field_definition(field_name, &string->p, + parent_scope); + assert(!ret); return &string->p; } static -void _string_declaration_free(struct declaration *declaration) +void _string_definition_free(struct definition *definition) { - struct declaration_string *string = - container_of(declaration, struct declaration_string, p); + struct definition_string *string = + container_of(definition, struct definition_string, p); - type_unref(string->p.type); + declaration_unref(string->p.declaration); g_free(string->value); g_free(string); } + +char *get_string(struct definition *field) +{ + struct definition_string *string_definition = + container_of(field, struct definition_string, p); + + assert(string_definition->value != NULL); + + return string_definition->value; +}