time: implement MMModemTime boilerplate
Signed-off-by: Thomas Tuttle <ttuttle@chromium.org>
This commit is contained in:

committed by
Dan Williams

parent
835e14d8d5
commit
7f12201494
@@ -123,7 +123,9 @@ modem_manager_SOURCES = \
|
|||||||
mm-modem-location.c \
|
mm-modem-location.c \
|
||||||
mm-modem-location.h \
|
mm-modem-location.h \
|
||||||
mm-modem-firmware.c \
|
mm-modem-firmware.c \
|
||||||
mm-modem-firmware.h
|
mm-modem-firmware.h \
|
||||||
|
mm-modem-time.c \
|
||||||
|
mm-modem-time.h
|
||||||
|
|
||||||
mm-manager-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManager.xml
|
mm-manager-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManager.xml
|
||||||
$(AM_V_GEN) dbus-binding-tool --prefix=mm_manager --mode=glib-server --output=$@ $<
|
$(AM_V_GEN) dbus-binding-tool --prefix=mm_manager --mode=glib-server --output=$@ $<
|
||||||
@@ -169,8 +171,11 @@ mm-modem-location-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManag
|
|||||||
mm-modem-firmware-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManager.Modem.Firmware.xml
|
mm-modem-firmware-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManager.Modem.Firmware.xml
|
||||||
$(AM_V_GEN) dbus-binding-tool --prefix=mm_modem_firmware --mode=glib-server --output=$@ $<
|
$(AM_V_GEN) dbus-binding-tool --prefix=mm_modem_firmware --mode=glib-server --output=$@ $<
|
||||||
|
|
||||||
|
mm-modem-time-glue.h: $(top_srcdir)/introspection/org.freedesktop.ModemManager.Modem.Time.xml
|
||||||
|
$(AM_V_GEN) dbus-binding-tool --prefix=mm_modem_time --mode=glib-server --output=$@ $<
|
||||||
|
|
||||||
modem_manager_SOURCES += $(loc_sources)
|
modem_manager_SOURCES += $(loc_sources)
|
||||||
|
|
||||||
BUILT_SOURCES += mm-modem-location-glue.h mm-modem-firmware-glue.h
|
BUILT_SOURCES += mm-modem-location-glue.h mm-modem-firmware-glue.h mm-modem-time-glue.h
|
||||||
|
|
||||||
CLEANFILES = $(BUILT_SOURCES)
|
CLEANFILES = $(BUILT_SOURCES)
|
||||||
|
153
src/mm-modem-time.c
Normal file
153
src/mm-modem-time.c
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
/* -*- 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) 2011 The Chromium OS Authors
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <dbus/dbus-glib.h>
|
||||||
|
|
||||||
|
#include "mm-modem-time.h"
|
||||||
|
#include "mm-errors.h"
|
||||||
|
#include "mm-callback-info.h"
|
||||||
|
#include "mm-marshal.h"
|
||||||
|
|
||||||
|
static void impl_modem_time_get_network_time (MMModemTime *self,
|
||||||
|
DBusGMethodInvocation *context);
|
||||||
|
|
||||||
|
#include "mm-modem-time-glue.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NETWORK_TIME_CHANGED,
|
||||||
|
LAST_SIGNAL
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[LAST_SIGNAL] = { 0 };
|
||||||
|
|
||||||
|
static void
|
||||||
|
async_get_call_done (MMModemTime *self,
|
||||||
|
const char *network_time,
|
||||||
|
GError *error,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data;
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
dbus_g_method_return_error (context, error);
|
||||||
|
else
|
||||||
|
dbus_g_method_return (context, network_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
time_get_invoke (MMCallbackInfo *info)
|
||||||
|
{
|
||||||
|
MMModemTimeGetNetworkTimeFn callback = (MMModemTimeGetNetworkTimeFn) info->callback;
|
||||||
|
|
||||||
|
callback ((MMModemTime *) info->modem, NULL, info->error, info->user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
async_get_call_not_supported (MMModemTime *self,
|
||||||
|
MMModemTimeGetNetworkTimeFn callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
MMCallbackInfo *info;
|
||||||
|
|
||||||
|
info = mm_callback_info_new_full (MM_MODEM (self),
|
||||||
|
time_get_invoke,
|
||||||
|
G_CALLBACK (callback),
|
||||||
|
user_data);
|
||||||
|
info->error = g_error_new_literal (MM_MODEM_ERROR,
|
||||||
|
MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
|
||||||
|
"Operation not supported");
|
||||||
|
|
||||||
|
mm_callback_info_schedule (info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mm_modem_time_get_network_time (MMModemTime *self,
|
||||||
|
MMModemTimeGetNetworkTimeFn callback,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_return_if_fail (MM_IS_MODEM_TIME (self));
|
||||||
|
g_return_if_fail (callback != NULL);
|
||||||
|
|
||||||
|
if (MM_MODEM_TIME_GET_INTERFACE (self)->get_network_time)
|
||||||
|
MM_MODEM_TIME_GET_INTERFACE (self)->get_network_time (self, callback, user_data);
|
||||||
|
else
|
||||||
|
async_get_call_not_supported (self, callback, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
impl_modem_time_get_network_time (MMModemTime *self,
|
||||||
|
DBusGMethodInvocation *context)
|
||||||
|
{
|
||||||
|
mm_modem_time_get_network_time (self, async_get_call_done, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE))
|
||||||
|
|
||||||
|
static void
|
||||||
|
mm_modem_time_init (gpointer g_iface)
|
||||||
|
{
|
||||||
|
GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
|
||||||
|
static gboolean initialized = FALSE;
|
||||||
|
|
||||||
|
if (initialized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_object_interface_install_property
|
||||||
|
(g_iface,
|
||||||
|
g_param_spec_boxed (MM_MODEM_TIME_NETWORK_TIMEZONE,
|
||||||
|
"NetworkTimezone",
|
||||||
|
"The network timezone data",
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT,
|
||||||
|
G_PARAM_READABLE));
|
||||||
|
|
||||||
|
signals[NETWORK_TIME_CHANGED] =
|
||||||
|
g_signal_new ("network-time-changed",
|
||||||
|
iface_type,
|
||||||
|
G_SIGNAL_RUN_FIRST,
|
||||||
|
0, NULL, NULL,
|
||||||
|
g_cclosure_marshal_VOID__STRING,
|
||||||
|
G_TYPE_NONE, 1,
|
||||||
|
G_TYPE_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
GType
|
||||||
|
mm_modem_time_get_type (void)
|
||||||
|
{
|
||||||
|
static GType time_type = 0;
|
||||||
|
|
||||||
|
if (!G_UNLIKELY (time_type)) {
|
||||||
|
const GTypeInfo time_info = {
|
||||||
|
sizeof(MMModemTime), /* class_size */
|
||||||
|
mm_modem_time_init, /* base_init */
|
||||||
|
NULL, /* base_finalize */
|
||||||
|
NULL,
|
||||||
|
NULL, /* class_finalize */
|
||||||
|
NULL, /* class_data */
|
||||||
|
0,
|
||||||
|
0, /* n_preallocs */
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
time_type = g_type_register_static (G_TYPE_INTERFACE,
|
||||||
|
"MMModemTime",
|
||||||
|
&time_info, 0);
|
||||||
|
|
||||||
|
g_type_interface_add_prerequisite (time_type, G_TYPE_OBJECT);
|
||||||
|
dbus_g_object_type_install_info (time_type, &dbus_glib_mm_modem_time_object_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
return time_type;
|
||||||
|
}
|
52
src/mm-modem-time.h
Normal file
52
src/mm-modem-time.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/* -*- 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) 2011 The Chromium OS Authors
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MM_MODEM_TIME_H
|
||||||
|
#define MM_MODEM_TIME_H
|
||||||
|
|
||||||
|
#include <mm-modem.h>
|
||||||
|
|
||||||
|
#define MM_TYPE_MODEM_TIME (mm_modem_time_get_type ())
|
||||||
|
#define MM_MODEM_TIME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_TIME, MMModemTime))
|
||||||
|
#define MM_IS_MODEM_TIME(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_TIME))
|
||||||
|
#define MM_MODEM_TIME_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), MM_TYPE_MODEM_TIME, MMModemTime))
|
||||||
|
|
||||||
|
#define MM_DBUS_INTERFACE_MODEM_TIME "org.freedesktop.ModemManager.Modem.Time"
|
||||||
|
|
||||||
|
#define MM_MODEM_TIME_NETWORK_TIMEZONE "network-timezone"
|
||||||
|
|
||||||
|
typedef struct _MMModemTime MMModemTime;
|
||||||
|
|
||||||
|
typedef void (*MMModemTimeGetNetworkTimeFn) (MMModemTime *self,
|
||||||
|
const char *network_time,
|
||||||
|
GError *error,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
struct _MMModemTime {
|
||||||
|
GTypeInterface g_iface;
|
||||||
|
|
||||||
|
/* Methods */
|
||||||
|
void (*get_network_time) (MMModemTime *self,
|
||||||
|
MMModemTimeGetNetworkTimeFn callback,
|
||||||
|
gpointer user_data);
|
||||||
|
};
|
||||||
|
|
||||||
|
GType mm_modem_time_get_type (void);
|
||||||
|
|
||||||
|
void mm_modem_time_get_network_time (MMModemTime *self,
|
||||||
|
MMModemTimeGetNetworkTimeFn callback,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
|
#endif /* MM_MODEM_TIME_H */
|
Reference in New Issue
Block a user