network-manager-applet r858 - in branches/mbca: . src src/connection-editor
- From: kaijanma svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r858 - in branches/mbca: . src src/connection-editor
- Date: Mon, 18 Aug 2008 12:35:09 +0000 (UTC)
Author: kaijanma
Date: Mon Aug 18 12:35:09 2008
New Revision: 858
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=858&view=rev
Log:
load libmbca dynamically if available
Modified:
branches/mbca/configure.ac
branches/mbca/src/applet-device-gsm.c
branches/mbca/src/applet.c
branches/mbca/src/applet.h
branches/mbca/src/connection-editor/nm-connection-list.c
Modified: branches/mbca/configure.ac
==============================================================================
--- branches/mbca/configure.ac (original)
+++ branches/mbca/configure.ac Mon Aug 18 12:35:09 2008
@@ -219,7 +219,7 @@
CFLAGS="$CFLAGS -DWITH_MBCA"
PKG_CHECK_MODULES(MBCA, libmbca)
NMA_CFLAGS="$NMA_CFLAGS $MBCA_CFLAGS"
- NMA_LIBS="$NMA_LIBS $MBCA_LIBS"
+ #NMA_LIBS="$NMA_LIBS $MBCA_LIBS"
fi
Modified: branches/mbca/src/applet-device-gsm.c
==============================================================================
--- branches/mbca/src/applet-device-gsm.c (original)
+++ branches/mbca/src/applet-device-gsm.c Mon Aug 18 12:35:09 2008
@@ -84,6 +84,10 @@
MBCAConfiguration* conf;
+ if (!applet_open_mbca (applet))
+ g_return_if_reached (); /* this cb should not be called without
+ * libmbca */
+
switch (state)
{
case MBCA_STATE_READY:
@@ -93,7 +97,7 @@
}
case MBCA_STATE_DONE:
{
- conf = mbca_assistant_get_configuration (assistant);
+ conf = applet->mbca_assistant_get_configuration_func (assistant);
connection = nm_connection_new ();
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -152,7 +156,7 @@
nm_connection_add_setting (connection, NM_SETTING (s_ppp));
- mbca_free_configuration (conf);
+ applet->mbca_free_configuration_func (conf);
if (dns_servers)
g_array_free (dns_servers, TRUE);
@@ -195,48 +199,8 @@
}
}
+#endif
-static NMConnection *
-gsm_new_auto_connection (NMDevice *device,
- NMApplet *applet,
- gpointer user_data)
-{
- UdiAssistant* ua;
- const gchar* udi;
- GSList* iter;
-
- udi = nm_device_get_udi (device);
-
- for (iter = applet->mbca_assistants; iter; iter = iter->next) {
- UdiAssistant* tmp = iter->data;
- if (!strcmp (tmp->udi, udi))
- {
- mbca_assistant_present (tmp->assistant);
- break;
- }
- }
- if (!iter)
- {
- /* not found */
- ua = g_malloc (sizeof (UdiAssistant));
- ua->udi = g_strdup (udi);
- ua->assistant = mbca_assistant_new ();
- g_signal_connect (G_OBJECT (ua->assistant), "state-changed",
- G_CALLBACK (assistant_state_changed_cb), applet);
- applet->mbca_assistants = g_slist_prepend (applet->mbca_assistants, ua);
- mbca_assistant_run_for_device (ua->assistant,
- MBCA_DEVICE_PSEUDO,
- NULL, NULL);
- }
-
- nm_warning ("There's a new GSM modem being configured and no "
- "configuration is yet available. You can safely ignore the "
- "next warninig, if any, about missing default configuration."
- );
- return NULL;
-}
-
-#else
#define DEFAULT_GSM_NAME _("Auto GSM network connection")
@@ -250,7 +214,50 @@
NMSettingSerial *s_serial;
NMSettingPPP *s_ppp;
NMSettingConnection *s_con;
-
+
+#ifdef WITH_MBCA
+ UdiAssistant* ua;
+ const gchar* udi;
+ GSList* iter;
+
+ if (applet_open_mbca (applet))
+ {
+ udi = nm_device_get_udi (device);
+
+ for (iter = applet->mbca_assistants; iter; iter = iter->next) {
+ UdiAssistant* tmp = iter->data;
+ if (!strcmp (tmp->udi, udi))
+ {
+ applet->mbca_assistant_present_func (tmp->assistant);
+ break;
+ }
+ }
+ if (!iter)
+ {
+ /* not found */
+ ua = g_malloc (sizeof (UdiAssistant));
+ ua->udi = g_strdup (udi);
+ ua->assistant = applet->mbca_assistant_new_func ();
+ g_signal_connect (G_OBJECT (ua->assistant), "state-changed",
+ G_CALLBACK (assistant_state_changed_cb), applet);
+ applet->mbca_assistants = g_slist_prepend (applet->mbca_assistants, ua);
+ applet->mbca_assistant_run_for_device_func (ua->assistant,
+ MBCA_DEVICE_PSEUDO,
+ NULL, NULL);
+ }
+
+ nm_warning ("There's a new GSM modem being configured and no "
+ "configuration is yet available. You can safely ignore the "
+ "next warninig, if any, about missing default configuration."
+ );
+ return NULL;
+ }
+ else
+ {
+ /* continue to default code */
+ }
+#endif
+
connection = nm_connection_new ();
s_gsm = NM_SETTING_GSM (nm_setting_gsm_new ());
@@ -276,7 +283,7 @@
return connection;
}
-#endif
+
static void
@@ -333,13 +340,14 @@
NMApplet *applet)
{
GSMMenuItemInfo *info;
- GtkWidget *item;
+ GtkWidget *item = NULL;
#ifdef WITH_MBCA
- item = gtk_check_menu_item_new_with_label (_("Configure..."));
-#else
- item = gtk_check_menu_item_new_with_label (DEFAULT_GSM_NAME);
+ if (applet_open_mbca (applet))
+ item = gtk_check_menu_item_new_with_label (_("Configure..."));
#endif
+ if (!item)
+ item = gtk_check_menu_item_new_with_label (DEFAULT_GSM_NAME);
gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
@@ -498,6 +506,9 @@
gsm_device_added (NMDevice *device, NMApplet *applet)
{
GSList *connections, *all;
+
+ if (!applet_open_mbca (applet))
+ return;
all = applet_get_all_connections (applet);
connections = utils_filter_connections_for_device (device, all);
Modified: branches/mbca/src/applet.c
==============================================================================
--- branches/mbca/src/applet.c (original)
+++ branches/mbca/src/applet.c Mon Aug 18 12:35:09 2008
@@ -893,6 +893,52 @@
return connection;
}
+#ifdef WITH_MBCA
+gboolean
+applet_open_mbca (NMApplet *applet)
+{
+ if (applet->mbca_module)
+ return TRUE;
+
+ applet->mbca_module = g_module_open ("libmbca", 0);
+ if (!applet->mbca_module)
+ return FALSE;
+
+ if (!g_module_symbol (applet->mbca_module,
+ "mbca_assistant_abort",
+ (gpointer)(&applet->mbca_assistant_abort_func)));
+ g_warn_if_reached ();
+
+ if (!g_module_symbol (applet->mbca_module,
+ "mbca_assistant_present",
+ (gpointer)(&applet->mbca_assistant_present_func)));
+ g_warn_if_reached ();
+
+ if (!g_module_symbol (applet->mbca_module,
+ "mbca_assistant_new",
+ (gpointer)(&applet->mbca_assistant_new_func)));
+ g_warn_if_reached ();
+
+ if (!g_module_symbol (applet->mbca_module,
+ "mbca_assistant_run_for_device",
+ (gpointer)(&applet->mbca_assistant_run_for_device_func)));
+ g_warn_if_reached ();
+
+ if (!g_module_symbol (applet->mbca_module,
+ "mbca_assistant_get_configuration",
+ (gpointer)(&applet->mbca_assistant_get_configuration_func)));
+ g_warn_if_reached ();
+
+ if (!g_module_symbol (applet->mbca_module,
+ "mbca_free_configuration",
+ (gpointer)(&applet->mbca_free_configuration_func)));
+ g_warn_if_reached ();
+
+ return TRUE;
+}
+#endif
+
+
static guint32
nma_menu_add_devices (GtkWidget *menu, NMApplet *applet)
{
@@ -2247,13 +2293,17 @@
#ifdef WITH_MBCA
GSList* iter = NULL;
-
+
for (iter = applet->mbca_assistants; iter; iter = iter->next) {
MBCAAssistant* assistant = iter->data;
- mbca_assistant_abort (assistant);
+ if (!applet_open_mbca (applet))
+ g_return_if_reached (); /* no assistants without libmbca */
+ applet->mbca_assistant_abort_func (assistant);
/* let the cb handle freeing of resources */
}
+ if (applet->mbca_module)
+ g_module_close (applet->mbca_module);
#endif
if (applet->update_timestamps_id)
@@ -2301,6 +2351,7 @@
#ifdef WITH_MBCA
applet->mbca_assistants = NULL;
+ applet->mbca_module = NULL;
#endif
}
Modified: branches/mbca/src/applet.h
==============================================================================
--- branches/mbca/src/applet.h (original)
+++ branches/mbca/src/applet.h Mon Aug 18 12:35:09 2008
@@ -155,7 +155,17 @@
NotifyNotification* notification;
#ifdef WITH_MBCA
- GSList* mbca_assistants; /* list of UdiAssistant */
+ GSList *mbca_assistants; /* list of UdiAssistant */
+ GModule *mbca_module;
+ void (*mbca_assistant_abort_func) (MBCAAssistant*);
+ void (*mbca_assistant_present_func) (MBCAAssistant*);
+ MBCAAssistant* (*mbca_assistant_new_func) ();
+ gint (*mbca_assistant_run_for_device_func) (MBCAAssistant*,
+ MBCADeviceType,
+ const gchar*,
+ const gchar*);
+ MBCAConfiguration* (*mbca_assistant_get_configuration_func) (MBCAAssistant*);
+ void (*mbca_free_configuration_func) (MBCAConfiguration*);
#endif
} NMApplet;
@@ -208,5 +218,9 @@
NMConnection * applet_find_active_connection_for_device (NMDevice *device,
NMApplet *applet,
NMActiveConnection **out_active);
+
+#ifdef WITH_MBCA
+gboolean applet_open_mbca (NMApplet *applet);
+#endif
#endif
Modified: branches/mbca/src/connection-editor/nm-connection-list.c
==============================================================================
--- branches/mbca/src/connection-editor/nm-connection-list.c (original)
+++ branches/mbca/src/connection-editor/nm-connection-list.c Mon Aug 18 12:35:09 2008
@@ -749,7 +749,11 @@
NMSettingConnection *s_con;
NMSetting *type_setting = NULL;
MBCAConfiguration* conf;
-
+
+ GModule *mbca_module = NULL;
+ MBCAConfiguration* (*get_configuration_func) (MBCAAssistant*) = NULL;
+ void (*free_configuration_func) (MBCAConfiguration*) = NULL;
+
NMConnectionList *list = user_data;
NMSettingIP4Config* ipv4conf;
@@ -762,6 +766,22 @@
case MBCA_STATE_RUNNING:
return;
case MBCA_STATE_DONE:
+ mbca_module = g_module_open ("libmbca", 0);
+ g_return_if_fail (mbca_module); /* this function should never get
+ * called without a prior usage of
+ * libmbca in
+ * create_new_connection_for_type
+ */
+ if (!g_module_symbol (mbca_module,
+ "mbca_assistant_get_configuration",
+ (gpointer)(&get_configuration_func)))
+ g_return_if_reached ();
+
+ if (!g_module_symbol (mbca_module,
+ "mbca_free_configuration",
+ (gpointer)(&free_configuration_func)))
+ g_return_if_reached ();
+
connection = nm_connection_new ();
s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -770,7 +790,7 @@
ipv4conf = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
nm_connection_add_setting (connection, NM_SETTING (ipv4conf));
- conf = mbca_assistant_get_configuration (assistant);
+ conf = get_configuration_func (assistant);
s_con->id = g_strdup (conf->name);
s_con->autoconnect = FALSE;
@@ -840,7 +860,8 @@
add_connection (list, connection, NULL, NULL);
g_hash_table_remove (list->editors, connection);
- mbca_free_configuration (conf);
+ free_configuration_func (conf);
+ g_module_close (mbca_module);
if (dns_servers)
g_array_free (dns_servers, TRUE);
/* FALLTHROUGH */
@@ -863,7 +884,8 @@
NMSetting *type_setting = NULL;
GType mb_type;
#ifdef WITH_MBCA
- MBCAAssistant* assistant;
+ MBCAAssistant *assistant = NULL;
+ GModule *mbca_module = NULL;
#endif
ctype = nm_connection_lookup_setting_type (connection_type);
@@ -891,54 +913,79 @@
} else if ((ctype == NM_TYPE_SETTING_GSM) || (ctype == NM_TYPE_SETTING_CDMA)) {
#ifdef WITH_MBCA
-
- assistant = mbca_assistant_new ();
- g_signal_connect (G_OBJECT (assistant), "state-changed",
- G_CALLBACK (mbca_assistant_state_changed_cb), list);
- mbca_assistant_run_for_device (assistant, MBCA_DEVICE_PSEUDO,
- NULL, NULL);
+ mbca_module = g_module_open ("libmbca", 0);
+#endif
+ if (mbca_module)
+ {
+#ifdef WITH_MBCA
+ MBCAAssistant* (*new_assistant_func)() = NULL;
+ gint (*run_func)(MBCAAssistant*,
+ MBCADeviceType,
+ const gchar*,
+ const gchar*) = NULL;
+
+ if (!g_module_symbol (mbca_module,
+ "mbca_assistant_new",
+ (gpointer)(&new_assistant_func))
+ )
+ g_return_val_if_reached (NULL);
+
+ if (!g_module_symbol (mbca_module,
+ "mbca_assistant_run_for_device",
+ (gpointer)(&run_func))
+ )
+ g_return_val_if_reached (NULL);
+
+ assistant = new_assistant_func ();
+ g_signal_connect (G_OBJECT (assistant), "state-changed",
+ G_CALLBACK (mbca_assistant_state_changed_cb), list);
+ run_func (assistant, MBCA_DEVICE_PSEUDO, NULL, NULL);
- mb_type = NM_TYPE_SETTING_GSM; /* get rid of compiler warning about
- * unused variable */
-#else
+ mb_type = NM_TYPE_SETTING_GSM; /* get rid of compiler warning about
+ * unused variable */
+ g_module_close (mbca_module);
+#endif
+ }
+ else
+ {
+ /* MBCA support not compiled in or libmbca is missing */
- /* Since GSM is a placeholder for both GSM and CDMA; ask the user which
- * one they really want.
- */
- mb_type = mobile_wizard_ask_connection_type ();
- if (mb_type == NM_TYPE_SETTING_GSM) {
- NMSettingGsm *s_gsm;
-
- s_con->id = get_next_available_name (list, _("GSM connection %d"));
- s_con->type = g_strdup (NM_SETTING_GSM_SETTING_NAME);
- s_con->autoconnect = FALSE;
-
- add_default_serial_setting (connection);
-
- type_setting = nm_setting_gsm_new ();
- s_gsm = NM_SETTING_GSM (type_setting);
- s_gsm->number = g_strdup ("*99#"); /* De-facto standard for GSM */
-
- nm_connection_add_setting (connection, nm_setting_ppp_new ());
- } else if (mb_type == NM_TYPE_SETTING_CDMA) {
- NMSettingCdma *s_cdma;
-
- s_con->id = get_next_available_name (list, _("CDMA connection %d"));
- s_con->type = g_strdup (NM_SETTING_CDMA_SETTING_NAME);
- s_con->autoconnect = FALSE;
-
- add_default_serial_setting (connection);
-
- type_setting = nm_setting_cdma_new ();
- s_cdma = NM_SETTING_CDMA (type_setting);
- s_cdma->number = g_strdup ("#777"); /* De-facto standard for CDMA */
-
- nm_connection_add_setting (connection, nm_setting_ppp_new ());
- } else {
- /* user canceled; do nothing */
+ /* Since GSM is a placeholder for both GSM and CDMA; ask the user which
+ * one they really want.
+ */
+ mb_type = mobile_wizard_ask_connection_type ();
+ if (mb_type == NM_TYPE_SETTING_GSM) {
+ NMSettingGsm *s_gsm;
+
+ s_con->id = get_next_available_name (list, _("GSM connection %d"));
+ s_con->type = g_strdup (NM_SETTING_GSM_SETTING_NAME);
+ s_con->autoconnect = FALSE;
+
+ add_default_serial_setting (connection);
+
+ type_setting = nm_setting_gsm_new ();
+ s_gsm = NM_SETTING_GSM (type_setting);
+ s_gsm->number = g_strdup ("*99#"); /* De-facto standard for GSM */
+
+ nm_connection_add_setting (connection, nm_setting_ppp_new ());
+ } else if (mb_type == NM_TYPE_SETTING_CDMA) {
+ NMSettingCdma *s_cdma;
+
+ s_con->id = get_next_available_name (list, _("CDMA connection %d"));
+ s_con->type = g_strdup (NM_SETTING_CDMA_SETTING_NAME);
+ s_con->autoconnect = FALSE;
+
+ add_default_serial_setting (connection);
+
+ type_setting = nm_setting_cdma_new ();
+ s_cdma = NM_SETTING_CDMA (type_setting);
+ s_cdma->number = g_strdup ("#777"); /* De-facto standard for CDMA */
+
+ nm_connection_add_setting (connection, nm_setting_ppp_new ());
+ } else {
+ /* user canceled; do nothing */
+ }
}
-
-#endif
} else if (ctype == NM_TYPE_SETTING_VPN) {
char *service = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]