gclue-modem.c 8.85 KB
Newer Older
Zeeshan Ali's avatar
Zeeshan Ali committed
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
/* vim: set et ts=8 sw=8: */
/*
 * Copyright (C) 2014 Red Hat, Inc.
 *
 * Geoclue 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.
 *
 * Geoclue 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.
 *
 * You should have received a copy of the GNU General Public License along
 * with Geoclue; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 */

#include <stdlib.h>
#include <glib.h>
#include <string.h>
#include "gclue-modem.h"
#include "gclue-marshal.h"

/**
 * SECTION:gclue-modem
 * @short_description: Modem handler
 *
32 33 34 35
 * This interface is implemented by Modem handing modules. Currently there is
 * only one class, ModemManager implementing this interface. Normally it
 * wouldn't make sense to have it separate from the class but intention is to
 * make it very easy to add alternative modem sources, e.g ofono-based.
Zeeshan Ali's avatar
Zeeshan Ali committed
36 37
 **/

38 39 40 41 42 43 44 45 46 47 48 49 50 51
G_DEFINE_INTERFACE (GClueModem, gclue_modem, 0);

static void
gclue_modem_default_init (GClueModemInterface *iface)
{
        GParamSpec *spec;

        spec = g_param_spec_boolean ("is-3g-available",
                                     "Is3GAvailable",
                                     "Is 3G Available?",
                                     FALSE,
                                     G_PARAM_READABLE);
        g_object_interface_install_property (iface, spec);

Zeeshan Ali's avatar
Zeeshan Ali committed
52 53 54 55 56 57 58
        spec = g_param_spec_boolean ("is-cdma-available",
                                     "IsCDMAAvailable",
                                     "Is CDMA Available?",
                                     FALSE,
                                     G_PARAM_READABLE);
        g_object_interface_install_property (iface, spec);

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        spec = g_param_spec_boolean ("is-gps-available",
                                     "IsGPSAvailable",
                                     "Is GPS Available?",
                                     FALSE,
                                     G_PARAM_READABLE);
        g_object_interface_install_property (iface, spec);

        g_signal_new ("fix-3g",
                      GCLUE_TYPE_MODEM,
                      G_SIGNAL_RUN_LAST,
                      0,
                      NULL,
                      NULL,
                      gclue_marshal_VOID__UINT_UINT_ULONG_ULONG,
                      G_TYPE_NONE,
                      4,
                      G_TYPE_UINT,
                      G_TYPE_UINT,
                      G_TYPE_ULONG,
                      G_TYPE_ULONG);

Zeeshan Ali's avatar
Zeeshan Ali committed
80 81 82 83 84 85 86 87 88 89 90 91
        g_signal_new ("fix-cdma",
                      GCLUE_TYPE_MODEM,
                      G_SIGNAL_RUN_LAST,
                      0,
                      NULL,
                      NULL,
                      gclue_marshal_VOID__DOUBLE_DOUBLE,
                      G_TYPE_NONE,
                      2,
                      G_TYPE_DOUBLE,
                      G_TYPE_DOUBLE);

92 93 94 95 96 97 98 99 100 101
        g_signal_new ("fix-gps",
                      GCLUE_TYPE_MODEM,
                      G_SIGNAL_RUN_LAST,
                      0,
                      NULL,
                      NULL,
                      g_cclosure_marshal_VOID__STRING,
                      G_TYPE_NONE,
                      1,
                      G_TYPE_STRING);
Zeeshan Ali's avatar
Zeeshan Ali committed
102 103 104 105 106
}

gboolean
gclue_modem_get_is_3g_available (GClueModem *modem)
{
107 108 109
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);

        return GCLUE_MODEM_GET_INTERFACE (modem)->get_is_3g_available (modem);
Zeeshan Ali's avatar
Zeeshan Ali committed
110 111
}

Zeeshan Ali's avatar
Zeeshan Ali committed
112 113 114 115 116 117 118 119
gboolean
gclue_modem_get_is_cdma_available (GClueModem *modem)
{
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);

        return GCLUE_MODEM_GET_INTERFACE (modem)->get_is_cdma_available (modem);
}

Zeeshan Ali's avatar
Zeeshan Ali committed
120 121 122
gboolean
gclue_modem_get_is_gps_available (GClueModem *modem)
{
123 124 125
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);

        return GCLUE_MODEM_GET_INTERFACE (modem)->get_is_gps_available (modem);
Zeeshan Ali's avatar
Zeeshan Ali committed
126 127 128 129 130 131 132 133 134 135 136
}

