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);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_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) {
MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(libhal_ctx_get_user_data(ctx));
if (plugin) {
- g_message("Got HAL device added on %s", udi);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "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_warning("Error getting interface name of %s (%s): %s", udi, derr.name, derr.message);
+ 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) {
MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(libhal_ctx_get_user_data(ctx));
if (plugin) {
- g_message("Got HAL device added on %s", udi);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Got HAL device added on %s", udi);
mtetherd_status_plugin_device_removed(plugin, udi);
//plugin->priv->net_on = FALSE;
//enable_button_set_text(plugin->priv->enable_button, plugin->priv->net_on);
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->dbus_connection);
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Got DBUS Glib connection: %p", plugin->dbus_connection);
}
if (plugin->dbus_connection) {
plugin->hal_context = libhal_ctx_new();
if (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->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;
}
}
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) {
for (i = 0; i < ndevices; i++) {
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 (interface) {
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);
+ 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 {
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
+#include <glib/gprintf.h>
#include <gtk/gtk.h>
#include <hildon/hildon.h>
#include "plugin.h"
gpointer devices;
gboolean usb_plugged;
MTetherDStatusPluginUsbNetState usbnet_state;
+ FILE *log_fp;
+ guint log_handler;
};
#ifndef IMAGE_DIR
#define IMAGE_DIR "/usr/share/pixmaps"
#endif
+#ifndef BIN_DIR
+#define BIN_DIR "/usr/bin"
+#endif
#ifndef SBIN_DIR
#define SBIN_DIR "/usr/sbin"
#endif
+#ifndef TMP_DIR
+#define TMP_DIR "/tmp"
+#endif
// The UDI contains the MAC address and is thus unsuitable for
// loaded status checking, so we just use the interface name
static const char *USBNET_INTERFACE = "usb0";
+const char *MTETHERD_LOG_DOMAIN = "mtetherd";
HD_DEFINE_PLUGIN_MODULE(MTetherDStatusPlugin, mtetherd_status_plugin, HD_TYPE_STATUS_MENU_ITEM);
static void mtetherd_status_plugin_class_finalize(MTetherDStatusPluginClass *klass) { }
static void mtetherd_status_plugin_finalize(GObject *object) {
- g_message("Destroying mtetherd status plugin");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Destroying mtetherd status plugin");
MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(object);
if (plugin && plugin->priv) {
mtetherd_hal_finalize(plugin);
mtetherd_device_list_free(plugin->priv->devices);
+ if (plugin->priv->log_fp) {
+ g_log_remove_handler(MTETHERD_LOG_DOMAIN, plugin->priv->log_handler);
+ fclose(plugin->priv->log_fp);
+ }
}
}
if (plugin && plugin->priv && plugin->priv->enable_button) {
switch (plugin->priv->usbnet_state) {
case MTETHERD_STATUS_PLUGIN_USB_NET_ENABLED:
- hildon_button_set_text(HILDON_BUTTON(plugin->priv->enable_button), "Toggle USB Networking", "Enabled");
+ hildon_button_set_text(HILDON_BUTTON(plugin->priv->enable_button), "USB networking", "Enabled");
break;
case MTETHERD_STATUS_PLUGIN_USB_NET_DISABLED:
- hildon_button_set_text(HILDON_BUTTON(plugin->priv->enable_button), "Toggle USB Networking", "Disabled");
+ hildon_button_set_text(HILDON_BUTTON(plugin->priv->enable_button), "USB networking", "Disabled");
break;
default:
- hildon_button_set_text(HILDON_BUTTON(plugin->priv->enable_button), "Toggle USB Networking", "Unknown");
+ hildon_button_set_text(HILDON_BUTTON(plugin->priv->enable_button), "USB networking", "Unknown");
break;
}
}
const char *arg;
switch (plugin->priv->usbnet_state) {
case MTETHERD_STATUS_PLUGIN_USB_NET_ENABLED:
- arg = SBIN_DIR "mtetherd-usbnet-disable.sh";
+ arg = SBIN_DIR "/mtetherd-usbnet-disable.sh";
break;
case MTETHERD_STATUS_PLUGIN_USB_NET_DISABLED:
- arg = SBIN_DIR "mtetherd-usbnet-enable.sh";
+ arg = SBIN_DIR "/mtetherd-usbnet-enable.sh";
break;
default:
arg = NULL;
}
if (arg) {
g_debug("Launching %s", arg);
- const char *command[] = { "/usr/bin/sudo", arg, NULL };
+ const char *command[] = { BIN_DIR "/sudo", arg, NULL };
if (!mtetherd_launch_script(command)) {
- g_error("Error launching USB networking script");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error launching USB networking script");
}
}
}
}
}
+static void mtetherd_status_plugin_log(const gchar *domain, GLogLevelFlags level, const gchar *message, gpointer data) {
+ MTetherDStatusPlugin *plugin = MTETHERD_STATUS_PLUGIN(data);
+
+ if (plugin && plugin->priv && plugin->priv->log_fp) {
+ char *levelstr;
+ switch (level) {
+ case G_LOG_LEVEL_ERROR:
+ levelstr = "** Error **";
+ break;
+ case G_LOG_LEVEL_CRITICAL:
+ levelstr = "** CRITICAL **";
+ break;
+ case G_LOG_LEVEL_WARNING:
+ levelstr = "** Warning **";
+ break;
+ case G_LOG_LEVEL_MESSAGE:
+ levelstr = "-- Notice --";
+ break;
+ case G_LOG_LEVEL_INFO:
+ levelstr = "-- Info --";
+ break;
+ case G_LOG_LEVEL_DEBUG:
+ levelstr = "(Debug)";
+ break;
+ case G_LOG_FLAG_RECURSION:
+ levelstr = "** RECURSION **";
+ break;
+ case G_LOG_FLAG_FATAL:
+ levelstr = "** FATAL **";
+ break;
+ default:
+ levelstr = "";
+ break;
+ }
+ g_fprintf(plugin->priv->log_fp, "mtetherd: %s %s\n", levelstr, message);
+ fflush(plugin->priv->log_fp);
+ }
+}
+
static void mtetherd_status_plugin_init(MTetherDStatusPlugin *plugin) {
plugin->priv = MTETHERD_STATUS_PLUGIN_GET_PRIVATE(plugin);
- plugin->priv->enable_button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
- if (plugin->priv->enable_button) {
- GError *err = NULL;
- GdkPixbuf *icon = gdk_pixbuf_new_from_file(IMAGE_DIR "/mtetherd-net-icon.png", &err);
- if (err) {
- g_warning("Can't load mtetherd icon: %s", err->message);
- g_error_free(err);
- err = NULL;
+ if (plugin->priv) {
+ plugin->priv->log_fp = fopen(TMP_DIR "/mtetherd-status.log", "a");
+ if (plugin->priv->log_fp) {
+ plugin->priv->log_handler = g_log_set_handler(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MASK, mtetherd_status_plugin_log, plugin);
+ }
+
+ plugin->priv->enable_button = hildon_button_new(HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
+ if (plugin->priv->enable_button) {
+ GError *err = NULL;
+ GdkPixbuf *icon = gdk_pixbuf_new_from_file(IMAGE_DIR "/mtetherd-net-icon.png", &err);
+ if (err) {
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "Can't load mtetherd icon: %s", err->message);
+ g_error_free(err);
+ err = NULL;
+ }
+ if (icon) {
+ GtkWidget *image = gtk_image_new_from_pixbuf(icon);
+ hildon_button_set_image(HILDON_BUTTON(plugin->priv->enable_button), image);
+ hildon_button_set_image_position(HILDON_BUTTON(plugin->priv->enable_button), GTK_POS_LEFT);
+ g_object_unref(icon);
+ }
+ mtetherd_status_plugin_enable_button_set_text(plugin);
+ g_signal_connect(plugin->priv->enable_button, "clicked", G_CALLBACK(mtetherd_status_plugin_enable_button_clicked), plugin);
+ gtk_container_add(GTK_CONTAINER(plugin), plugin->priv->enable_button);
+ gtk_widget_show_all(plugin->priv->enable_button);
}
- if (icon) {
- GtkWidget *image = gtk_image_new_from_pixbuf(icon);
- hildon_button_set_image(HILDON_BUTTON(plugin->priv->enable_button), image);
- hildon_button_set_image_position(HILDON_BUTTON(plugin->priv->enable_button), GTK_POS_LEFT);
- g_object_unref(icon);
+
+ if (mtetherd_hal_init(plugin)) {
+ plugin->priv->usb_plugged = mtetherd_usb_state(plugin);
+ plugin->priv->devices = mtetherd_device_list_new();
+ mtetherd_hal_device_scan(plugin);
+ } else {
+ plugin->priv->usb_plugged = FALSE;
}
- mtetherd_status_plugin_enable_button_set_text(plugin);
- g_signal_connect(plugin->priv->enable_button, "clicked", G_CALLBACK(mtetherd_status_plugin_enable_button_clicked), plugin);
- gtk_container_add(GTK_CONTAINER(plugin), plugin->priv->enable_button);
- gtk_widget_show_all(plugin->priv->enable_button);
+
+ // Update the button status
+ mtetherd_status_plugin_usb_plugged_show(plugin);
}
- if (mtetherd_hal_init(plugin)) {
- plugin->priv->usb_plugged = mtetherd_usb_state(plugin);
- plugin->priv->devices = mtetherd_device_list_new();
- mtetherd_hal_device_scan(plugin);
- } else {
- plugin->priv->usb_plugged = FALSE;
- }
-
- // Update the button status
- mtetherd_status_plugin_usb_plugged_show(plugin);
-
hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Initialized mtetherd status plugin");
}
mtetherd_status_plugin_enable_button_set_text(plugin);
}
hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Starting network on %s", interface);
- g_debug("Launching " SBIN_DIR "/mtetherd-net-setup.sh");
+ g_debug("Launching %s", SBIN_DIR "/mtetherd-net-setup.sh");
gchar *addr = mtetherd_device_get_addr(device);
gchar *netmask = mtetherd_device_get_netmask(device);
gchar *dhcp_start = mtetherd_device_get_dhcp_start(device);
gchar *dhcp_end = mtetherd_device_get_dhcp_end(device);
- const char *command[] = { "/usr/bin/sudo", SBIN_DIR "/mtetherd-net-setup.sh", interface, addr, netmask, dhcp_start, dhcp_end, NULL };
+ const char *command[] = { BIN_DIR "/sudo", SBIN_DIR "/mtetherd-net-setup.sh", interface, addr, netmask, dhcp_start, dhcp_end, NULL };
if (!mtetherd_launch_script(command)) {
- g_warning("Error launching USB networking setup script");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error launching USB networking setup script");
}
g_free(addr);
g_free(netmask);
g_free(dhcp_start);
g_free(dhcp_end);
} else {
- g_warning("Error adding network interface to list: Maximum number of devices exceeded");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error adding network interface to list: Maximum number of devices exceeded");
}
}
}
mtetherd_status_plugin_enable_button_set_text(plugin);
}
hildon_banner_show_informationf(GTK_WIDGET(plugin), NULL, "Shutting down network on %s", interface);
- g_debug("Launching " SBIN_DIR "/mtetherd-net-shutdown.sh");
- const char *command[] = { "/usr/bin/sudo", SBIN_DIR "/mtetherd-net-shutdown.sh", interface, NULL };
+ g_debug("Launching %s", SBIN_DIR "/mtetherd-net-shutdown.sh");
+ const char *command[] = { BIN_DIR "/sudo", SBIN_DIR "/mtetherd-net-shutdown.sh", interface, NULL };
if (!mtetherd_launch_script(command)) {
- g_warning("Error launching USB networking shutdown script");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error launching USB networking shutdown script");
}
}
if (!mtetherd_device_list_remove(plugin->priv->devices, udi)) {
- g_warning("Error removing network interface from list: Not found");
+ g_log(MTETHERD_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "Error removing network interface from list: Not found");
}
}
}