context: new '--test-enable' to enable the Test interface

This commit is contained in:
Aleksander Morgado
2013-11-22 13:47:11 +01:00
parent 243720414e
commit 65f87561c5
7 changed files with 82 additions and 4 deletions

View File

@@ -2,4 +2,4 @@
[D-BUS Service] [D-BUS Service]
Name=org.freedesktop.ModemManager1 Name=org.freedesktop.ModemManager1
Exec=@abs_top_builddir@/src/ModemManager --test-session --test-no-auto-scan Exec=@abs_top_builddir@/src/ModemManager --test-session --test-no-auto-scan --test-enable

View File

@@ -141,6 +141,8 @@ ModemManager_CPPFLAGS = \
-I$(top_builddir)/libmm-glib \ -I$(top_builddir)/libmm-glib \
-I${top_srcdir}/libmm-glib/generated \ -I${top_srcdir}/libmm-glib/generated \
-I${top_builddir}/libmm-glib/generated \ -I${top_builddir}/libmm-glib/generated \
-I${top_srcdir}/libmm-glib/generated/tests \
-I${top_builddir}/libmm-glib/generated/tests \
-DPLUGINDIR=\"$(pkglibdir)\" -DPLUGINDIR=\"$(pkglibdir)\"
ModemManager_LDADD = \ ModemManager_LDADD = \
@@ -148,7 +150,8 @@ ModemManager_LDADD = \
$(GUDEV_LIBS) \ $(GUDEV_LIBS) \
$(builddir)/libmodem-helpers.la \ $(builddir)/libmodem-helpers.la \
$(builddir)/libport.la \ $(builddir)/libport.la \
$(top_builddir)/libqcdm/src/libqcdm.la $(top_builddir)/libqcdm/src/libqcdm.la \
$(top_builddir)/libmm-glib/generated/tests/libmm-test-generated.la
nodist_ModemManager_SOURCES = \ nodist_ModemManager_SOURCES = \
mm-daemon-enums-types.h \ mm-daemon-enums-types.h \

View File

