context: new '--test-plugin-dir' to allow specifying where the plugins are
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
|
||||
[D-BUS Service]
|
||||
Name=org.freedesktop.ModemManager1
|
||||
Exec=@abs_top_builddir@/src/ModemManager --test-session --test-no-auto-scan --test-enable --debug
|
||||
Exec=@abs_top_builddir@/src/ModemManager --test-session --test-no-auto-scan --test-enable --test-plugin-dir="@abs_top_builddir@/plugins/.libs" --debug
|
||||
|
||||
@@ -63,6 +63,7 @@ bus_acquired_cb (GDBusConnection *connection,
|
||||
/* Create Manager object */
|
||||
g_assert (!manager);
|
||||
manager = mm_manager_new (connection,
|
||||
mm_context_get_test_plugin_dir (),
|
||||
!mm_context_get_test_no_auto_scan (),
|
||||
mm_context_get_test_enable (),
|
||||
&error);
|
||||
|
||||
@@ -71,11 +71,13 @@ mm_context_get_relative_timestamps (void)
|
||||
static gboolean test_session;
|
||||
static gboolean test_no_auto_scan;
|
||||
static gboolean test_enable;
|
||||
static gchar *test_plugin_dir;
|
||||
|
||||
static const GOptionEntry test_entries[] = {
|
||||
{ "test-session", 0, 0, G_OPTION_ARG_NONE, &test_session, "Run in session DBus", NULL },
|
||||
{ "test-no-auto-scan", 0, 0, G_OPTION_ARG_NONE, &test_no_auto_scan, "Don't auto-scan looking for devices", NULL },
|
||||
{ "test-enable", 0, 0, G_OPTION_ARG_NONE, &test_enable, "Enable the Test interface in the daemon", NULL },
|
||||
{ "test-plugin-dir", 0, 0, G_OPTION_ARG_STRING, &test_plugin_dir, "Path to look for plugins", "[PATH]" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@@ -111,6 +113,12 @@ mm_context_get_test_enable (void)
|
||||
return test_enable;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
mm_context_get_test_plugin_dir (void)
|
||||
{
|
||||
return test_plugin_dir ? test_plugin_dir : PLUGINDIR;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
|
||||
@@ -31,5 +31,6 @@ gboolean mm_context_get_relative_timestamps (void);
|
||||
gboolean mm_context_get_test_session (void);
|
||||
gboolean mm_context_get_test_no_auto_scan (void);
|
||||
gboolean mm_context_get_test_enable (void);
|
||||
const gchar *mm_context_get_test_plugin_dir (void);
|
||||
|
||||
#endif /* MM_CONTEXT_H */
|
||||
|
||||
+23
-1
@@ -45,6 +45,7 @@ enum {
|
||||
PROP_CONNECTION,
|
||||
PROP_AUTO_SCAN,
|
||||
PROP_ENABLE_TEST,
|
||||
PROP_PLUGIN_DIR,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
@@ -55,6 +56,8 @@ struct _MMManagerPrivate {
|
||||
gboolean auto_scan;
|
||||
/* Whether the test interface is enabled */
|
||||
gboolean enable_test;
|
||||
/* Path to look for plugins */
|
||||
gchar *plugin_dir;
|
||||
/* The UDev client */
|
||||
GUdevClient *udev;
|
||||
/* The authorization provider */
|
||||
@@ -760,6 +763,7 @@ out:
|
||||
|
||||
MMManager *
|
||||
mm_manager_new (GDBusConnection *connection,
|
||||
const gchar *plugin_dir,
|
||||
gboolean auto_scan,
|
||||
gboolean enable_test,
|
||||
GError **error)
|
||||
@@ -770,6 +774,7 @@ mm_manager_new (GDBusConnection *connection,
|
||||
NULL, /* cancellable */
|
||||
error,
|
||||
MM_MANAGER_CONNECTION, connection,
|
||||
MM_MANAGER_PLUGIN_DIR, plugin_dir,
|
||||
MM_MANAGER_AUTO_SCAN, auto_scan,
|
||||
MM_MANAGER_ENABLE_TEST, enable_test,
|
||||
NULL);
|
||||
@@ -795,6 +800,10 @@ set_property (GObject *object,
|
||||
case PROP_ENABLE_TEST:
|
||||
priv->enable_test = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_PLUGIN_DIR:
|
||||
g_free (priv->plugin_dir);
|
||||
priv->plugin_dir = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -819,6 +828,9 @@ get_property (GObject *object,
|
||||
case PROP_ENABLE_TEST:
|
||||
g_value_set_boolean (value, priv->enable_test);
|
||||
break;
|
||||
case PROP_PLUGIN_DIR:
|
||||
g_value_set_string (value, priv->plugin_dir);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -878,7 +890,7 @@ initable_init (GInitable *initable,
|
||||
g_signal_connect (priv->udev, "uevent", G_CALLBACK (handle_uevent), initable);
|
||||
|
||||
/* Create plugin manager */
|
||||
priv->plugin_manager = mm_plugin_manager_new (error);
|
||||
priv->plugin_manager = mm_plugin_manager_new (priv->plugin_dir, error);
|
||||
if (!priv->plugin_manager)
|
||||
return FALSE;
|
||||
|
||||
@@ -916,6 +928,8 @@ finalize (GObject *object)
|
||||
{
|
||||
MMManagerPrivate *priv = MM_MANAGER (object)->priv;
|
||||
|
||||
g_free (priv->plugin_dir);
|
||||
|
||||
g_hash_table_destroy (priv->devices);
|
||||
|
||||
if (priv->udev)
|
||||
@@ -985,4 +999,12 @@ mm_manager_class_init (MMManagerClass *manager_class)
|
||||
"Enable the Test interface",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_PLUGIN_DIR,
|
||||
g_param_spec_string (MM_MANAGER_PLUGIN_DIR,
|
||||
"Plugin directory",
|
||||
"Where to look for plugins",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#define MM_MANAGER_CONNECTION "connection" /* Construct-only */
|
||||
#define MM_MANAGER_AUTO_SCAN "auto-scan" /* Construct-only */
|
||||
#define MM_MANAGER_ENABLE_TEST "enable-test" /* Construct-only */
|
||||
#define MM_MANAGER_PLUGIN_DIR "plugin-dir" /* Construct-only */
|
||||
|
||||
typedef struct _MMManagerPrivate MMManagerPrivate;
|
||||
|
||||
@@ -48,6 +49,7 @@ typedef struct {
|
||||
GType mm_manager_get_type (void);
|
||||
|
||||
MMManager *mm_manager_new (GDBusConnection *bus,
|
||||
const gchar *plugin_dir,
|
||||
gboolean auto_scan,
|
||||
gboolean enable_test,
|
||||
GError **error);
|
||||
|
||||
+67
-5
@@ -39,9 +39,18 @@ static void initable_iface_init (GInitableIface *iface);
|
||||
|
||||
G_DEFINE_TYPE_EXTENDED (MMPluginManager, mm_plugin_manager, G_TYPE_OBJECT, 0,
|
||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||
initable_iface_init));
|
||||
initable_iface_init))
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_PLUGIN_DIR,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
struct _MMPluginManagerPrivate {
|
||||
/* Path to look for plugins */
|
||||
gchar *plugin_dir;
|
||||
|
||||
/* This list contains all plugins except for the generic one, order is not
|
||||
* important. It is loaded once when the program starts, and the list is NOT
|
||||
* expected to change after that.*/
|
||||
@@ -805,10 +814,10 @@ load_plugins (MMPluginManager *self,
|
||||
}
|
||||
|
||||
/* Get printable UTF-8 string of the path */
|
||||
plugindir_display = g_filename_display_name (PLUGINDIR);
|
||||
plugindir_display = g_filename_display_name (self->priv->plugin_dir);
|
||||
|
||||
mm_dbg ("Looking for plugins in '%s'", plugindir_display);
|
||||
dir = g_dir_open (PLUGINDIR, 0, NULL);
|
||||
dir = g_dir_open (self->priv->plugin_dir, 0, NULL);
|
||||
if (!dir) {
|
||||
g_set_error (error,
|
||||
MM_CORE_ERROR,
|
||||
@@ -825,7 +834,7 @@ load_plugins (MMPluginManager *self,
|
||||
if (!g_str_has_suffix (fname, G_MODULE_SUFFIX))
|
||||
continue;
|
||||
|
||||
path = g_module_build_path (PLUGINDIR, fname);
|
||||
path = g_module_build_path (self->priv->plugin_dir, fname);
|
||||
plugin = load_plugin (path);
|
||||
g_free (path);
|
||||
|
||||
@@ -869,11 +878,13 @@ out:
|
||||
}
|
||||
|
||||
MMPluginManager *
|
||||
mm_plugin_manager_new (GError **error)
|
||||
mm_plugin_manager_new (const gchar *plugin_dir,
|
||||
GError **error)
|
||||
{
|
||||
return g_initable_new (MM_TYPE_PLUGIN_MANAGER,
|
||||
NULL,
|
||||
error,
|
||||
MM_PLUGIN_MANAGER_PLUGIN_DIR, plugin_dir,
|
||||
NULL);
|
||||
}
|
||||
|
||||
@@ -886,6 +897,43 @@ mm_plugin_manager_init (MMPluginManager *manager)
|
||||
MMPluginManagerPrivate);
|
||||
}
|
||||
|
||||
static void
|
||||
set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
MMPluginManagerPrivate *priv = MM_PLUGIN_MANAGER (object)->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PLUGIN_DIR:
|
||||
g_free (priv->plugin_dir);
|
||||
priv->plugin_dir = 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)
|
||||
{
|
||||
MMPluginManagerPrivate *priv = MM_PLUGIN_MANAGER (object)->priv;
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_PLUGIN_DIR:
|
||||
g_value_set_string (value, priv->plugin_dir);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
initable_init (GInitable *initable,
|
||||
GCancellable *cancellable,
|
||||
@@ -907,6 +955,9 @@ dispose (GObject *object)
|
||||
}
|
||||
g_clear_object (&self->priv->generic);
|
||||
|
||||
g_free (self->priv->plugin_dir);
|
||||
self->priv->plugin_dir = NULL;
|
||||
|
||||
G_OBJECT_CLASS (mm_plugin_manager_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
@@ -925,4 +976,15 @@ mm_plugin_manager_class_init (MMPluginManagerClass *manager_class)
|
||||
|
||||
/* Virtual methods */
|
||||
object_class->dispose = dispose;
|
||||
object_class->set_property = set_property;
|
||||
object_class->get_property = get_property;
|
||||
|
||||
/* Properties */
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_PLUGIN_DIR,
|
||||
g_param_spec_string (MM_PLUGIN_MANAGER_PLUGIN_DIR,
|
||||
"Plugin directory",
|
||||
"Where to look for plugins",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#define MM_IS_PLUGIN_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_PLUGIN_MANAGER))
|
||||
#define MM_PLUGIN_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_PLUGIN_MANAGER, MMPluginManagerClass))
|
||||
|
||||
#define MM_PLUGIN_MANAGER_PLUGIN_DIR "plugin-dir" /* Construct-only */
|
||||
|
||||
typedef struct _MMPluginManager MMPluginManager;
|
||||
typedef struct _MMPluginManagerClass MMPluginManagerClass;
|
||||
typedef struct _MMPluginManagerPrivate MMPluginManagerPrivate;
|
||||
@@ -46,7 +48,8 @@ struct _MMPluginManagerClass {
|
||||
|
||||
GType mm_plugin_manager_get_type (void);
|
||||
|
||||
MMPluginManager *mm_plugin_manager_new (GError **error);
|
||||
MMPluginManager *mm_plugin_manager_new (const gchar *plugindir,
|
||||
GError **error);
|
||||
|
||||
/* Asynchronous operation to find the best plugin giving support to a
|
||||
* given device. */
|
||||
|
||||
Reference in New Issue
Block a user