From 8774cc756a74ba7e4a8bfef0be0de669215900ae Mon Sep 17 00:00:00 2001 From: Tambet Ingo Date: Wed, 2 Jan 2008 13:42:52 +0000 Subject: [PATCH] 2008-01-02 Tambet Ingo * libnm-util/nm-setting-serial.c (nm_setting_serial_class_init): * Mark the properties with G_PARAM_CONSTRUCT so that they get the default values. * src/nm-gsm-device.c: Add preliminary support for monitoring * device. It only monitors the monitoring device and prints out the output for now. Or more precicely, doesn't do absolutely anything right now since the montoring device argument is never set. * src/nm-serial-device.c (serial_debug): Implement. It's very * verbose and thus requires it's own knob to turn it on. (config_fd): Add NMSettingSerial to the arguments list. (nm_serial_device_open): Ditto. (get_reply_got_data): Ignore the terminators at the beginning of the output. (nm_serial_device_get_io_channel): Implement. * src/nm-manager.c: Add NMDBusManager to the private data of the * NMManager. Asking a new reference every time (and forgetting to release it sometimes) is a pain and it's not like NMManager could work without dbus. (nm_manager_add_device): Register the added device on dbus here. * src/nm-hal-manager.c (modem_device_creator): Pass NULL for now * for the monitoring device. * src/nm-device.c (constructor): Don't export the device here, * instead export it when it's added to the NMManager's device list. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3203 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 27 ++++ libnm-util/nm-setting-serial.c | 10 +- src/nm-device.c | 9 -- src/nm-gsm-device.c | 183 +++++++++++++++++++++++++++- src/nm-gsm-device.h | 5 +- src/nm-hal-manager.c | 2 +- src/nm-manager.c | 36 +++--- src/nm-serial-device.c | 93 ++++++++++---- src/nm-serial-device.h | 7 +- system-settings/src/dbus-settings.h | 2 +- 10 files changed, 313 insertions(+), 61 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8dfe98a816..5ec063f21e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2008-01-02 Tambet Ingo + + * libnm-util/nm-setting-serial.c (nm_setting_serial_class_init): Mark the properties + with G_PARAM_CONSTRUCT so that they get the default values. + + * src/nm-gsm-device.c: Add preliminary support for monitoring device. It only monitors + the monitoring device and prints out the output for now. Or more precicely, doesn't + do absolutely anything right now since the montoring device argument is never set. + + * src/nm-serial-device.c (serial_debug): Implement. It's very verbose and thus + requires it's own knob to turn it on. + (config_fd): Add NMSettingSerial to the arguments list. + (nm_serial_device_open): Ditto. + (get_reply_got_data): Ignore the terminators at the beginning of the output. + (nm_serial_device_get_io_channel): Implement. + + * src/nm-manager.c: Add NMDBusManager to the private data of the NMManager. Asking + a new reference every time (and forgetting to release it sometimes) is a pain and + it's not like NMManager could work without dbus. + (nm_manager_add_device): Register the added device on dbus here. + + * src/nm-hal-manager.c (modem_device_creator): Pass NULL for now for the monitoring + device. + + * src/nm-device.c (constructor): Don't export the device here, instead export + it when it's added to the NMManager's device list. + 2007-12-31 Dan Williams * src/nm-device-interface.c diff --git a/libnm-util/nm-setting-serial.c b/libnm-util/nm-setting-serial.c index c278af9161..8fbbcabf97 100644 --- a/libnm-util/nm-setting-serial.c +++ b/libnm-util/nm-setting-serial.c @@ -100,7 +100,7 @@ nm_setting_serial_class_init (NMSettingSerialClass *setting_class) "Baud", "Baud rate", 0, G_MAXUINT, 57600, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); g_object_class_install_property (object_class, PROP_BITS, @@ -108,7 +108,7 @@ nm_setting_serial_class_init (NMSettingSerialClass *setting_class) "Bits", "Bits", 5, 8, 8, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); g_object_class_install_property (object_class, PROP_PARITY, @@ -116,7 +116,7 @@ nm_setting_serial_class_init (NMSettingSerialClass *setting_class) "Parity", "Parity", 'E', 'o', 'n', - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); g_object_class_install_property (object_class, PROP_STOPBITS, @@ -124,7 +124,7 @@ nm_setting_serial_class_init (NMSettingSerialClass *setting_class) "Stopbits", "Stopbits", 1, 2, 1, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); g_object_class_install_property (object_class, PROP_SEND_DELAY, @@ -132,5 +132,5 @@ nm_setting_serial_class_init (NMSettingSerialClass *setting_class) "SendDelay", "Send delay", 0, G_MAXUINT64, 0, - G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE)); + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE)); } diff --git a/src/nm-device.c b/src/nm-device.c index 920017f7f4..457044792d 100644 --- a/src/nm-device.c +++ b/src/nm-device.c @@ -144,7 +144,6 @@ constructor (GType type, GObject *object; NMDevice *dev; NMDevicePrivate *priv; - NMDBusManager *manager; object = G_OBJECT_CLASS (nm_device_parent_class)->constructor (type, n_construct_params, @@ -182,14 +181,6 @@ constructor (GType type, nm_print_device_capabilities (dev); - manager = nm_dbus_manager_get (); - - nm_info ("(%s): exporting device as %s", priv->iface, priv->udi); - dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (manager), - priv->udi, object); - - g_object_unref (manager); - priv->initialized = TRUE; return object; diff --git a/src/nm-gsm-device.c b/src/nm-gsm-device.c index 3ab4378c0b..461573b371 100644 --- a/src/nm-gsm-device.c +++ b/src/nm-gsm-device.c @@ -1,5 +1,6 @@ /* -*- Mode: C; tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ +#include #include #include "nm-gsm-device.h" #include "nm-device-interface.h" @@ -9,6 +10,13 @@ G_DEFINE_TYPE (NMGsmDevice, nm_gsm_device, NM_TYPE_SERIAL_DEVICE) +enum { + PROP_0, + PROP_MONITOR_IFACE, + + LAST_PROP +}; + typedef enum { NM_GSM_SECRET_NONE = 0, NM_GSM_SECRET_PIN, @@ -18,6 +26,9 @@ typedef enum { #define NM_GSM_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_GSM_DEVICE, NMGsmDevicePrivate)) typedef struct { + char *monitor_iface; + NMSerialDevice *monitor_device; + NMGsmSecret need_secret; guint pending_id; } NMGsmDevicePrivate; @@ -28,17 +39,19 @@ static void automatic_registration (NMSerialDevice *device); NMGsmDevice * nm_gsm_device_new (const char *udi, - const char *iface, + const char *data_iface, + const char *monitor_iface, const char *driver) { g_return_val_if_fail (udi != NULL, NULL); - g_return_val_if_fail (iface != NULL, NULL); + g_return_val_if_fail (data_iface != NULL, NULL); g_return_val_if_fail (driver != NULL, NULL); return (NMGsmDevice *) g_object_new (NM_TYPE_GSM_DEVICE, NM_DEVICE_INTERFACE_UDI, udi, - NM_DEVICE_INTERFACE_IFACE, iface, + NM_DEVICE_INTERFACE_IFACE, data_iface, NM_DEVICE_INTERFACE_DRIVER, driver, + NM_GSM_DEVICE_MONITOR_IFACE, monitor_iface, NULL); } @@ -130,7 +143,7 @@ manual_registration_done (NMSerialDevice *device, gpointer user_data) { gsm_device_set_pending (NM_GSM_DEVICE (device), 0); - + switch (reply_index) { case 0: do_dial (device); @@ -441,10 +454,13 @@ real_act_stage1_prepare (NMDevice *device) { NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (device); NMSerialDevice *serial_device = NM_SERIAL_DEVICE (device); + NMSettingSerial *setting; priv->need_secret = NM_GSM_SECRET_NONE; - if (!nm_serial_device_open (serial_device)) + setting = NM_SETTING_SERIAL (gsm_device_get_setting (NM_GSM_DEVICE (device), NM_TYPE_SETTING_SERIAL)); + + if (!nm_serial_device_open (serial_device, setting)) return NM_ACT_STAGE_RETURN_FAILURE; priv->pending_id = nm_serial_device_flash (serial_device, 100, init_modem, NULL); @@ -519,6 +535,78 @@ real_deactivate_quickly (NMDevice *device) NM_DEVICE_CLASS (nm_gsm_device_parent_class)->deactivate_quickly (device); } +/*****************************************************************************/ +/* Monitor device handling */ + +static gboolean +monitor_device_got_data (GIOChannel *source, + GIOCondition condition, + gpointer data) +{ + gsize bytes_read; + char buf[4096]; + GIOStatus status; + + if (condition & G_IO_IN) { + do { + status = g_io_channel_read_chars (source, buf, 4096, &bytes_read, NULL); + + if (bytes_read) { + buf[bytes_read] = '\0'; + /* Do nothing with the data for now */ + nm_debug ("Monitor got unhandled data: '%s'", buf); + } + } while (bytes_read == 4096 || status == G_IO_STATUS_AGAIN); + } + + if (condition & G_IO_HUP || condition & G_IO_ERR) { + return FALSE; + } + + return TRUE; +} + +static gboolean +setup_monitor_device (NMGsmDevice *device) +{ + NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (device); + GIOChannel *channel; + NMSettingSerial *setting; + + if (!priv->monitor_iface) { + nm_debug ("No monitoring udi provided"); + return FALSE; + } + + priv->monitor_device = g_object_new (NM_TYPE_SERIAL_DEVICE, + NM_DEVICE_INTERFACE_UDI, nm_device_get_udi (NM_DEVICE (device)), + NM_DEVICE_INTERFACE_IFACE, priv->monitor_iface, + NULL); + + if (!priv->monitor_device) { + nm_warning ("Creation of the monitoring device failed"); + return FALSE; + } + + setting = NM_SETTING_SERIAL (nm_setting_serial_new ()); + if (!nm_serial_device_open (priv->monitor_device, setting)) { + nm_warning ("Monitoring device open failed"); + g_object_unref (setting); + g_object_unref (priv->monitor_device); + return FALSE; + } + + g_object_unref (setting); + + channel = nm_serial_device_get_io_channel (priv->monitor_device); + g_io_add_watch (channel, G_IO_IN | G_IO_ERR | G_IO_HUP, + monitor_device_got_data, device); + + g_io_channel_unref (channel); + + return TRUE; +} + /*****************************************************************************/ static void @@ -527,6 +615,77 @@ nm_gsm_device_init (NMGsmDevice *self) nm_device_set_device_type (NM_DEVICE (self), DEVICE_TYPE_GSM); } +static GObject* +constructor (GType type, + guint n_construct_params, + GObjectConstructParam *construct_params) +{ + GObject *object; + + object = G_OBJECT_CLASS (nm_gsm_device_parent_class)->constructor (type, + n_construct_params, + construct_params); + if (!object) + return NULL; + + /* FIXME: Make the monitor device not required for now */ + setup_monitor_device (NM_GSM_DEVICE (object)); +#if 0 + if (!setup_monitor_device (NM_GSM_DEVICE (object))) { + g_object_unref (object); + object = NULL; + } +#endif + + return object; +} + +static void +set_property (GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_MONITOR_IFACE: + /* Construct only */ + priv->monitor_iface = g_value_dup_string (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) +{ + NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_MONITOR_IFACE: + g_value_set_string (value, priv->monitor_iface); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +finalize (GObject *object) +{ + NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (object); + + if (priv->monitor_device) + g_object_unref (priv->monitor_device); + + g_free (priv->monitor_iface); + + G_OBJECT_CLASS (nm_gsm_device_parent_class)->finalize (object); +} + static void nm_gsm_device_class_init (NMGsmDeviceClass *klass) { @@ -535,9 +694,23 @@ nm_gsm_device_class_init (NMGsmDeviceClass *klass) g_type_class_add_private (object_class, sizeof (NMGsmDevicePrivate)); + object_class->constructor = constructor; + object_class->get_property = get_property; + object_class->set_property = set_property; + object_class->finalize = finalize; + device_class->get_generic_capabilities = real_get_generic_capabilities; device_class->check_connection_complete = real_check_connection_complete; device_class->act_stage1_prepare = real_act_stage1_prepare; device_class->connection_secrets_updated = real_connection_secrets_updated; device_class->deactivate_quickly = real_deactivate_quickly; + + /* Properties */ + g_object_class_install_property + (object_class, PROP_MONITOR_IFACE, + g_param_spec_string (NM_GSM_DEVICE_MONITOR_IFACE, + "Monitoring interface", + "Monitoring interface", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); } diff --git a/src/nm-gsm-device.h b/src/nm-gsm-device.h index 9a460ae23d..ca88bdcfeb 100644 --- a/src/nm-gsm-device.h +++ b/src/nm-gsm-device.h @@ -14,6 +14,8 @@ G_BEGIN_DECLS #define NM_IS_GSM_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_GSM_DEVICE)) #define NM_GSM_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_GSM_DEVICE, NMGsmDeviceClass)) +#define NM_GSM_DEVICE_MONITOR_IFACE "monitor-iface" + typedef struct { NMSerialDevice parent; } NMGsmDevice; @@ -25,7 +27,8 @@ typedef struct { GType nm_gsm_device_get_type (void); NMGsmDevice *nm_gsm_device_new (const char *udi, - const char *iface, + const char *data_iface, + const char *monitor_iface, const char *driver); G_END_DECLS diff --git a/src/nm-hal-manager.c b/src/nm-hal-manager.c index 7c5c84fdcb..a1ccce3630 100644 --- a/src/nm-hal-manager.c +++ b/src/nm-hal-manager.c @@ -205,7 +205,7 @@ modem_device_creator (NMHalManager *manager, const char *udi) } if (serial_device && driver_name) - device = (NMDevice *) nm_gsm_device_new (udi, serial_device + strlen ("/dev/"), driver_name); + device = (NMDevice *) nm_gsm_device_new (udi, serial_device + strlen ("/dev/"), NULL, driver_name); libhal_free_string (serial_device); libhal_free_string (driver_name); diff --git a/src/nm-manager.c b/src/nm-manager.c index 335a8f419c..33c06611c0 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -60,6 +60,8 @@ typedef struct { GSList *devices; NMState state; + NMDBusManager *dbus_mgr; + GHashTable *user_connections; DBusGProxy *user_proxy; @@ -160,6 +162,8 @@ nm_manager_init (NMManager *manager) priv->sleeping = FALSE; priv->state = NM_STATE_DISCONNECTED; + priv->dbus_mgr = nm_dbus_manager_get (); + priv->user_connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, @@ -248,6 +252,9 @@ finalize (GObject *object) while (g_slist_length (priv->devices)) nm_manager_remove_device (manager, NM_DEVICE (priv->devices->data), TRUE); + if (priv->dbus_mgr) + g_object_unref (priv->dbus_mgr); + G_OBJECT_CLASS (nm_manager_parent_class)->finalize (object); } @@ -653,20 +660,18 @@ internal_new_connection_cb (DBusGProxy *proxy, { struct GetSettingsInfo *info; DBusGProxy *con_proxy; - NMDBusManager * dbus_mgr; DBusGConnection * g_connection; DBusGProxyCall *call; DBusGProxy *secrets_proxy; + NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager); - dbus_mgr = nm_dbus_manager_get (); - g_connection = nm_dbus_manager_get_connection (dbus_mgr); + g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr); con_proxy = dbus_g_proxy_new_for_name (g_connection, dbus_g_proxy_get_bus_name (proxy), path, NM_DBUS_IFACE_SETTINGS_CONNECTION); if (!con_proxy) { nm_warning ("Error: could not init user connection proxy"); - g_object_unref (dbus_mgr); return; } @@ -674,7 +679,6 @@ internal_new_connection_cb (DBusGProxy *proxy, dbus_g_proxy_get_bus_name (proxy), path, NM_DBUS_IFACE_SETTINGS_CONNECTION_SECRETS); - g_object_unref (dbus_mgr); if (!secrets_proxy) { nm_warning ("Error: could not init user connection secrets proxy"); g_object_unref (con_proxy); @@ -779,16 +783,13 @@ query_connections (NMManager *manager, } if (!*proxy) { - NMDBusManager * dbus_mgr; DBusGConnection * g_connection; - dbus_mgr = nm_dbus_manager_get (); - g_connection = nm_dbus_manager_get_connection (dbus_mgr); + g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr); *proxy = dbus_g_proxy_new_for_name (g_connection, service, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS); - g_object_unref (dbus_mgr); if (!*proxy) { nm_warning ("Error: could not init settings proxy"); return; @@ -864,18 +865,16 @@ NMManager * nm_manager_new (void) { GObject *object; - DBusGConnection *connection; - NMDBusManager * dbus_mgr; + NMManagerPrivate *priv; object = g_object_new (NM_TYPE_MANAGER, NULL); + priv = NM_MANAGER_GET_PRIVATE (object); - dbus_mgr = nm_dbus_manager_get (); - connection = nm_dbus_manager_get_connection (dbus_mgr); - dbus_g_connection_register_g_object (connection, + dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (priv->dbus_mgr), NM_DBUS_PATH, object); - g_signal_connect (dbus_mgr, + g_signal_connect (priv->dbus_mgr, "name-owner-changed", G_CALLBACK (nm_manager_name_owner_changed), NM_MANAGER (object)); @@ -1061,6 +1060,13 @@ nm_manager_add_device (NMManager *manager, NMDevice *device) nm_device_interface_deactivate (NM_DEVICE_INTERFACE (device)); + nm_info ("(%s): exporting device as %s", + nm_device_get_iface (device), + nm_device_get_udi (device)); + dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (priv->dbus_mgr), + nm_device_get_udi (device), + G_OBJECT (device)); + manager_device_added (manager, device); } diff --git a/src/nm-serial-device.c b/src/nm-serial-device.c index d72ec01030..5301e83aee 100644 --- a/src/nm-serial-device.c +++ b/src/nm-serial-device.c @@ -16,10 +16,11 @@ #include "nm-device-interface.h" #include "nm-device-private.h" #include "ppp-manager/nm-ppp-manager.h" -#include "nm-setting-serial.h" #include "nm-setting-ppp.h" #include "nm-utils.h" +/* #define NM_DEBUG_SERIAL 1 */ + G_DEFINE_TYPE (NMSerialDevice, nm_serial_device, NM_TYPE_DEVICE) #define NM_SERIAL_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SERIAL_DEVICE, NMSerialDevicePrivate)) @@ -166,6 +167,33 @@ parse_stopbits (guint i) return stopbits; } +#ifdef NM_DEBUG_SERIAL +static inline void +serial_debug (const char *prefix, const char *data, int len) +{ + GString *str; + int i; + + str = g_string_sized_new (len); + for (i = 0; i < len; i++) { + if (data[i] == '\0') + g_string_append_c (str, ' '); + else if (data[i] == '\r') + g_string_append_c (str, '\n'); + else + g_string_append_c (str, data[i]); + } + + nm_debug ("%s '%s'", prefix, str->str); + g_string_free (str, TRUE); +} +#else +static inline void +serial_debug (const char *prefix, const char *data, int len) +{ +} +#endif /* NM_DEBUG_SERIAL */ + static NMSetting * serial_device_get_setting (NMSerialDevice *device, GType setting_type) { @@ -185,18 +213,15 @@ serial_device_get_setting (NMSerialDevice *device, GType setting_type) } static gboolean -config_fd (NMSerialDevice *device) +config_fd (NMSerialDevice *device, NMSettingSerial *setting) { NMSerialDevicePrivate *priv = NM_SERIAL_DEVICE_GET_PRIVATE (device); - NMSettingSerial *setting; struct termio stbuf; int speed; int bits; int parity; int stopbits; - setting = NM_SETTING_SERIAL (serial_device_get_setting (device, NM_TYPE_SETTING_SERIAL)); - speed = parse_baudrate (setting->baud); bits = parse_bits (setting->bits); parity = parse_parity (setting->parity); @@ -224,13 +249,15 @@ config_fd (NMSerialDevice *device) } gboolean -nm_serial_device_open (NMSerialDevice *device) +nm_serial_device_open (NMSerialDevice *device, + NMSettingSerial *setting) { NMSerialDevicePrivate *priv; const char *iface; char *path; g_return_val_if_fail (NM_IS_SERIAL_DEVICE (device), FALSE); + g_return_val_if_fail (NM_IS_SETTING_SERIAL (setting), FALSE); priv = NM_SERIAL_DEVICE_GET_PRIVATE (device); iface = nm_device_get_iface (NM_DEVICE (device)); @@ -252,7 +279,7 @@ nm_serial_device_open (NMSerialDevice *device) return FALSE; } - config_fd (device); + config_fd (device, setting); priv->channel = g_io_channel_unix_new (priv->fd); @@ -293,10 +320,7 @@ nm_serial_device_send_command (NMSerialDevice *device, GByteArray *command) fd = NM_SERIAL_DEVICE_GET_PRIVATE (device)->fd; setting = NM_SETTING_SERIAL (serial_device_get_setting (device, NM_TYPE_SETTING_SERIAL)); - g_print ("Sending: "); - for (i = 0; i < command->len; i++) - g_print ("%c", command->data[i]); - g_print ("\n"); + serial_debug ("Sending:", (char *) command->data, command->len); for (i = 0; i < command->len; i++) { again: @@ -399,20 +423,25 @@ get_reply_got_data (GIOChannel *source, if (bytes_read > 0) { char *p; - g_print ("Got: "); - for (i = 0; i < bytes_read; i++) - g_print ("%c", buf[i]); - g_print ("\n"); + serial_debug ("Got:", buf, bytes_read); p = &buf[0]; for (i = 0; i < bytes_read && !done; i++, p++) { int j; + gboolean is_terminator = FALSE; - for (j = 0; j < strlen (info->terminators); j++) - if (*p == info->terminators[j]) + for (j = 0; j < strlen (info->terminators); j++) { + if (*p == info->terminators[j]) { + is_terminator = TRUE; + break; + } + } + + if (is_terminator) { + /* Ignore terminators in the beginning of the output */ + if (info->result->len > 0) done = TRUE; - - if (!done) + } else g_string_append_c (info->result, *p); } } @@ -530,10 +559,7 @@ wait_for_reply_got_data (GIOChannel *source, } if (bytes_read > 0) { - g_print ("Got: "); - for (i = 0; i < bytes_read; i++) - g_print ("%c", buf[i]); - g_print ("\n"); + serial_debug ("Got:", buf, bytes_read); for (i = 0; info->str_needles[i]; i++) { if (strcasestr (buf, info->str_needles[i])) { @@ -769,6 +795,20 @@ nm_serial_device_flash (NMSerialDevice *device, g_free); } +GIOChannel * +nm_serial_device_get_io_channel (NMSerialDevice *device) +{ + NMSerialDevicePrivate *priv; + + g_return_val_if_fail (NM_IS_SERIAL_DEVICE (device), 0); + + priv = NM_SERIAL_DEVICE_GET_PRIVATE (device); + if (priv->channel) + return g_io_channel_ref (priv->channel); + + return NULL; +} + static void ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_data) { @@ -901,6 +941,12 @@ real_is_up (NMDevice *device) return TRUE; } +static guint32 +real_get_generic_capabilities (NMDevice *dev) +{ + return NM_DEVICE_CAP_NM_SUPPORTED; +} + /*****************************************************************************/ static void @@ -929,6 +975,7 @@ nm_serial_device_class_init (NMSerialDeviceClass *klass) /* Virtual methods */ object_class->finalize = finalize; + parent_class->get_generic_capabilities = real_get_generic_capabilities; parent_class->is_up = real_is_up; parent_class->check_connection_complete = real_check_connection_complete; parent_class->act_stage2_config = real_act_stage2_config; diff --git a/src/nm-serial-device.h b/src/nm-serial-device.h index 782787fa3c..6f30047a19 100644 --- a/src/nm-serial-device.h +++ b/src/nm-serial-device.h @@ -4,6 +4,7 @@ #define NM_SERIAL_DEVICE_H #include +#include G_BEGIN_DECLS @@ -41,7 +42,9 @@ typedef void (*NMSerialFlashFn) (NMSerialDevice *device, -gboolean nm_serial_device_open (NMSerialDevice *device); +gboolean nm_serial_device_open (NMSerialDevice *device, + NMSettingSerial *setting); + void nm_serial_device_close (NMSerialDevice *device); gboolean nm_serial_device_send_command (NMSerialDevice *device, GByteArray *command); @@ -72,6 +75,8 @@ guint nm_serial_device_flash (NMSerialDevice *device, NMSerialFlashFn callback, gpointer user_data); +GIOChannel *nm_serial_device_get_io_channel (NMSerialDevice *device); + G_END_DECLS #endif /* NM_SERIAL_DEVICE_H */ diff --git a/system-settings/src/dbus-settings.h b/system-settings/src/dbus-settings.h index f9762f504b..bca0969742 100644 --- a/system-settings/src/dbus-settings.h +++ b/system-settings/src/dbus-settings.h @@ -54,7 +54,7 @@ NMSysconfigConnectionSettings *nm_sysconfig_connection_settings_new (NMConnectio DBusGConnection *g_conn); /* - * NMSysconfigSetttings + * NMSysconfigSettings */ typedef struct _NMSysconfigSettings NMSysconfigSettings; typedef struct _NMSysconfigSettingsClass NMSysconfigSettingsClass;