~binli/ubuntu/vivid/modemmanager/lp1441095

« back to all changes in this revision

Viewing changes to src/mm-callback-info.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre, Mathieu Trudel-Lapierre, Michael Biebl, Marius B. Kotsbak
  • Date: 2013-06-11 10:35:42 UTC
  • mfrom: (1.2.1) (16.1.20 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130611103542-xm7vvifc252viorj
Tags: 0.7.991-1
[ Mathieu Trudel-Lapierre ]
* New upstream release.
* debian/patches/handle_data07_capabilities_probing.patch,
  debian/patches/git_skip_add_utf8_check_219424a.patch,
  debian/patches/git_lte_etsi_mode_0af47c7.patch,
  debian/patches/git_lte_4g_parsing_90489ae.patch,
  debian/patches/git_lp1015328_segfault_in_clck_parser_318aaa0.patch,
  debian/patches/git_better_handle_ucs2_convert_e07c216.patch: Dropped,
  these patches were cherry-picks; included upstream
* debian/patches/ericsson_h5321gw_usbids.patch: dropped, included upstream.
* debian/control:
  - clean up build-depends: remove xsltproc, bump
    libglib2.0-dev to (>= 2.30.2), libgudev-1.0-dev to (>= 147).
  - Add gtk-doc-tools to Build-Depends.
  - Add libqmi-glib-dev to Build-Depends.
  - Add gnome-common to Build-Depends.
  - Bump debhelper Build-Depends to >= 9.
  - Make sure libmm-glib0 pre-depends on multiarch-support (lintian).
  - Make libmm-glib0 Multi-Arch: same.
  - Make sure all binary packages (except modemmanager-dbg) are priority
    optional.
  - Update short descriptions.
  - Breaks network-manager (<< 0.9.8.2-1) since otherwise NetworkManager
    will not see ModemManager with its new API.
* debian/compat: bump to compat level 9.
* debian/rules:
  - Replace --with-docs with --enable-gtk-doc.
  - Fix autoreconf to run gnome-autogen.sh.
  - Drop the override for installdocs; docs/spec.html isn't being built
    anymore.
  - Run dh_install with --fail-missing.
  - Remove test pppd plugin which we shouldn't install.
  - Drop old cruft for getting git snapshots.
  - We don't need to exclude the pppd path from makeshlibs, since nothing
    gets installed there.
* debian/patches/lp700316_usb_blacklist.patch: refreshed.
* debian/patches/arduino-blacklist.patch: refreshed.
* debian/patches/linux-default-usb-id.patch: refreshed.
* debian/*.install: make sure the files are properly installed given the new
  packages, also take into account multiarch paths.
* debian/modemmanager.install: install the new mmcli binary.
* debian/ubuntu/modemmanager.upstart: fix the name for the ModemManager
  binary, since it was changed upstream.
* debian/patches/dbus_remove_max_replies_per_connection_limit.patch: dropped,
  included upstream.

[ Michael Biebl ]
* Add symbols file for libmm-glib0.

[ Marius B. Kotsbak ]
* Added binary packages modemmanager-doc and libmm-glib-doc for gtk-docs.
* Split out modemmanager-dev package containing header files and .pc file.
  - add dependency on modemmanager-dev from libmm-glib-dev
    as stated in "mm-glib.pc"
  - add proper replaces/breaks for modemmanager-dev because of moved files
* Build-depends: added "libglib2.0-doc" for the cross references in the doc
  to work.
* debian/rules: make dh_makeshlibs override multiarch aware.
* Update standards version to current 3.9.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
 
/*
3
 
 * This program is free software; you can redistribute it and/or modify
4
 
 * it under the terms of the GNU General Public License as published by
5
 
 * the Free Software Foundation; either version 2 of the License, or
6
 
 * (at your option) any later version.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details:
12
 
 *
13
 
 * Copyright (C) 2008 Novell, Inc.
14
 
 * Copyright (C) 2009 - 2010 Red Hat, Inc.
15
 
 */
16
 
 
17
 
#include "mm-callback-info.h"
18
 
#include "mm-errors.h"
19
 
 
20
 
#define CALLBACK_INFO_RESULT "callback-info-result"
21
 
 
22
 
static void
23
 
invoke_mm_modem_fn (MMCallbackInfo *info)
24
 
{
25
 
    MMModemFn callback = (MMModemFn) info->callback;
26
 
 
27
 
    callback (info->modem, info->error, info->user_data);
28
 
}
29
 
 
30
 
static void
31
 
invoke_mm_modem_uint_fn (MMCallbackInfo *info)
32
 
{
33
 
    MMModemUIntFn callback = (MMModemUIntFn) info->callback;
34
 
 
35
 
    callback (info->modem,
36
 
              GPOINTER_TO_UINT (mm_callback_info_get_data (info, CALLBACK_INFO_RESULT)),
37
 
              info->error, info->user_data);
38
 
}
39
 
 
40
 
static void
41
 
invoke_mm_modem_string_fn (MMCallbackInfo *info)
42
 
{
43
 
    MMModemStringFn callback = (MMModemStringFn) info->callback;
44
 
 
45
 
    callback (info->modem,
46
 
              (const char *) mm_callback_info_get_data (info, CALLBACK_INFO_RESULT),
47
 
              info->error, info->user_data);
48
 
}
49
 
 
50
 
static void
51
 
modem_destroyed_cb (gpointer data, GObject *destroyed)
52
 
{
53
 
    MMCallbackInfo *info = data;
54
 
 
55
 
    /* Reset modem pointer, so that callback know that they shouldn't do
56
 
     * anything else */
57
 
    info->modem = NULL;
58
 
 
59
 
    /* Overwrite any possible previous error set */
60
 
    g_clear_error (&(info->error));
61
 
    info->error = g_error_new_literal (MM_MODEM_ERROR,
62
 
                                       MM_MODEM_ERROR_REMOVED,
63
 
                                       "The modem was removed.");
64
 
 
65
 
    /* Only schedule the info if not already done before */
66
 
    if (!info->pending_id)
67
 
        mm_callback_info_schedule (info);
68
 
}
69
 
 
70
 
static void
71
 
callback_info_done (gpointer user_data)
72
 
{
73
 
    MMCallbackInfo *info = (MMCallbackInfo *) user_data;
74
 
 
75
 
    info->pending_id = 0;
76
 
    info->called = TRUE;
77
 
 
78
 
    if (info->invoke_fn && info->callback)
79
 
        info->invoke_fn (info);
80
 
 
81
 
    mm_callback_info_unref (info);
82
 
}
83
 
 
84
 
static gboolean
85
 
callback_info_do (gpointer user_data)
86
 
{
87
 
    /* Nothing here, everything is done in callback_info_done to make sure the info->callback
88
 
       always gets called, even if the pending call gets cancelled. */
89
 
    return FALSE;
90
 
}
91
 
 
92
 
void
93
 
mm_callback_info_schedule (MMCallbackInfo *info)
94
 
{
95
 
    g_return_if_fail (info != NULL);
96
 
    g_return_if_fail (info->pending_id == 0);
97
 
    g_return_if_fail (info->called == FALSE);
98
 
 
99
 
    g_warn_if_fail (info->chain_left == 0);
100
 
 
101
 
    info->pending_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, callback_info_do, info, callback_info_done);
102
 
}
103
 
 
104
 
