udev: modem port refactor; convert 'hso' to udev
Create a base MMPort class to handle both tty and net ports generically, and move plugins over to that. Also port the 'hso' plugin to udev.
This commit is contained in:
@@ -84,20 +84,24 @@ libmm_plugin_huawei_la_LDFLAGS = \
|
||||
# HSO
|
||||
|
||||
libmm_plugin_hso_la_SOURCES = \
|
||||
mm-plugin-hso.c \
|
||||
mm-plugin-hso.h \
|
||||
mm-modem-gsm-hso-glue.h \
|
||||
mm-modem-hso.c \
|
||||
mm-modem-hso.h \
|
||||
mm-plugin-hso.c \
|
||||
mm-plugin-hso.h
|
||||
mm-modem-hso.h
|
||||
|
||||
mm-modem-gsm-hso-glue.h: $(top_srcdir)/introspection/mm-modem-gsm-hso.xml
|
||||
dbus-binding-tool --prefix=mm_modem_gsm_hso --mode=glib-server --output=$@ $<
|
||||
|
||||
libmm_plugin_hso_la_CPPFLAGS = \
|
||||
$(MM_CFLAGS) \
|
||||
$(GUDEV_CFLAGS) \
|
||||
-I$(top_srcdir)/src
|
||||
|
||||
libmm_plugin_hso_la_LDFLAGS = -module -avoid-version
|
||||
libmm_plugin_hso_la_LDFLAGS = \
|
||||
$(GUDEV_LDFLAGS) \
|
||||
-module \
|
||||
-avoid-version
|
||||
|
||||
# MBM
|
||||
|
||||
|
@@ -71,18 +71,11 @@ get_imsi (MMModemGsmCard *modem,
|
||||
{
|
||||
MMSerialPort *primary;
|
||||
MMCallbackInfo *info;
|
||||
GError *error = NULL;
|
||||
|
||||
info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
if (primary)
|
||||
mm_serial_port_queue_command_cached (primary, "+CIMI", 3, get_string_done, info);
|
||||
else {
|
||||
g_set_error (&error, MM_MODEM_ERROR, MM_MODEM_ERROR_OPERATION_NOT_SUPPORTED,
|
||||
"Operation not supported; primary port unusable");
|
||||
get_string_done (primary, NULL, error, user_data);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command_cached (primary, "+CIMI", 3, get_string_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -1,4 +1,18 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -7,9 +21,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "mm-modem-hso.h"
|
||||
#include "mm-modem-simple.h"
|
||||
#include "mm-serial.h"
|
||||
#include "mm-serial-parsers.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
@@ -34,26 +51,24 @@ typedef struct {
|
||||
#define OWANDATA_TAG "_OWANDATA: "
|
||||
|
||||
MMModem *
|
||||
mm_modem_hso_new (const char *serial_device,
|
||||
const char *network_device,
|
||||
const char *driver)
|
||||
mm_modem_hso_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin)
|
||||
{
|
||||
g_return_val_if_fail (serial_device != NULL, NULL);
|
||||
g_return_val_if_fail (network_device != NULL, NULL);
|
||||
g_return_val_if_fail (device != NULL, NULL);
|
||||
g_return_val_if_fail (driver != NULL, NULL);
|
||||
g_return_val_if_fail (plugin != NULL, NULL);
|
||||
|
||||
return MM_MODEM (g_object_new (MM_TYPE_MODEM_HSO,
|
||||
MM_SERIAL_DEVICE, serial_device,
|
||||
MM_SERIAL_SEND_DELAY, (guint64) 10000,
|
||||
MM_MODEM_MASTER_DEVICE, device,
|
||||
MM_MODEM_DRIVER, driver,
|
||||
MM_MODEM_DEVICE, network_device,
|
||||
MM_MODEM_PLUGIN, plugin,
|
||||
MM_MODEM_IP_METHOD, MM_MODEM_IP_METHOD_STATIC,
|
||||
MM_MODEM_TYPE, MM_MODEM_TYPE_GSM,
|
||||
NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
hso_enable_done (MMSerial *serial,
|
||||
hso_enable_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -86,11 +101,14 @@ hso_enable (MMModemHso *self,
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
char *command;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
command = g_strdup_printf ("AT_OWANCALL=%d,%d,1", hso_get_cid (self), enabled ? 1 : 0);
|
||||
mm_serial_queue_command (MM_SERIAL (self), command, 3, hso_enable_done, info);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, command, 3, hso_enable_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
@@ -161,19 +179,20 @@ hso_disabled (MMModem *modem,
|
||||
}
|
||||
|
||||
static void
|
||||
auth_done (MMSerial *serial,
|
||||
auth_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModemHso *self = MM_MODEM_HSO (info->modem);
|
||||
|
||||
if (error) {
|
||||
info->error = g_error_copy (error);
|
||||
mm_callback_info_schedule (info);
|
||||
} else
|
||||
/* success, kill any existing connections first */
|
||||
hso_enable (MM_MODEM_HSO (serial), FALSE, hso_disabled, info);
|
||||
hso_enable (self, FALSE, hso_disabled, info);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -184,24 +203,32 @@ mm_hso_modem_authenticate (MMModemHso *self,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMSerialPort *primary;
|
||||
|
||||
g_return_if_fail (MM_IS_MODEM_HSO (self));
|
||||
g_return_if_fail (callback != NULL);
|
||||
|
||||
info = mm_callback_info_new (MM_MODEM (self), callback, user_data);
|
||||
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (self), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
if (username || password) {
|
||||
char *command;
|
||||
|
||||
// FIXME: if QCPDPP fails, try OPDPP. AT&T Quicksilver uses a different
|
||||
// chipset (ie, not Qualcomm) and the auth command is OPDPP instead of
|
||||
// the Qualcomm-specific QCPDPP.
|
||||
|
||||
command = g_strdup_printf ("AT$QCPDPP=%d,1,\"%s\",\"%s\"",
|
||||
hso_get_cid (self),
|
||||
password ? password : "",
|
||||
username ? username : "");
|
||||
|
||||
mm_serial_queue_command (MM_SERIAL (self), command, 3, auth_done, info);
|
||||
mm_serial_port_queue_command (primary, command, 3, auth_done, info);
|
||||
g_free (command);
|
||||
} else
|
||||
auth_done (MM_SERIAL (self), NULL, NULL, info);
|
||||
auth_done (primary, NULL, NULL, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -234,7 +261,7 @@ parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
||||
}
|
||||
|
||||
static void
|
||||
modem_enable_done (MMSerial *serial,
|
||||
modem_enable_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -242,8 +269,8 @@ modem_enable_done (MMSerial *serial,
|
||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||
MMModem *parent_modem_iface;
|
||||
|
||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (serial));
|
||||
parent_modem_iface->enable (MM_MODEM (serial),
|
||||
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (info->modem));
|
||||
parent_modem_iface->enable (info->modem,
|
||||
GPOINTER_TO_INT (mm_callback_info_get_data (info, "enable")),
|
||||
parent_enable_done, info);
|
||||
}
|
||||
@@ -255,14 +282,18 @@ enable (MMModem *modem,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
mm_callback_info_set_data (info, "enable", GINT_TO_POINTER (enable), NULL);
|
||||
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
|
||||
if (do_enable)
|
||||
modem_enable_done (MM_SERIAL (modem), NULL, NULL, info);
|
||||
modem_enable_done (primary, NULL, NULL, info);
|
||||
else
|
||||
mm_serial_queue_command (MM_SERIAL (modem), "AT_OWANCALL=1,0,0", 3, modem_enable_done, info);
|
||||
mm_serial_port_queue_command (primary, "AT_OWANCALL=1,0,0", 3, modem_enable_done, info);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -296,7 +327,7 @@ ip4_config_invoke (MMCallbackInfo *info)
|
||||
}
|
||||
|
||||
static void
|
||||
get_ip4_config_done (MMSerial *serial,
|
||||
get_ip4_config_done (MMSerialPort *port,
|
||||
GString *response,
|
||||
GError *error,
|
||||
gpointer user_data)
|
||||
@@ -317,7 +348,7 @@ get_ip4_config_done (MMSerial *serial,
|
||||
goto out;
|
||||
}
|
||||
|
||||
cid = hso_get_cid (MM_MODEM_HSO (serial));
|
||||
cid = hso_get_cid (MM_MODEM_HSO (info->modem));
|
||||
dns_array = g_array_sized_new (FALSE, TRUE, sizeof (guint32), 2);
|
||||
items = g_strsplit (response->str + strlen (OWANDATA_TAG), ", ", 0);
|
||||
|
||||
@@ -359,10 +390,13 @@ get_ip4_config (MMModem *modem,
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
char *command;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new_full (modem, ip4_config_invoke, G_CALLBACK (callback), user_data);
|
||||
command = g_strdup_printf ("AT_OWANDATA=%d", hso_get_cid (MM_MODEM_HSO (modem)));
|
||||
mm_serial_queue_command (MM_SERIAL (modem), command, 3, get_ip4_config_done, info);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, command, 3, get_ip4_config_done, info);
|
||||
g_free (command);
|
||||
}
|
||||
|
||||
@@ -372,9 +406,12 @@ disconnect (MMModem *modem,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMCallbackInfo *info;
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_new (modem, callback, user_data);
|
||||
mm_serial_queue_command (MM_SERIAL (modem), "AT_OWANCALL=1,0,0", 3, NULL, info);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT_OWANCALL=1,0,0", 3, NULL, info);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -408,23 +445,25 @@ impl_hso_authenticate (MMModemHso *self,
|
||||
}
|
||||
|
||||
static void
|
||||
connection_enabled (MMSerial *serial,
|
||||
connection_enabled (MMSerialPort *port,
|
||||
GMatchInfo *info,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMModemHso *self = MM_MODEM_HSO (user_data);
|
||||
MMModemHsoPrivate *priv = MM_MODEM_HSO_GET_PRIVATE (self);
|
||||
char *str;
|
||||
|
||||
str = g_match_info_fetch (info, 2);
|
||||
if (str[0] == '1')
|
||||
connect_pending_done (MM_MODEM_HSO (serial));
|
||||
connect_pending_done (self);
|
||||
else if (str[0] == '3') {
|
||||
MMCallbackInfo *cb_info = MM_MODEM_HSO_GET_PRIVATE (serial)->connect_pending_data;
|
||||
MMCallbackInfo *cb_info = priv->connect_pending_data;
|
||||
|
||||
if (cb_info)
|
||||
cb_info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||
"Call setup failed");
|
||||
|
||||
connect_pending_done (MM_MODEM_HSO (serial));
|
||||
connect_pending_done (self);
|
||||
} else if (str[0] == '0')
|
||||
/* FIXME: disconnected. do something when we have modem status signals */
|
||||
;
|
||||
@@ -521,16 +560,82 @@ simple_connect (MMModemSimple *simple,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
grab_port (MMModem *modem,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
GError **error)
|
||||
{
|
||||
MMGenericGsm *gsm = MM_GENERIC_GSM (modem);
|
||||
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
||||
const char *sys[] = { "tty", "net", NULL };
|
||||
GUdevClient *client;
|
||||
GUdevDevice *device = NULL;
|
||||
MMPort *port = NULL;
|
||||
const char *sysfs_path;
|
||||
|
||||
client = g_udev_client_new (sys);
|
||||
if (!client) {
|
||||
g_set_error (error, 0, 0, "Could not get udev client.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
device = g_udev_client_query_by_subsystem_and_name (client, subsys, name);
|
||||
if (!device) {
|
||||
g_set_error (error, 0, 0, "Could not get udev device.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (device);
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get udev device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!strcmp (subsys, "tty")) {
|
||||
char *hsotype_path;
|
||||
char *contents = NULL;
|
||||
|
||||
hsotype_path = g_build_filename (sysfs_path, "hsotype", NULL);
|
||||
if (g_file_get_contents (hsotype_path, &contents, NULL, NULL)) {
|
||||
if (g_str_has_prefix (contents, "Control"))
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
g_free (contents);
|
||||
}
|
||||
g_free (hsotype_path);
|
||||
}
|
||||
|
||||
port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error);
|
||||
if (!port)
|
||||
goto out;
|
||||
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
g_object_set (G_OBJECT (port), MM_SERIAL_PORT_SEND_DELAY, (guint64) 10000, NULL);
|
||||
if (ptype == MM_PORT_TYPE_PRIMARY) {
|
||||
GRegex *regex;
|
||||
|
||||
mm_generic_gsm_set_unsolicited_registration (gsm, TRUE);
|
||||
|
||||
regex = g_regex_new ("_OWANCALL: (\\d), (\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, connection_enabled, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (device)
|
||||
g_object_unref (device);
|
||||
g_object_unref (client);
|
||||
return !!port;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_modem_hso_init (MMModemHso *self)
|
||||
{
|
||||
GRegex *regex;
|
||||
|
||||
mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (self), TRUE);
|
||||
|
||||
regex = g_regex_new ("_OWANCALL: (\\d), (\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_add_unsolicited_msg_handler (MM_SERIAL (self), regex, connection_enabled, NULL, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -546,39 +651,7 @@ modem_init (MMModem *modem_class)
|
||||
modem_class->connect = do_connect;
|
||||
modem_class->get_ip4_config = get_ip4_config;
|
||||
modem_class->disconnect = disconnect;
|
||||
}
|
||||
|
||||
static GObject*
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
char *modem_device;
|
||||
char *serial_device;
|
||||
|
||||
object = G_OBJECT_CLASS (mm_modem_hso_parent_class)->constructor (type,
|
||||
n_construct_params,
|
||||
construct_params);
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
/* Make sure both serial device and data device are provided */
|
||||
g_object_get (object,
|
||||
MM_MODEM_DEVICE, &modem_device,
|
||||
MM_SERIAL_DEVICE, &serial_device,
|
||||
NULL);
|
||||
|
||||
if (!modem_device || !serial_device || !strcmp (modem_device, serial_device)) {
|
||||
g_warning ("No network device provided");
|
||||
g_object_unref (object);
|
||||
object = NULL;
|
||||
}
|
||||
|
||||
g_free (modem_device);
|
||||
g_free (serial_device);
|
||||
|
||||
return object;
|
||||
modem_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -599,7 +672,6 @@ mm_modem_hso_class_init (MMModemHsoClass *klass)
|
||||
g_type_class_add_private (object_class, sizeof (MMModemHsoPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->finalize = finalize;
|
||||
}
|
||||
|
||||
|
@@ -1,16 +1,30 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_HSO_H
|
||||
#define MM_MODEM_HSO_H
|
||||
|
||||
#include "mm-generic-gsm.h"
|
||||
|
||||
#define MM_TYPE_MODEM_HSO (mm_modem_hso_get_type ())
|
||||
#define MM_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_HSO, MMModemHso))
|
||||
#define MM_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
#define MM_IS_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_HSO))
|
||||
#define MM_IS_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_HSO))
|
||||
#define MM_MODEM_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
#define MM_TYPE_MODEM_HSO (mm_modem_hso_get_type ())
|
||||
#define MM_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_HSO, MMModemHso))
|
||||
#define MM_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
#define MM_IS_MODEM_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_HSO))
|
||||
#define MM_IS_MODEM_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_HSO))
|
||||
#define MM_MODEM_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_HSO, MMModemHsoClass))
|
||||
|
||||
typedef struct {
|
||||
MMGenericGsm parent;
|
||||
@@ -22,9 +36,9 @@ typedef struct {
|
||||
|
||||
GType mm_modem_hso_get_type (void);
|
||||
|
||||
MMModem *mm_modem_hso_new (const char *serial_device,
|
||||
const char *network_device,
|
||||
const char *driver);
|
||||
MMModem *mm_modem_hso_new (const char *device,
|
||||
const char *driver,
|
||||
const char *plugin);
|
||||
|
||||
void mm_hso_modem_authenticate (MMModemHso *self,
|
||||
const char *username,
|
||||
|
@@ -192,7 +192,7 @@ set_network_mode (MMModemGsmNetwork *modem,
|
||||
case MM_MODEM_GSM_NETWORK_MODE_3G_ONLY:
|
||||
/* Allowed values */
|
||||
mm_callback_info_set_data (info, "mode", GUINT_TO_POINTER (mode), NULL);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, set_network_mode_get_done, info);
|
||||
return;
|
||||
@@ -244,7 +244,7 @@ get_network_mode (MMModemGsmNetwork *modem,
|
||||
MMSerialPort *primary;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, get_network_mode_done, info);
|
||||
}
|
||||
@@ -329,7 +329,7 @@ set_band (MMModemGsmNetwork *modem,
|
||||
case MM_MODEM_GSM_NETWORK_BAND_U2100:
|
||||
case MM_MODEM_GSM_NETWORK_BAND_PCS:
|
||||
mm_callback_info_set_data (info, "band", GUINT_TO_POINTER (band), NULL);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, set_band_get_done, info);
|
||||
return;
|
||||
@@ -381,7 +381,7 @@ get_band (MMModemGsmNetwork *modem,
|
||||
MMCallbackInfo *info;
|
||||
|
||||
info = mm_callback_info_uint_new (MM_MODEM (modem), callback, user_data);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_SERIAL_PORT_TYPE_PRIMARY);
|
||||
primary = mm_generic_gsm_get_port (MM_GENERIC_GSM (modem), MM_PORT_TYPE_PRIMARY);
|
||||
g_assert (primary);
|
||||
mm_serial_port_queue_command (primary, "AT^SYSCFG?", 3, get_band_done, info);
|
||||
}
|
||||
@@ -503,11 +503,11 @@ grab_port (MMModem *modem,
|
||||
GError **error)
|
||||
{
|
||||
MMGenericGsm *gsm = MM_GENERIC_GSM (modem);
|
||||
MMSerialPortType ptype = MM_SERIAL_PORT_TYPE_IGNORED;
|
||||
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
||||
const char *sys[] = { "tty", NULL };
|
||||
GUdevClient *client;
|
||||
GUdevDevice *device = NULL;
|
||||
MMSerialPort *port = NULL;
|
||||
MMPort *port = NULL;
|
||||
int usbif;
|
||||
|
||||
client = g_udev_client_new (sys);
|
||||
@@ -529,41 +529,42 @@ grab_port (MMModem *modem,
|
||||
}
|
||||
|
||||
if (usbif == 0) {
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_SERIAL_PORT_TYPE_PRIMARY))
|
||||
ptype = MM_SERIAL_PORT_TYPE_PRIMARY;
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_PRIMARY))
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
} else if (usbif == 1) {
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_SERIAL_PORT_TYPE_SECONDARY))
|
||||
ptype = MM_SERIAL_PORT_TYPE_SECONDARY;
|
||||
if (!mm_generic_gsm_get_port (gsm, MM_PORT_TYPE_SECONDARY))
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
}
|
||||
|
||||
port = mm_generic_gsm_grab_port (gsm, subsys, name, ptype, error);
|
||||
if (!port)
|
||||
goto out;
|
||||
|
||||
if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY) {
|
||||
g_object_set (G_OBJECT (port), MM_SERIAL_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
} else if (ptype == MM_SERIAL_PORT_TYPE_SECONDARY) {
|
||||
GRegex *regex;
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
if (ptype == MM_PORT_TYPE_SECONDARY) {
|
||||
GRegex *regex;
|
||||
|
||||
g_object_set (G_OBJECT (port), MM_SERIAL_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
|
||||
mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (modem), TRUE);
|
||||
mm_generic_gsm_set_unsolicited_registration (MM_GENERIC_GSM (modem), TRUE);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^RSSI:(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, handle_signal_quality_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^RSSI:(\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_signal_quality_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^MODE:(\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, handle_mode_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^MODE:(\\d),(\\d)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_mode_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^DSFLOWRPT:(.+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, handle_status_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^DSFLOWRPT:(.+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, handle_status_change, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\^BOOT:.+\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, NULL, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\^BOOT:.+\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, NULL, modem, NULL);
|
||||
g_regex_unref (regex);
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
|
@@ -224,7 +224,7 @@ grab_port (MMPlugin *plugin,
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!devfile) {
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
@@ -1,18 +1,43 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <gmodule.h>
|
||||
|
||||
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "mm-plugin-hso.h"
|
||||
#include "mm-modem-hso.h"
|
||||
|
||||
static void plugin_init (MMPlugin *plugin_class);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMPluginHso, mm_plugin_hso, G_TYPE_OBJECT,
|
||||
G_DEFINE_TYPE_EXTENDED (MMPluginHso, mm_plugin_hso, MM_TYPE_PLUGIN_BASE,
|
||||
0, G_IMPLEMENT_INTERFACE (MM_TYPE_PLUGIN, plugin_init))
|
||||
|
||||
int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
|
||||
int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
|
||||
|
||||
#define MM_PLUGIN_HSO_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PLUGIN_HSO, MMPluginHsoPrivate))
|
||||
|
||||
typedef struct {
|
||||
GUdevClient *client;
|
||||
} MMPluginHsoPrivate;
|
||||
|
||||
|
||||
G_MODULE_EXPORT MMPlugin *
|
||||
mm_plugin_create (void)
|
||||
{
|
||||
@@ -21,204 +46,200 @@ mm_plugin_create (void)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static char *
|
||||
get_driver_name (GUdevDevice *device)
|
||||
{
|
||||
GUdevDevice *parent = NULL;
|
||||
const char *driver;
|
||||
char *ret;
|
||||
|
||||
driver = g_udev_device_get_driver (device);
|
||||
if (!driver) {
|
||||
parent = g_udev_device_get_parent (device);
|
||||
if (parent)
|
||||
driver = g_udev_device_get_driver (parent);
|
||||
}
|
||||
|
||||
if (driver)
|
||||
ret = g_strdup (driver);
|
||||
if (parent)
|
||||
g_object_unref (parent);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static GUdevDevice *
|
||||
find_physical_device (GUdevDevice *child)
|
||||
{
|
||||
GUdevDevice *iter, *old = NULL;
|
||||
const char *type;
|
||||
|
||||
g_return_val_if_fail (child != NULL, NULL);
|
||||
|
||||
/* Walk the parents to find the first 'usb_device' for this device. */
|
||||
iter = g_object_ref (child);
|
||||
while (iter) {
|
||||
type = g_udev_device_get_devtype (iter);
|
||||
if (type && !strcmp (type, "usb_device"))
|
||||
return iter;
|
||||
|
||||
old = iter;
|
||||
iter = g_udev_device_get_parent (old);
|
||||
g_object_unref (old);
|
||||
}
|
||||
g_object_unref (child);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static GUdevDevice *
|
||||
get_device (GUdevClient *client,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
GUdevDevice **physdev,
|
||||
char **driver,
|
||||
GError **error)
|
||||
{
|
||||
GUdevDevice *device = NULL;
|
||||
|
||||
if (strcmp (subsys, "tty") && strcmp (subsys, "net")) {
|
||||
g_set_error (error, 0, 0, "Unsupported subsystem.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device = g_udev_client_query_by_subsystem_and_name (client, subsys, name);
|
||||
if (!device) {
|
||||
g_set_error (error, 0, 0, "Coud not get port's udev device.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*driver = get_driver_name (device);
|
||||
if (!*driver || strcmp (*driver, "hso")) {
|
||||
g_set_error (error, 0, 0, "Unsupported driver (not 'hso').");
|
||||
g_object_unref (device);
|
||||
device = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*physdev = find_physical_device (device);
|
||||
if (!*physdev) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical udev device.");
|
||||
g_object_unref (device);
|
||||
device = NULL;
|
||||
}
|
||||
|
||||
out:
|
||||
return device;
|
||||
}
|
||||
|
||||
static guint32
|
||||
supports_port (MMPlugin *plugin,
|
||||
const char *subsys,
|
||||
const char *name)
|
||||
{
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (plugin);
|
||||
GUdevDevice *device, *physdev = NULL;
|
||||
guint32 level = 0;
|
||||
char *driver = NULL;
|
||||
|
||||
g_return_val_if_fail (plugin != NULL, 0);
|
||||
g_return_val_if_fail (MM_IS_PLUGIN (plugin), 0);
|
||||
g_return_val_if_fail (subsys != NULL, 0);
|
||||
g_return_val_if_fail (name != NULL, 0);
|
||||
|
||||
device = get_device (priv->client, subsys, name, &physdev, &driver, NULL);
|
||||
if (device)
|
||||
level = 10;
|
||||
|
||||
g_free (driver);
|
||||
if (physdev)
|
||||
g_object_unref (physdev);
|
||||
if (device)
|
||||
g_object_unref (device);
|
||||
return level;
|
||||
}
|
||||
|
||||
static MMModem *
|
||||
grab_port (MMPlugin *plugin,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
GError **error)
|
||||
{
|
||||
MMPluginHso *self = MM_PLUGIN_HSO (plugin);
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (plugin);
|
||||
GUdevDevice *device = NULL, *physdev = NULL;
|
||||
const char *sysfs_path = NULL;
|
||||
char *driver = NULL, *devfile = NULL;
|
||||
MMModem *modem = NULL;
|
||||
|
||||
g_return_val_if_fail (subsys != NULL, NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
|
||||
device = get_device (priv->client, subsys, name, &physdev, &driver, error);
|
||||
if (!device) {
|
||||
g_set_error (error, 0, 0, "Could not get port's udev device.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devfile = g_strdup (g_udev_device_get_device_file (device));
|
||||
if (!devfile) {
|
||||
if (!strcmp (subsys, "net")) {
|
||||
/* Apparently 'hso' doesn't set up the right links for the netdevice,
|
||||
* and thus libgudev can't get the sysfs file path for it.
|
||||
*/
|
||||
devfile = g_strdup_printf ("/sys/class/net/%s", name);
|
||||
if (!g_file_test (devfile, G_FILE_TEST_EXISTS)) {
|
||||
g_free (devfile);
|
||||
devfile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!devfile) {
|
||||
g_set_error (error, 0, 0, "Could not get port's sysfs file.");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
modem = mm_plugin_base_find_modem (MM_PLUGIN_BASE (self), sysfs_path);
|
||||
if (!modem) {
|
||||
modem = mm_modem_hso_new (sysfs_path,
|
||||
driver,
|
||||
mm_plugin_get_name (plugin));
|
||||
|
||||
if (modem) {
|
||||
if (!mm_modem_grab_port (modem, subsys, name, error)) {
|
||||
g_object_unref (modem);
|
||||
modem = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (modem)
|
||||
mm_plugin_base_add_modem (MM_PLUGIN_BASE (self), modem);
|
||||
} else {
|
||||
if (!mm_modem_grab_port (modem, subsys, name, error))
|
||||
modem = NULL;
|
||||
}
|
||||
|
||||
out:
|
||||
g_free (devfile);
|
||||
g_free (driver);
|
||||
g_object_unref (device);
|
||||
g_object_unref (physdev);
|
||||
return modem;
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_name (MMPlugin *plugin)
|
||||
{
|
||||
return "HSO";
|
||||
}
|
||||
|
||||
static char **
|
||||
list_supported_udis (MMPlugin *plugin, LibHalContext *hal_ctx)
|
||||
{
|
||||
char **supported = NULL;
|
||||
char **devices;
|
||||
int num_devices;
|
||||
int i;
|
||||
|
||||
devices = libhal_find_device_by_capability (hal_ctx, "serial", &num_devices, NULL);
|
||||
if (devices) {
|
||||
GPtrArray *array;
|
||||
|
||||
array = g_ptr_array_new ();
|
||||
|
||||
for (i = 0; i < num_devices; i++) {
|
||||
char *udi = devices[i];
|
||||
|
||||
if (mm_plugin_supports_udi (plugin, hal_ctx, udi))
|
||||
g_ptr_array_add (array, g_strdup (udi));
|
||||
}
|
||||
|
||||
if (array->len > 0) {
|
||||
g_ptr_array_add (array, NULL);
|
||||
supported = (char **) g_ptr_array_free (array, FALSE);
|
||||
} else
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
g_strfreev (devices);
|
||||
|
||||
return supported;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_driver_name (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
char *parent_udi;
|
||||
char *driver = NULL;
|
||||
|
||||
parent_udi = libhal_device_get_property_string (ctx, udi, "info.parent", NULL);
|
||||
if (parent_udi) {
|
||||
driver = libhal_device_get_property_string (ctx, parent_udi, "info.linux.driver", NULL);
|
||||
libhal_free_string (parent_udi);
|
||||
}
|
||||
|
||||
return driver;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
supports_udi (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi)
|
||||
{
|
||||
char *driver_name;
|
||||
gboolean supported = FALSE;
|
||||
|
||||
driver_name = get_driver_name (hal_ctx, udi);
|
||||
if (driver_name && !strcmp (driver_name, "hso")) {
|
||||
char *sysfs_path;
|
||||
|
||||
sysfs_path = libhal_device_get_property_string (hal_ctx, udi, "linux.sysfs_path", NULL);
|
||||
if (sysfs_path) {
|
||||
char *hso_type_path;
|
||||
gchar *contents = NULL;
|
||||
gsize length;
|
||||
|
||||
hso_type_path = g_build_filename (sysfs_path, "hsotype", NULL);
|
||||
libhal_free_string (sysfs_path);
|
||||
|
||||
if (g_file_get_contents (hso_type_path, &contents, &length, NULL)) {
|
||||
if (g_str_has_prefix (contents, "Control"))
|
||||
supported = TRUE;
|
||||
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
g_free (hso_type_path);
|
||||
}
|
||||
}
|
||||
|
||||
libhal_free_string (driver_name);
|
||||
|
||||
return supported;
|
||||
}
|
||||
|
||||
static char *
|
||||
get_netdev (LibHalContext *ctx, const char *udi)
|
||||
{
|
||||
char *serial_parent, *netdev = NULL;
|
||||
char **netdevs;
|
||||
int num, i;
|
||||
|
||||
/* Get the serial interface's originating device UDI, used to find the
|
||||
* originating device's netdev.
|
||||
*/
|
||||
serial_parent = libhal_device_get_property_string (ctx, udi, "serial.originating_device", NULL);
|
||||
if (!serial_parent)
|
||||
serial_parent = libhal_device_get_property_string (ctx, udi, "info.parent", NULL);
|
||||
if (!serial_parent)
|
||||
return NULL;
|
||||
|
||||
/* Look for the originating device's netdev */
|
||||
netdevs = libhal_find_device_by_capability (ctx, "net", &num, NULL);
|
||||
for (i = 0; netdevs && !netdev && (i < num); i++) {
|
||||
char *netdev_parent, *tmp;
|
||||
|
||||
netdev_parent = libhal_device_get_property_string (ctx, netdevs[i], "net.originating_device", NULL);
|
||||
if (!netdev_parent)
|
||||
netdev_parent = libhal_device_get_property_string (ctx, netdevs[i], "net.physical_device", NULL);
|
||||
if (!netdev_parent)
|
||||
continue;
|
||||
|
||||
if (!strcmp (netdev_parent, serial_parent)) {
|
||||
/* We found it */
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.interface", NULL);
|
||||
if (tmp) {
|
||||
netdev = g_strdup (tmp);
|
||||
libhal_free_string (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
libhal_free_string (netdev_parent);
|
||||
}
|
||||
|
||||
if (!netdev) {
|
||||
/* Didn't find from netdev's parents. Try again with "grandparents" */
|
||||
char *serial_grandparent;
|
||||
|
||||
serial_grandparent = libhal_device_get_property_string (ctx, serial_parent, "info.parent", NULL);
|
||||
if (!serial_grandparent)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; netdevs && !netdev && (i < num); i++) {
|
||||
char *netdev_parent, *tmp;
|
||||
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.originating_device", NULL);
|
||||
if (!tmp)
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.physical_device", NULL);
|
||||
if (!tmp)
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "info.parent", NULL);
|
||||
if (!tmp)
|
||||
continue;
|
||||
|
||||
netdev_parent = libhal_device_get_property_string (ctx, tmp, "info.parent", NULL);
|
||||
libhal_free_string (tmp);
|
||||
|
||||
if (netdev_parent) {
|
||||
if (!strcmp (netdev_parent, serial_grandparent)) {
|
||||
/* We found it */
|
||||
tmp = libhal_device_get_property_string (ctx, netdevs[i], "net.interface", NULL);
|
||||
if (tmp) {
|
||||
netdev = g_strdup (tmp);
|
||||
libhal_free_string (tmp);
|
||||
}
|
||||
}
|
||||
|
||||
libhal_free_string (netdev_parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
libhal_free_string_array (netdevs);
|
||||
libhal_free_string (serial_parent);
|
||||
|
||||
return netdev;
|
||||
}
|
||||
|
||||
static MMModem *
|
||||
create_modem (MMPlugin *plugin, LibHalContext *hal_ctx, const char *udi)
|
||||
{
|
||||
char *serial_device;
|
||||
char *net_device;
|
||||
char *driver;
|
||||
MMModem *modem;
|
||||
|
||||
serial_device = libhal_device_get_property_string (hal_ctx, udi, "serial.device", NULL);
|
||||
g_return_val_if_fail (serial_device != NULL, NULL);
|
||||
|
||||
driver = get_driver_name (hal_ctx, udi);
|
||||
g_return_val_if_fail (driver != NULL, NULL);
|
||||
|
||||
net_device = get_netdev (hal_ctx, udi);
|
||||
g_return_val_if_fail (net_device != NULL, NULL);
|
||||
|
||||
modem = MM_MODEM (mm_modem_hso_new (serial_device, net_device, driver));
|
||||
|
||||
g_free (serial_device);
|
||||
g_free (net_device);
|
||||
g_free (driver);
|
||||
|
||||
return modem;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
@@ -226,17 +247,33 @@ plugin_init (MMPlugin *plugin_class)
|
||||
{
|
||||
/* interface implementation */
|
||||
plugin_class->get_name = get_name;
|
||||
plugin_class->list_supported_udis = list_supported_udis;
|
||||
plugin_class->supports_udi = supports_udi;
|
||||
plugin_class->create_modem = create_modem;
|
||||
plugin_class->supports_port = supports_port;
|
||||
plugin_class->grab_port = grab_port;
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_hso_init (MMPluginHso *self)
|
||||
{
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (self);
|
||||
const char *subsys[] = { "tty", "net", NULL };
|
||||
|
||||
priv->client = g_udev_client_new (subsys);
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
MMPluginHsoPrivate *priv = MM_PLUGIN_HSO_GET_PRIVATE (object);
|
||||
|
||||
g_object_unref (priv->client);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_plugin_hso_class_init (MMPluginHsoClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (MMPluginHsoPrivate));
|
||||
|
||||
object_class->dispose = dispose;
|
||||
}
|
||||
|
@@ -1,24 +1,39 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_PLUGIN_HSO_H
|
||||
#define MM_PLUGIN_HSO_H
|
||||
|
||||
#include "mm-plugin.h"
|
||||
#include "mm-plugin-base.h"
|
||||
#include "mm-generic-gsm.h"
|
||||
|
||||
#define MM_TYPE_PLUGIN_HSO (mm_plugin_hso_get_type ())
|
||||
#define MM_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHso))
|
||||
#define MM_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
#define MM_IS_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_IS_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_PLUGIN_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
#define MM_TYPE_PLUGIN_HSO (mm_plugin_hso_get_type ())
|
||||
#define MM_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHso))
|
||||
#define MM_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
#define MM_IS_PLUGIN_HSO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_IS_PLUGIN_HSO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PLUGIN_HSO))
|
||||
#define MM_PLUGIN_HSO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_HSO, MMPluginHsoClass))
|
||||
|
||||
typedef struct {
|
||||
GObject parent;
|
||||
MMPluginBase parent;
|
||||
} MMPluginHso;
|
||||
|
||||
typedef struct {
|
||||
GObjectClass parent;
|
||||
MMPluginBaseClass parent;
|
||||
} MMPluginHsoClass;
|
||||
|
||||
GType mm_plugin_hso_get_type (void);
|
||||
|
@@ -277,7 +277,7 @@ grab_port (MMPlugin *plugin,
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!devfile) {
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
@@ -199,7 +199,7 @@ grab_port (MMPlugin *plugin,
|
||||
}
|
||||
|
||||
sysfs_path = g_udev_device_get_sysfs_path (physdev);
|
||||
if (!devfile) {
|
||||
if (!sysfs_path) {
|
||||
g_set_error (error, 0, 0, "Could not get port's physical device sysfs path.");
|
||||
goto out;
|
||||
}
|
||||
|
@@ -21,8 +21,10 @@ modem_manager_SOURCES = \
|
||||
mm-manager.h \
|
||||
mm-modem.c \
|
||||
mm-modem.h \
|
||||
mm-serial.c \
|
||||
mm-serial.h \
|
||||
mm-port.c \
|
||||
mm-port.h \
|
||||
mm-modem-base.c \
|
||||
mm-modem-base.h \
|
||||
mm-serial-port.c \
|
||||
mm-serial-port.h \
|
||||
mm-serial-parsers.c \
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "mm-generic-cdma.h"
|
||||
#include "mm-modem-cdma.h"
|
||||
#include "mm-modem-simple.h"
|
||||
#include "mm-serial-port.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-callback-info.h"
|
||||
#include "mm-serial-parsers.h"
|
||||
@@ -24,6 +25,7 @@ typedef struct {
|
||||
|
||||
MMSerialPort *primary;
|
||||
MMSerialPort *secondary;
|
||||
MMPort *data;
|
||||
} MMGenericCdmaPrivate;
|
||||
|
||||
MMModem *
|
||||
@@ -64,7 +66,7 @@ check_valid (MMGenericCdma *self)
|
||||
MMGenericCdmaPrivate *priv = MM_GENERIC_CDMA_GET_PRIVATE (self);
|
||||
gboolean new_valid = FALSE;
|
||||
|
||||
if (priv->primary)
|
||||
if (priv->primary && priv->data)
|
||||
new_valid = TRUE;
|
||||
|
||||
if (priv->valid != new_valid) {
|
||||
@@ -76,12 +78,7 @@ check_valid (MMGenericCdma *self)
|
||||
static gboolean
|
||||
owns_port (MMModem *modem, const char *subsys, const char *name)
|
||||
{
|
||||
MMGenericCdma *self = MM_GENERIC_CDMA (modem);
|
||||
|
||||
if (strcmp (subsys, "tty"))
|
||||
return FALSE;
|
||||
|
||||
return !!mm_serial_get_port (MM_SERIAL (self), name);
|
||||
return !!mm_modem_base_get_port (MM_MODEM_BASE (modem), subsys, name);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -92,30 +89,45 @@ grab_port (MMModem *modem,
|
||||
{
|
||||
MMGenericCdma *self = MM_GENERIC_CDMA (modem);
|
||||
MMGenericCdmaPrivate *priv = MM_GENERIC_CDMA_GET_PRIVATE (self);
|
||||
MMSerialPortType ptype = MM_SERIAL_PORT_TYPE_IGNORED;
|
||||
MMSerialPort *port;
|
||||
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
||||
MMPort *port;
|
||||
|
||||
if (strcmp (subsys, "tty"))
|
||||
return FALSE;
|
||||
g_return_val_if_fail (!strcmp (subsys, "net") || !strcmp (subsys, "tty"), FALSE);
|
||||
|
||||
if (!priv->primary)
|
||||
ptype = MM_SERIAL_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_SERIAL_PORT_TYPE_SECONDARY;
|
||||
if (!strcmp (subsys, "tty")) {
|
||||
if (!priv->primary)
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
}
|
||||
|
||||
port = mm_serial_add_port (MM_SERIAL (self), name, ptype);
|
||||
g_object_set (G_OBJECT (port), MM_SERIAL_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
mm_serial_port_set_response_parser (port,
|
||||
mm_serial_parser_v1_parse,
|
||||
mm_serial_parser_v1_new (),
|
||||
mm_serial_parser_v1_destroy);
|
||||
port = mm_modem_base_add_port (MM_MODEM_BASE (self), subsys, name, ptype);
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
g_object_set (G_OBJECT (port), MM_PORT_CARRIER_DETECT, FALSE, NULL);
|
||||
mm_serial_port_set_response_parser (MM_SERIAL_PORT (port),
|
||||
mm_serial_parser_v1_parse,
|
||||
mm_serial_parser_v1_new (),
|
||||
mm_serial_parser_v1_destroy);
|
||||
}
|
||||
|
||||
if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY) {
|
||||
priv->primary = port;
|
||||
g_object_notify (G_OBJECT (self), MM_MODEM_DATA_DEVICE);
|
||||
check_valid (self);
|
||||
} else if (ptype == MM_SERIAL_PORT_TYPE_SECONDARY)
|
||||
priv->secondary = port;
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
if (ptype == MM_PORT_TYPE_PRIMARY) {
|
||||
priv->primary = MM_SERIAL_PORT (port);
|
||||
if (!priv->data) {
|
||||
priv->data = port;
|
||||
g_object_notify (G_OBJECT (self), MM_MODEM_DATA_DEVICE);
|
||||
}
|
||||
check_valid (self);
|
||||
} else if (ptype == MM_PORT_TYPE_SECONDARY)
|
||||
priv->secondary = MM_SERIAL_PORT (port);
|
||||
} else {
|
||||
/* Net device (if any) is the preferred data port */
|
||||
if (priv->data && MM_IS_SERIAL_PORT (priv->data)) {
|
||||
priv->data = port;
|
||||
g_object_notify (G_OBJECT (self), MM_MODEM_DATA_DEVICE);
|
||||
check_valid (self);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -124,22 +136,24 @@ static void
|
||||
release_port (MMModem *modem, const char *subsys, const char *name)
|
||||
{
|
||||
MMGenericCdmaPrivate *priv = MM_GENERIC_CDMA_GET_PRIVATE (modem);
|
||||
MMSerialPort *port;
|
||||
MMPort *port;
|
||||
|
||||
if (strcmp (subsys, "tty"))
|
||||
return;
|
||||
|
||||
port = mm_serial_get_port (MM_SERIAL (modem), name);
|
||||
port = mm_modem_base_get_port (MM_MODEM_BASE (modem), subsys, name);
|
||||
if (!port)
|
||||
return;
|
||||
|
||||
if (port == priv->primary) {
|
||||
mm_serial_remove_port (MM_SERIAL (modem), port);
|
||||
if (port == MM_PORT (priv->primary)) {
|
||||
mm_modem_base_remove_port (MM_MODEM_BASE (modem), port);
|
||||
priv->primary = NULL;
|
||||
}
|
||||
|
||||
if (port == priv->secondary) {
|
||||
mm_serial_remove_port (MM_SERIAL (modem), port);
|
||||
if (port == priv->data) {
|
||||
priv->data = NULL;
|
||||
g_object_notify (G_OBJECT (modem), MM_MODEM_DATA_DEVICE);
|
||||
}
|
||||
|
||||
if (port == MM_PORT (priv->secondary)) {
|
||||
mm_modem_base_remove_port (MM_MODEM_BASE (modem), port);
|
||||
priv->secondary = NULL;
|
||||
}
|
||||
|
||||
@@ -732,8 +746,8 @@ get_property (GObject *object, guint prop_id,
|
||||
|
||||
switch (prop_id) {
|
||||
case MM_MODEM_PROP_DATA_DEVICE:
|
||||
if (priv->primary)
|
||||
g_value_set_string (value, mm_serial_port_get_device (priv->primary));
|
||||
if (priv->data)
|
||||
g_value_set_string (value, mm_port_get_device (priv->data));
|
||||
else
|
||||
g_value_set_string (value, NULL);
|
||||
break;
|
||||
@@ -844,7 +858,10 @@ mm_generic_cdma_get_type (void)
|
||||
(GInterfaceInitFunc) modem_simple_init
|
||||
};
|
||||
|
||||
generic_cdma_type = g_type_register_static (MM_TYPE_SERIAL, "MMGenericCdma", &generic_cdma_type_info, 0);
|
||||
generic_cdma_type = g_type_register_static (MM_TYPE_MODEM_BASE,
|
||||
"MMGenericCdma",
|
||||
&generic_cdma_type_info,
|
||||
0);
|
||||
|
||||
g_type_add_interface_static (generic_cdma_type, MM_TYPE_MODEM, &modem_iface_info);
|
||||
g_type_add_interface_static (generic_cdma_type, MM_TYPE_MODEM_CDMA, &modem_cdma_iface_info);
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#define MM_GENERIC_CDMA_H
|
||||
|
||||
#include "mm-modem.h"
|
||||
#include "mm-serial.h"
|
||||
#include "mm-modem-base.h"
|
||||
|
||||
#define MM_TYPE_GENERIC_CDMA (mm_generic_cdma_get_type ())
|
||||
#define MM_GENERIC_CDMA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_GENERIC_CDMA, MMGenericCdma))
|
||||
@@ -14,11 +14,11 @@
|
||||
#define MM_GENERIC_CDMA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_GENERIC_CDMA, MMGenericCdmaClass))
|
||||
|
||||
typedef struct {
|
||||
MMSerial parent;
|
||||
MMModemBase parent;
|
||||
} MMGenericCdma;
|
||||
|
||||
typedef struct {
|
||||
MMSerialClass parent;
|
||||
MMModemBaseClass parent;
|
||||
} MMGenericCdmaClass;
|
||||
|
||||
GType mm_generic_cdma_get_type (void);
|
||||
|
@@ -37,6 +37,7 @@ typedef struct {
|
||||
|
||||
MMSerialPort *primary;
|
||||
MMSerialPort *secondary;
|
||||
MMPort *data;
|
||||
} MMGenericGsmPrivate;
|
||||
|
||||
static void get_registration_status (MMSerialPort *port, MMCallbackInfo *info);
|
||||
@@ -187,7 +188,7 @@ check_valid (MMGenericGsm *self)
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||
gboolean new_valid = FALSE;
|
||||
|
||||
if (priv->primary)
|
||||
if (priv->primary && priv->data)
|
||||
new_valid = TRUE;
|
||||
|
||||
if (priv->valid != new_valid) {
|
||||
@@ -199,44 +200,50 @@ check_valid (MMGenericGsm *self)
|
||||
static gboolean
|
||||
owns_port (MMModem *modem, const char *subsys, const char *name)
|
||||
{
|
||||
MMGenericGsm *self = MM_GENERIC_GSM (modem);
|
||||
|
||||
if (strcmp (subsys, "tty"))
|
||||
return FALSE;
|
||||
|
||||
return !!mm_serial_get_port (MM_SERIAL (self), name);
|
||||
return !!mm_modem_base_get_port (MM_MODEM_BASE (modem), subsys, name);
|
||||
}
|
||||
|
||||
MMSerialPort *
|
||||
MMPort *
|
||||
mm_generic_gsm_grab_port (MMGenericGsm *self,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMSerialPortType ptype,
|
||||
MMPortType ptype,
|
||||
GError **error)
|
||||
{
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||
MMSerialPort *port = NULL;
|
||||
MMPort *port = NULL;
|
||||
GRegex *regex;
|
||||
|
||||
if (strcmp (subsys, "tty"))
|
||||
return NULL;
|
||||
g_return_val_if_fail (!strcmp (subsys, "net") || !strcmp (subsys, "tty"), FALSE);
|
||||
|
||||
port = mm_serial_add_port (MM_SERIAL (self), name, ptype);
|
||||
mm_serial_port_set_response_parser (port,
|
||||
mm_serial_parser_v1_parse,
|
||||
mm_serial_parser_v1_new (),
|
||||
mm_serial_parser_v1_destroy);
|
||||
port = mm_modem_base_add_port (MM_MODEM_BASE (self), subsys, name, ptype);
|
||||
if (MM_IS_SERIAL_PORT (port)) {
|
||||
mm_serial_port_set_response_parser (MM_SERIAL_PORT (port),
|
||||
mm_serial_parser_v1_parse,
|
||||
mm_serial_parser_v1_new (),
|
||||
mm_serial_parser_v1_destroy);
|
||||
|
||||
regex = g_regex_new ("\\r\\n\\+CREG: (\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (port, regex, reg_state_changed, self, NULL);
|
||||
g_regex_unref (regex);
|
||||
regex = g_regex_new ("\\r\\n\\+CREG: (\\d+)\\r\\n", G_REGEX_RAW | G_REGEX_OPTIMIZE, 0, NULL);
|
||||
mm_serial_port_add_unsolicited_msg_handler (MM_SERIAL_PORT (port), regex, reg_state_changed, self, NULL);
|
||||
g_regex_unref (regex);
|
||||
|
||||
if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY) {
|
||||
priv->primary = port;
|
||||
g_object_notify (G_OBJECT (self), MM_MODEM_DATA_DEVICE);
|
||||
check_valid (self);
|
||||
} else if (ptype == MM_SERIAL_PORT_TYPE_SECONDARY)
|
||||
priv->secondary = port;
|
||||
if (ptype == MM_PORT_TYPE_PRIMARY) {
|
||||
priv->primary = MM_SERIAL_PORT (port);
|
||||
if (!priv->data) {
|
||||
priv->data = port;
|
||||
g_object_notify (G_OBJECT (self), MM_MODEM_DATA_DEVICE);
|
||||
}
|
||||
check_valid (self);
|
||||
} else if (ptype == MM_PORT_TYPE_SECONDARY)
|
||||
priv->secondary = MM_SERIAL_PORT (port);
|
||||
} else {
|
||||
/* Net device (if any) is the preferred data port */
|
||||
if (priv->data && MM_IS_SERIAL_PORT (priv->data)) {
|
||||
priv->data = port;
|
||||
g_object_notify (G_OBJECT (self), MM_MODEM_DATA_DEVICE);
|
||||
check_valid (self);
|
||||
}
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
@@ -249,12 +256,14 @@ grab_port (MMModem *modem,
|
||||
{
|
||||
MMGenericGsm *self = MM_GENERIC_GSM (modem);
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (self);
|
||||
MMSerialPortType ptype = MM_SERIAL_PORT_TYPE_IGNORED;
|
||||
MMPortType ptype = MM_PORT_TYPE_IGNORED;
|
||||
|
||||
if (!priv->primary)
|
||||
ptype = MM_SERIAL_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_SERIAL_PORT_TYPE_SECONDARY;
|
||||
if (!strcmp (subsys, "tty")) {
|
||||
if (!priv->primary)
|
||||
ptype = MM_PORT_TYPE_PRIMARY;
|
||||
else if (!priv->secondary)
|
||||
ptype = MM_PORT_TYPE_SECONDARY;
|
||||
}
|
||||
|
||||
return !!mm_generic_gsm_grab_port (self, subsys, name, ptype, error);
|
||||
}
|
||||
@@ -263,26 +272,31 @@ static void
|
||||
release_port (MMModem *modem, const char *subsys, const char *name)
|
||||
{
|
||||
MMGenericGsmPrivate *priv = MM_GENERIC_GSM_GET_PRIVATE (modem);
|
||||
MMSerialPort *port;
|
||||
MMPort *port;
|
||||
|
||||
if (strcmp (subsys, "tty"))
|
||||
return;
|
||||
|
||||
port = mm_serial_get_port (MM_SERIAL (modem), name);
|
||||
port = mm_modem_base_get_port (MM_MODEM_BASE (modem), subsys, name);
|
||||
if (!port)
|
||||
return;
|
||||
|
||||
if (port == priv->primary) {
|
||||
mm_serial_remove_port (MM_SERIAL (modem), port);
|
||||
if (port == MM_PORT (priv->primary)) {
|
||||
mm_modem_base_remove_port (MM_MODEM_BASE (modem), port);
|
||||
priv->primary = NULL;
|
||||
check_valid (MM_GENERIC_GSM (modem));
|
||||
}
|
||||
|
||||
if (port == priv->secondary) {
|
||||
mm_serial_remove_port (MM_SERIAL (modem), port);
|
||||
priv->secondary = NULL;
|
||||
check_valid (MM_GENERIC_GSM (modem));
|
||||
if (port == priv->data) {
|
||||
priv->data = NULL;
|
||||
g_object_notify (G_OBJECT (modem), MM_MODEM_DATA_DEVICE);
|
||||
}
|
||||
|
||||
if (port == MM_PORT (priv->secondary)) {
|
||||
mm_modem_base_remove_port (MM_MODEM_BASE (modem), port);
|
||||
priv->secondary = NULL;
|
||||
}
|
||||
|
||||
check_valid (MM_GENERIC_GSM (modem));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1407,14 +1421,14 @@ sms_send (MMModemGsmSms *modem,
|
||||
|
||||
MMSerialPort *
|
||||
mm_generic_gsm_get_port (MMGenericGsm *modem,
|
||||
MMSerialPortType ptype)
|
||||
MMPortType ptype)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_GENERIC_GSM (modem), NULL);
|
||||
g_return_val_if_fail (ptype != MM_SERIAL_PORT_TYPE_UNKNOWN, NULL);
|
||||
g_return_val_if_fail (ptype != MM_PORT_TYPE_UNKNOWN, NULL);
|
||||
|
||||
if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY)
|
||||
if (ptype == MM_PORT_TYPE_PRIMARY)
|
||||
return MM_GENERIC_GSM_GET_PRIVATE (modem)->primary;
|
||||
else if (ptype == MM_SERIAL_PORT_TYPE_SECONDARY)
|
||||
else if (ptype == MM_PORT_TYPE_SECONDARY)
|
||||
return MM_GENERIC_GSM_GET_PRIVATE (modem)->secondary;
|
||||
|
||||
return NULL;
|
||||
@@ -1757,8 +1771,8 @@ get_property (GObject *object, guint prop_id,
|
||||
|
||||
switch (prop_id) {
|
||||
case MM_MODEM_PROP_DATA_DEVICE:
|
||||
if (priv->primary)
|
||||
g_value_set_string (value, mm_serial_port_get_device (priv->primary));
|
||||
if (priv->data)
|
||||
g_value_set_string (value, mm_port_get_device (priv->data));
|
||||
else
|
||||
g_value_set_string (value, NULL);
|
||||
break;
|
||||
@@ -1915,7 +1929,10 @@ mm_generic_gsm_get_type (void)
|
||||
(GInterfaceInitFunc) modem_simple_init
|
||||
};
|
||||
|
||||
generic_gsm_type = g_type_register_static (MM_TYPE_SERIAL, "MMGenericGsm", &generic_gsm_type_info, 0);
|
||||
generic_gsm_type = g_type_register_static (MM_TYPE_MODEM_BASE,
|
||||
"MMGenericGsm",
|
||||
&generic_gsm_type_info,
|
||||
0);
|
||||
|
||||
g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM, &modem_iface_info);
|
||||
g_type_add_interface_static (generic_gsm_type, MM_TYPE_MODEM_GSM_CARD, &modem_gsm_card_info);
|
||||
|
@@ -4,7 +4,8 @@
|
||||
#define MM_GENERIC_GSM_H
|
||||
|
||||
#include "mm-modem-gsm-network.h"
|
||||
#include "mm-serial.h"
|
||||
#include "mm-modem-base.h"
|
||||
#include "mm-serial-port.h"
|
||||
|
||||
#define MM_TYPE_GENERIC_GSM (mm_generic_gsm_get_type ())
|
||||
#define MM_GENERIC_GSM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_GENERIC_GSM, MMGenericGsm))
|
||||
@@ -29,11 +30,11 @@ typedef enum {
|
||||
|
||||
|
||||
typedef struct {
|
||||
MMSerial parent;
|
||||
MMModemBase parent;
|
||||
} MMGenericGsm;
|
||||
|
||||
typedef struct {
|
||||
MMSerialClass parent;
|
||||
MMModemBaseClass parent;
|
||||
} MMGenericGsmClass;
|
||||
|
||||
GType mm_generic_gsm_get_type (void);
|
||||
@@ -59,12 +60,12 @@ void mm_generic_gsm_check_pin (MMGenericGsm *modem,
|
||||
gpointer user_data);
|
||||
|
||||
MMSerialPort *mm_generic_gsm_get_port (MMGenericGsm *modem,
|
||||
MMSerialPortType ptype);
|
||||
MMPortType ptype);
|
||||
|
||||
MMSerialPort *mm_generic_gsm_grab_port (MMGenericGsm *modem,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMSerialPortType ptype,
|
||||
GError **error);
|
||||
MMPort *mm_generic_gsm_grab_port (MMGenericGsm *modem,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType ptype,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_GENERIC_GSM_H */
|
||||
|
156
src/mm-modem-base.c
Normal file
156
src/mm-modem-base.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mm-modem-base.h"
|
||||
#include "mm-serial-port.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-options.h"
|
||||
|
||||
G_DEFINE_TYPE (MMModemBase, mm_modem_base, G_TYPE_OBJECT)
|
||||
|
||||
#define MM_MODEM_BASE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_MODEM_BASE, MMModemBasePrivate))
|
||||
|
||||
typedef struct {
|
||||
GHashTable *ports;
|
||||
} MMModemBasePrivate;
|
||||
|
||||
static char *
|
||||
get_hash_key (const char *subsys, const char *name)
|
||||
{
|
||||
return g_strdup_printf ("%s%s", subsys, name);
|
||||
}
|
||||
|
||||
MMPort *
|
||||
mm_modem_base_get_port (MMModemBase *self,
|
||||
const char *subsys,
|
||||
const char *name)
|
||||
{
|
||||
MMPort *port;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
g_return_val_if_fail (MM_IS_MODEM_BASE (self), NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
g_return_val_if_fail (subsys != NULL, NULL);
|
||||
|
||||
g_return_val_if_fail (!strcmp (subsys, "net") || !strcmp (subsys, "tty"), NULL);
|
||||
|
||||
key = get_hash_key (subsys, name);
|
||||
port = g_hash_table_lookup (MM_MODEM_BASE_GET_PRIVATE (self)->ports, key);
|
||||
g_free (key);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
find_primary (gpointer key, gpointer data, gpointer user_data)
|
||||
{
|
||||
MMPort **found = user_data;
|
||||
MMPort *port = MM_PORT (data);
|
||||
|
||||
if (!*found && (mm_port_get_port_type (port) == MM_PORT_TYPE_PRIMARY))
|
||||
*found = port;
|
||||
}
|
||||
|
||||
MMPort *
|
||||
mm_modem_base_add_port (MMModemBase *self,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType ptype)
|
||||
{
|
||||
MMModemBasePrivate *priv = MM_MODEM_BASE_GET_PRIVATE (self);
|
||||
MMPort *port = NULL;
|
||||
char *key;
|
||||
|
||||
g_return_val_if_fail (MM_IS_MODEM_BASE (self), NULL);
|
||||
g_return_val_if_fail (subsys != NULL, NULL);
|
||||
g_return_val_if_fail (name != NULL, NULL);
|
||||
g_return_val_if_fail (ptype != MM_PORT_TYPE_UNKNOWN, NULL);
|
||||
|
||||
g_return_val_if_fail (!strcmp (subsys, "net") || !strcmp (subsys, "tty"), NULL);
|
||||
|
||||
key = get_hash_key (subsys, name);
|
||||
port = g_hash_table_lookup (priv->ports, key);
|
||||
g_free (key);
|
||||
g_return_val_if_fail (port == NULL, NULL);
|
||||
|
||||
if (ptype == MM_PORT_TYPE_PRIMARY) {
|
||||
g_hash_table_foreach (priv->ports, find_primary, &port);
|
||||
g_return_val_if_fail (port == NULL, FALSE);
|
||||
}
|
||||
|
||||
if (!strcmp (subsys, "tty"))
|
||||
port = MM_PORT (mm_serial_port_new (name, ptype));
|
||||
else if (!strcmp (subsys, "net")) {
|
||||
port = MM_PORT (g_object_new (MM_TYPE_PORT,
|
||||
MM_PORT_DEVICE, name,
|
||||
MM_PORT_SUBSYS, MM_PORT_SUBSYS_NET,
|
||||
MM_PORT_TYPE, ptype,
|
||||
NULL));
|
||||
}
|
||||
|
||||
if (!port)
|
||||
return NULL;
|
||||
|
||||
key = get_hash_key (subsys, name);
|
||||
g_hash_table_insert (priv->ports, key, port);
|
||||
return port;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_modem_base_remove_port (MMModemBase *self, MMPort *port)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_MODEM_BASE (self), FALSE);
|
||||
g_return_val_if_fail (port != NULL, FALSE);
|
||||
|
||||
return g_hash_table_remove (MM_MODEM_BASE_GET_PRIVATE (self)->ports, port);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_modem_base_init (MMModemBase *self)
|
||||
{
|
||||
MMModemBasePrivate *priv = MM_MODEM_BASE_GET_PRIVATE (self);
|
||||
|
||||
priv->ports = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
MMModemBase *self = MM_MODEM_BASE (object);
|
||||
MMModemBasePrivate *priv = MM_MODEM_BASE_GET_PRIVATE (self);
|
||||
|
||||
g_hash_table_destroy (priv->ports);
|
||||
|
||||
G_OBJECT_CLASS (mm_modem_base_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_modem_base_class_init (MMModemBaseClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (MMModemBasePrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->finalize = finalize;
|
||||
}
|
59
src/mm-modem-base.h
Normal file
59
src/mm-modem-base.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_BASE_H
|
||||
#define MM_MODEM_BASE_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "mm-port.h"
|
||||
|
||||
#define MM_TYPE_MODEM_BASE (mm_modem_base_get_type ())
|
||||
#define MM_MODEM_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_MODEM_BASE, MMModemBase))
|
||||
#define MM_MODEM_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_MODEM_BASE, MMModemBaseClass))
|
||||
#define MM_IS_MODEM_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_MODEM_BASE))
|
||||
#define MM_IS_MODEM_BASE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_MODEM_BASE))
|
||||
#define MM_MODEM_BASE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MODEM_BASE, MMModemBaseClass))
|
||||
|
||||
typedef struct _MMModemBase MMModemBase;
|
||||
typedef struct _MMModemBaseClass MMModemBaseClass;
|
||||
|
||||
struct _MMModemBase {
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
struct _MMModemBaseClass {
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
GType mm_modem_base_get_type (void);
|
||||
|
||||
MMPort *mm_modem_base_get_port (MMModemBase *self,
|
||||
const char *subsys,
|
||||
const char *name);
|
||||
|
||||
MMPort *mm_modem_base_add_port (MMModemBase *self,
|
||||
const char *subsys,
|
||||
const char *name,
|
||||
MMPortType ptype);
|
||||
|
||||
gboolean mm_modem_base_remove_port (MMModemBase *self,
|
||||
MMPort *port);
|
||||
|
||||
#endif /* MM_MODEM_BASE_H */
|
||||
|
238
src/mm-port.c
Normal file
238
src/mm-port.c
Normal file
@@ -0,0 +1,238 @@
|
||||
/* -*- 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) 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mm-port.h"
|
||||
|
||||
G_DEFINE_TYPE (MMPort, mm_port, G_TYPE_OBJECT)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DEVICE,
|
||||
PROP_SUBSYS,
|
||||
PROP_TYPE,
|
||||
PROP_CARRIER_DETECT,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
#define MM_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_PORT, MMPortPrivate))
|
||||
|
||||
typedef struct {
|
||||
char *device;
|
||||
MMPortSubsys subsys;
|
||||
MMPortType ptype;
|
||||
gboolean carrier_detect;
|
||||
} MMPortPrivate;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static GObject*
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
MMPortPrivate *priv;
|
||||
|
||||
object = G_OBJECT_CLASS (mm_port_parent_class)->constructor (type,
|
||||
n_construct_params,
|
||||
construct_params);
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = MM_PORT_GET_PRIVATE (object);
|
||||
|
||||
if (!priv->device) {
|
||||
g_warning ("MMPort: no device provided");
|
||||
g_object_unref (object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (priv->subsys == MM_PORT_SUBSYS_UNKNOWN) {
|
||||
g_warning ("MMPort: invalid port subsystem");
|
||||
g_object_unref (object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (priv->ptype == MM_PORT_TYPE_UNKNOWN) {
|
||||
g_warning ("MMPort: invalid port type");
|
||||
g_object_unref (object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
const char *
|
||||
mm_port_get_device (MMPort *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
g_return_val_if_fail (MM_IS_PORT (self), NULL);
|
||||
|
||||
return MM_PORT_GET_PRIVATE (self)->device;
|
||||
}
|
||||
|
||||
MMPortSubsys
|
||||
mm_port_get_subsys (MMPort *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, MM_PORT_SUBSYS_UNKNOWN);
|
||||
g_return_val_if_fail (MM_IS_PORT (self), MM_PORT_SUBSYS_UNKNOWN);
|
||||
|
||||
return MM_PORT_GET_PRIVATE (self)->subsys;
|
||||
}
|
||||
|
||||
MMPortType
|
||||
mm_port_get_port_type (MMPort *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, MM_PORT_TYPE_UNKNOWN);
|
||||
g_return_val_if_fail (MM_IS_PORT (self), MM_PORT_TYPE_UNKNOWN);
|
||||
|
||||
return MM_PORT_GET_PRIVATE (self)->ptype;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_port_get_carrier_detect (MMPort *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, MM_PORT_TYPE_UNKNOWN);
|
||||
g_return_val_if_fail (MM_IS_PORT (self), MM_PORT_TYPE_UNKNOWN);
|
||||
|
||||
return MM_PORT_GET_PRIVATE (self)->carrier_detect;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_port_init (MMPort *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
MMPortPrivate *priv = MM_PORT_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DEVICE:
|
||||
/* Construct only */
|
||||
priv->device = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_SUBSYS:
|
||||
/* Construct only */
|
||||
priv->subsys = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_TYPE:
|
||||
/* Construct only */
|
||||
priv->ptype = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_CARRIER_DETECT:
|
||||
priv->carrier_detect = g_value_get_boolean (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)
|
||||
{
|
||||
MMPortPrivate *priv = MM_PORT_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DEVICE:
|
||||
g_value_set_string (value, priv->device);
|
||||
break;
|
||||
case PROP_SUBSYS:
|
||||
g_value_set_uint (value, priv->subsys);
|
||||
break;
|
||||
case PROP_TYPE:
|
||||
g_value_set_uint (value, priv->ptype);
|
||||
break;
|
||||
case PROP_CARRIER_DETECT:
|
||||
g_value_set_boolean (value, priv->carrier_detect);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
MMPortPrivate *priv = MM_PORT_GET_PRIVATE (object);
|
||||
|
||||
g_free (priv->device);
|
||||
|
||||
G_OBJECT_CLASS (mm_port_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_port_class_init (MMPortClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (MMPortPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_DEVICE,
|
||||
g_param_spec_string (MM_PORT_DEVICE,
|
||||
"Device",
|
||||
"Device",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_SUBSYS,
|
||||
g_param_spec_uint (MM_PORT_SUBSYS,
|
||||
"Subsystem",
|
||||
"Subsystem",
|
||||
MM_PORT_SUBSYS_UNKNOWN,
|
||||
MM_PORT_SUBSYS_LAST,
|
||||
MM_PORT_SUBSYS_UNKNOWN,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_TYPE,
|
||||
g_param_spec_uint (MM_PORT_TYPE,
|
||||
"Type",
|
||||
"Type",
|
||||
MM_PORT_TYPE_UNKNOWN,
|
||||
MM_PORT_TYPE_LAST,
|
||||
MM_PORT_TYPE_UNKNOWN,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_CARRIER_DETECT,
|
||||
g_param_spec_boolean (MM_PORT_CARRIER_DETECT,
|
||||
"Carrier Detect",
|
||||
"Has Carrier Detect",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
||||
}
|
74
src/mm-port.h
Normal file
74
src/mm-port.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* -*- 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) 2009 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_PORT_H
|
||||
#define MM_PORT_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
typedef enum {
|
||||
MM_PORT_SUBSYS_UNKNOWN = 0x0,
|
||||
MM_PORT_SUBSYS_TTY,
|
||||
MM_PORT_SUBSYS_NET,
|
||||
|
||||
MM_PORT_SUBSYS_LAST = MM_PORT_SUBSYS_NET
|
||||
} MMPortSubsys;
|
||||
|
||||
typedef enum {
|
||||
MM_PORT_TYPE_UNKNOWN = 0x0,
|
||||
MM_PORT_TYPE_PRIMARY,
|
||||
MM_PORT_TYPE_SECONDARY,
|
||||
MM_PORT_TYPE_IGNORED,
|
||||
|
||||
MM_PORT_TYPE_LAST = MM_PORT_TYPE_IGNORED
|
||||
} MMPortType;
|
||||
|
||||
#define MM_TYPE_PORT (mm_port_get_type ())
|
||||
#define MM_PORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PORT, MMPort))
|
||||
#define MM_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_PORT, MMPortClass))
|
||||
#define MM_IS_PORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_PORT))
|
||||
#define MM_IS_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_PORT))
|
||||
#define MM_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PORT, MMPortClass))
|
||||
|
||||
#define MM_PORT_DEVICE "device"
|
||||
#define MM_PORT_SUBSYS "subsys"
|
||||
#define MM_PORT_TYPE "type"
|
||||
#define MM_PORT_CARRIER_DETECT "carrier-detect"
|
||||
|
||||
typedef struct _MMPort MMPort;
|
||||
typedef struct _MMPortClass MMPortClass;
|
||||
|
||||
struct _MMPort {
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
struct _MMPortClass {
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
GType mm_port_get_type (void);
|
||||
|
||||
const char * mm_port_get_device (MMPort *self);
|
||||
|
||||
MMPortSubsys mm_port_get_subsys (MMPort *self);
|
||||
|
||||
MMPortType mm_port_get_port_type (MMPort *self);
|
||||
|
||||
gboolean mm_port_get_carrier_detect (MMPort *self);
|
||||
|
||||
#endif /* MM_PORT_H */
|
||||
|
@@ -33,17 +33,15 @@
|
||||
|
||||
static gboolean mm_serial_port_queue_process (gpointer data);
|
||||
|
||||
G_DEFINE_TYPE (MMSerialPort, mm_serial_port, G_TYPE_OBJECT)
|
||||
G_DEFINE_TYPE (MMSerialPort, mm_serial_port, MM_TYPE_PORT)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_DEVICE,
|
||||
PROP_BAUD,
|
||||
PROP_BITS,
|
||||
PROP_PARITY,
|
||||
PROP_STOPBITS,
|
||||
PROP_SEND_DELAY,
|
||||
PROP_CARRIER_DETECT,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
@@ -68,13 +66,11 @@ typedef struct {
|
||||
|
||||
struct termios old_t;
|
||||
|
||||
char *device;
|
||||
guint baud;
|
||||
guint bits;
|
||||
char parity;
|
||||
guint stopbits;
|
||||
guint64 send_delay;
|
||||
gboolean carrier_detect;
|
||||
|
||||
guint queue_schedule;
|
||||
guint watch_id;
|
||||
@@ -88,14 +84,6 @@ typedef struct {
|
||||
GDestroyNotify notify;
|
||||
} MMUnsolicitedMsgHandler;
|
||||
|
||||
const char *
|
||||
mm_serial_port_get_device (MMSerialPort *self)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_SERIAL_PORT (self), NULL);
|
||||
|
||||
return MM_SERIAL_PORT_GET_PRIVATE (self)->device;
|
||||
}
|
||||
|
||||
static void
|
||||
mm_serial_port_set_cached_reply (MMSerialPort *self,
|
||||
const char *command,
|
||||
@@ -279,7 +267,8 @@ config_fd (MMSerialPort *self)
|
||||
stbuf.c_cflag |= (speed | bits | CREAD | 0 | parity | stopbits);
|
||||
|
||||
if (ioctl (priv->fd, TCSETA, &stbuf) < 0) {
|
||||
g_warning ("(%s) cannot control device (errno %d)", priv->device, errno);
|
||||
g_warning ("(%s) cannot control device (errno %d)",
|
||||
mm_port_get_device (MM_PORT (self)), errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -639,7 +628,7 @@ data_available (GIOChannel *source,
|
||||
/* Make sure the string doesn't grow too long */
|
||||
if (priv->response->len > SERIAL_BUF_SIZE) {
|
||||
g_warning ("%s (%s): response buffer filled before repsonse received",
|
||||
G_STRFUNC, mm_serial_port_get_device (self));
|
||||
G_STRFUNC, mm_port_get_device (MM_PORT (self)));
|
||||
g_string_erase (priv->response, 0, (SERIAL_BUF_SIZE / 2));
|
||||
}
|
||||
|
||||
@@ -655,6 +644,7 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
|
||||
{
|
||||
MMSerialPortPrivate *priv;
|
||||
char *devfile;
|
||||
const char *device;
|
||||
|
||||
g_return_val_if_fail (MM_IS_SERIAL_PORT (self), FALSE);
|
||||
|
||||
@@ -664,20 +654,22 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
|
||||
/* Already open */
|
||||
return TRUE;
|
||||
|
||||
g_debug ("(%s) opening serial device...", priv->device);
|
||||
devfile = g_strdup_printf ("/dev/%s", priv->device);
|
||||
device = mm_port_get_device (MM_PORT (self));
|
||||
|
||||
g_debug ("(%s) opening serial device...", device);
|
||||
devfile = g_strdup_printf ("/dev/%s", device);
|
||||
priv->fd = open (devfile, O_RDWR | O_EXCL | O_NONBLOCK | O_NOCTTY);
|
||||
g_free (devfile);
|
||||
|
||||
if (priv->fd < 0) {
|
||||
g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_OPEN_FAILED,
|
||||
"Could not open serial device %s: %s", priv->device, strerror (errno));
|
||||
"Could not open serial device %s: %s", device, strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (ioctl (priv->fd, TCGETA, &priv->old_t) < 0) {
|
||||
g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_OPEN_FAILED,
|
||||
"Could not open serial device %s: %s", priv->device, strerror (errno));
|
||||
"Could not open serial device %s: %s", device, strerror (errno));
|
||||
close (priv->fd);
|
||||
priv->fd = -1;
|
||||
return FALSE;
|
||||
@@ -685,7 +677,7 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
|
||||
|
||||
if (!config_fd (self)) {
|
||||
g_set_error (error, MM_SERIAL_ERROR, MM_SERIAL_OPEN_FAILED,
|
||||
"Could not open serial device %s: %s", priv->device, strerror (errno));
|
||||
"Could not open serial device %s: %s", device, strerror (errno));
|
||||
close (priv->fd);
|
||||
priv->fd = -1;
|
||||
return FALSE;
|
||||
@@ -709,7 +701,7 @@ mm_serial_port_close (MMSerialPort *self)
|
||||
priv = MM_SERIAL_PORT_GET_PRIVATE (self);
|
||||
|
||||
if (priv->fd >= 0) {
|
||||
g_message ("Closing device '%s'", priv->device);
|
||||
g_message ("Closing device '%s'", mm_port_get_device (MM_PORT (self)));
|
||||
|
||||
if (priv->channel) {
|
||||
g_source_remove (priv->watch_id);
|
||||
@@ -867,7 +859,7 @@ mm_serial_port_is_connected (MMSerialPort *self)
|
||||
|
||||
priv = MM_SERIAL_PORT_GET_PRIVATE (self);
|
||||
|
||||
if (!priv->carrier_detect)
|
||||
if (!mm_port_get_carrier_detect (MM_PORT (self)))
|
||||
return FALSE;
|
||||
|
||||
if (priv->fd < 0)
|
||||
@@ -882,10 +874,12 @@ mm_serial_port_is_connected (MMSerialPort *self)
|
||||
/*****************************************************************************/
|
||||
|
||||
MMSerialPort *
|
||||
mm_serial_port_new (const char *name)
|
||||
mm_serial_port_new (const char *name, MMPortType ptype)
|
||||
{
|
||||
return MM_SERIAL_PORT (g_object_new (MM_TYPE_SERIAL_PORT,
|
||||
MM_SERIAL_PORT_DEVICE, name,
|
||||
MM_PORT_DEVICE, name,
|
||||
MM_PORT_SUBSYS, MM_PORT_SUBSYS_TTY,
|
||||
MM_PORT_TYPE, ptype,
|
||||
NULL));
|
||||
}
|
||||
|
||||
@@ -902,38 +896,12 @@ mm_serial_port_init (MMSerialPort *self)
|
||||
priv->parity = 'n';
|
||||
priv->stopbits = 1;
|
||||
priv->send_delay = 1000;
|
||||
priv->carrier_detect = TRUE;
|
||||
|
||||
priv->queue = g_queue_new ();
|
||||
priv->command = g_string_new_len ("AT", SERIAL_BUF_SIZE);
|
||||
priv->response = g_string_sized_new (SERIAL_BUF_SIZE);
|
||||
}
|
||||
|
||||
static GObject*
|
||||
constructor (GType type,
|
||||
guint n_construct_params,
|
||||
GObjectConstructParam *construct_params)
|
||||
{
|
||||
GObject *object;
|
||||
MMSerialPortPrivate *priv;
|
||||
|
||||
object = G_OBJECT_CLASS (mm_serial_port_parent_class)->constructor (type,
|
||||
n_construct_params,
|
||||
construct_params);
|
||||
if (!object)
|
||||
return NULL;
|
||||
|
||||
priv = MM_SERIAL_PORT_GET_PRIVATE (object);
|
||||
|
||||
if (!priv->device) {
|
||||
g_warning ("No device provided");
|
||||
g_object_unref (object);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
@@ -941,10 +909,6 @@ set_property (GObject *object, guint prop_id,
|
||||
MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DEVICE:
|
||||
/* Construct only */
|
||||
priv->device = g_path_get_basename (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_BAUD:
|
||||
priv->baud = g_value_get_uint (value);
|
||||
break;
|
||||
@@ -960,9 +924,6 @@ set_property (GObject *object, guint prop_id,
|
||||
case PROP_SEND_DELAY:
|
||||
priv->send_delay = g_value_get_uint64 (value);
|
||||
break;
|
||||
case PROP_CARRIER_DETECT:
|
||||
priv->carrier_detect = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -976,9 +937,6 @@ get_property (GObject *object, guint prop_id,
|
||||
MMSerialPortPrivate *priv = MM_SERIAL_PORT_GET_PRIVATE (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DEVICE:
|
||||
g_value_set_string (value, priv->device);
|
||||
break;
|
||||
case PROP_BAUD:
|
||||
g_value_set_uint (value, priv->baud);
|
||||
break;
|
||||
@@ -994,9 +952,6 @@ get_property (GObject *object, guint prop_id,
|
||||
case PROP_SEND_DELAY:
|
||||
g_value_set_uint64 (value, priv->send_delay);
|
||||
break;
|
||||
case PROP_CARRIER_DETECT:
|
||||
g_value_set_boolean (value, priv->carrier_detect);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -1015,7 +970,6 @@ finalize (GObject *object)
|
||||
g_queue_free (priv->queue);
|
||||
g_string_free (priv->command, TRUE);
|
||||
g_string_free (priv->response, TRUE);
|
||||
g_free (priv->device);
|
||||
|
||||
while (priv->unsolicited_msg_handlers) {
|
||||
MMUnsolicitedMsgHandler *handler = (MMUnsolicitedMsgHandler *) priv->unsolicited_msg_handlers->data;
|
||||
@@ -1043,20 +997,11 @@ mm_serial_port_class_init (MMSerialPortClass *klass)
|
||||
g_type_class_add_private (object_class, sizeof (MMSerialPortPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->constructor = constructor;
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
object_class->finalize = finalize;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_DEVICE,
|
||||
g_param_spec_string (MM_SERIAL_PORT_DEVICE,
|
||||
"Device",
|
||||
"Serial device",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_BAUD,
|
||||
g_param_spec_uint (MM_SERIAL_PORT_BAUD,
|
||||
@@ -1096,12 +1041,4 @@ mm_serial_port_class_init (MMSerialPortClass *klass)
|
||||
"Send delay",
|
||||
0, G_MAXUINT64, 0,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_CARRIER_DETECT,
|
||||
g_param_spec_boolean (MM_SERIAL_PORT_CARRIER_DETECT,
|
||||
"CarrierDetect",
|
||||
"Has carrier detect",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
@@ -21,12 +21,7 @@
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
typedef enum {
|
||||
MM_SERIAL_PORT_TYPE_UNKNOWN = 0x0,
|
||||
MM_SERIAL_PORT_TYPE_PRIMARY,
|
||||
MM_SERIAL_PORT_TYPE_SECONDARY,
|
||||
MM_SERIAL_PORT_TYPE_IGNORED
|
||||
} MMSerialPortType;
|
||||
#include "mm-port.h"
|
||||
|
||||
#define MM_TYPE_SERIAL_PORT (mm_serial_port_get_type ())
|
||||
#define MM_SERIAL_PORT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_SERIAL_PORT, MMSerialPort))
|
||||
@@ -35,13 +30,11 @@ typedef enum {
|
||||
#define MM_IS_SERIAL_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_SERIAL_PORT))
|
||||
#define MM_SERIAL_PORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_SERIAL_PORT, MMSerialPortClass))
|
||||
|
||||
#define MM_SERIAL_PORT_DEVICE "serial-device"
|
||||
#define MM_SERIAL_PORT_BAUD "baud"
|
||||
#define MM_SERIAL_PORT_BITS "bits"
|
||||
#define MM_SERIAL_PORT_PARITY "parity"
|
||||
#define MM_SERIAL_PORT_STOPBITS "stopbits"
|
||||
#define MM_SERIAL_PORT_SEND_DELAY "send-delay"
|
||||
#define MM_SERIAL_PORT_CARRIER_DETECT "carrier-detect"
|
||||
|
||||
typedef struct _MMSerialPort MMSerialPort;
|
||||
typedef struct _MMSerialPortClass MMSerialPortClass;
|
||||
@@ -63,16 +56,16 @@ typedef void (*MMSerialFlashFn) (MMSerialPort *port,
|
||||
gpointer user_data);
|
||||
|
||||
struct _MMSerialPort {
|
||||
GObject parent;
|
||||
MMPort parent;
|
||||
};
|
||||
|
||||
struct _MMSerialPortClass {
|
||||
GObjectClass parent;
|
||||
MMPortClass parent;
|
||||
};
|
||||
|
||||
GType mm_serial_port_get_type (void);
|
||||
|
||||
MMSerialPort *mm_serial_port_new (const char *name);
|
||||
MMSerialPort *mm_serial_port_new (const char *name, MMPortType ptype);
|
||||
|
||||
void mm_serial_port_add_unsolicited_msg_handler (MMSerialPort *self,
|
||||
GRegex *regex,
|
||||
@@ -108,7 +101,5 @@ guint mm_serial_port_flash (MMSerialPort *self,
|
||||
|
||||
gboolean mm_serial_port_is_connected (MMSerialPort *self);
|
||||
|
||||
const char *mm_serial_port_get_device (MMSerialPort *self);
|
||||
|
||||
#endif /* MM_SERIAL_PORT_H */
|
||||
|
||||
|
154
src/mm-serial.c
154
src/mm-serial.c
@@ -1,154 +0,0 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mm-serial.h"
|
||||
#include "mm-errors.h"
|
||||
#include "mm-options.h"
|
||||
|
||||
#define TYPE_TAG "type"
|
||||
|
||||
G_DEFINE_TYPE (MMSerial, mm_serial, G_TYPE_OBJECT)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
#define MM_SERIAL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MM_TYPE_SERIAL, MMSerialPrivate))
|
||||
|
||||
typedef struct {
|
||||
GHashTable *ports;
|
||||
} MMSerialPrivate;
|
||||
|
||||
MMSerialPort *
|
||||
mm_serial_get_port (MMSerial *self, const char *name)
|
||||
{
|
||||
return g_hash_table_lookup (MM_SERIAL_GET_PRIVATE (self)->ports, name);
|
||||
}
|
||||
|
||||
static void
|
||||
find_primary (gpointer key, gpointer data, gpointer user_data)
|
||||
{
|
||||
MMSerialPort **found = user_data;
|
||||
MMSerialPort *port = MM_SERIAL_PORT (data);
|
||||
MMSerialPortType ptype;
|
||||
|
||||
if (*found)
|
||||
return;
|
||||
|
||||
ptype = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (port), TYPE_TAG));
|
||||
if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY)
|
||||
*found = port;
|
||||
}
|
||||
|
||||
MMSerialPort *
|
||||
mm_serial_add_port (MMSerial *self,
|
||||
const char *name,
|
||||
MMSerialPortType ptype)
|
||||
{
|
||||
MMSerialPrivate *priv = MM_SERIAL_GET_PRIVATE (self);
|
||||
MMSerialPort *port = NULL;
|
||||
|
||||
g_return_val_if_fail (MM_IS_SERIAL (self), FALSE);
|
||||
g_return_val_if_fail (name != NULL, FALSE);
|
||||
g_return_val_if_fail (ptype != MM_SERIAL_PORT_TYPE_UNKNOWN, FALSE);
|
||||
|
||||
g_return_val_if_fail (g_hash_table_lookup (priv->ports, name) == NULL, FALSE);
|
||||
|
||||
if (ptype == MM_SERIAL_PORT_TYPE_PRIMARY) {
|
||||
g_hash_table_foreach (priv->ports, find_primary, &port);
|
||||
g_return_val_if_fail (port == NULL, FALSE);
|
||||
}
|
||||
|
||||
port = mm_serial_port_new (name);
|
||||
if (!port)
|
||||
return NULL;
|
||||
|
||||
g_object_set_data (G_OBJECT (port), TYPE_TAG, GUINT_TO_POINTER (ptype));
|
||||
g_hash_table_insert (priv->ports, g_strdup (name), port);
|
||||
return port;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_serial_remove_port (MMSerial *self, MMSerialPort *port)
|
||||
{
|
||||
g_return_val_if_fail (MM_IS_SERIAL (self), FALSE);
|
||||
g_return_val_if_fail (port != NULL, FALSE);
|
||||
|
||||
return g_hash_table_remove (MM_SERIAL_GET_PRIVATE (self)->ports, port);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
mm_serial_init (MMSerial *self)
|
||||
{
|
||||
MMSerialPrivate *priv = MM_SERIAL_GET_PRIVATE (self);
|
||||
|
||||
priv->ports = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object, guint prop_id,
|
||||
const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
switch (prop_id) {
|
||||
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)
|
||||
{
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
MMSerial *self = MM_SERIAL (object);
|
||||
MMSerialPrivate *priv = MM_SERIAL_GET_PRIVATE (self);
|
||||
|
||||
g_hash_table_destroy (priv->ports);
|
||||
|
||||
G_OBJECT_CLASS (mm_serial_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
mm_serial_class_init (MMSerialClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (MMSerialPrivate));
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
object_class->finalize = finalize;
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
/* -*- 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 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef MM_SERIAL_H
|
||||
#define MM_SERIAL_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib/gtypes.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "mm-serial-port.h"
|
||||
|
||||
#define MM_TYPE_SERIAL (mm_serial_get_type ())
|
||||
#define MM_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_SERIAL, MMSerial))
|
||||
#define MM_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_SERIAL, MMSerialClass))
|
||||
#define MM_IS_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_SERIAL))
|
||||
#define MM_IS_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_SERIAL))
|
||||
#define MM_SERIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_SERIAL, MMSerialClass))
|
||||
|
||||
typedef struct _MMSerial MMSerial;
|
||||
typedef struct _MMSerialClass MMSerialClass;
|
||||
|
||||
struct _MMSerial {
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
struct _MMSerialClass {
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
GType mm_serial_get_type (void);
|
||||
|
||||
MMSerialPort *mm_serial_get_port (MMSerial *self,
|
||||
const char *name);
|
||||
|
||||
MMSerialPort *mm_serial_add_port (MMSerial *self,
|
||||
const char *name,
|
||||
MMSerialPortType ptype);
|
||||
|
||||
gboolean mm_serial_remove_port (MMSerial *self,
|
||||
MMSerialPort *port);
|
||||
|
||||
#endif /* MM_SERIAL_H */
|
||||
|
Reference in New Issue
Block a user