aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/mm-bearer.c327
-rw-r--r--src/mm-bearer.h61
3 files changed, 390 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 58c1504b..ba1dc5e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -110,6 +110,8 @@ modem_manager_SOURCES = \
mm-plugin-manager.h \
mm-sim.h \
mm-sim.c \
+ mm-bearer.h \
+ mm-bearer.c \
mm-base-modem-at.h \
mm-base-modem-at.c \
mm-base-modem.h \
diff --git a/src/mm-bearer.c b/src/mm-bearer.c
new file mode 100644
index 00000000..272c3136
--- /dev/null
+++ b/src/mm-bearer.c
@@ -0,0 +1,327 @@
+/* -*- 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) 2008 - 2009 Novell, Inc.
+ * Copyright (C) 2009 - 2011 Red Hat, Inc.
+ * Copyright (C) 2011 Google, Inc.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <ctype.h>
+
+#include <ModemManager.h>
+
+#include <mm-enums-types.h>
+#include <mm-errors-types.h>
+#include <mm-gdbus-bearer.h>
+
+#include "mm-iface-modem.h"
+#include "mm-bearer.h"
+#include "mm-base-modem-at.h"
+#include "mm-base-modem.h"
+#include "mm-utils.h"
+#include "mm-log.h"
+#include "mm-modem-helpers.h"
+
+static void async_initable_iface_init (GAsyncInitableIface *iface);
+
+G_DEFINE_TYPE_EXTENDED (MMBearer, mm_bearer, MM_GDBUS_TYPE_BEARER_SKELETON, 0,
+ G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
+ async_initable_iface_init));
+
+enum {
+ PROP_0,
+ PROP_PATH,
+ PROP_CONNECTION,
+ PROP_MODEM,
+ PROP_LAST
+};
+
+static GParamSpec *properties[PROP_LAST];
+
+struct _MMBearerPrivate {
+ /* The connection to the system bus */
+ GDBusConnection *connection;
+ /* The modem which owns this BEARER */
+ MMBaseModem *modem;
+ /* The path where the BEARER object is exported */
+ gchar *path;
+};
+
+/*****************************************************************************/
+/* CONNECT */
+
+static gboolean
+handle_connect (MMBearer *self,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_number)
+{
+ return FALSE;
+}
+
+/*****************************************************************************/
+/* DISCONNECT */
+
+static gboolean
+handle_disconnect (MMBearer *self,
+ GDBusMethodInvocation *invocation,
+ const gchar *arg_number)
+{
+ return FALSE;
+}
+
+/*****************************************************************************/
+
+static void
+mm_bearer_export (MMBearer *self)
+{
+ GError *error = NULL;
+
+ /* Handle method invocations */
+ g_signal_connect (self,
+ "handle-connect",
+ G_CALLBACK (handle_connect),
+ NULL);
+ g_signal_connect (self,
+ "handle-disconnect",
+ G_CALLBACK (handle_disconnect),
+ NULL);
+
+ if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self),
+ self->priv->connection,
+ self->priv->path,
+ &error)) {
+ mm_warn ("couldn't export BEARER at '%s': '%s'",
+ self->priv->path,
+ error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+mm_bearer_unexport (MMBearer *self)
+{
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self));
+}
+
+/*****************************************************************************/
+
+MMBearer *
+mm_bearer_new_finish (GAsyncInitable *initable,
+ GAsyncResult *res,
+ GError **error)
+{
+ return MM_BEARER (g_async_initable_new_finish (initable, res, error));
+}
+
+static gboolean
+initable_init_finish (GAsyncInitable *initable,
+ GAsyncResult *result,
+ GError **error)
+{
+ return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
+}
+
+static void
+initable_init_async (GAsyncInitable *initable,
+ int io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ /* Set defaults */
+ mm_gdbus_bearer_set_interface (MM_GDBUS_BEARER (initable), NULL);
+ mm_gdbus_bearer_set_connected (MM_GDBUS_BEARER (initable), FALSE);
+ mm_gdbus_bearer_set_suspended (MM_GDBUS_BEARER (initable), FALSE);
+ mm_gdbus_bearer_set_ip4_config (MM_GDBUS_BEARER (initable), NULL);
+ mm_gdbus_bearer_set_ip6_config (MM_GDBUS_BEARER (initable), NULL);
+ /* Complete */
+ result = g_simple_async_result_new (G_OBJECT (initable),
+ callback,
+ user_data,
+ initable_init_async);
+ g_simple_async_result_set_op_res_gboolean (result, TRUE);
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+void
+mm_bearer_new (MMBaseModem *modem,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ gchar *path;
+ static guint32 id = 0;
+
+ /* Build the unique path for the Bearer, and create the object */
+ path = g_strdup_printf (MM_DBUS_PATH"/Bearers/%d", id++);
+ g_async_initable_new_async (MM_TYPE_BEARER,
+ G_PRIORITY_DEFAULT,
+ cancellable,
+ callback,
+ user_data,
+ MM_BEARER_PATH, path,
+ MM_BEARER_MODEM, modem,
+ NULL);
+ g_free (path);
+}
+
+static void
+set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MMBearer *self = MM_BEARER (object);
+
+ switch (prop_id) {
+ case PROP_PATH:
+ g_free (self->priv->path);
+ self->priv->path = g_value_dup_string (value);
+ break;
+ case PROP_CONNECTION:
+ if (self->priv->connection)
+ g_object_unref (self->priv->connection);
+ self->priv->connection = g_value_dup_object (value);
+
+ /* Export when we get a DBus connection */
+ if (self->priv->connection)
+ mm_bearer_export (self);
+ else
+ mm_bearer_unexport (self);
+ break;
+ case PROP_MODEM:
+ if (self->priv->modem)
+ g_object_unref (self->priv->modem);
+ self->priv->modem = g_value_dup_object (value);
+ if (self->priv->modem) {
+ /* Bind the modem's connection (which is set when it is exported,
+ * and unset when unexported) to the BEARER's connection */
+ g_object_bind_property (self->priv->modem, MM_BASE_MODEM_CONNECTION,
+ self, MM_BEARER_CONNECTION,
+ G_BINDING_DEFAULT);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MMBearer *self = MM_BEARER (object);
+
+ switch (prop_id) {
+ case PROP_PATH:
+ g_value_set_string (value, self->priv->path);
+ break;
+ case PROP_CONNECTION:
+ g_value_set_object (value, self->priv->connection);
+ break;
+ case PROP_MODEM:
+ g_value_set_object (value, self->priv->modem);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+mm_bearer_init (MMBearer *self)
+{
+ /* Initialize private data */
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
+ MM_TYPE_BEARER,
+ MMBearerPrivate);
+}
+
+static void
+finalize (GObject *object)
+{
+ MMBearer *self = MM_BEARER (object);
+
+ g_free (self->priv->path);
+
+ G_OBJECT_CLASS (mm_bearer_parent_class)->finalize (object);
+}
+
+static void
+dispose (GObject *object)
+{
+ MMBearer *self = MM_BEARER (object);
+
+ if (self->priv->connection)
+ g_clear_object (&self->priv->connection);
+
+ if (self->priv->modem)
+ g_clear_object (&self->priv->modem);
+
+ G_OBJECT_CLASS (mm_bearer_parent_class)->dispose (object);
+}
+
+static void
+async_initable_iface_init (GAsyncInitableIface *iface)
+{
+ iface->init_async = initable_init_async;
+ iface->init_finish = initable_init_finish;
+}
+
+static void
+mm_bearer_class_init (MMBearerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (object_class, sizeof (MMBearerPrivate));
+
+ /* Virtual methods */
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+ object_class->finalize = finalize;
+ object_class->dispose = dispose;
+
+ properties[PROP_CONNECTION] =
+ g_param_spec_object (MM_BEARER_CONNECTION,
+ "Connection",
+ "GDBus connection to the system bus.",
+ G_TYPE_DBUS_CONNECTION,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_CONNECTION, properties[PROP_CONNECTION]);
+
+ properties[PROP_PATH] =
+ g_param_spec_string (MM_BEARER_PATH,
+ "Path",
+ "DBus path of the Bearer",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+ g_object_class_install_property (object_class, PROP_PATH, properties[PROP_PATH]);
+
+ properties[PROP_MODEM] =
+ g_param_spec_object (MM_BEARER_MODEM,
+ "Modem",
+ "The Modem which owns this Bearer",
+ MM_TYPE_BASE_MODEM,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_MODEM, properties[PROP_MODEM]);
+}
diff --git a/src/mm-bearer.h b/src/mm-bearer.h
new file mode 100644
index 00000000..ea598e59
--- /dev/null
+++ b/src/mm-bearer.h
@@ -0,0 +1,61 @@
+/* -*- 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:
+ *
+ * Author: Aleksander Morgado <aleksander@lanedo.com>
+ *
+ * Copyright (C) 2011 Google, Inc.
+ */
+
+#ifndef MM_BEARER_H
+#define MM_BEARER_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <mm-gdbus-bearer.h>
+#include "mm-base-modem.h"
+
+#define MM_TYPE_BEARER (mm_bearer_get_type ())
+#define MM_BEARER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BEARER, MMBearer))
+#define MM_BEARER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BEARER, MMBearerClass))
+#define MM_IS_BEARER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BEARER))
+#define MM_IS_BEARER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BEARER))
+#define MM_BEARER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BEARER, MMBearerClass))
+
+typedef struct _MMBearer MMBearer;
+typedef struct _MMBearerClass MMBearerClass;
+typedef struct _MMBearerPrivate MMBearerPrivate;
+
+#define MM_BEARER_PATH "bearer-path"
+#define MM_BEARER_CONNECTION "bearer-connection"
+#define MM_BEARER_MODEM "bearer-modem"
+
+struct _MMBearer {
+ MmGdbusBearerSkeleton parent;
+ MMBearerPrivate *priv;
+};
+
+struct _MMBearerClass {
+ MmGdbusBearerSkeletonClass parent;
+};
+
+GType mm_bearer_get_type (void);
+
+void mm_bearer_new (MMBaseModem *modem,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+MMBearer *mm_bearer_new_finish (GAsyncInitable *initable,
+ GAsyncResult *res,
+ GError **error);
+
+#endif /* MM_BEARER_H */