MMCallbackInfo *
105
 
mm_callback_info_new_full (MMModem *modem,
106
 
                           MMCallbackInfoInvokeFn invoke_fn,
107
 
                           GCallback callback,
108
 
                           gpointer user_data)
109
 
{
110
 
    MMCallbackInfo *info;
111
 
 
112
 
    g_return_val_if_fail (modem != NULL, NULL);
113
 
 
114
 
    info = g_slice_new0 (MMCallbackInfo);
115
 
    g_datalist_init (&info->qdata);
116
 
    info->modem = modem;
117
 
    g_object_weak_ref (G_OBJECT (modem), modem_destroyed_cb, info);
118
 
    info->invoke_fn = invoke_fn;
119
 
    info->callback = callback;
120
 
    info->user_data = user_data;
121
 
    info->refcount = 1;
122
 
 
123
 
    return info;
124
 
}
125
 
 
126
 
MMCallbackInfo *
127
 
mm_callback_info_new (MMModem *modem, MMModemFn callback, gpointer user_data)
128
 
{
129
 
    g_return_val_if_fail (modem != NULL, NULL);
130
 
 
131
 
    return mm_callback_info_new_full (modem, invoke_mm_modem_fn, (GCallback) callback, user_data);
132
 
}
133
 
 
134
 
MMCallbackInfo *
135
 
mm_callback_info_uint_new (MMModem *modem,
136
 
                           MMModemUIntFn callback,
137
 
                           gpointer user_data)
138
 
