samsung: port plugin to the refactored probing logic

This commit is contained in:
Aleksander Morgado
2012-07-18 18:22:07 +02:00
parent 03a0fee4ff
commit fc9a7dbbd9
2 changed files with 22 additions and 56 deletions

View File

@@ -28,59 +28,25 @@
#include "mm-broadband-modem-samsung.h" #include "mm-broadband-modem-samsung.h"
#include "mm-log.h" #include "mm-log.h"
G_DEFINE_TYPE (MMPluginSamsung, mm_plugin_samsung, MM_TYPE_PLUGIN_BASE) G_DEFINE_TYPE (MMPluginSamsung, mm_plugin_samsung, MM_TYPE_PLUGIN)
int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION; int mm_plugin_major_version = MM_PLUGIN_MAJOR_VERSION;
int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION; int mm_plugin_minor_version = MM_PLUGIN_MINOR_VERSION;
static MMBaseModem * static MMBaseModem *
grab_port (MMPluginBase *base, create_modem (MMPlugin *self,
MMBaseModem *existing, const gchar *sysfs_path,
MMPortProbe *probe, const gchar *driver,
guint16 vendor,
guint16 product,
GList *probes,
GError **error) GError **error)
{ {
MMBaseModem *modem = NULL; return MM_BASE_MODEM (mm_broadband_modem_samsung_new (sysfs_path,
const gchar *name, *subsys, *driver;
guint16 vendor = 0, product = 0;
mm_dbg(" existing %p", existing);
/* The Samsung plugin uses AT and net ports */
if (!mm_port_probe_is_at (probe) &&
!g_str_equal (mm_port_probe_get_port_subsys (probe), "net")) {
g_set_error (error, 0, 0, "Ignoring non-AT/net port");
return NULL;
}
subsys = mm_port_probe_get_port_subsys (probe);
name = mm_port_probe_get_port_name (probe);
driver = mm_port_probe_get_port_driver (probe);
mm_dbg("subsys %s name %s driver %s", subsys, name, driver);
/* Try to get Product IDs from udev. */
mm_plugin_base_get_device_ids (base, subsys, name, &vendor, &product);
mm_dbg("vendor 0x%04x product 0x%04x", vendor, product);
/* If this is the first port being grabbed, create a new modem object */
if (!existing)
modem = MM_BASE_MODEM (mm_broadband_modem_samsung_new (mm_port_probe_get_port_physdev (probe),
driver, driver,
mm_plugin_get_name (MM_PLUGIN (base)), mm_plugin_get_name (self),
vendor, vendor,
product)); product));
if (!mm_base_modem_grab_port (existing ? existing : modem,
subsys,
name,
mm_port_probe_get_port_type (probe),
MM_AT_PORT_FLAG_NONE,
error)) {
mm_dbg("mm_base_modem_grab_port failed; releasing");
if (modem)
g_object_unref (modem);
return NULL;
}
return existing ? existing : modem;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -94,10 +60,10 @@ mm_plugin_create (void)
{ 0, 0 } }; { 0, 0 } };
return MM_PLUGIN ( return MM_PLUGIN (
g_object_new (MM_TYPE_PLUGIN_SAMSUNG, g_object_new (MM_TYPE_PLUGIN_SAMSUNG,
MM_PLUGIN_BASE_NAME, "Samsung", MM_PLUGIN_NAME, "Samsung",
MM_PLUGIN_BASE_ALLOWED_SUBSYSTEMS, subsystems, MM_PLUGIN_ALLOWED_SUBSYSTEMS, subsystems,
MM_PLUGIN_BASE_ALLOWED_PRODUCT_IDS, products, MM_PLUGIN_ALLOWED_PRODUCT_IDS, products,
MM_PLUGIN_BASE_ALLOWED_AT, TRUE, MM_PLUGIN_ALLOWED_AT, TRUE,
NULL)); NULL));
} }
@@ -109,7 +75,7 @@ mm_plugin_samsung_init (MMPluginSamsung *self)
static void static void
mm_plugin_samsung_class_init (MMPluginSamsungClass *klass) mm_plugin_samsung_class_init (MMPluginSamsungClass *klass)
{ {
MMPluginBaseClass *pb_class = MM_PLUGIN_BASE_CLASS (klass); MMPluginClass *plugin_class = MM_PLUGIN_CLASS (klass);
pb_class->grab_port = grab_port; plugin_class->create_modem = create_modem;
} }

View File

@@ -23,7 +23,7 @@
#ifndef MM_PLUGIN_SAMSUNG_H #ifndef MM_PLUGIN_SAMSUNG_H
#define MM_PLUGIN_SAMSUNG_H #define MM_PLUGIN_SAMSUNG_H
#include "mm-plugin-base.h" #include "mm-plugin.h"
#define MM_TYPE_PLUGIN_SAMSUNG (mm_plugin_samsung_get_type ()) #define MM_TYPE_PLUGIN_SAMSUNG (mm_plugin_samsung_get_type ())
#define MM_PLUGIN_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_SAMSUNG, MMPluginSamsung)) #define MM_PLUGIN_SAMSUNG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_PLUGIN_SAMSUNG, MMPluginSamsung))
@@ -33,11 +33,11 @@
#define MM_PLUGIN_SAMSUNG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_SAMSUNG, MMPluginSamsungClass)) #define MM_PLUGIN_SAMSUNG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_SAMSUNG, MMPluginSamsungClass))
typedef struct { typedef struct {
MMPluginBase parent; MMPlugin parent;
} MMPluginSamsung; } MMPluginSamsung;
typedef struct { typedef struct {
MMPluginBaseClass parent; MMPluginClass parent;
} MMPluginSamsungClass; } MMPluginSamsungClass;
GType mm_plugin_samsung_get_type (void); GType mm_plugin_samsung_get_type (void);