2006-03-09 Dan Williams <dcbw@redhat.com>

Track pending call requests in the applet, and report how many are
	outstanding, and how long each completed one takes.

	* gnome/applet/applet-dbus-devices.c
	  gnome/applet/applet-dbus-vpn.c
		- Track pending calls

	* gnome/applet/applet-dbus.[ch]
		- Remove some unused enums
		- (nma_dbus_send_with_callback, nma_dbus_send_with_callback_replied):
			new functions to track dbus pending calls and spit out some
			statistics about them


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1571 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams
2006-03-09 17:23:00 +00:00
parent 9b158b1e23
commit 9e3fccf682
5 changed files with 281 additions and 145 deletions

View File

@@ -1,3 +1,18 @@
2006-03-09 Dan Williams <dcbw@redhat.com>
Track pending call requests in the applet, and report how many are
outstanding, and how long each completed one takes.
* gnome/applet/applet-dbus-devices.c
gnome/applet/applet-dbus-vpn.c
- Track pending calls
* gnome/applet/applet-dbus.[ch]
- Remove some unused enums
- (nma_dbus_send_with_callback, nma_dbus_send_with_callback_replied):
new functions to track dbus pending calls and spit out some
statistics about them
2006-03-09 Robert Love <rml@novell.com>
* src/NetworkManagerAP.c, src/NetworkManagerAP.h: Have the function

View File

