core: implemented new MMBaseCall object

This commit is contained in:
Riccardo Vangelisti
2015-05-04 11:11:43 +02:00
committed by Aleksander Morgado
parent c3bec1537b
commit ec5c539f55
4 changed files with 1518 additions and 0 deletions

1030
src/mm-base-call.c Normal file

File diff suppressed because it is too large Load Diff

102
src/mm-base-call.h Normal file
View File

@@ -0,0 +1,102 @@
/* -*- 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) 2015 Riccardo Vangelisti <riccardo.vangelisti@sadel.it>
*/
#ifndef MM_BASE_CALL_H
#define MM_BASE_CALL_H
#include <glib.h>
#include <glib-object.h>
#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include "mm-base-modem.h"
#define MM_TYPE_BASE_CALL (mm_base_call_get_type ())
#define MM_BASE_CALL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_BASE_CALL, MMBaseCall))
#define MM_BASE_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_BASE_CALL, MMBaseCallClass))
#define MM_IS_BASE_CALL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_BASE_CALL))
#define MM_IS_BASE_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_BASE_CALL))
#define MM_BASE_CALL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_BASE_CALL, MMBaseCallClass))
typedef struct _MMBaseCall MMBaseCall;
typedef struct _MMBaseCallClass MMBaseCallClass;
typedef struct _MMBaseCallPrivate MMBaseCallPrivate;
#define MM_BASE_CALL_PATH "call-path"
#define MM_BASE_CALL_CONNECTION "call-connection"
#define MM_BASE_CALL_MODEM "call-modem"
struct _MMBaseCall {
MmGdbusCallSkeleton parent;
MMBaseCallPrivate *priv;
};
struct _MMBaseCallClass {
MmGdbusCallSkeletonClass parent;
/* Start the call */
void (* start) (MMBaseCall *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* start_finish) (MMBaseCall *self,
GAsyncResult *res,
GError **error);
/* Accept the call */
void (* accept) (MMBaseCall *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* accept_finish) (MMBaseCall *self,
GAsyncResult *res,
GError **error);
/* Hangup the call */
void (* hangup) (MMBaseCall *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* hangup_finish) (MMBaseCall *self,
GAsyncResult *res,
GError **error);
/* Delete the call */
void (* delete) (MMBaseCall *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean (* delete_finish) (MMBaseCall *self,
GAsyncResult *res,
GError **error);
};
GType mm_base_call_get_type (void);
/* This one can be overriden by plugins */
MMBaseCall *mm_base_call_new (MMBaseModem *modem);
MMBaseCall *mm_base_call_new_from_properties (MMBaseModem *modem,
MMCallProperties *properties,
GError **error);
void mm_base_call_export (MMBaseCall *self);
void mm_base_call_unexport (MMBaseCall *self);
const gchar *mm_base_call_get_path (MMBaseCall *self);
void mm_base_call_delete (MMBaseCall *self,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_base_call_delete_finish (MMBaseCall *self,
GAsyncResult *res,
GError **error);
#endif /* MM_BASE_CALL_H */

311
src/mm-call-list.c Normal file
View File

@@ -0,0 +1,311 @@
/* -*- 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) 2015 Marco Bascetta <marco.bascetta@sadel.it>
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <ModemManager.h>
#define _LIBMM_INSIDE_MM
#include <libmm-glib.h>
#include "mm-iface-modem-messaging.h"
#include "mm-call-list.h"
#include "mm-base-call.h"
#include "mm-log.h"
G_DEFINE_TYPE (MMCallList, mm_call_list, G_TYPE_OBJECT);
enum {
PROP_0,
PROP_MODEM,
PROP_LAST
};
static GParamSpec *properties[PROP_LAST];
enum {
SIGNAL_CALL_ADDED,
SIGNAL_CALL_DELETED,
SIGNAL_LAST
};
static guint signals[SIGNAL_LAST];
struct _MMCallListPrivate {
/* The owner modem */
MMBaseModem *modem;
/* List of call objects */
GList *list;
};
/*****************************************************************************/
guint
mm_call_list_get_count (MMCallList *self)
{
return g_list_length (self->priv->list);
}
GStrv
mm_call_list_get_paths (MMCallList *self)
{
GStrv path_list = NULL;
GList *l;
guint i;
path_list = g_new0 (gchar *,
1 + g_list_length (self->priv->list));
for (i = 0, l = self->priv->list; l; l = g_list_next (l)) {
const gchar *path;
/* Don't try to add NULL paths (not yet exported CALL objects) */
path = mm_base_call_get_path (MM_BASE_CALL (l->data));
if (path)
path_list[i++] = g_strdup (path);
}
return path_list;
}
/*****************************************************************************/
typedef struct {
MMCallList *self;
GSimpleAsyncResult *result;
gchar *path;
} DeleteCallContext;
static void
delete_call_context_complete_and_free (DeleteCallContext *ctx)
{
g_simple_async_result_complete (ctx->result);
g_object_unref (ctx->result);
g_object_unref (ctx->self);
g_free (ctx->path);
g_free (ctx);
}
gboolean
mm_call_list_delete_call_finish (MMCallList *self,
GAsyncResult *res,
GError **error)
{
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
}
static guint
cmp_call_by_path (MMBaseCall *call,
const gchar *path)
{
return g_strcmp0 (mm_base_call_get_path (call), path);
}
static void
delete_ready (MMBaseCall *call,
GAsyncResult *res,
DeleteCallContext *ctx)
{
GError *error = NULL;
GList *l;
if (!mm_base_call_delete_finish (call, res, &error)) {
/* We report the error */
g_simple_async_result_take_error (ctx->result, error);
delete_call_context_complete_and_free (ctx);
return;
}
/* The CALL was properly deleted, we now remove it from our list */
l = g_list_find_custom (ctx->self->priv->list,
ctx->path,
(GCompareFunc)cmp_call_by_path);
if (l) {
g_object_unref (MM_BASE_CALL (l->data));
ctx->self->priv->list = g_list_delete_link (ctx->self->priv->list, l);
}
/* We don't need to unref the CALL any more, but we can use the
* reference we got in the method, which is the one kept alive
* during the async operation. */
mm_base_call_unexport (call);
g_signal_emit (ctx->self,
signals[SIGNAL_CALL_DELETED], 0,
ctx->path);
g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE);
delete_call_context_complete_and_free (ctx);
}
void
mm_call_list_delete_call (MMCallList *self,
const gchar *call_path,
GAsyncReadyCallback callback,
gpointer user_data)
{
DeleteCallContext *ctx;
GList *l;
l = g_list_find_custom (self->priv->list,
(gpointer)call_path,
(GCompareFunc)cmp_call_by_path);
if (!l) {
g_simple_async_report_error_in_idle (G_OBJECT (self),
callback,
user_data,
MM_CORE_ERROR,
MM_CORE_ERROR_NOT_FOUND,
"No CALL found with path '%s'",
call_path);
return;
}
/* Delete all CALL parts */
ctx = g_new0 (DeleteCallContext, 1);
ctx->self = g_object_ref (self);
ctx->path = g_strdup (call_path);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_call_list_delete_call);
mm_base_call_delete (MM_BASE_CALL (l->data),
(GAsyncReadyCallback)delete_ready,
ctx);
}
/*****************************************************************************/
void
mm_call_list_add_call (MMCallList *self,
MMBaseCall *call)
{
self->priv->list = g_list_prepend (self->priv->list, g_object_ref (call));
g_signal_emit (self, signals[SIGNAL_CALL_ADDED], 0,
mm_base_call_get_path (call),
FALSE);
}
/*****************************************************************************/
MMCallList *
mm_call_list_new (MMBaseModem *modem)
{
/* Create the object */
return g_object_new (MM_TYPE_CALL_LIST,
MM_CALL_LIST_MODEM, modem,
NULL);
}
static void
set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
MMCallList *self = MM_CALL_LIST (object);
switch (prop_id) {
case PROP_MODEM:
g_clear_object (&self->priv->modem);
self->priv->modem = g_value_dup_object (value);
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)
{
MMCallList *self = MM_CALL_LIST (object);
switch (prop_id) {
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_call_list_init (MMCallList *self)
{
/* Initialize private data */
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
MM_TYPE_CALL_LIST,
MMCallListPrivate);
}
static void
dispose (GObject *object)
{
MMCallList *self = MM_CALL_LIST (object);
g_clear_object (&self->priv->modem);
g_list_free_full (self->priv->list, (GDestroyNotify)g_object_unref);
G_OBJECT_CLASS (mm_call_list_parent_class)->dispose (object);
}
static void
mm_call_list_class_init (MMCallListClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (MMCallListPrivate));
/* Virtual methods */
object_class->get_property = get_property;
object_class->set_property = set_property;
object_class->dispose = dispose;
/* Properties */
properties[PROP_MODEM] =
g_param_spec_object (MM_CALL_LIST_MODEM,
"Modem",
"The Modem which owns this CALL list",
MM_TYPE_BASE_MODEM,
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_MODEM, properties[PROP_MODEM]);
/* Signals */
signals[SIGNAL_CALL_ADDED] =
g_signal_new (MM_CALL_ADDED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMCallListClass, call_added),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN);
signals[SIGNAL_CALL_DELETED] =
g_signal_new (MM_CALL_DELETED,
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (MMCallListClass, call_deleted),
NULL, NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE, 1, G_TYPE_STRING);
}

