| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
|
| 3 |
/* |
| 4 |
* libqmi-glib -- GLib/GIO based library to control QMI devices |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public |
| 8 |
* License as published by the Free Software Foundation; either |
| 9 |
* version 2 of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the |
| 18 |
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 |
* Boston, MA 02110-1301 USA. |
| 20 |
* |
| 21 |
* Copyright (C) 2017 Aleksander Morgado <[email protected]> |
| 22 |
*/ |
| 23 |
|
| 24 |
#include <glib.h> |
| 25 |
|
| 26 |
#include "qmi-message-context.h" |
| 27 |
|
| 28 |
/*****************************************************************************/ |
| 29 |
/* Basic context */ |
| 30 |
|
| 31 |
struct _QmiMessageContext { |
| 32 |
volatile gint ref_count; |
| 33 |
|
| 34 |
/* Vendor ID */ |
| 35 |
guint16 vendor_id; |
| 36 |
}; |
| 37 |
|
| 38 |
QmiMessageContext * |
| 39 |
qmi_message_context_new (void) |
| 40 |
{ |
| 41 |
QmiMessageContext *self; |
| 42 |
|
| 43 |
self = g_slice_new0 (QmiMessageContext); |
| 44 |
self->ref_count = 1; |
| 45 |
return self; |
| 46 |
} |
| 47 |
|
| 48 |
GType |
| 49 |
qmi_message_context_get_type (void) |
| 50 |
{ |
| 51 |
static gsize g_define_type_id_initialized = 0; |
| 52 |
|
| 53 |
if (g_once_init_enter (&g_define_type_id_initialized)) { |
| 54 |
GType g_define_type_id = |
| 55 |
g_boxed_type_register_static (g_intern_static_string ("QmiMessageContext"), |
| 56 |
(GBoxedCopyFunc) qmi_message_context_ref, |
| 57 |
(GBoxedFreeFunc) qmi_message_context_unref); |
| 58 |
|
| 59 |
g_once_init_leave (&g_define_type_id_initialized, g_define_type_id); |
| 60 |
} |
| 61 |
|
| 62 |
return g_define_type_id_initialized; |
| 63 |
} |
| 64 |
|
| 65 |
QmiMessageContext * |
| 66 |
qmi_message_context_ref (QmiMessageContext *self) |
| 67 |
{ |
| 68 |
g_return_val_if_fail (self != NULL, NULL); |
| 69 |
|
| 70 |
g_atomic_int_inc (&self->ref_count); |
| 71 |
return self; |
| 72 |
} |
| 73 |
|
| 74 |
void |
| 75 |
qmi_message_context_unref (QmiMessageContext *self) |
| 76 |
{ |
| 77 |
g_return_if_fail (self != NULL); |
| 78 |
|
| 79 |
if (g_atomic_int_dec_and_test (&self->ref_count)) { |
| 80 |
g_slice_free (QmiMessageContext, self); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/*****************************************************************************/ |
| 85 |
/* Vendor ID */ |
| 86 |
|
| 87 |
void |
| 88 |
qmi_message_context_set_vendor_id (QmiMessageContext *self, |
| 89 |
guint16 vendor_id) |
| 90 |
{ |
| 91 |
g_return_if_fail (self != NULL); |
| 92 |
|
| 93 |
self->vendor_id = vendor_id; |
| 94 |
} |
| 95 |
|
| 96 |
guint16 |
| 97 |
qmi_message_context_get_vendor_id (QmiMessageContext *self) |
| 98 |
{ |
| 99 |
g_return_val_if_fail (self != NULL, QMI_MESSAGE_VENDOR_GENERIC); |
| 100 |
return self->vendor_id; |
| 101 |
} |