{
139
 
    g_return_val_if_fail (modem != NULL, NULL);
140
 
 
141
 
    return mm_callback_info_new_full (modem, invoke_mm_modem_uint_fn, (GCallback) callback, user_data);
142
 
}
143
 
 
144
 
MMCallbackInfo *
145
 
mm_callback_info_string_new (MMModem *modem,
146
 
                             MMModemStringFn callback,
147
 
                             gpointer user_data)
148
 
{
149
 
    g_return_val_if_fail (modem != NULL, NULL);
150
 
 
151
 
    return mm_callback_info_new_full (modem, invoke_mm_modem_string_fn, (GCallback) callback, user_data);
152
 
}
153
 
 
154
 
gpointer
155
 
mm_callback_info_get_result (MMCallbackInfo *info)
156
 
{
157
 
    g_return_val_if_fail (info != NULL, NULL);
158
 
 
159
 
    return mm_callback_info_get_data (info, CALLBACK_INFO_RESULT);
160
 
}
161
 
 
162
 
void
163
 
mm_callback_info_set_result (MMCallbackInfo *info,
164
 
                             gpointer data,
165
 
                             GDestroyNotify destroy)
166
 
{
167
 
    g_return_if_fail (info != NULL);
168
 
 
169
 
    mm_callback_info_set_data (info, CALLBACK_INFO_RESULT, data, destroy);
170
 
}
171
 
 
172
 
void
173
 
mm_callback_info_set_data (MMCallbackInfo *info,
174
 
                           const char *key,
175
 
                           gpointer data,
176
 
                           GDestroyNotify destroy)
177
 
{
178
 
    g_return_if_fail (info != NULL);
179
 
    g_return_if_fail (key != NULL);
180
 
 
181
 
    g_datalist_id_set_data_full (&info->qdata, g_quark_from_string (key), data,
182
 
                                 data ? destroy : (GDestroyNotify) NULL);
183
 
}
184
 
 
185
 
gpointer
186
 
mm_callback_info_get_data (MMCallbackInfo *info, const char *key)
187
 
{
188
 
    GQuark quark;
189
 
 
190
 
    g_return_val_if_fail (info != NULL, NULL);
191
 
    g_return_val_if_fail (key != NULL, NULL);
192
 
 
193
 
    quark = g_quark_try_string (key);
194
 
 
195
 
    return quark ? g_datalist_id_get_data (&info->qdata, quark) : NULL;
196
 
}
197
 
 
198
 
gboolean
199
 
mm_callback_info_check_modem_removed (MMCallbackInfo *info)
200
 
{
201
 
    g_return_val_if_fail (info != NULL, TRUE);
202
 
 
203
 
    return (info->modem ? FALSE : TRUE);
204
 
}
205
 
 
206
 
MMCallbackInfo *
207
 
mm_callback_info_ref (MMCallbackInfo *info)
208
 
{
209
 
    g_return_val_if_fail (info != NULL, NULL);
210
 
    g_return_val_if_fail (info->refcount > 0, NULL);
211
 
 
212
 
    info->refcount++;
213
 
    return info;
214
 
}
215
 
 
216
 
void
217
 
mm_callback_info_unref (MMCallbackInfo *info)
218
 
{
219
 
    g_return_if_fail (info != NULL);
220
 
 
221
 
    info->refcount--;
222
 
    if (info->refcount == 0) {
223
 
        if (info->error)
224
 
            g_error_free (info->error);
225
 
 
226
 
        if (info->modem)
227
 
            g_object_weak_unref (G_OBJECT (info->modem), modem_destroyed_cb, info);
228
 
 
229
 
        g_datalist_clear (&info->qdata);
230
 
        g_slice_free (MMCallbackInfo, info);
231
 
    }
232
 
}
233
 
 
234
 
void
235
 
mm_callback_info_chain_start (MMCallbackInfo *info, guint num)
236
 
{
237
 
    g_return_if_fail (info != NULL);
238
 
    g_return_if_fail (num > 0);
239
 
    g_return_if_fail (info->chain_left == 0);
240
 
 
241
 
    info->chain_left = num;
242
 
}
243
 
 
244
 
void
245
 
mm_callback_info_chain_complete_one (MMCallbackInfo *info)
246
 
{
247
 
    g_return_if_fail (info != NULL);
248
 
    g_return_if_fail (info->chain_left > 0);
249
 
 
250
 
    info->chain_left--;
251
 
    if (info->chain_left == 0)
252
 
        mm_callback_info_schedule (info);
253
 
}
254