Commit 1dbe9fd0 authored by Dan Williams's avatar Dan Williams
Browse files

2006-08-06 Dan Williams <dcbw@redhat.com>

	* gnome/applet/applet-dbus-devices.c
	  gnome/applet/applet-dbus-vpn.c
	  gnome/applet/applet-dbus.c
	  gnome/applet/applet-dbus.h
	  src/nm-dbus-nmi.c
	  utils/nm-utils.c
	  utils/nm-utils.h
		- Make pending call tracking code generic,
		so we can use it in NM as well as the applet


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1940 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 92077eb5
2006-08-06 Dan Williams <dcbw@redhat.com>
* gnome/applet/applet-dbus-devices.c
gnome/applet/applet-dbus-vpn.c
gnome/applet/applet-dbus.c
gnome/applet/applet-dbus.h
src/nm-dbus-nmi.c
utils/nm-utils.c
utils/nm-utils.h
- Make pending call tracking code generic,
so we can use it in NM as well as the applet
2006-08-06 Dan Williams <dcbw@redhat.com> 2006-08-06 Dan Williams <dcbw@redhat.com>
* src/nm-activation-request.c * src/nm-activation-request.c
......
...@@ -56,7 +56,7 @@ static void nma_dbus_nm_state_cb (DBusPendingCall *pcall, void *user_data) ...@@ -56,7 +56,7 @@ static void nma_dbus_nm_state_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (pcall != NULL); g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -97,7 +97,7 @@ void nma_dbus_update_nm_state (NMApplet *applet) ...@@ -97,7 +97,7 @@ void nma_dbus_update_nm_state (NMApplet *applet)
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_nm_state_cb, applet, NULL, __func__); nma_dbus_nm_state_cb, applet, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
...@@ -127,7 +127,7 @@ static void nma_dbus_device_get_driver_cb (DBusPendingCall *pcall, void *user_da ...@@ -127,7 +127,7 @@ static void nma_dbus_device_get_driver_cb (DBusPendingCall *pcall, void *user_da
g_return_if_fail (pcall != NULL); g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -186,7 +186,7 @@ static void nma_dbus_device_get_driver (NetworkDevice *dev, NMApplet *applet) ...@@ -186,7 +186,7 @@ static void nma_dbus_device_get_driver (NetworkDevice *dev, NMApplet *applet)
data->dev = dev; data->dev = dev;
data->applet = applet; data->applet = applet;
if (!nma_dbus_send_with_callback (applet->connection, message, if (!nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_get_driver_cb, data, NULL, __func__)) nma_dbus_device_get_driver_cb, data, NULL, __func__))
{ {
network_device_unref (dev); network_device_unref (dev);
...@@ -212,7 +212,7 @@ static void nma_dbus_update_wireless_enabled_cb (DBusPendingCall *pcall, void *u ...@@ -212,7 +212,7 @@ static void nma_dbus_update_wireless_enabled_cb (DBusPendingCall *pcall, void *u
g_return_if_fail (pcall != NULL); g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -256,7 +256,7 @@ static void nma_dbus_update_wireless_enabled (NMApplet *applet) ...@@ -256,7 +256,7 @@ static void nma_dbus_update_wireless_enabled (NMApplet *applet)
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getWirelessEnabled"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getWirelessEnabled")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_update_wireless_enabled_cb, applet, NULL, __func__); nma_dbus_update_wireless_enabled_cb, applet, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
...@@ -303,7 +303,7 @@ static void hal_info_product_cb (DBusPendingCall *pcall, void *user_data) ...@@ -303,7 +303,7 @@ static void hal_info_product_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (cb_data->parent_op != NULL); g_return_if_fail (cb_data->parent_op != NULL);
g_return_if_fail (cb_data->vendor != NULL); g_return_if_fail (cb_data->vendor != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -351,7 +351,7 @@ static void hal_info_vendor_cb (DBusPendingCall *pcall, void *user_data) ...@@ -351,7 +351,7 @@ static void hal_info_vendor_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (cb_data->dev != NULL); g_return_if_fail (cb_data->dev != NULL);
g_return_if_fail (cb_data->parent_op != NULL); g_return_if_fail (cb_data->parent_op != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -386,7 +386,7 @@ static void hal_info_vendor_cb (DBusPendingCall *pcall, void *user_data) ...@@ -386,7 +386,7 @@ static void hal_info_vendor_cb (DBusPendingCall *pcall, void *user_data)
product_cb_data->parent_op = g_strdup (cb_data->parent_op); product_cb_data->parent_op = g_strdup (cb_data->parent_op);
product_cb_data->vendor = g_strdup (info_vendor); product_cb_data->vendor = g_strdup (info_vendor);
nma_dbus_send_with_callback (cb_data->applet->connection, message, nm_dbus_send_with_callback (cb_data->applet->connection, message,
hal_info_product_cb, product_cb_data, hal_info_product_cb, product_cb_data,
(DBusFreeFunction) free_hal_info_cb_data, __func__); (DBusFreeFunction) free_hal_info_cb_data, __func__);
dbus_message_unref (message); dbus_message_unref (message);
...@@ -416,7 +416,7 @@ static void hal_net_physdev_cb (DBusPendingCall *pcall, void *user_data) ...@@ -416,7 +416,7 @@ static void hal_net_physdev_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (cb_data->applet != NULL); g_return_if_fail (cb_data->applet != NULL);
g_return_if_fail (cb_data->dev != NULL); g_return_if_fail (cb_data->dev != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -451,7 +451,7 @@ static void hal_net_physdev_cb (DBusPendingCall *pcall, void *user_data) ...@@ -451,7 +451,7 @@ static void hal_net_physdev_cb (DBusPendingCall *pcall, void *user_data)
vendor_cb_data->dev = cb_data->dev; vendor_cb_data->dev = cb_data->dev;
vendor_cb_data->parent_op = g_strdup (op); vendor_cb_data->parent_op = g_strdup (op);
nma_dbus_send_with_callback (cb_data->applet->connection, message, nm_dbus_send_with_callback (cb_data->applet->connection, message,
hal_info_vendor_cb, vendor_cb_data, hal_info_vendor_cb, vendor_cb_data,
(DBusFreeFunction) free_hal_info_cb_data, __func__); (DBusFreeFunction) free_hal_info_cb_data, __func__);
dbus_message_unref (message); dbus_message_unref (message);
...@@ -490,7 +490,7 @@ static void nma_dbus_update_device_info_from_hal (NetworkDevice *dev, NMApplet * ...@@ -490,7 +490,7 @@ static void nma_dbus_update_device_info_from_hal (NetworkDevice *dev, NMApplet *
network_device_ref (dev); network_device_ref (dev);
cb_data->dev = dev; cb_data->dev = dev;
nma_dbus_send_with_callback (cb_data->applet->connection, message, nm_dbus_send_with_callback (cb_data->applet->connection, message,
hal_net_physdev_cb, cb_data, hal_net_physdev_cb, cb_data,
(DBusFreeFunction) free_hal_info_cb_data, __func__); (DBusFreeFunction) free_hal_info_cb_data, __func__);
dbus_message_unref (message); dbus_message_unref (message);
...@@ -555,7 +555,7 @@ static void nma_dbus_net_properties_cb (DBusPendingCall *pcall, void *user_data) ...@@ -555,7 +555,7 @@ static void nma_dbus_net_properties_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (cb_data->applet != NULL); g_return_if_fail (cb_data->applet != NULL);
g_return_if_fail (cb_data->dev_op != NULL); g_return_if_fail (cb_data->dev_op != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
applet = cb_data->applet; applet = cb_data->applet;
...@@ -647,7 +647,7 @@ void nma_dbus_device_update_one_network (NMApplet *applet, const char *dev_path, ...@@ -647,7 +647,7 @@ void nma_dbus_device_update_one_network (NMApplet *applet, const char *dev_path,
cb_data->act_net = (active_net_path && strlen (active_net_path)) ? g_strdup (active_net_path) : NULL; cb_data->act_net = (active_net_path && strlen (active_net_path)) ? g_strdup (active_net_path) : NULL;
cb_data->applet = applet; cb_data->applet = applet;
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_net_properties_cb, cb_data, nma_dbus_net_properties_cb, cb_data,
(DBusFreeFunction) free_net_prop_cb_data, __func__); (DBusFreeFunction) free_net_prop_cb_data, __func__);
dbus_message_unref (message); dbus_message_unref (message);
...@@ -761,7 +761,7 @@ static void nma_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_da ...@@ -761,7 +761,7 @@ static void nma_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_da
g_return_if_fail (pcall != NULL); g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -871,7 +871,7 @@ void nma_dbus_device_update_one_device (NMApplet *applet, const char *dev_path) ...@@ -871,7 +871,7 @@ void nma_dbus_device_update_one_device (NMApplet *applet, const char *dev_path)
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_properties_cb, applet, NULL, __func__); nma_dbus_device_properties_cb, applet, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
...@@ -905,7 +905,7 @@ static void nma_dbus_device_activated_cb (DBusPendingCall *pcall, void *user_dat ...@@ -905,7 +905,7 @@ static void nma_dbus_device_activated_cb (DBusPendingCall *pcall, void *user_dat
char * icon = NULL; char * icon = NULL;
#endif #endif
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
nma_dbus_device_properties_cb (pcall, applet); nma_dbus_device_properties_cb (pcall, applet);
...@@ -961,7 +961,7 @@ void nma_dbus_device_activated (NMApplet *applet, const char *dev_path, const ch ...@@ -961,7 +961,7 @@ void nma_dbus_device_activated (NMApplet *applet, const char *dev_path, const ch
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_activated_cb, cb_data, NULL, __func__); nma_dbus_device_activated_cb, cb_data, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
...@@ -972,7 +972,7 @@ static void nma_dbus_device_deactivated_cb (DBusPendingCall *pcall, void *user_d ...@@ -972,7 +972,7 @@ static void nma_dbus_device_deactivated_cb (DBusPendingCall *pcall, void *user_d
{ {
NMApplet * applet = (NMApplet *) user_data; NMApplet * applet = (NMApplet *) user_data;
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
nma_dbus_device_properties_cb (pcall, applet); nma_dbus_device_properties_cb (pcall, applet);
...@@ -995,7 +995,7 @@ void nma_dbus_device_deactivated (NMApplet *applet, const char *dev_path) ...@@ -995,7 +995,7 @@ void nma_dbus_device_deactivated (NMApplet *applet, const char *dev_path)
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_deactivated_cb, applet, NULL, __func__); nma_dbus_device_deactivated_cb, applet, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
...@@ -1018,7 +1018,7 @@ static void nma_dbus_update_devices_cb (DBusPendingCall *pcall, void *user_data) ...@@ -1018,7 +1018,7 @@ static void nma_dbus_update_devices_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (pcall != NULL); g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -1072,7 +1072,7 @@ void nma_dbus_update_devices (NMApplet *applet) ...@@ -1072,7 +1072,7 @@ void nma_dbus_update_devices (NMApplet *applet)
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_update_devices_cb, applet, NULL, __func__); nma_dbus_update_devices_cb, applet, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
...@@ -1096,7 +1096,7 @@ static void nma_dbus_update_dialup_cb (DBusPendingCall *pcall, void *user_data) ...@@ -1096,7 +1096,7 @@ static void nma_dbus_update_dialup_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (pcall != NULL); g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -1158,7 +1158,7 @@ void nma_dbus_update_dialup (NMApplet *applet) ...@@ -1158,7 +1158,7 @@ void nma_dbus_update_dialup (NMApplet *applet)
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDialup"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDialup")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_update_dialup_cb, applet, NULL, __func__); nma_dbus_update_dialup_cb, applet, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
......
...@@ -117,7 +117,7 @@ static void nma_dbus_vpn_properties_cb (DBusPendingCall *pcall, void *user_data) ...@@ -117,7 +117,7 @@ static void nma_dbus_vpn_properties_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (cb_data->applet != NULL); g_return_if_fail (cb_data->applet != NULL);
g_return_if_fail (cb_data->name != NULL); g_return_if_fail (cb_data->name != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
applet = cb_data->applet; applet = cb_data->applet;
...@@ -188,7 +188,7 @@ void nma_dbus_vpn_update_one_vpn_connection (NMApplet *applet, const char *vpn_n ...@@ -188,7 +188,7 @@ void nma_dbus_vpn_update_one_vpn_connection (NMApplet *applet, const char *vpn_n
cb_data->applet = applet; cb_data->applet = applet;
cb_data->name = g_strdup (vpn_name); cb_data->name = g_strdup (vpn_name);
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_vpn_properties_cb, cb_data, nma_dbus_vpn_properties_cb, cb_data,
(DBusFreeFunction) free_vpn_props_cb_data, __func__); (DBusFreeFunction) free_vpn_props_cb_data, __func__);
dbus_message_unref (message); dbus_message_unref (message);
...@@ -212,7 +212,7 @@ static void nma_dbus_vpn_update_vpn_connections_cb (DBusPendingCall *pcall, void ...@@ -212,7 +212,7 @@ static void nma_dbus_vpn_update_vpn_connections_cb (DBusPendingCall *pcall, void
g_return_if_fail (pcall != NULL); g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL); g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -268,7 +268,7 @@ void nma_dbus_vpn_update_vpn_connections (NMApplet *applet) ...@@ -268,7 +268,7 @@ void nma_dbus_vpn_update_vpn_connections (NMApplet *applet)
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "getVPNConnections"))) if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "getVPNConnections")))
{ {
nma_dbus_send_with_callback (applet->connection, message, nm_dbus_send_with_callback (applet->connection, message,
nma_dbus_vpn_update_vpn_connections_cb, applet, NULL, __func__); nma_dbus_vpn_update_vpn_connections_cb, applet, NULL, __func__);
dbus_message_unref (message); dbus_message_unref (message);
} }
......
...@@ -43,135 +43,17 @@ ...@@ -43,135 +43,17 @@
#define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist" #define DBUS_NO_SERVICE_ERROR "org.freedesktop.DBus.Error.ServiceDoesNotExist"
/* #define DBUS_PENDING_CALL_DEBUG */
typedef struct PCallInfo
{
DBusPendingCall * pcall;
char * caller;
guint32 id;
GTimeVal start;
} PCallInfo;
static GStaticMutex pcall_mutex = G_STATIC_MUTEX_INIT;
static GHashTable * pcall_table = NULL;
static guint32 pcall_gid = 0;
static guint32 pcall_pending = 0;
gboolean
nma_dbus_send_with_callback (DBusConnection *connection,
DBusMessage *msg,
DBusPendingCallNotifyFunction func,
gpointer data,
DBusFreeFunction free_func,
const char *caller)
{
PCallInfo * info;
DBusPendingCall * pcall = NULL;
g_return_val_if_fail (connection != NULL, FALSE);
g_return_val_if_fail (msg != NULL, FALSE);
g_return_val_if_fail (func != NULL, FALSE);
g_return_val_if_fail (caller != NULL, FALSE);
dbus_connection_send_with_reply (connection, msg, &pcall, -1);
if (!pcall)
{
g_warning ("Error: '%s' couldn't send dbus message.", caller);
if (free_func)
(*free_func)(data);
return FALSE;
}
dbus_pending_call_set_notify (pcall, func, data, free_func);
if (!(info = g_malloc0 (sizeof (PCallInfo))))
return FALSE;
info->caller = g_strdup (caller);
info->pcall = pcall;
g_get_current_time (&info->start);
dbus_pending_call_ref (pcall);
g_static_mutex_lock (&pcall_mutex);
info->id = pcall_gid++;
pcall_pending++;
if (!pcall_table)
pcall_table = g_hash_table_new (g_direct_hash, g_direct_equal);
g_hash_table_insert (pcall_table, pcall, info);
#ifdef DBUS_PENDING_CALL_DEBUG
nm_info ("PCall Debug: registered ID %d (%p), initiated by '%s'. Total "
"pending: %d", info->id, pcall, info->caller, pcall_pending);
#endif
g_static_mutex_unlock (&pcall_mutex);
return TRUE;
}
void
nma_dbus_send_with_callback_replied (DBusPendingCall *pcall,
const char *caller)
{
PCallInfo * info;
#ifdef DBUS_PENDING_CALL_DEBUG
GTimeVal now;
long elapsed_ms = 0;
#endif
g_return_if_fail (pcall != NULL);
g_return_if_fail (caller != NULL);
g_static_mutex_lock (&pcall_mutex);
if (!(info = g_hash_table_lookup (pcall_table, pcall)))
{
nm_warning ("Error: couldn't find pending call %p in tracking"
" table.", pcall);
goto out;
}
pcall_pending--;
#ifdef DBUS_PENDING_CALL_DEBUG
g_get_current_time (&now);
if (info->start.tv_usec > now.tv_usec)
{
now.tv_sec--;
now.tv_usec = G_USEC_PER_SEC - (info->start.tv_usec - now.tv_usec);
}
else
now.tv_usec -= info->start.tv_usec;
now.tv_sec -= info->start.tv_sec;
elapsed_ms = now.tv_sec * G_USEC_PER_SEC + now.tv_usec;
elapsed_ms /= 1000;
nm_info ("PCall Debug: unregistered ID %d (%p), %s -> %s,"
" %lums elapsed. Total pending: %d", info->id, info->pcall, info->caller,
caller, elapsed_ms, pcall_pending);
#endif
g_hash_table_remove (pcall_table, pcall);
g_free (info->caller);
dbus_pending_call_unref (info->pcall);
g_free (info);
out:
g_static_mutex_unlock (&pcall_mutex);
}
/* /*
* nma_dbus_filter * nma_dbus_filter
* *
*/ */
static DBusHandlerResult nma_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data) static DBusHandlerResult nma_dbus_filter (DBusConnection *connection, DBusMessage *message, void *user_data)
{ {
NMApplet *applet = (NMApplet *)user_data; NMApplet * applet = (NMApplet *)user_data;
gboolean handled = TRUE; gboolean handled = TRUE;
const char * object_path;
const char * object_path; const char * member;
const char * member; const char * interface;
const char * interface;
g_return_val_if_fail (applet != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); g_return_val_if_fail (applet != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED); g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
......
...@@ -40,13 +40,4 @@ void nma_dbus_enable_networking (NMApplet *applet, gboolean enabled); ...@@ -40,13 +40,4 @@ void nma_dbus_enable_networking (NMApplet *applet, gboolean enabled);
void nma_free_gui_data_model (NMApplet *applet); void nma_free_gui_data_model (NMApplet *applet);
void nma_free_dbus_data_model (NMApplet *applet); void nma_free_dbus_data_model (NMApplet *applet);
gboolean nma_dbus_send_with_callback (DBusConnection *connection,
DBusMessage *msg,
DBusPendingCallNotifyFunction func,
gpointer data,
DBusFreeFunction free_func,
const char *caller);
void nma_dbus_send_with_callback_replied(DBusPendingCall *pcall,
const char *caller);
#endif #endif
...@@ -57,10 +57,9 @@ static void nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall, NMActRe ...@@ -57,10 +57,9 @@ static void nm_dbus_get_user_key_for_network_cb (DBusPendingCall *pcall, NMActRe
ap = nm_act_request_get_ap (req); ap = nm_act_request_get_ap (req);
g_assert (ap); g_assert (ap);
dbus_pending_call_ref (pcall); nm_dbus_send_with_callback_replied (pcall, __func__);
if (!dbus_pending_call_get_completed (pcall)) dbus_pending_call_ref (pcall);
goto out;
if (!(reply = dbus_pending_call_steal_reply (pcall))) if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out; goto out;
...@@ -162,12 +161,13 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMActRequest ...@@ -162,12 +161,13 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMActRequest
DBUS_TYPE_INT32, &attempt, DBUS_TYPE_INT32, &attempt,
DBUS_TYPE_BOOLEAN, &new_key, DBUS_TYPE_BOOLEAN, &new_key,
DBUS_TYPE_INVALID); DBUS_TYPE_INVALID);
if (dbus_connection_send_with_reply (connection, message, &pcall, INT_MAX) && pcall) if ((pcall = nm_dbus_send_with_callback (connection, message,
(DBusPendingCallNotifyFunction) nm_dbus_get_user_key_for_network_cb,
req, NULL, __func__)))
{ {
nm_act_request_ref (req); nm_act_request_ref (req);
nm_act_request_set_stage (req, NM_ACT_STAGE_NEED_USER_KEY); nm_act_request_set_stage (req, NM_ACT_STAGE_NEED_USER_KEY);
nm_act_request_set_user_key_pending_call (req, pcall); nm_act_request_set_user_key_pending_call (req, pcall);
dbus_pending_call_set_notify (pcall, (DBusPendingCallNotifyFunction) nm_dbus_get_user_key_for_network_cb, req, NULL);
} }
else else
nm_warning ("nm_dbus_get_user_key_for_network(): could not send dbus message"); nm_warning ("nm_dbus_get_user_key_for_network(): could not send dbus message");
...@@ -357,6 +357,8 @@ static void nm_dbus_get_network_data_cb (DBusPendingCall *pcall, void *user_data ...@@ -357,6 +357,8 @@ static void nm_dbus_get_network_data_cb (DBusPendingCall *pcall, void *user_data
g_return_if_fail (cb_data->network != NULL); g_return_if_fail (cb_data->network != NULL);
g_return_if_fail (cb_data->list != NULL); g_return_if_fail (cb_data->list != NULL);
nm_dbus_send_with_callback_replied (pcall, __func__);
dbus_pending_call_ref (pcall); dbus_pending_call_ref (pcall);