libmm-glib: added support for Modem.Voice and Call interfaces

This commit is contained in:
Riccardo Vangelisti
2015-04-27 11:38:57 +02:00
committed by Aleksander Morgado
parent 0feb4acef4
commit 0bf4ad6b66
14 changed files with 1968 additions and 0 deletions

View File

@@ -120,6 +120,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* Copyright (C) 2008 - 2009 Novell, Inc. * Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2012 Red Hat, Inc. * Copyright (C) 2009 - 2012 Red Hat, Inc.
* Copyright (C) 2011 - 2012 Google, Inc. * Copyright (C) 2011 - 2012 Google, Inc.
* Copyright (C) 2015 - Riccardo Vangelisti riccardo.vangelisti@sadel.it
* Copyright (C) 2015 - Marco Bascetta marco.bascetta@sadel.it
*/ */
#ifndef _MODEM_MANAGER_NAMES_H_ #ifndef _MODEM_MANAGER_NAMES_H_
@@ -133,6 +135,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define MM_DBUS_BEARER_PREFIX MM_DBUS_PATH "/Bearer" #define MM_DBUS_BEARER_PREFIX MM_DBUS_PATH "/Bearer"
#define MM_DBUS_SIM_PREFIX MM_DBUS_PATH "/SIM" #define MM_DBUS_SIM_PREFIX MM_DBUS_PATH "/SIM"
#define MM_DBUS_SMS_PREFIX MM_DBUS_PATH "/SMS" #define MM_DBUS_SMS_PREFIX MM_DBUS_PATH "/SMS"
#define MM_DBUS_CALL_PREFIX MM_DBUS_PATH "/Call"
/* Prefix for DBus errors */ /* Prefix for DBus errors */
#define MM_DBUS_ERROR_PREFIX "org.freedesktop.ModemManager1.Error" #define MM_DBUS_ERROR_PREFIX "org.freedesktop.ModemManager1.Error"

View File

@@ -40,6 +40,10 @@ libmm_glib_la_SOURCES = \
mm-sms.c \ mm-sms.c \
mm-modem-messaging.h \ mm-modem-messaging.h \
mm-modem-messaging.c \ mm-modem-messaging.c \
mm-modem-voice.h \
mm-modem-voice.c \
mm-call.h \
mm-call.c \
mm-bearer.h \ mm-bearer.h \
mm-bearer.c \ mm-bearer.c \
mm-common-helpers.h \ mm-common-helpers.h \
@@ -52,6 +56,8 @@ libmm_glib_la_SOURCES = \
mm-bearer-properties.c \ mm-bearer-properties.c \
mm-sms-properties.h \ mm-sms-properties.h \
mm-sms-properties.c \ mm-sms-properties.c \
mm-call-properties.h \
mm-call-properties.c \
mm-bearer-ip-config.h \ mm-bearer-ip-config.h \
mm-bearer-ip-config.c \ mm-bearer-ip-config.c \
mm-location-common.h \ mm-location-common.h \
@@ -116,11 +122,14 @@ include_HEADERS = \
mm-modem-simple.h \ mm-modem-simple.h \
mm-sim.h \ mm-sim.h \
mm-sms.h \ mm-sms.h \
mm-modem-voice.h \
mm-call.h \
mm-bearer.h \ mm-bearer.h \
mm-simple-status.h \ mm-simple-status.h \
mm-simple-connect-properties.h \ mm-simple-connect-properties.h \
mm-bearer-properties.h \ mm-bearer-properties.h \
mm-sms-properties.h \ mm-sms-properties.h \
mm-call-properties.h \
mm-bearer-ip-config.h \ mm-bearer-ip-config.h \
mm-location-common.h \ mm-location-common.h \
mm-location-3gpp.h \ mm-location-3gpp.h \

View File

