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));
//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);
+ //mtetherd_status_plugin_usb_plugged_show(plugin);
+ mtetherd_status_plugin_usb_plugged(plugin);
}
}
}
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);
+ 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_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);
}
+ //plugin->priv->net_on = TRUE;
+ //enable_button_set_text(plugin->priv->enable_button, plugin->priv->net_on);
}
}
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);
- }
+ mtetherd_status_plugin_device_removed(plugin, udi);
+ //plugin->priv->net_on = FALSE;
+ //enable_button_set_text(plugin->priv->enable_button, plugin->priv->net_on);
}
}
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) {
err = NULL;
return FALSE;
} else {
- g_message("Got DBUS Glib connection: %p", plugin->priv->dbus_connection);
+ g_message("Got DBUS Glib connection: %p", plugin->dbus_connection);
}
if (plugin->dbus_connection) {
plugin->hal_context = libhal_ctx_new();
} else {
g_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;
}
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);
- }
}
}
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);
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_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;
+}
+
+