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:
+4
-2
@@ -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 \
|
||||
|
||||
+56
-39
@@ -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);
|
||||
|
||||
+64
-47
@@ -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);
|
||||
|
||||
+10
-9
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
@@ -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));
|
||||
}
|
||||
@@ -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 */
|
||||
|
||||
+18
-81
@@ -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));
|
||||
}
|
||||
|
||||
+4
-13
@@ -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
@@ -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