@@ -12,6 +12,7 @@ GENERATED_H = \
mm-gdbus-manager.h \ mm-gdbus-manager.h \
mm-gdbus-sim.h \ mm-gdbus-sim.h \
mm-gdbus-sms.h \ mm-gdbus-sms.h \
mm-gdbus-call.h \
mm-gdbus-bearer.h \ mm-gdbus-bearer.h \
mm-gdbus-modem.h mm-gdbus-modem.h
@@ -22,6 +23,7 @@ GENERATED_C = \
mm-gdbus-manager.c \ mm-gdbus-manager.c \
mm-gdbus-sim.c \ mm-gdbus-sim.c \
mm-gdbus-sms.c \ mm-gdbus-sms.c \
mm-gdbus-call.c \
mm-gdbus-bearer.c \ mm-gdbus-bearer.c \
mm-gdbus-modem.c mm-gdbus-modem.c
@@ -29,9 +31,11 @@ GENERATED_DOC = \
mm-gdbus-doc-org.freedesktop.ModemManager1.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Sim.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Sim.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Sms.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Sms.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Call.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Bearer.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Bearer.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Messaging.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Messaging.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Voice.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Location.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Location.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Time.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Time.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Firmware.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Firmware.xml \
@@ -98,6 +102,7 @@ mm_gdbus_modem_generated = \
mm-gdbus-modem.c \ mm-gdbus-modem.c \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Messaging.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Messaging.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Voice.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Location.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Location.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Time.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Time.xml \
mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Firmware.xml \ mm-gdbus-doc-org.freedesktop.ModemManager1.Modem.Firmware.xml \
@@ -110,6 +115,7 @@ mm_gdbus_modem_generated = \
mm_gdbus_modem_deps = \ mm_gdbus_modem_deps = \
$(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.xml \ $(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.xml \
$(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Messaging.xml \ $(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Messaging.xml \
$(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Voice.xml \
$(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Location.xml \ $(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Location.xml \
$(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Time.xml \ $(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Time.xml \
$(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Firmware.xml \ $(top_srcdir)/introspection/org.freedesktop.ModemManager1.Modem.Firmware.xml \
@@ -175,6 +181,20 @@ $(mm_gdbus_sms_generated): $(top_srcdir)/introspection/org.freedesktop.ModemMana
$< \ $< \
$(NULL) $(NULL)
# Call interface
mm_gdbus_call_generated = \
mm-gdbus-call.h \
mm-gdbus-call.c \
mm-gdbus-doc-org.freedesktop.ModemManager1.Call.xml
$(mm_gdbus_call_generated): $(top_srcdir)/introspection/org.freedesktop.ModemManager1.Call.xml
$(AM_V_GEN) $(GDBUS_CODEGEN) \
--interface-prefix org.freedesktop.ModemManager1. \
--c-namespace=MmGdbus \
--generate-docbook mm-gdbus-doc \
--generate-c-code mm-gdbus-call \
$< \
$(NULL)
nodist_libmm_generated_la_SOURCES = \ nodist_libmm_generated_la_SOURCES = \
$(GENERATED_H) \ $(GENERATED_H) \
$(GENERATED_C) $(GENERATED_C)

View File

@@ -41,6 +41,7 @@
# include <mm-modem-simple.h> # include <mm-modem-simple.h>
# include <mm-modem-location.h> # include <mm-modem-location.h>
# include <mm-modem-messaging.h> # include <mm-modem-messaging.h>
# include <mm-modem-voice.h>
# include <mm-modem-time.h> # include <mm-modem-time.h>
# include <mm-modem-firmware.h> # include <mm-modem-firmware.h>
# include <mm-modem-signal.h> # include <mm-modem-signal.h>

View File

@@ -0,0 +1,478 @@
/* -*- 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>
*/
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include "mm-errors-types.h"
#include "mm-enums-types.h"
#include "mm-common-helpers.h"
#include "mm-call-properties.h"
/**
* SECTION: mm-call-properties
* @title: MMCallProperties
* @short_description: Helper object to handle CALL properties.
*
* The #MMCallProperties is an object handling the properties to be set
* in newly created CALL objects.
*
* This object is created by the user and passed to ModemManager with either
* mm_modem_voice_create() or mm_modem_voice_create_sync().
*/
G_DEFINE_TYPE (MMCallProperties, mm_call_properties, G_TYPE_OBJECT)
#define PROPERTY_NUMBER "number"
#define PROPERTY_DIRECTION "direction"
#define PROPERTY_STATE_REASON "state-reason"
#define PROPERTY_STATE "state"
struct _MMCallPropertiesPrivate {
gchar *number;
MMCallDirection direction;
MMCallState state;
MMCallStateReason state_reason;
};
/*****************************************************************************/
/**
* mm_call_properties_set_number:
* @self: A #MMCallProperties.
* @text: The number to set, in UTF-8.
*
* Sets the call number.
*/
void
mm_call_properties_set_number (MMCallProperties *self,
const gchar *number)
{
g_return_if_fail (MM_IS_CALL_PROPERTIES (self));
g_free (self->priv->number);
self->priv->number = g_strdup (number);
}
/**
* mm_call_properties_get_number:
* @self: A #MMCallProperties.
*
* Gets the number, in UTF-8.
*
* Returns: the call number, or %NULL if it doesn't contain any (anonymous caller). Do not free the returned value, it is owned by @self.
*/
const gchar *
mm_call_properties_get_number (MMCallProperties *self)
{
g_return_val_if_fail (MM_IS_CALL_PROPERTIES (self), NULL);
return self->priv->number;
}
/*****************************************************************************/
/**
* mm_call_properties_set_direction:
* @self: A #MMCallProperties.
* @direction: the call direction
*
* Sets the call direction
*/
void
mm_call_properties_set_direction (MMCallProperties *self,
MMCallDirection direction)
{
g_return_if_fail (MM_IS_CALL_PROPERTIES (self));
self->priv->direction = direction;
}
/**
* mm_call_properties_get_direction:
* @self: A #MMCallProperties.
*
* Gets the call direction.
*
* Returns: the call direction.
*/
MMCallDirection
mm_call_properties_get_direction (MMCallProperties *self)
{
g_return_val_if_fail (MM_IS_CALL_PROPERTIES (self), MM_CALL_DIRECTION_UNKNOWN);
return self->priv->direction;
}
/*****************************************************************************/
/**
* mm_call_properties_set_state:
* @self: A #MMCallProperties.
* @state: the call state
*
* Sets the call state
*/
void
mm_call_properties_set_state (MMCallProperties *self,
MMCallState state)
{
g_return_if_fail (MM_IS_CALL_PROPERTIES (self));
self->priv->state = state;
}
/**
* mm_call_properties_get_state:
* @self: A #MMCallProperties.
*
* Gets the call state.
*
* Returns: the call state.
*/
MMCallState
mm_call_properties_get_state (MMCallProperties *self)
{
g_return_val_if_fail (MM_IS_CALL_PROPERTIES (self), MM_CALL_STATE_UNKNOWN);
return self->priv->state;
}
/*****************************************************************************/
/**
* mm_call_properties_set_state_reason:
* @self: A #MMCallProperties.
* @state_reason: the call state_reason
*
* Sets the call state reason
*/
void
mm_call_properties_set_state_reason (MMCallProperties *self,
MMCallStateReason state_reason)
{
g_return_if_fail (MM_IS_CALL_PROPERTIES (self));
self->priv->state_reason = state_reason;
}
/**
* mm_call_properties_get_state_reason:
* @self: A #MMCallProperties.
*
* Gets the call state reason.
*
* Returns: the call state reason.
*/
MMCallStateReason
mm_call_properties_get_state_reason (MMCallProperties *self)
{
g_return_val_if_fail (MM_IS_CALL_PROPERTIES (self), MM_CALL_STATE_UNKNOWN);
return self->priv->state_reason;
}
/*****************************************************************************/
GVariant *
mm_call_properties_get_dictionary (MMCallProperties *self)
{
GVariantBuilder builder;
/* We do allow NULL */
if (!self)
return NULL;
g_return_val_if_fail (MM_IS_CALL_PROPERTIES (self), NULL);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
if (self->priv->number)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_NUMBER,
g_variant_new_string (self->priv->number));
if (self->priv->state_reason != MM_CALL_STATE_REASON_UNKNOWN)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_STATE_REASON,
g_variant_new_uint32 (self->priv->state_reason));
if (self->priv->state != MM_CALL_STATE_UNKNOWN)
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_STATE,
g_variant_new_uint32 (self->priv->state));
g_variant_builder_add (&builder,
"{sv}",
PROPERTY_DIRECTION,
g_variant_new_uint32 (self->priv->direction));
return g_variant_ref_sink (g_variant_builder_end (&builder));
}
/*****************************************************************************/
static gboolean
consume_string (MMCallProperties *self,
const gchar *key,
const gchar *value,
GError **error)
{
if (g_str_equal (key, PROPERTY_NUMBER)) {
mm_call_properties_set_number (self, value);
} else if (g_str_equal (key, PROPERTY_DIRECTION)) {
MMCallDirection direction;
GError *inner_error = NULL;
direction = mm_common_get_call_direction_from_string (value, &inner_error);
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
}
mm_call_properties_set_direction(self, direction);
} else if (g_str_equal (key, PROPERTY_STATE)) {
MMCallState state;
GError *inner_error = NULL;
state = mm_common_get_call_state_from_string (value, &inner_error);
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
}
mm_call_properties_set_state(self, state);
} else if (g_str_equal (key, PROPERTY_STATE_REASON)) {
MMCallStateReason state_reason;
GError *inner_error = NULL;
state_reason = mm_common_get_call_state_reason_from_string (value, &inner_error);
if (inner_error) {
g_propagate_error (error, inner_error);
return FALSE;
}
mm_call_properties_set_state_reason(self, state_reason);
} else {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Invalid properties string, unexpected key '%s'",
key);
return FALSE;
}
return TRUE;
}
typedef struct {
MMCallProperties *properties;
GError *error;
} ParseKeyValueContext;
static gboolean
key_value_foreach (const gchar *key,
const gchar *value,
ParseKeyValueContext *ctx)
{
return consume_string (ctx->properties,
key,
value,
&ctx->error);
}
MMCallProperties *
mm_call_properties_new_from_string (const gchar *str,
GError **error)
{
ParseKeyValueContext ctx;
ctx.properties = mm_call_properties_new ();
ctx.error = NULL;
mm_common_parse_key_value_string (str,
&ctx.error,
(MMParseKeyValueForeachFn)key_value_foreach,
&ctx);
/* If error, destroy the object */
if (ctx.error) {
g_propagate_error (error, ctx.error);
g_object_unref (ctx.properties);
ctx.properties = NULL;
}
return ctx.properties;
}
/*****************************************************************************/
static gboolean
consume_variant (MMCallProperties *properties,
const gchar *key,
GVariant *value,
GError **error)
{
if (g_str_equal (key, PROPERTY_NUMBER))
mm_call_properties_set_number (
properties,
g_variant_get_string (value, NULL));
else if (g_str_equal (key, PROPERTY_DIRECTION))
mm_call_properties_set_direction (
properties,
g_variant_get_uint32 (value));
else if (g_str_equal (key, PROPERTY_STATE))
mm_call_properties_set_state (
properties,
g_variant_get_uint32 (value));
else if (g_str_equal (key, PROPERTY_STATE_REASON))
mm_call_properties_set_state_reason (
properties,
g_variant_get_uint32 (value));
else {
/* Set error */
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Invalid properties dictionary, unexpected key '%s'",
key);
return FALSE;
}
return TRUE;
}
MMCallProperties *
mm_call_properties_new_from_dictionary (GVariant *dictionary,
GError **error)
{
GError *inner_error = NULL;
GVariantIter iter;
gchar *key;
GVariant *value;
MMCallProperties *properties;
properties = mm_call_properties_new ();
if (!dictionary)
return properties;
if (!g_variant_is_of_type (dictionary, G_VARIANT_TYPE ("a{sv}"))) {
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Cannot create call properties from dictionary: "
"invalid variant type received");
g_object_unref (properties);
return NULL;
}
g_variant_iter_init (&iter, dictionary);
while (!inner_error &&
g_variant_iter_next (&iter, "{sv}", &key, &value)) {
consume_variant (properties,
key,
value,
&inner_error);
g_free (key);
g_variant_unref (value);
}
/* If error, destroy the object */
if (inner_error) {
g_propagate_error (error, inner_error);
g_object_unref (properties);
properties = NULL;
}
return properties;
}
/*****************************************************************************/
/**
* mm_call_properties_dup:
* @orig: a #MMCallProperties
*
* Returns a copy of @orig.
*
* Returns: (transfer full): a #MMCallProperties
*/
MMCallProperties *
mm_call_properties_dup (MMCallProperties *orig)
{
GVariant *dict;
MMCallProperties *copy;
GError *error = NULL;
g_return_val_if_fail (MM_IS_CALL_PROPERTIES (orig), NULL);
dict = mm_call_properties_get_dictionary (orig);
copy = mm_call_properties_new_from_dictionary (dict, &error);
g_assert_no_error (error);
g_variant_unref (dict);
return copy;
}
/*****************************************************************************/
/**
* mm_call_properties_new:
*
* Creates a new empty #MMCallProperties.
*
* Returns: (transfer full): a #MMCallProperties. The returned value should be freed with g_object_unref().
*/
MMCallProperties *
mm_call_properties_new (void)
{
return (MM_CALL_PROPERTIES (g_object_new (MM_TYPE_CALL_PROPERTIES, NULL)));
}
static void
mm_call_properties_init (MMCallProperties *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self),
MM_TYPE_CALL_PROPERTIES,
MMCallPropertiesPrivate);
self->priv->number = NULL;
self->priv->direction = MM_CALL_DIRECTION_UNKNOWN;
self->priv->state = MM_CALL_STATE_UNKNOWN;
self->priv->state_reason = MM_CALL_STATE_REASON_UNKNOWN;
}
static void
finalize (GObject *object)
{
MMCallProperties *self = MM_CALL_PROPERTIES (object);
g_free (self->priv->number);
G_OBJECT_CLASS (mm_call_properties_parent_class)->finalize (object);
}
static void
mm_call_properties_class_init (MMCallPropertiesClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof (MMCallPropertiesPrivate));
object_class->finalize = finalize;
}

