aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib/mm-modem-location.c
blob: 4f88d7eeb88ed293f0b49dfabb3c826b9dd544a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * libmm -- Access modem status & information from glib applications
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
 *
 * Copyright (C) 2012 Google, Inc.
 * Copyright (C) 2012 Lanedo GmbH <aleksander@lanedo.com>
 */

#include <gio/gio.h>

#include "mm-helpers.h"
#include "mm-modem-location.h"

/**
 * mm_modem_location_get_path:
 * @self: A #MMModemLocation.
 *
 * Gets the DBus path of the #MMObject which implements this interface.
 *
 * Returns: (transfer none): The DBus path of the #MMObject object.
 */
const gchar *
mm_modem_location_get_path (MMModemLocation *self)
{
    g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);

    RETURN_NON_EMPTY_CONSTANT_STRING (
        g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
}

/**
 * mm_modem_location_dup_path:
 * @self: A #MMModemLocation.
 *
 * Gets a copy of the DBus path of the #MMObject object which implements this interface.
 *
 * Returns: (transfer full): The DBus path of the #MMObject. The returned value should be freed with g_free().
 */
gchar *
mm_modem_location_dup_path (MMModemLocation *self)
{
    gchar *value;

    g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);

    g_object_get (G_OBJECT (self),
                  "g-object-path", &value,
                  NULL);
    RETURN_NON_EMPTY_STRING (value);
}

MMModemLocationSource
mm_modem_location_get_capabilities (MMModemLocation *self)
{
    g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self),
                          MM_MODEM_LOCATION_SOURCE_NONE);

    return (MMModemLocationSource) mm_gdbus_modem_location_get_capabilities (self);
}

MMModemLocationSource
mm_modem_location_get_enabled (MMModemLocation *self)
{
    g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE);

    return (MMModemLocationSource) mm_gdbus_modem_location_get_enabled (self);
}

gboolean
mm_modem_location_signals_location (MMModemLocation *self)
{
    g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE);

    return mm_gdbus_modem_location_get_signals_location (self);
}

gboolean
mm_modem_location_setup_finish (MMModemLocation *self,
                                GAsyncResult *res,
                                GError **error)
{
    g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE);

    return mm_gdbus_modem_location_call_setup_finish (self, res, error);
}

void
mm_modem_location_setup (MMModemLocation *self,
                         MMModemLocationSource sources,
                         gboolean signal_location,
                         GCancellable *cancellable,
                         GAsyncReadyCallback callback,
                         gpointer user_data)
{
    g_return_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self));

    mm_gdbus_modem_location_call_setup (self,
                                        sources,
                                        signal_location,
                                        cancellable,
                                        callback,
                                        user_data);
}

gboolean
mm_modem_location_setup_sync (MMModemLocation *self,
                              MMModemLocationSource sources,
                              gboolean signal_location,
                              GCancellable *cancellable,
                              GError **error)
{
    g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), FALSE);

    return mm_gdbus_modem_location_call_setup_sync (self,
                                                    sources,
                                                    signal_location,
                                                    cancellable,
                                                    error);
}

static MMLocation3gpp *
build_3gpp_location (GVariant *dictionary,
                     GError **error)
{
    MMLocation3gpp *location = NULL;
    GError *inner_error = NULL;
    GVariant *value;
    guint source;
    GVariantIter iter;

    if (!dictionary)
        return NULL;

    g_variant_iter_init (&iter, dictionary);
    while (!location &&
           !inner_error &&
           g_variant_iter_next (&iter, "{uv}", &source, &value)) {
        /* If we have 3GPP LAC/CI location, build result */
        if (source == MM_MODEM_LOCATION_SOURCE_3GPP_LAC_CI)
            location = mm_location_3gpp_new_from_string_variant (value, &inner_error);

        g_variant_unref (value);
    }

    g_variant_unref (dictionary);

    if (inner_error)
        g_propagate_error (error, inner_error);

    return (MMLocation3gpp *)location;
}

MMLocation3gpp *
mm_modem_location_get_3gpp_finish (MMModemLocation *self,
                                   GAsyncResult *res,
                                   GError **error)
{

    GVariant *dictionary = NULL;

    g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), NULL);

    if (!mm_gdbus_modem_location_call_get_location_finish (self, &dictionary, res, error))
        return NULL;

    return build_3gpp_location (dictionary, error);
}

void
mm_modem_location_get_3gpp (MMModemLocation *self,
                            GCancellable *cancellable,
                            GAsyncReadyCallback callback,
                            gpointer user_data)
{
    g_return_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self));

    mm_gdbus_modem_location_call_get_location (self,
                                               cancellable,
                                               callback,
                                               user_data);
}

MMLocation3gpp *
mm_modem_location_get_3gpp_sync (MMModemLocation *self,
                                 GCancellable *cancellable,
                                 GError **error)
{
    GVariant *dictionary = NULL;

    g_return_val_if_fail (MM_GDBUS_IS_MODEM_LOCATION (self), NULL);

    if (!mm_gdbus_modem_location_call_get_location_sync (self, &dictionary, cancellable, error))
        return NULL;

    return build_3gpp_location (dictionary, error);
}