@@ -56,6 +56,8 @@ static void nma_dbus_nm_state_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -90,15 +92,13 @@ out:
void nma_dbus_update_nm_state (NMApplet *applet)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
g_return_if_fail (applet != NULL);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "state")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_nm_state_cb, applet, NULL);
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_nm_state_cb, applet, NULL, __func__);
dbus_message_unref (message);
}
}
@@ -127,6 +127,8 @@ static void nma_dbus_device_get_driver_cb (DBusPendingCall *pcall, void *user_da
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -170,7 +172,6 @@ out:
static void nma_dbus_device_get_driver (NetworkDevice *dev, NMApplet *applet)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
const char * op;
g_return_if_fail (applet != NULL);
@@ -178,16 +179,18 @@ static void nma_dbus_device_get_driver (NetworkDevice *dev, NMApplet *applet)
op = network_device_get_nm_path (dev);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, op, NM_DBUS_INTERFACE_DEVICES, "getDriver")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
{
DriverCBData * data = g_malloc0 (sizeof (DriverCBData));
network_device_ref (dev);
data->dev = dev;
data->applet = applet;
dbus_pending_call_set_notify (pcall, nma_dbus_device_get_driver_cb, data, NULL);
if (!nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_get_driver_cb, data, NULL, __func__))
{
network_device_unref (dev);
g_free (data);
}
dbus_message_unref (message);
}
@@ -209,6 +212,8 @@ static void nma_dbus_update_wireless_enabled_cb (DBusPendingCall *pcall, void *u
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -246,15 +251,13 @@ out:
static void nma_dbus_update_wireless_enabled (NMApplet *applet)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
g_return_if_fail (applet != NULL);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getWirelessEnabled")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_update_wireless_enabled_cb, applet, NULL);
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_update_wireless_enabled_cb, applet, NULL, __func__);
dbus_message_unref (message);
}
}
@@ -270,14 +273,14 @@ typedef struct HalInfoCBData
static void free_hal_info_cb_data (HalInfoCBData *cb_data)
{
if (cb_data)
{
if (!cb_data)
return;
network_device_unref (cb_data->dev);
g_free (cb_data->parent_op);
g_free (cb_data->vendor);
memset (cb_data, 0, sizeof (HalInfoCBData));
g_free (cb_data);
}
}
@@ -300,6 +303,8 @@ 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->vendor != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -346,6 +351,8 @@ 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->parent_op != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -364,26 +371,24 @@ static void hal_info_vendor_cb (DBusPendingCall *pcall, void *user_data)
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &info_vendor, DBUS_TYPE_INVALID))
{
DBusMessage * message;
DBusPendingCall * product_pcall = NULL;
if ((message = dbus_message_new_method_call ("org.freedesktop.Hal", cb_data->parent_op,
"org.freedesktop.Hal.Device", "GetPropertyString")))
{
const char * prop = "info.product";
HalInfoCBData *product_cb_data = g_malloc0 (sizeof (HalInfoCBData));
dbus_message_append_args (message, DBUS_TYPE_STRING, &prop, DBUS_TYPE_INVALID);
dbus_connection_send_with_reply (cb_data->applet->connection, message, &product_pcall, -1);
if (product_pcall)
{
HalInfoCBData * product_cb_data = g_malloc0 (sizeof (HalInfoCBData));
product_cb_data->applet = cb_data->applet;
network_device_ref (cb_data->dev);
product_cb_data->dev = cb_data->dev;
product_cb_data->parent_op = g_strdup (cb_data->parent_op);
product_cb_data->vendor = g_strdup (info_vendor);
dbus_pending_call_set_notify (product_pcall, hal_info_product_cb, product_cb_data, (DBusFreeFunction) free_hal_info_cb_data);
}
nma_dbus_send_with_callback (cb_data->applet->connection, message,
hal_info_product_cb, product_cb_data,
(DBusFreeFunction) free_hal_info_cb_data, __func__);
dbus_message_unref (message);
}
}
@@ -411,6 +416,8 @@ 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->dev != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -430,25 +437,23 @@ static void hal_net_physdev_cb (DBusPendingCall *pcall, void *user_data)
if (dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &op, DBUS_TYPE_INVALID))
{
DBusMessage * message;
DBusPendingCall * vendor_pcall = NULL;
if ((message = dbus_message_new_method_call ("org.freedesktop.Hal", op,
"org.freedesktop.Hal.Device", "GetPropertyString")))
{
const char * prop = "info.vendor";
HalInfoCBData *vendor_cb_data = g_malloc0 (sizeof (HalInfoCBData));
dbus_message_append_args (message, DBUS_TYPE_STRING, &prop, DBUS_TYPE_INVALID);
dbus_connection_send_with_reply (cb_data->applet->connection, message, &vendor_pcall, -1);
if (vendor_pcall)
{
HalInfoCBData * vendor_cb_data = g_malloc0 (sizeof (HalInfoCBData));
vendor_cb_data->applet = cb_data->applet;
network_device_ref (cb_data->dev);
vendor_cb_data->dev = cb_data->dev;
vendor_cb_data->parent_op = g_strdup (op);
dbus_pending_call_set_notify (vendor_pcall, hal_info_vendor_cb, vendor_cb_data, (DBusFreeFunction) free_hal_info_cb_data);
}
nma_dbus_send_with_callback (cb_data->applet->connection, message,
hal_info_vendor_cb, vendor_cb_data,
(DBusFreeFunction) free_hal_info_cb_data, __func__);
dbus_message_unref (message);
}
}
@@ -468,7 +473,6 @@ out:
static void nma_dbus_update_device_info_from_hal (NetworkDevice *dev, NMApplet *applet)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
g_return_if_fail (applet != NULL);
g_return_if_fail (applet->connection != NULL);
@@ -478,18 +482,17 @@ static void nma_dbus_update_device_info_from_hal (NetworkDevice *dev, NMApplet *
"org.freedesktop.Hal.Device", "GetPropertyString")))
{
const char * prop = "net.physical_device";
HalInfoCBData *cb_data = g_malloc0 (sizeof (HalInfoCBData));
dbus_message_append_args (message, DBUS_TYPE_STRING, &prop, DBUS_TYPE_INVALID);
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
{
HalInfoCBData * cb_data = g_malloc0 (sizeof (HalInfoCBData));
cb_data->applet = applet;
network_device_ref (dev);
cb_data->dev = dev;
dbus_pending_call_set_notify (pcall, hal_net_physdev_cb, cb_data, (DBusFreeFunction) free_hal_info_cb_data);
}
nma_dbus_send_with_callback (cb_data->applet->connection, message,
hal_net_physdev_cb, cb_data,
(DBusFreeFunction) free_hal_info_cb_data, __func__);
dbus_message_unref (message);
}
}
@@ -517,11 +520,11 @@ typedef struct NetPropCBData
static void free_net_prop_cb_data (NetPropCBData *data)
{
if (data)
{
if (!data)
return;
g_free (data->dev_op);
g_free (data->act_net);
}
g_free (data);
}
@@ -552,6 +555,8 @@ 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->dev_op != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
applet = cb_data->applet;
if (!(reply = dbus_pending_call_steal_reply (pcall)))
@@ -628,24 +633,22 @@ out:
void nma_dbus_device_update_one_network (NMApplet *applet, const char *dev_path, const char *net_path, const char *active_net_path)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
g_return_if_fail (applet != NULL);
g_return_if_fail (dev_path != NULL);
g_return_if_fail (net_path != NULL);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, net_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
{
NetPropCBData * cb_data = g_malloc0 (sizeof (NetPropCBData));
cb_data->dev_op = g_strdup (dev_path);
cb_data->act_net = (active_net_path && strlen (active_net_path)) ? g_strdup (active_net_path) : NULL;
cb_data->applet = applet;
dbus_pending_call_set_notify (pcall, nma_dbus_net_properties_cb, cb_data, (DBusFreeFunction) free_net_prop_cb_data);
}
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_net_properties_cb, cb_data,
(DBusFreeFunction) free_net_prop_cb_data, __func__);
dbus_message_unref (message);
}
}
@@ -757,6 +760,8 @@ static void nma_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_da
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -859,16 +864,14 @@ out:
void nma_dbus_device_update_one_device (NMApplet *applet, const char *dev_path)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
g_return_if_fail (applet != NULL);
g_return_if_fail (dev_path != NULL);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_device_properties_cb, applet, NULL);
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_properties_cb, applet, NULL, __func__);
dbus_message_unref (message);
}
}
@@ -885,9 +888,7 @@ static void free_device_activated_cb_data (DeviceActivatedCBData *obj)
return;
obj->applet = NULL;
if (obj->essid)
g_free (obj->essid);
memset (obj, 0, sizeof (DeviceActivatedCBData));
g_free (obj);
}
@@ -903,6 +904,8 @@ static void nma_dbus_device_activated_cb (DBusPendingCall *pcall, void *user_dat
char * icon = NULL;
#endif
nma_dbus_send_with_callback_replied (pcall, __func__);
nma_dbus_device_properties_cb (pcall, applet);
/* Don't show anything if the applet isn't shown */
@@ -945,8 +948,7 @@ out:
void nma_dbus_device_activated (NMApplet *applet, const char *dev_path, const char *essid)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
DeviceActivatedCBData *cb_data = NULL;
DeviceActivatedCBData * cb_data = NULL;
g_return_if_fail (applet != NULL);
g_return_if_fail (dev_path != NULL);
@@ -958,9 +960,8 @@ 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")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_device_activated_cb, cb_data, NULL);
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_activated_cb, cb_data, NULL, __func__);
dbus_message_unref (message);
}
}
@@ -970,6 +971,8 @@ static void nma_dbus_device_deactivated_cb (DBusPendingCall *pcall, void *user_d
{
NMApplet * applet = (NMApplet *) user_data;
nma_dbus_send_with_callback_replied (pcall, __func__);
nma_dbus_device_properties_cb (pcall, applet);
#ifdef ENABLE_NOTIFY
@@ -985,16 +988,14 @@ static void nma_dbus_device_deactivated_cb (DBusPendingCall *pcall, void *user_d
void nma_dbus_device_deactivated (NMApplet *applet, const char *dev_path)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
g_return_if_fail (applet != NULL);
g_return_if_fail (dev_path != NULL);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, dev_path, NM_DBUS_INTERFACE_DEVICES, "getProperties")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_device_deactivated_cb, applet, NULL);
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_device_deactivated_cb, applet, NULL, __func__);
dbus_message_unref (message);
}
}
@@ -1016,6 +1017,8 @@ static void nma_dbus_update_devices_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -1063,15 +1066,13 @@ out:
void nma_dbus_update_devices (NMApplet *applet)
{
DBusMessage * message;
DBusPendingCall * pcall;
nma_free_data_model (applet);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDevices")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_update_devices_cb, applet, NULL);
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_update_devices_cb, applet, NULL, __func__);
dbus_message_unref (message);
}
nma_dbus_update_wireless_enabled (applet);
@@ -1094,6 +1095,8 @@ static void nma_dbus_update_dialup_cb (DBusPendingCall *pcall, void *user_data)
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -1140,6 +1143,27 @@ out:
}
/*
* nma_dbus_update_dialup
*
* Do an update of dial up devices.
*
*/
void nma_dbus_update_dialup (NMApplet *applet)
{
DBusMessage *message;
nma_free_data_model (applet);
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,
nma_dbus_update_dialup_cb, applet, NULL, __func__);
dbus_message_unref (message);
}
}
/*
* nma_dbus_dialup_activate_connection
*
@@ -1222,29 +1246,6 @@ void nma_dbus_dialup_deactivate_connection (NMApplet *applet, const char *name)
}
/*
* nma_dbus_update_dialup
*
* Do an update of dial up devices.
*
*/
void nma_dbus_update_dialup (NMApplet *applet)
{
DBusMessage *message;
DBusPendingCall *pcall;
nma_free_data_model (applet);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getDialup")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_update_dialup_cb, applet, NULL);
dbus_message_unref (message);
}
}
/*
* nma_dbus_device_remove_one_device
*

View File

@@ -117,6 +117,8 @@ 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->name != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
applet = cb_data->applet;
if (!(reply = dbus_pending_call_steal_reply (pcall)))
@@ -171,7 +173,6 @@ out:
void nma_dbus_vpn_update_one_vpn_connection (NMApplet *applet, const char *vpn_name)
{
DBusMessage * message;
DBusPendingCall * pcall = NULL;
g_return_if_fail (applet != NULL);
g_return_if_fail (vpn_name != NULL);
@@ -179,18 +180,18 @@ void nma_dbus_vpn_update_one_vpn_connection (NMApplet *applet, const char *vpn_n
nma_get_first_active_vpn_connection (applet);
if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH_VPN, NM_DBUS_INTERFACE_VPN, "getVPNConnectionProperties")))
{
dbus_message_append_args (message, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_INVALID);
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
dbus_message_unref (message);
if (pcall)
{
VpnPropsCBData * cb_data = g_malloc0 (sizeof (VpnPropsCBData));
dbus_message_append_args (message, DBUS_TYPE_STRING, &vpn_name, DBUS_TYPE_INVALID);
cb_data->applet = applet;
cb_data->name = g_strdup (vpn_name);
dbus_pending_call_set_notify (pcall, nma_dbus_vpn_properties_cb, cb_data, (DBusFreeFunction) free_vpn_props_cb_data);
}
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_vpn_properties_cb, cb_data,
(DBusFreeFunction) free_vpn_props_cb_data, __func__);
dbus_message_unref (message);
}
}
@@ -211,6 +212,8 @@ static void nma_dbus_vpn_update_vpn_connections_cb (DBusPendingCall *pcall, void
g_return_if_fail (pcall != NULL);
g_return_if_fail (applet != NULL);
nma_dbus_send_with_callback_replied (pcall, __func__);
if (!(reply = dbus_pending_call_steal_reply (pcall)))
goto out;
@@ -258,7 +261,6 @@ out:
void nma_dbus_vpn_update_vpn_connections (NMApplet *applet)
{
DBusMessage * message;
DBusPendingCall * pcall;
nma_free_vpn_connections (applet);
@@ -266,10 +268,9 @@ 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")))
{
dbus_connection_send_with_reply (applet->connection, message, &pcall, -1);
nma_dbus_send_with_callback (applet->connection, message,
nma_dbus_vpn_update_vpn_connections_cb, applet, NULL, __func__);
dbus_message_unref (message);
if (pcall)
dbus_pending_call_set_notify (pcall, nma_dbus_vpn_update_vpn_connections_cb, applet, NULL);
}
}

View File

@@ -28,6 +28,7 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <math.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include "applet.h"
@@ -42,6 +43,123 @@
#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;
GTimeVal now;
#ifdef DBUS_PENDING_CALL_DEBUG
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
*

View File

@@ -27,14 +27,6 @@
#include "NetworkManager.h"
#include "applet.h"
/* Return codes for functions that use dbus */
enum
{
RETURN_SUCCESS = 1,
RETURN_FAILURE = 0,
RETURN_NO_NM = -1
};
static inline gboolean message_is_error (DBusMessage *msg)
{
g_return_val_if_fail (msg != NULL, FALSE);
@@ -48,4 +40,13 @@ void nma_dbus_enable_networking (NMApplet *applet, gboolean enabled);
void nma_free_gui_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