View File

@@ -0,0 +1,94 @@
/* -*- 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_CALL_PROPERTIES_H
#define MM_CALL_PROPERTIES_H
#if !defined (__LIBMM_GLIB_H_INSIDE__) && !defined (LIBMM_GLIB_COMPILATION)
#error "Only <libmm-glib.h> can be included directly."
#endif
#include <ModemManager.h>
#include <glib-object.h>
G_BEGIN_DECLS
#define MM_TYPE_CALL_PROPERTIES (mm_call_properties_get_type ())
#define MM_CALL_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_CALL_PROPERTIES, MMCallProperties))
#define MM_CALL_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_CALL_PROPERTIES, MMCallPropertiesClass))
#define MM_IS_CALL_PROPERTIES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_CALL_PROPERTIES))
#define MM_IS_CALL_PROPERTIES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_CALL_PROPERTIES))
#define MM_CALL_PROPERTIES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_CALL_PROPERTIES, MMCallPropertiesClass))
typedef struct _MMCallProperties MMCallProperties;
typedef struct _MMCallPropertiesClass MMCallPropertiesClass;
typedef struct _MMCallPropertiesPrivate MMCallPropertiesPrivate;
/**
* MMCallProperties:
*
* The #MMCallProperties structure contains private data and should only be
* accessed using the provided API.
*/
struct _MMCallProperties {
/*< private >*/
GObject parent;
MMCallPropertiesPrivate *priv;
};
struct _MMCallPropertiesClass {
/*< private >*/
GObjectClass parent;
};
GType mm_call_properties_get_type (void);
MMCallProperties *mm_call_properties_new (void);
void mm_call_properties_set_number (MMCallProperties *self,
const gchar *text);
void mm_call_properties_set_direction (MMCallProperties *self,
MMCallDirection direction);
void mm_call_properties_set_state_reason (MMCallProperties *self,
MMCallStateReason state_reason);
void mm_call_properties_set_state (MMCallProperties *self,
MMCallState state);
const gchar *mm_call_properties_get_number (MMCallProperties *self);
MMCallDirection mm_call_properties_get_direction (MMCallProperties *self);
MMCallStateReason mm_call_properties_get_state_reason(MMCallProperties *self);
MMCallState mm_call_properties_get_state (MMCallProperties *self);
/*****************************************************************************/
/* ModemManager/libmm-glib/mmcli specific methods */
#if defined (_LIBMM_INSIDE_MM) || \
defined (_LIBMM_INSIDE_MMCLI) || \
defined (LIBMM_GLIB_COMPILATION)
MMCallProperties *mm_call_properties_new_from_string (const gchar *str,
GError **error);
MMCallProperties *mm_call_properties_new_from_dictionary (GVariant *dictionary,
GError **error);
MMCallProperties *mm_call_properties_dup (MMCallProperties *orig);
GVariant *mm_call_properties_get_dictionary (MMCallProperties *self);
#endif
G_END_DECLS
#endif /* MM_CALL_PROPERTIES_H */

422
libmm-glib/mm-call.c Normal file
View File

