along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <string.h>
#include "hal.h"
+#include "net.h"
+#include "plugin.h"
static const char *USBDEV_PATH = "/org/freedesktop/Hal/devices/usb_device_1d6b_2_musb_hdrc";
-static const char *USBNET_MODULE = "g_ether";
static void mtetherd_hal_device_condition(LibHalContext *ctx, const char *udi, const char *condition, const char *detail) {
MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(libhal_ctx_get_user_data(ctx));
if (plugin) {
- g_message("Got HAL condition %s on %s: %s", condition, udi, detail);
- //hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Got HAL condition %s on %s: %s", condition, udi, detail);
- if (strcmp("ButtonPressed", condition) == 0) {
- if (strcmp(USBDEV_PATH, udi) == 0) {
- mtetherd_status_plugin_usb_plugged_show(plugin);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got HAL condition %s on %s: %s", condition, udi, detail);
+ if (g_strcmp0("ButtonPressed", condition) == 0) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "is ButtonPressed");
+ if (g_strcmp0(USBDEV_PATH, udi) == 0) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "is %s", USBDEV_PATH);
+ mtetherd_status_plugin_usb_plugged(plugin);
}
}
}
MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(libhal_ctx_get_user_data(ctx));
if (plugin) {
- g_message("Got HAL device added on %s", udi);
- if (strcmp(USBDEV_PATH, udi) == 0) {
- plugin->priv->net_on = TRUE;
- enable_button_set_text(plugin->priv->enable_button, plugin->priv->net_on);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got HAL device added on %s", udi);
+ DBusError derr;
+ dbus_error_init(&derr);
+ char *interface = libhal_device_get_property_string(plugin->hal_context, udi, "net.interface", &derr);
+ if (dbus_error_is_set(&derr)) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error getting interface name of %s (%s): %s", udi, derr.name, derr.message);
+ dbus_error_free(&derr);
+ }
+ if (interface) {
+ MTetherDDevice *device = mtetherd_device_new(interface, udi);
+ if (device) {
+ mtetherd_status_plugin_device_added(plugin, device);
+ }
+ libhal_free_string(interface);
}
}
}
MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(libhal_ctx_get_user_data(ctx));
if (plugin) {
- g_message("Got HAL device added on %s", udi);
- if (strcmp(USBDEV_PATH, udi) == 0) {
- plugin->priv->net_on = FALSE;
- enable_button_set_text(plugin->priv->enable_button, plugin->priv->net_on);
- }
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got HAL device removed on %s", udi);
+ mtetherd_status_plugin_device_removed(plugin, udi);
}
}
gboolean mtetherd_hal_init(MTetherDStatusPlugin *plugin) {
if (plugin) {
- plugin->devices = NULL;
-
GError *err = NULL;
plugin->dbus_connection = hd_status_plugin_item_get_dbus_g_connection(HD_STATUS_PLUGIN_ITEM(plugin), DBUS_BUS_SYSTEM, &err);
if (err) {
- g_warning("Can't open DBUS connection: %s", err->message);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Can't open DBUS connection: %s", err->message);
g_error_free(err);
err = NULL;
return FALSE;
} else {
- g_message("Got DBUS Glib connection: %p", plugin->priv->dbus_connection);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got GDBUS connection: %p", plugin->dbus_connection);
}
if (plugin->dbus_connection) {
plugin->hal_context = libhal_ctx_new();
if (plugin->hal_context) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Got HAL context: %p", plugin->hal_context);
if (libhal_ctx_set_dbus_connection(plugin->hal_context, dbus_g_connection_get_connection(plugin->dbus_connection))) {
if (!libhal_ctx_set_user_data(plugin->hal_context, plugin)) {
- g_warning("Can't set user data of HAL context");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Can't set user data of HAL context");
}
if (!libhal_ctx_set_device_condition(plugin->hal_context, mtetherd_hal_device_condition)) {
- g_warning("Error assigning device condition callback");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error assigning device condition callback");
}
if (!libhal_ctx_set_device_added(plugin->hal_context, mtetherd_hal_device_added)) {
- g_warning("Error assigning device added callback");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error assigning device added callback");
}
if (!libhal_ctx_set_device_removed(plugin->hal_context, mtetherd_hal_device_removed)) {
- g_warning("Error assigning device removed callback");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error assigning device removed callback");
}
DBusError derr;
dbus_error_init(&derr);
if (!libhal_ctx_init(plugin->hal_context, &derr)) {
if (dbus_error_is_set(&derr)) {
- g_warning("Error initializing HAL context (%s): %s", derr.name, derr.message);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error initializing HAL context (%s): %s", derr.name, derr.message);
dbus_error_free(&derr);
} else {
- g_warning("Error initializing HAL context: unknown error");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error initializing HAL context: unknown error");
}
- libhal_ctx_free(plugin->priv->hal_context);
+ libhal_ctx_free(plugin->hal_context);
plugin->hal_context = NULL;
return FALSE;
}
} else {
- g_warning("Can't set DBUS connection of HAL context");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Can't set DBUS connection of HAL context");
libhal_ctx_free(plugin->hal_context);
plugin->hal_context = NULL;
return FALSE;
}
} else {
- g_warning("Can't allocate HAL context");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Can't allocate HAL context");
return FALSE;
}
}
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "HAL context initialized and connected");
return TRUE;
}
if (plugin->dbus_connection) {
dbus_g_connection_unref(plugin->dbus_connection);
}
- if (plugin->devices) {
- g_list_foreach(plugin->devices, (GFunc) g_object_unref);
- g_list_free(plugin->devices);
- }
}
}
int ndevices = 0;
char **udis = libhal_find_device_by_capability(plugin->hal_context, "net", &ndevices, &derr);
if (dbus_error_is_set(&derr)) {
- g_warning("Error loading list of network devices (%s): %s", derr.name, derr.message);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error loading list of network devices (%s): %s", derr.name, derr.message);
dbus_error_free(&derr);
}
if (udis) {
int i;
for (i = 0; i < ndevices; i++) {
- char *device = libhal_device_get_property_string(plugin->hal_context, udis[i], "net.interface", &derr);
+ char *interface = libhal_device_get_property_string(plugin->hal_context, udis[i], "net.interface", &derr);
if (dbus_error_is_set(&derr)) {
- g_warning("Error getting interface name of %s (%s): %s", udis[i], derr.name, derr.message);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error getting interface name of %s (%s): %s", udis[i], derr.name, derr.message);
dbus_error_free(&derr);
}
- if (device) {
- // Check if this is one of the supported devices
- plugin->devices = g_list_prepend(plugin->devices, udis[i]);
- libhal_free_string(device);
+ if (interface) {
+ MTetherDDevice *device = mtetherd_device_new(interface, udis[i]);
+ if (device) {
+ mtetherd_status_plugin_device_added(plugin, device);
+ }
+ libhal_free_string(interface);
}
}
libhal_free_string_array(udis);
}
}
+gboolean mtetherd_usb_state(MTetherDStatusPlugin *plugin) {
+ if (plugin) {
+ if (plugin->hal_context) {
+ DBusError derr;
+ dbus_error_init(&derr);
+ dbus_bool_t plugged = libhal_device_get_property_bool(plugin->hal_context, USBDEV_PATH, "button.state.value", &derr);
+ if (dbus_error_is_set(&derr)) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error getting USB plugged status (%s): %s", derr.name, derr.message);
+ //hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Error getting USB plugged status (%s): %s", derr.name, derr.message);
+ dbus_error_free(&derr);
+ } else {
+ return plugged;
+ }
+ }
+ }
+ return FALSE;
+}
+
+