@@ -64,6 +64,7 @@ bus_acquired_cb (GDBusConnection *connection,
g_assert (!manager); g_assert (!manager);
manager = mm_manager_new (connection, manager = mm_manager_new (connection,
!mm_context_get_test_no_auto_scan (), !mm_context_get_test_no_auto_scan (),
mm_context_get_test_enable (),
&error); &error);
if (!manager) { if (!manager) {
mm_warn ("Could not create manager: %s", error->message); mm_warn ("Could not create manager: %s", error->message);

View File

@@ -70,10 +70,12 @@ mm_context_get_relative_timestamps (void)
static gboolean test_session; static gboolean test_session;
static gboolean test_no_auto_scan; static gboolean test_no_auto_scan;
static gboolean test_enable;
static const GOptionEntry test_entries[] = { static const GOptionEntry test_entries[] = {
{ "test-session", 0, 0, G_OPTION_ARG_NONE, &test_session, "Run in session DBus", NULL }, { "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-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 },
{ NULL } { NULL }
}; };
@@ -103,6 +105,12 @@ mm_context_get_test_no_auto_scan (void)
return test_no_auto_scan; return test_no_auto_scan;
} }
gboolean
mm_context_get_test_enable (void)
{
return test_enable;
}
/*****************************************************************************/ /*****************************************************************************/
void void

View File

@@ -30,5 +30,6 @@ gboolean mm_context_get_relative_timestamps (void);
/* Testing support */ /* Testing support */
gboolean mm_context_get_test_session (void); gboolean mm_context_get_test_session (void);
gboolean mm_context_get_test_no_auto_scan (void); gboolean mm_context_get_test_no_auto_scan (void);
gboolean mm_context_get_test_enable (void);
#endif /* MM_CONTEXT_H */ #endif /* MM_CONTEXT_H */

View File

@@ -25,6 +25,7 @@
#include <ModemManager.h> #include <ModemManager.h>
#include <mm-errors-types.h> #include <mm-errors-types.h>
#include <mm-gdbus-manager.h> #include <mm-gdbus-manager.h>
#include <mm-gdbus-test.h>
#include "mm-manager.h" #include "mm-manager.h"
#include "mm-device.h" #include "mm-device.h"
@@ -43,6 +44,7 @@ enum {
PROP_0, PROP_0,
PROP_CONNECTION, PROP_CONNECTION,
PROP_AUTO_SCAN, PROP_AUTO_SCAN,
PROP_ENABLE_TEST,
LAST_PROP LAST_PROP
}; };
@@ -51,6 +53,8 @@ struct _MMManagerPrivate {
GDBusConnection *connection; GDBusConnection *connection;
/* Whether auto-scanning is enabled */ /* Whether auto-scanning is enabled */
gboolean auto_scan; gboolean auto_scan;
/* Whether the test interface is enabled */
gboolean enable_test;
/* The UDev client */ /* The UDev client */
GUdevClient *udev; GUdevClient *udev;
/* The authorization provider */ /* The authorization provider */
@@ -62,6 +66,9 @@ struct _MMManagerPrivate {
GHashTable *devices; GHashTable *devices;
/* The Object Manager server */ /* The Object Manager server */
GDBusObjectManagerServer *object_manager; GDBusObjectManagerServer *object_manager;
/* The Test interface support */
MmGdbusTest *test_skeleton;
}; };
/*****************************************************************************/ /*****************************************************************************/
@@ -569,6 +576,7 @@ mm_manager_num_modems (MMManager *self)
} }
/*****************************************************************************/ /*****************************************************************************/
/* Set logging */
typedef struct { typedef struct {
MMManager *self; MMManager *self;
@@ -628,6 +636,7 @@ handle_set_logging (MmGdbusOrgFreedesktopModemManager1 *manager,
} }
/*****************************************************************************/ /*****************************************************************************/
/* Manual scan */
typedef struct { typedef struct {
MMManager *self; MMManager *self;
@@ -681,9 +690,28 @@ handle_scan_devices (MmGdbusOrgFreedesktopModemManager1 *manager,
return TRUE; return TRUE;
} }
/*****************************************************************************/
/* Test profile setup */
static gboolean
handle_set_profile (MmGdbusTest *skeleton,
GDBusMethodInvocation *invocation,
const gchar *id,
const gchar *plugin_name,
const gchar *const *ports,
MMManager *self)
{
mm_info ("Test profile set to: %s", profile);
mm_gdbus_test_complete_set_profile (skeleton, invocation);
return TRUE;
}
/*****************************************************************************/
MMManager * MMManager *
mm_manager_new (GDBusConnection *connection, mm_manager_new (GDBusConnection *connection,
gboolean auto_scan, gboolean auto_scan,
gboolean enable_test,
GError **error) GError **error)
{ {
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
@@ -693,6 +721,7 @@ mm_manager_new (GDBusConnection *connection,
error, error,
MM_MANAGER_CONNECTION, connection, MM_MANAGER_CONNECTION, connection,
MM_MANAGER_AUTO_SCAN, auto_scan, MM_MANAGER_AUTO_SCAN, auto_scan,
MM_MANAGER_ENABLE_TEST, enable_test,
NULL); NULL);
} }
@@ -713,6 +742,9 @@ set_property (GObject *object,
case PROP_AUTO_SCAN: case PROP_AUTO_SCAN:
priv->auto_scan = g_value_get_boolean (value); priv->auto_scan = g_value_get_boolean (value);
break; break;
case PROP_ENABLE_TEST:
priv->enable_test = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -734,6 +766,9 @@ get_property (GObject *object,
case PROP_AUTO_SCAN: case PROP_AUTO_SCAN:
g_value_set_boolean (value, priv->auto_scan); g_value_set_boolean (value, priv->auto_scan);
break; break;
case PROP_ENABLE_TEST:
g_value_set_boolean (value, priv->enable_test);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@@ -764,6 +799,9 @@ mm_manager_init (MMManager *manager)
/* By default, enable autoscan */ /* By default, enable autoscan */
priv->auto_scan = TRUE; priv->auto_scan = TRUE;
/* By default, no test interface */
priv->enable_test = FALSE;
/* Setup Object Manager Server */ /* Setup Object Manager Server */
priv->object_manager = g_dbus_object_manager_server_new (MM_DBUS_PATH); priv->object_manager = g_dbus_object_manager_server_new (MM_DBUS_PATH);
@@ -805,6 +843,20 @@ initable_init (GInitable *initable,
g_dbus_object_manager_server_set_connection (priv->object_manager, g_dbus_object_manager_server_set_connection (priv->object_manager,
priv->connection); priv->connection);
/* Setup the Test skeleton and export the interface */
if (priv->enable_test) {
priv->test_skeleton = mm_gdbus_test_skeleton_new ();
g_signal_connect (priv->test_skeleton,
"handle-set-profile",
G_CALLBACK (handle_set_profile),
initable);
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->test_skeleton),
priv->connection,
MM_DBUS_PATH,
error))
return FALSE;
}
/* All good */ /* All good */
return TRUE; return TRUE;
} }
@@ -825,6 +877,9 @@ finalize (GObject *object)
if (priv->object_manager) if (priv->object_manager)
g_object_unref (priv->object_manager); g_object_unref (priv->object_manager);
if (priv->test_skeleton)
g_object_unref (priv->test_skeleton);
if (priv->connection) if (priv->connection)
g_object_unref (priv->connection); g_object_unref (priv->connection);
@@ -872,4 +927,12 @@ mm_manager_class_init (MMManagerClass *manager_class)
"Automatically look for new devices", "Automatically look for new devices",
TRUE, TRUE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class, PROP_ENABLE_TEST,
g_param_spec_boolean (MM_MANAGER_ENABLE_TEST,
"Enable tests",
"Enable the Test interface",
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
} }

View File

@@ -30,8 +30,9 @@
#define MM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_MANAGER)) #define MM_IS_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), MM_TYPE_MANAGER))
#define MM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MANAGER, MMManagerClass)) #define MM_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_MANAGER, MMManagerClass))
#define MM_MANAGER_CONNECTION "connection" /* Construct-only */ #define MM_MANAGER_CONNECTION "connection" /* Construct-only */
#define MM_MANAGER_AUTO_SCAN "auto-scan" /* Construct-only */ #define MM_MANAGER_AUTO_SCAN "auto-scan" /* Construct-only */
#define MM_MANAGER_ENABLE_TEST "enable-test" /* Construct-only */
typedef struct _MMManagerPrivate MMManagerPrivate; typedef struct _MMManagerPrivate MMManagerPrivate;
@@ -48,6 +49,7 @@ GType mm_manager_get_type (void);
MMManager *mm_manager_new (GDBusConnection *bus, MMManager *mm_manager_new (GDBusConnection *bus,
gboolean auto_scan, gboolean auto_scan,
gboolean enable_test,
GError **error); GError **error);
void mm_manager_start (MMManager *manager, void mm_manager_start (MMManager *manager,