@@ -0,0 +1,422 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* libmm -- Access modem status & information from glib applications
*
* 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>
*/
#include "string.h"
#include "mm-helpers.h"
#include "mm-call.h"
#include "mm-modem.h"
/**
* SECTION: mm-call
* @title: MMCall
* @short_description: The call interface
*
* The #MMCall is an object providing access to the methods, signals and
* properties of the call interface.
*
* When the call is exposed and available in the bus, it is ensured that at
* least this interface is also available.
*/
G_DEFINE_TYPE (MMCall, mm_call, MM_GDBUS_TYPE_CALL_PROXY)
/*****************************************************************************/
/**
* mm_call_get_path:
* @self: A #MMCall.
*
* Gets the DBus path of the #MMCall object.
*
* Returns: (transfer none): The DBus path of the #MMCall object.
*/
const gchar *
mm_call_get_path (MMCall *self)
{
g_return_val_if_fail (MM_IS_CALL (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (
g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
}
/**
* mm_call_dup_path:
* @self: A #MMCall.
*
* Gets a copy of the DBus path of the #MMCall object.
*
* Returns: (transfer full): The DBus path of the #MMCall object. The returned value should be freed with g_free().
*/
gchar *
mm_call_dup_path (MMCall *self)
{
gchar *value;
g_return_val_if_fail (MM_IS_CALL (self), NULL);
g_object_get (G_OBJECT (self),
"g-object-path", &value,
NULL);
RETURN_NON_EMPTY_STRING (value);
}
/*****************************************************************************/
/**
* mm_call_get_number:
* @self: A #MMCall.
*
* Gets the call number. In outgoing calls contains the dialing number or
* the remote number in incoming calls
*
* <warning>The returned value is only valid until the property changes so
* it is only safe to use this function on the thread where
* @self was constructed. Use mm_call_dup_number() if on another
* thread.</warning>
*
* Returns: (transfer none): The number, or %NULL if it couldn't be retrieved.
*/
const gchar *
mm_call_get_number (MMCall *self)
{
g_return_val_if_fail (MM_IS_CALL (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (
mm_gdbus_call_get_number (MM_GDBUS_CALL (self)));
}
/**
* mm_call_dup_number:
* @self: A #MMCall.
*
* Gets the call number. In outgoing calls contains the dialing number or
* the remote number in incoming calls
*
* Returns: (transfer full): The number, or %NULL if it couldn't be retrieved. The returned value should be freed with g_free().
*/
gchar *
mm_call_dup_number (MMCall *self)
{
g_return_val_if_fail (MM_IS_CALL (self), NULL);
RETURN_NON_EMPTY_STRING (
mm_gdbus_call_dup_number (MM_GDBUS_CALL (self)));
}
/*****************************************************************************/
/**
* mm_call_get_direction:
* @self: A #MMCall.
*
* Gets the call direction.
*
* Returns: a #MMCallDirection.
*/
MMCallDirection
mm_call_get_direction (MMCall *self)
{
g_return_val_if_fail (MM_IS_CALL (self), MM_CALL_DIRECTION_INCOMING);
return (MMCallDirection) mm_gdbus_call_get_direction (MM_GDBUS_CALL (self));
}
/*****************************************************************************/
/**
* mm_call_get_state:
* @self: A #MMCall.
*
* Gets the current state of call.
*
* Returns: a #MMCallState.
*/
MMCallState
mm_call_get_state (MMCall *self)
{
g_return_val_if_fail (MM_IS_CALL (self), MM_CALL_STATE_UNKNOWN);
return (MMCallState) mm_gdbus_call_get_state (MM_GDBUS_CALL (self));
}
/*****************************************************************************/
/**
* mm_call_get_state_reason:
* @self: A #MMCall.
*
* Gets the reason of why the call changes its state.
*
* Returns: a #MMCallStateReason.
*/
MMCallStateReason
mm_call_get_state_reason (MMCall *self)
{
g_return_val_if_fail (MM_IS_CALL (self), MM_CALL_STATE_REASON_UNKNOWN);
return (MMCallStateReason) mm_gdbus_call_get_state_reason (MM_GDBUS_CALL (self));
}
/*****************************************************************************/
/**
* mm_call_start_finish:
* @self: A #MMCall.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_call_start().
* @error: Return location for error or %NULL.
*
* Finishes an operation started with mm_call_start().
*
* Returns: %TRUE if the operation succeded, %FALSE if @error is set.
*/
gboolean
mm_call_start_finish (MMCall *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (MM_IS_CALL (self), FALSE);
return mm_gdbus_call_call_start_finish (MM_GDBUS_CALL (self), res, error);
}
/**
* mm_call_start:
* @self: A #MMCall.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
* @user_data: User data to pass to @callback.
*
* Asynchronously requests to queue the call.
*
* Call objects can only be executed once.
*
* When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
* You can then call mm_call_start_finish() to get the result of the operation.
*
* See mm_call_start_sync() for the synchronous, blocking version of this method.
*/
void
mm_call_start (MMCall *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_CALL (self));
mm_gdbus_call_call_start (MM_GDBUS_CALL (self),
cancellable,
callback,
user_data);
}
/**
* mm_call_start_sync:
* @self: A #MMCall.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
* Synchronously requests to queue the call for delivery.
*
* Call objects can only be sent once.
*
* The calling thread is blocked until a reply is received.
* See mm_call_start() for the asynchronous version of this method.
*
* Returns: %TRUE if the operation succeded, %FALSE if @error is set.
*/
gboolean
mm_call_start_sync (MMCall *self,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (MM_IS_CALL (self), FALSE);
return mm_gdbus_call_call_start_sync (MM_GDBUS_CALL (self),
cancellable,
error);
}
/*****************************************************************************/
/**
* mm_call_accept_finish:
* @self: A #MMCall.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_call_accept().
* @error: Return location for error or %NULL.
*
* Finishes an operation accepted with mm_call_accept().
*
* Returns: %TRUE if the operation succeded, %FALSE if @error is set.
*/
gboolean
mm_call_accept_finish (MMCall *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (MM_IS_CALL (self), FALSE);
return mm_gdbus_call_call_accept_finish (MM_GDBUS_CALL (self), res, error);
}
/**
* mm_call_accept:
* @self: A #MMCall.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
* @user_data: User data to pass to @callback.
*
* Asynchronously requests to accept the incoming call.
*
* Call objects can only be executed once.
*
* When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
* You can then call mm_call_accept_finish() to get the result of the operation.
*
* See mm_call_accept_sync() for the synchronous, blocking version of this method.
*/
void
mm_call_accept (MMCall *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_CALL (self));
mm_gdbus_call_call_accept (MM_GDBUS_CALL (self),
cancellable,
callback,
user_data);
}
/**
* mm_call_accept_sync:
* @self: A #MMCall.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
* Synchronously requests to accept the incoming call.
*
* Call objects can only be sent once.
*
* The calling thread is blocked until an incoming call is ready.
* See mm_call_accept() for the asynchronous version of this method.
*
* Returns: %TRUE if the operation succeded, %FALSE if @error is set.
*/
gboolean
mm_call_accept_sync (MMCall *self,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (MM_IS_CALL (self), FALSE);
return mm_gdbus_call_call_accept_sync (MM_GDBUS_CALL (self),
cancellable,
error);
}
/*****************************************************************************/
/**
* mm_call_hangup_finish:
* @self: A #MMCall.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_call_hangup().
* @error: Return location for error or %NULL.
*
* Finishes an operation hanguped with mm_call_hangup().
*
* Returns: %TRUE if the operation succeded, %FALSE if @error is set.
*/
gboolean
mm_call_hangup_finish (MMCall *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (MM_IS_CALL (self), FALSE);
return mm_gdbus_call_call_hangup_finish (MM_GDBUS_CALL (self), res, error);
}
/**
* mm_call_hangup:
* @self: A #MMCall.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
* @user_data: User data to pass to @callback.
*
* Asynchronously requests to hangup the call.
*
* Call objects can only be executed once.
*
* When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
* You can then call mm_call_hangup_finish() to get the result of the operation.
*
* See mm_call_hangup_sync() for the synchronous, blocking version of this method.
*/
void
mm_call_hangup (MMCall *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_CALL (self));
mm_gdbus_call_call_hangup (MM_GDBUS_CALL (self),
cancellable,
callback,
user_data);
}
/**
* mm_call_hangup_sync:
* @self: A #MMCall.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
* Synchronously requests to hangup the call.
*
* Call objects can only be sent once.
*
* The calling thread is blocked until an incoming call is ready.
* See mm_call_hangup() for the asynchronous version of this method.
*
* Returns: %TRUE if the operation succeded, %FALSE if @error is set.
*/
gboolean
mm_call_hangup_sync (MMCall *self,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (MM_IS_CALL (self), FALSE);
return mm_gdbus_call_call_hangup_sync (MM_GDBUS_CALL (self),
cancellable,
error);
}
/*****************************************************************************/
static void
mm_call_init (MMCall *self)
{
}
static void
mm_call_class_init (MMCallClass *call_class)
{
}

118
libmm-glib/mm-call.h Normal file
View File

@@ -0,0 +1,118 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* libmm -- Access modem status & information from glib applications
*
* 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_CALL_H_
#define _MM_CALL_H_
#if !defined (__LIBMM_GLIB_H_INSIDE__) && !defined (LIBMM_GLIB_COMPILATION)
#error "Only <libmm-glib.h> can be included directly."
#endif
#include <ModemManager.h>
#include "mm-gdbus-call.h"
#include "mm-call-properties.h"
G_BEGIN_DECLS
#define MM_TYPE_CALL (mm_call_get_type ())
#define MM_CALL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_CALL, MMCall))
#define MM_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_CALL, MMCallClass))
#define MM_IS_CALL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_CALL))
#define MM_IS_CALL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_CALL))
#define MM_CALL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_CALL, MMCallClass))
typedef struct _MMCall MMCall;
typedef struct _MMCallClass MMCallClass;
/**
* MMCall:
*
* The #MMCall structure contains private data and should only be accessed
* using the provided API.
*/
struct _MMCall {
/*< private >*/
MmGdbusCallProxy parent;
gpointer unused;
};
struct _MMCallClass {
/*< private >*/
MmGdbusCallProxyClass parent;
};
GType mm_call_get_type (void);
const gchar *mm_call_get_path (MMCall *self);
gchar *mm_call_dup_path (MMCall *self);
const gchar *mm_call_get_number (MMCall *self);
gchar *mm_call_dup_number (MMCall *self);
MMCallState mm_call_get_state (MMCall *self);
MMCallStateReason mm_call_get_state_reason (MMCall *self);
MMCallDirection mm_call_get_direction (MMCall *self);
void mm_call_start (MMCall *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_call_start_finish (MMCall *self,
GAsyncResult *res,
GError **error);
gboolean mm_call_start_sync (MMCall *self,
GCancellable *cancellable,
GError **error);
void mm_call_accept (MMCall *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_call_accept_finish (MMCall *self,
GAsyncResult *res,
GError **error);
gboolean mm_call_accept_sync (MMCall *self,
GCancellable *cancellable,
GError **error);
void mm_call_hangup (MMCall *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_call_hangup_finish (MMCall *self,
GAsyncResult *res,
GError **error);
gboolean mm_call_hangup_sync (MMCall *self,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* _MM_CALL_H_ */

View File

@@ -1001,6 +1001,72 @@ mm_common_get_sms_cdma_service_category_from_string (const gchar *str,
return MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN; return MM_SMS_CDMA_SERVICE_CATEGORY_UNKNOWN;
} }
MMCallDirection
mm_common_get_call_direction_from_string (const gchar *str,
GError **error)
{
GEnumClass *enum_class;
guint i;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_CALL_DIRECTION));
for (i = 0; enum_class->values[i].value_nick; i++) {
if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick))
return enum_class->values[i].value;
}
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Couldn't match '%s' with a valid MMCallDirection value",
str);
return MM_CALL_DIRECTION_UNKNOWN;
}
MMCallState
mm_common_get_call_state_from_string (const gchar *str,
GError **error)
{
GEnumClass *enum_class;
guint i;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_CALL_STATE));
for (i = 0; enum_class->values[i].value_nick; i++) {
if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick))
return enum_class->values[i].value;
}
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Couldn't match '%s' with a valid MMCallState value",
str);
return MM_CALL_STATE_UNKNOWN;
}
MMCallStateReason
mm_common_get_call_state_reason_from_string (const gchar *str,
GError **error)
{
GEnumClass *enum_class;
guint i;
enum_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_CALL_STATE_REASON));
for (i = 0; enum_class->values[i].value_nick; i++) {
if (!g_ascii_strcasecmp (str, enum_class->values[i].value_nick))
return enum_class->values[i].value;
}
g_set_error (error,
MM_CORE_ERROR,
MM_CORE_ERROR_INVALID_ARGS,
"Couldn't match '%s' with a valid MMCallStateReason value",
str);
return MM_CALL_STATE_REASON_UNKNOWN;
}
MMOmaFeature MMOmaFeature
mm_common_get_oma_features_from_string (const gchar *str, mm_common_get_oma_features_from_string (const gchar *str,
GError **error) GError **error)