75
src/mm-call-list.h Normal file
View File

@@ -0,0 +1,75 @@
/* -*- 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) 2015 Marco Bascetta <marco.bascetta@sadel.it>
*/
#ifndef MM_CALL_LIST_H
#define MM_CALL_LIST_H
#include <glib.h>
#include <glib-object.h>
#include "mm-base-modem.h"
#include "mm-base-call.h"
#define MM_TYPE_CALL_LIST (mm_call_list_get_type ())
#define MM_CALL_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_CALL_LIST, MMCallList))
#define MM_CALL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_CALL_LIST, MMCallListClass))
#define MM_IS_CALL_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_CALL_LIST))
#define MM_IS_CALL_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_CALL_LIST))
#define MM_CALL_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_CALL_LIST, MMCallListClass))
typedef struct _MMCallList MMCallList;
typedef struct _MMCallListClass MMCallListClass;
typedef struct _MMCallListPrivate MMCallListPrivate;
#define MM_CALL_LIST_MODEM "call-list-modem"
#define MM_CALL_ADDED "call-added"
#define MM_CALL_DELETED "call-deleted"
struct _MMCallList {
GObject parent;
MMCallListPrivate *priv;
};
struct _MMCallListClass {
GObjectClass parent;
/* Signals */
void (*call_added) (MMCallList *self,
const gchar *call_path,
gboolean received);
void (*call_deleted) (MMCallList *self,
const gchar *call_path);
};
GType mm_call_list_get_type (void);
MMCallList *mm_call_list_new (MMBaseModem *modem);
GStrv mm_call_list_get_paths (MMCallList *self);
guint mm_call_list_get_count (MMCallList *self);
void mm_call_list_add_call (MMCallList *self,
MMBaseCall *call);
void mm_call_list_delete_call (MMCallList *self,
const gchar *call_path,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_call_list_delete_call_finish (MMCallList *self,
GAsyncResult *res,
GError **error);
#endif /* MM_CALL_LIST_H */