void
gclue_modem_enable_3g (GClueModem         *modem,
                       GCancellable       *cancellable,
                       GAsyncReadyCallback callback,
                       gpointer            user_data)
{
        g_return_if_fail (GCLUE_IS_MODEM (modem));
        g_return_if_fail (gclue_modem_get_is_3g_available (modem));

137 138 139 140
        GCLUE_MODEM_GET_INTERFACE (modem)->enable_3g (modem,
                                                      cancellable,
                                                      callback,
                                                      user_data);
Zeeshan Ali's avatar
Zeeshan Ali committed
141 142 143 144 145 146 147
}

gboolean
gclue_modem_enable_3g_finish (GClueModem   *modem,
                              GAsyncResult *result,
                              GError      **error)
{
148 149 150 151 152
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);

        return GCLUE_MODEM_GET_INTERFACE (modem)->enable_3g_finish (modem,
                                                                    result,
                                                                    error);
Zeeshan Ali's avatar
Zeeshan Ali committed
153 154
}

Zeeshan Ali's avatar
Zeeshan Ali committed
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
void
gclue_modem_enable_cdma (GClueModem         *modem,
                         GCancellable       *cancellable,
                         GAsyncReadyCallback callback,
                         gpointer            user_data)
{
        g_return_if_fail (GCLUE_IS_MODEM (modem));
        g_return_if_fail (gclue_modem_get_is_cdma_available (modem));

        GCLUE_MODEM_GET_INTERFACE (modem)->enable_cdma (modem,
                                                        cancellable,
                                                        callback,
                                                        user_data);
}

gboolean
gclue_modem_enable_cdma_finish (GClueModem   *modem,
                                GAsyncResult *result,
                                GError      **error)
{
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);

        return GCLUE_MODEM_GET_INTERFACE (modem)->enable_cdma_finish (modem,
                                                                      result,
                                                                      error);
}

Zeeshan Ali's avatar
Zeeshan Ali committed
182 183 184 185 186 187 188 189 190
void
gclue_modem_enable_gps (GClueModem         *modem,
                        GCancellable       *cancellable,
                        GAsyncReadyCallback callback,
                        gpointer            user_data)
{
        g_return_if_fail (GCLUE_IS_MODEM (modem));
        g_return_if_fail (gclue_modem_get_is_gps_available (modem));

191 192 193 194
        GCLUE_MODEM_GET_INTERFACE (modem)->enable_gps (modem,
                                                       cancellable,
                                                       callback,
                                                       user_data);
Zeeshan Ali's avatar
Zeeshan Ali committed
195 196 197 198 199 200 201
}

gboolean
gclue_modem_enable_gps_finish (GClueModem   *modem,
                               GAsyncResult *result,
                               GError      **error)
{
202 203 204 205 206
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);

        return GCLUE_MODEM_GET_INTERFACE (modem)->enable_gps_finish (modem,
                                                                     result,
                                                                     error);
Zeeshan Ali's avatar
Zeeshan Ali committed
207 208 209 210 211 212 213 214 215 216
}

gboolean
gclue_modem_disable_3g (GClueModem   *modem,
                        GCancellable *cancellable,
                        GError      **error)
{
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);
        g_return_val_if_fail (gclue_modem_get_is_3g_available (modem), FALSE);

217 218 219
        return GCLUE_MODEM_GET_INTERFACE (modem)->disable_3g (modem,
                                                              cancellable,
                                                              error);
Zeeshan Ali's avatar
Zeeshan Ali committed
220 221
}

Zeeshan Ali's avatar
Zeeshan Ali committed
222 223 224 225 226 227 228 229 230 231 232 233 234
gboolean
gclue_modem_disable_cdma (GClueModem   *modem,
                          GCancellable *cancellable,
                          GError      **error)
{
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);
        g_return_val_if_fail (gclue_modem_get_is_cdma_available (modem), FALSE);

        return GCLUE_MODEM_GET_INTERFACE (modem)->disable_cdma (modem,
                                                                cancellable,
                                                                error);
}

Zeeshan Ali's avatar
Zeeshan Ali committed
235 236 237 238 239 240 241 242
gboolean
gclue_modem_disable_gps (GClueModem   *modem,
                         GCancellable *cancellable,
                         GError      **error)
{
        g_return_val_if_fail (GCLUE_IS_MODEM (modem), FALSE);
        g_return_val_if_fail (gclue_modem_get_is_gps_available (modem), FALSE);

243 244 245
        return GCLUE_MODEM_GET_INTERFACE (modem)->disable_gps (modem,
                                                               cancellable,
                                                               error);
Zeeshan Ali's avatar
Zeeshan Ali committed
246
}