View File

@@ -63,6 +63,14 @@ MMSmsCdmaTeleserviceId mm_common_get_sms_cdma_teleservice_id_from_string (co
GError **error); GError **error);
MMSmsCdmaServiceCategory mm_common_get_sms_cdma_service_category_from_string (const gchar *str, MMSmsCdmaServiceCategory mm_common_get_sms_cdma_service_category_from_string (const gchar *str,
GError **error); GError **error);
MMCallDirection mm_common_get_call_direction_from_string (const gchar *str,
GError **error);
MMCallState mm_common_get_call_state_from_string (const gchar *str,
GError **error);
MMCallStateReason mm_common_get_call_state_reason_from_string (const gchar *str,
GError **error);
MMOmaFeature mm_common_get_oma_features_from_string (const gchar *str, MMOmaFeature mm_common_get_oma_features_from_string (const gchar *str,
GError **error); GError **error);
MMOmaSessionType mm_common_get_oma_session_type_from_string (const gchar *str, MMOmaSessionType mm_common_get_oma_session_type_from_string (const gchar *str,

599
libmm-glib/mm-modem-voice.c Normal file
View File

@@ -0,0 +1,599 @@
/* -*- 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) 2015 Aleksander Morgado <aleksander@gnu.org>
* Copyright (C) 2015 Marco Bascetta <marco.bascetta@sadel.it>
*/
#include <gio/gio.h>
#include "mm-helpers.h"
#include "mm-common-helpers.h"
#include "mm-errors-types.h"
#include "mm-modem-voice.h"
/**
* SECTION: mm-modem-voice
* @title: MMModemVoice
* @short_description: The Voice interface
*
* The #MMModemVoice is an object providing access to the methods, signals and
* properties of the Voice interface.
*
* The Voice interface is exposed whenever a modem has voice capabilities.
*/
G_DEFINE_TYPE (MMModemVoice, mm_modem_voice, MM_GDBUS_TYPE_MODEM_VOICE_PROXY)
/*****************************************************************************/
/**
* mm_modem_voice_get_path:
* @self: A #MMModemVoice.
*
* 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_voice_get_path (MMModemVoice *self)
{
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), NULL);
RETURN_NON_EMPTY_CONSTANT_STRING (
g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
}
/**
* mm_modem_voice_dup_path:
* @self: A #MMModemVoice.
*
* 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_voice_dup_path (MMModemVoice *self)
{
gchar *value;
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), NULL);
g_object_get (G_OBJECT (self),
"g-object-path", &value,
NULL);
RETURN_NON_EMPTY_STRING (value);
}
/*****************************************************************************/
typedef struct {
MMModemVoice *self;
GSimpleAsyncResult *result;
GCancellable *cancellable;
gchar **call_paths;
GList *call_objects;
guint i;
} ListCallContext;
static void
call_object_list_free (GList *list)
{
g_list_free_full (list, (GDestroyNotify) g_object_unref);
}
static void
list_call_context_complete_and_free (ListCallContext *ctx)
{
g_simple_async_result_complete_in_idle (ctx->result);
g_strfreev (ctx->call_paths);
call_object_list_free (ctx->call_objects);
g_object_unref (ctx->result);
if (ctx->cancellable)
g_object_unref (ctx->cancellable);
g_object_ref (ctx->self);
g_slice_free (ListCallContext, ctx);
}
/**
* mm_modem_voice_list_call_finish:
* @self: A #MMModem.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_voice_list_call().
* @error: Return location for error or %NULL.
*
* Finishes an operation started with mm_modem_voice_list_call().
*
* Returns: (element-type ModemManager.Call) (transfer full): A list of #MMCall objects, or #NULL if either not found or @error is set. The returned value should be freed with g_list_free_full() using g_object_unref() as #GDestroyNotify function.
*/
GList *
mm_modem_voice_list_call_finish (MMModemVoice *self,
GAsyncResult *res,
GError **error)
{
GList *list;
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
list = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
/* The list we got, including the objects within, is owned by the async result;
* so we'll make sure we return a new list */
g_list_foreach (list, (GFunc)g_object_ref, NULL);
return g_list_copy (list);
}
static void create_next_call (ListCallContext *ctx);
static void
list_build_object_ready (GDBusConnection *connection,
GAsyncResult *res,
ListCallContext *ctx)
{
GError *error = NULL;
GObject *call;
GObject *source_object;
source_object = g_async_result_get_source_object (res);
call = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, &error);
g_object_unref (source_object);
if (error) {
g_simple_async_result_take_error (ctx->result, error);
list_call_context_complete_and_free (ctx);
return;
}
/* Keep the object */
ctx->call_objects = g_list_prepend (ctx->call_objects, call);
/* If no more calls, just end here. */
if (!ctx->call_paths[++ctx->i]) {
g_simple_async_result_set_op_res_gpointer (ctx->result,
ctx->call_objects,
(GDestroyNotify)call_object_list_free);
ctx->call_objects = NULL;
list_call_context_complete_and_free (ctx);
return;
}
/* Keep on creating next object */
create_next_call (ctx);
}
static void
create_next_call (ListCallContext *ctx)
{
g_async_initable_new_async (MM_TYPE_CALL,
G_PRIORITY_DEFAULT,
ctx->cancellable,
(GAsyncReadyCallback)list_build_object_ready,
ctx,
"g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"g-name", MM_DBUS_SERVICE,
"g-connection", g_dbus_proxy_get_connection (G_DBUS_PROXY (ctx->self)),
"g-object-path", ctx->call_paths[ctx->i],
"g-interface-name", "org.freedesktop.ModemManager1.Call",
NULL);
}
/**
* mm_modem_voice_list_call:
* @self: A #MMModemVoice.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
* @user_data: User data to pass to @callback.
*
* Asynchronously lists the #MMCall objects in the modem.
*
* When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
* You can then call mm_modem_voice_list_call_finish() to get the result of the operation.
*
* See mm_modem_voice_list_call_sync() for the synchronous, blocking version of this method.
*/
void
mm_modem_voice_list_call (MMModemVoice *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
ListCallContext *ctx;
g_return_if_fail (MM_IS_MODEM_VOICE (self));
ctx = g_slice_new0 (ListCallContext);
ctx->self = g_object_ref (self);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_modem_voice_list_call);
if (cancellable)
ctx->cancellable = g_object_ref (cancellable);
ctx->call_paths = mm_gdbus_modem_voice_dup_calls (MM_GDBUS_MODEM_VOICE (self));
/* If no CALL, just end here. */
if (!ctx->call_paths || !ctx->call_paths[0]) {
g_simple_async_result_set_op_res_gpointer (ctx->result, NULL, NULL);
list_call_context_complete_and_free (ctx);
return;
}
/* Got list of paths. If at least one found, start creating objects for each */
ctx->i = 0;
create_next_call (ctx);
}
/**
* mm_modem_voice_list_call_sync:
* @self: A #MMModemVoice.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
* Synchronously lists the #MMCall objects in the modem.
*
* The calling thread is blocked until a reply is received. See mm_modem_voice_list_call()
* for the asynchronous version of this method.
*
* Returns: (element-type MMCall) (transfer full): A list of #MMCall objects, or #NULL if either not found or @error is set. The returned value should be freed with g_list_free_full() using g_object_unref() as #GDestroyNotify function.
*/
GList *
mm_modem_voice_list_call_sync (MMModemVoice *self,
GCancellable *cancellable,
GError **error)
{
GList *call_objects = NULL;
gchar **call_paths = NULL;
guint i;
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), NULL);
call_paths = mm_gdbus_modem_voice_dup_calls (MM_GDBUS_MODEM_VOICE (self));
/* Only non-empty lists are returned */
if (!call_paths)
return NULL;
for (i = 0; call_paths[i]; i++) {
GObject *call;
call = g_initable_new (MM_TYPE_CALL,
cancellable,
error,
"g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"g-name", MM_DBUS_SERVICE,
"g-connection", g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
"g-object-path", call_paths[i],
"g-interface-name", "org.freedesktop.ModemManager1.Call",
NULL);
if (!call) {
call_object_list_free (call_objects);
g_strfreev (call_paths);
return NULL;
}
/* Keep the object */
call_objects = g_list_prepend (call_objects, call);
}
g_strfreev (call_paths);
return call_objects;
}
/*****************************************************************************/
typedef struct {
GSimpleAsyncResult *result;
GCancellable *cancellable;
} CreateCallContext;
static void
create_call_context_complete_and_free (CreateCallContext *ctx)
{
g_simple_async_result_complete (ctx->result);
g_object_unref (ctx->result);
if (ctx->cancellable)
g_object_unref (ctx->cancellable);
g_slice_free (CreateCallContext, ctx);
}
/**
* mm_modem_voice_create_call_finish:
* @self: A #MMModemVoice.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_voice_create_call().
* @error: Return location for error or %NULL.
*
* Finishes an operation started with mm_modem_voice_create_call().
*
* Returns: (transfer full): A newly created #MMCall, or %NULL if @error is set. The returned value should be freed with g_object_unref().
*/
MMCall *
mm_modem_voice_create_call_finish (MMModemVoice *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), NULL);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error))
return NULL;
return g_object_ref (g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res)));
}
static void
new_call_object_ready (GDBusConnection *connection,
GAsyncResult *res,
CreateCallContext *ctx)
{
GError *error = NULL;
GObject *call;
GObject *source_object;
source_object = g_async_result_get_source_object (res);
call = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object), res, &error);
g_object_unref (source_object);
if (error)
g_simple_async_result_take_error (ctx->result, error);
else
g_simple_async_result_set_op_res_gpointer (ctx->result,
call,
(GDestroyNotify)g_object_unref);
create_call_context_complete_and_free (ctx);
}
static void
create_call_ready (MMModemVoice *self,
GAsyncResult *res,
CreateCallContext *ctx)
{
GError *error = NULL;
gchar *call_path = NULL;
if (!mm_gdbus_modem_voice_call_create_call_finish (MM_GDBUS_MODEM_VOICE (self),
&call_path,
res,
&error)) {
g_simple_async_result_take_error (ctx->result, error);
create_call_context_complete_and_free (ctx);
g_free (call_path);
return;
}
g_async_initable_new_async (MM_TYPE_CALL,
G_PRIORITY_DEFAULT,
ctx->cancellable,
(GAsyncReadyCallback)new_call_object_ready,
ctx,
"g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"g-name", MM_DBUS_SERVICE,
"g-connection", g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
"g-object-path", call_path,
"g-interface-name", "org.freedesktop.ModemManager1.Call",
NULL);
g_free (call_path);
}
/**
* mm_modem_voice_create_call:
* @self: A #MMModemVoice.
* @properties: A ##MMCallProperties object with the properties to use.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
* @user_data: User data to pass to @callback.
*
* Asynchronously creates a new #MMCall in the modem.
*
* When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
* You can then call mm_modem_voice_create_call_finish() to get the result of the operation.
*
* See mm_modem_voice_create_call_sync() for the synchronous, blocking version of this method.
*/
void
mm_modem_voice_create_call (MMModemVoice *self,
MMCallProperties *properties,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
CreateCallContext *ctx;
GVariant *dictionary;
g_return_if_fail (MM_IS_MODEM_VOICE (self));
ctx = g_slice_new0 (CreateCallContext);
ctx->result = g_simple_async_result_new (G_OBJECT (self),
callback,
user_data,
mm_modem_voice_create_call);
if (cancellable)
ctx->cancellable = g_object_ref (cancellable);
dictionary = (mm_call_properties_get_dictionary (properties));
mm_gdbus_modem_voice_call_create_call (
MM_GDBUS_MODEM_VOICE (self),
dictionary,
cancellable,
(GAsyncReadyCallback)create_call_ready,
ctx);
g_variant_unref (dictionary);
}
/**
* mm_modem_voice_create_call_sync:
* @self: A #MMModemVoice.
* @properties: A ##MMCallProperties object with the properties to use.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
*
* Synchronously creates a new #MMCall in the modem.
*
* The calling thread is blocked until a reply is received. See mm_modem_voice_create_call()
* for the asynchronous version of this method.
*
* Returns: (transfer full): A newly created #MMCall, or %NULL if @error is set. The returned value should be freed with g_object_unref().
*/
MMCall *
mm_modem_voice_create_call_sync (MMModemVoice *self,
MMCallProperties *properties,
GCancellable *cancellable,
GError **error)
{
MMCall *call = NULL;
gchar *call_path = NULL;
GVariant *dictionary;
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), NULL);
dictionary = (mm_call_properties_get_dictionary (properties));
mm_gdbus_modem_voice_call_create_call_sync (MM_GDBUS_MODEM_VOICE (self),
dictionary,
&call_path,
cancellable,
error);
if (call_path) {
call = g_initable_new (MM_TYPE_CALL,
cancellable,
error,
"g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
"g-name", MM_DBUS_SERVICE,
"g-connection", g_dbus_proxy_get_connection (G_DBUS_PROXY (self)),
"g-object-path", call_path,
"g-interface-name", "org.freedesktop.ModemManager1.Call",
NULL);
g_free (call_path);
}
g_variant_unref (dictionary);
return (call ? MM_CALL (call) : NULL);
}
/*****************************************************************************/
/**
* mm_modem_voice_delete_call_finish:
* @self: A #MMModemVoice.
* @res: The #GAsyncResult obtained from the #GAsyncReadyCallback passed to mm_modem_voice_delete_call().
* @error: Return location for error or %NULL.
*
* Finishes an operation started with mm_modem_voice_delete_call().
*
* Returns: %TRUE if the call was deleted, %FALSE if @error is set.
*/
gboolean
mm_modem_voice_delete_call_finish (MMModemVoice *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), FALSE);
return mm_gdbus_modem_voice_call_delete_call_finish (MM_GDBUS_MODEM_VOICE (self), res, error);
}
/**
* mm_modem_voice_delete_call:
* @self: A #MMModemVoice.
* @call: Path of the #MMCall to delete.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL.
* @user_data: User data to pass to @callback.
*
* Asynchronously deletes a given #MMCall from the modem.
*
* When the operation is finished, @callback will be invoked in the <link linkend="g-main-context-push-thread-default">thread-default main loop</link> of the thread you are calling this method from.
* You can then call mm_modem_voice_delete_finish() to get the result of the operation.
*
* See mm_modem_voice_delete_sync() for the synchronous, blocking version of this method.
*/
void
mm_modem_voice_delete_call (MMModemVoice *self,
const gchar *call,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (MM_IS_MODEM_VOICE (self));
mm_gdbus_modem_voice_call_delete_call (MM_GDBUS_MODEM_VOICE (self),
call,
cancellable,
callback,
user_data);
}
/**
* mm_modem_voice_delete_call_sync:
* @self: A #MMModemVoice.
* @call: Path of the #MMCall to delete.
* @cancellable: (allow-none): A #GCancellable or %NULL.
* @error: Return location for error or %NULL.
* Synchronously deletes a given #MMCall from the modem.
*
* The calling thread is blocked until a reply is received. See mm_modem_voice_delete_call()
* for the asynchronous version of this method.
*
* Returns: %TRUE if the CALL was deleted, %FALSE if @error is set.
*/
gboolean
mm_modem_voice_delete_call_sync (MMModemVoice *self,
const gchar *call,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (MM_IS_MODEM_VOICE (self), FALSE);
return mm_gdbus_modem_voice_call_delete_call_sync (MM_GDBUS_MODEM_VOICE (self),
call,
cancellable,
error);
}
/*****************************************************************************/
static void
mm_modem_voice_init (MMModemVoice *self)
{
/* Setup private data */
}
static void
finalize (GObject *object)
{
//MMModemVoice *self = MM_MODEM_VOICE (object);
G_OBJECT_CLASS (mm_modem_voice_parent_class)->finalize (object);
}
static void
mm_modem_voice_class_init (MMModemVoiceClass *modem_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (modem_class);
//g_type_class_add_private (object_class, sizeof (MMModemVoicePrivate));
/* Virtual methods */
object_class->finalize = finalize;
}

