diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-01-13 17:17:53 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:14:51 +0100 |
commit | 2052b8184f0581e562d7caccc319e78bb6d27b65 (patch) | |
tree | 1eeaaa7e757d8c91bf7fd0250d63b37f21804232 /src | |
parent | 536865040e79076a5dbbbceb23501b4f15df249e (diff) |
core: new boxed type for 0-terminated array of guint16 values
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/mm-private-boxed-types.c | 52 | ||||
-rw-r--r-- | src/mm-private-boxed-types.h | 28 |
3 files changed, 82 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index fad45bc3..cf80c0e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -119,6 +119,8 @@ modem_manager_SOURCES = \ mm-log.h \ mm-private-enums-types.h \ mm-private-enums-types.c \ + mm-private-boxed-types.h \ + mm-private-boxed-types.c \ mm-callback-info.c \ mm-callback-info.h \ $(auth_sources) \ diff --git a/src/mm-private-boxed-types.c b/src/mm-private-boxed-types.c new file mode 100644 index 00000000..ad9d62d1 --- /dev/null +++ b/src/mm-private-boxed-types.c @@ -0,0 +1,52 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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: + * + * Copyright (C) 2012 - Google, Inc. + */ + +#include "mm-private-boxed-types.h" +#include "string.h" + +static guint16 * +uint16_array_copy (guint16 *array) +{ + guint16 *dup; + guint i; + + if (!array) + return NULL; + + /* Get 0-terminated array size */ + for (i = 0; array[i]; i++); + + dup = g_new (guint16, i + 1); + memcpy (dup, array, i * sizeof (guint16)); + dup[i] = 0; + return dup; +} + +GType +mm_uint16_array_get_type (void) +{ + static volatile gsize g_define_type_id__volatile = 0; + + if (g_once_init_enter (&g_define_type_id__volatile)) { + GType g_define_type_id = + g_boxed_type_register_static (g_intern_static_string ("MMUint16Array"), + (GBoxedCopyFunc) uint16_array_copy, + (GBoxedFreeFunc) g_free); + + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} diff --git a/src/mm-private-boxed-types.h b/src/mm-private-boxed-types.h new file mode 100644 index 00000000..e13aaf9d --- /dev/null +++ b/src/mm-private-boxed-types.h @@ -0,0 +1,28 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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: + * + * Copyright (C) 2012 - Google, Inc. + */ + +#ifndef __MM_PRIVATE_BOXED_TYPES_H__ +#define __MM_PRIVATE_BOXED_TYPES_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +GType mm_uint16_array_get_type (void) G_GNUC_CONST; +#define MM_TYPE_UINT16_ARRAY (mm_uint16_array_get_type ()) + +G_END_DECLS + +#endif /* __MM_PRIVATE_BOXED_TYPES_H__ */ |