core: new boxed type for 0-terminated array of guint16 values

This commit is contained in:
Aleksander Morgado
2012-03-15 14:14:51 +01:00
parent 536865040e
commit 2052b8184f
3 changed files with 82 additions and 0 deletions
+2
View File
@@ -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) \
+52
View File
@@ -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;
}
+28
View File
@@ -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__ */