111
libmm-glib/mm-modem-voice.h Normal file
View File

@@ -0,0 +1,111 @@
/* -*- 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 Aleksander Morgado <aleksander@gnu.org>
* Copyright (C) 2012 Marco Bascetta <marco.bascetta@sadel.it>
*/
#ifndef _MM_MODEM_VOICE_H_
#define _MM_MODEM_VOICE_H_
#if !defined (__LIBMM_GLIB_H_INSIDE__) && !defined (LIBMM_GLIB_COMPILATION)
#error "Only <libmm-glib.h> can be included directly."
#endif
#include <ModemManager.h>
#include "mm-gdbus-modem.h"
#include "mm-call.h"
#include "mm-call-properties.h"
G_BEGIN_DECLS
#define MM_TYPE_MODEM_VOICE (mm_modem_voice_get_type ())
#define MM_MODEM_VOICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_VOICE, MMModemVoice))
#define MM_MODEM_VOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_VOICE, MMModemVoiceClass))
#define MM_IS_MODEM_VOICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_VOICE))
#define MM_IS_MODEM_VOICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_MODEM_VOICE))
#define MM_MODEM_VOICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_VOICE, MMModemVoiceClass))
typedef struct _MMModemVoice MMModemVoice;
typedef struct _MMModemVoiceClass MMModemVoiceClass;
typedef struct _MMModemVoicePrivate MMModemVoicePrivate;
/**
* MMModemVoice:
*
* The #MMModemVoice structure contains private data and should only be accessed
* using the provided API.
*/
struct _MMModemVoice {
/*< private >*/
MmGdbusModemVoiceProxy parent;
MMModemVoicePrivate *priv;
};
struct _MMModemVoiceClass {
/*< private >*/
MmGdbusModemVoiceProxyClass parent;
};
GType mm_modem_voice_get_type (void);
const gchar *mm_modem_voice_get_path (MMModemVoice *self);
gchar *mm_modem_voice_dup_path (MMModemVoice *self);
void mm_modem_voice_create_call (MMModemVoice *self,
MMCallProperties *properties,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
MMCall *mm_modem_voice_create_call_finish (MMModemVoice *self,
GAsyncResult *res,
GError **error);
MMCall *mm_modem_voice_create_call_sync (MMModemVoice *self,
MMCallProperties *properties,
GCancellable *cancellable,
GError **error);
void mm_modem_voice_list_call (MMModemVoice *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GList *mm_modem_voice_list_call_finish (MMModemVoice *self,
GAsyncResult *res,
GError **error);
GList *mm_modem_voice_list_call_sync (MMModemVoice *self,
GCancellable *cancellable,
GError **error);
void mm_modem_voice_delete_call (MMModemVoice *self,
const gchar *call,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean mm_modem_voice_delete_call_finish (MMModemVoice *self,
GAsyncResult *res,
GError **error);
gboolean mm_modem_voice_delete_call_sync (MMModemVoice *self,
const gchar *call,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* _MM_MODEM_VOICE_H_ */

View File

@@ -340,6 +340,42 @@ mm_object_peek_modem_messaging (MMObject *self)
/*****************************************************************************/ /*****************************************************************************/
/**
* mm_object_get_modem_voice:
* @self: A #MMObject.
*
* Gets the #MMModemVoice instance for the D-Bus interface org.freedesktop.ModemManager1.Modem.Modemvoice on @self, if any.
*
* Returns: (transfer full): A #MMModemVoice that must be freed with g_object_unref() or %NULL if @self does not implement the interface.
*/
MMModemVoice *
mm_object_get_modem_voice (MMObject *self)
{
g_return_val_if_fail (MM_IS_OBJECT (MM_GDBUS_OBJECT (self)), NULL);
return (MMModemVoice *)mm_gdbus_object_get_modem_voice (MM_GDBUS_OBJECT (self));
}
/**
* mm_object_peek_modem_voice: (skip)
* @self: A #MMObject.
*
* Like mm_object_get_modem_voice() but doesn't increase the reference count on the returned object.
*
* <warning>It is not safe to use the returned object if you are on another thread than the one where the #MMManager is running.</warning>
*
* Returns: (transfer none): A #MMModemVoice or %NULL if @self does not implement the interface. Do not free the returned object, it is owned by @self.
*/
MMModemVoice *
mm_object_peek_modem_voice (MMObject *self)
{
g_return_val_if_fail (MM_IS_OBJECT (MM_GDBUS_OBJECT (self)), NULL);
return (MMModemVoice *)mm_gdbus_object_peek_modem_voice (MM_GDBUS_OBJECT (self));
}
/*****************************************************************************/
/** /**
* mm_object_get_modem_time: * mm_object_get_modem_time:
* @self: A #MMObject. * @self: A #MMObject.

View File

@@ -38,6 +38,7 @@
#include "mm-modem-simple.h" #include "mm-modem-simple.h"
#include "mm-modem-location.h" #include "mm-modem-location.h"
#include "mm-modem-messaging.h" #include "mm-modem-messaging.h"
#include "mm-modem-voice.h"
#include "mm-modem-time.h" #include "mm-modem-time.h"
#include "mm-modem-firmware.h" #include "mm-modem-firmware.h"
#include "mm-modem-signal.h" #include "mm-modem-signal.h"
@@ -84,6 +85,7 @@ MMModemCdma *mm_object_get_modem_cdma (MMObject *self);
MMModemSimple *mm_object_get_modem_simple (MMObject *self); MMModemSimple *mm_object_get_modem_simple (MMObject *self);
MMModemLocation *mm_object_get_modem_location (MMObject *self); MMModemLocation *mm_object_get_modem_location (MMObject *self);
MMModemMessaging *mm_object_get_modem_messaging (MMObject *self); MMModemMessaging *mm_object_get_modem_messaging (MMObject *self);
MMModemVoice *mm_object_get_modem_voice (MMObject *self);
MMModemTime *mm_object_get_modem_time (MMObject *self); MMModemTime *mm_object_get_modem_time (MMObject *self);
MMModemFirmware *mm_object_get_modem_firmware (MMObject *self); MMModemFirmware *mm_object_get_modem_firmware (MMObject *self);
MMModemSignal *mm_object_get_modem_signal (MMObject *self); MMModemSignal *mm_object_get_modem_signal (MMObject *self);
@@ -96,6 +98,7 @@ MMModemCdma *mm_object_peek_modem_cdma (MMObject *self);
MMModemSimple *mm_object_peek_modem_simple (MMObject *self); MMModemSimple *mm_object_peek_modem_simple (MMObject *self);
MMModemLocation *mm_object_peek_modem_location (MMObject *self); MMModemLocation *mm_object_peek_modem_location (MMObject *self);
MMModemMessaging *mm_object_peek_modem_messaging (MMObject *self); MMModemMessaging *mm_object_peek_modem_messaging (MMObject *self);
MMModemVoice *mm_object_peek_modem_voice (MMObject *self);
MMModemTime *mm_object_peek_modem_time (MMObject *self); MMModemTime *mm_object_peek_modem_time (MMObject *self);
MMModemFirmware *mm_object_peek_modem_firmware (MMObject *self); MMModemFirmware *mm_object_peek_modem_firmware (MMObject *self);
MMModemSignal *mm_object_peek_modem_signal (MMObject *self); MMModemSignal *mm_object_peek_modem_signal (MMObject *self);