-
Notifications
You must be signed in to change notification settings - Fork 65
add auto refresh when usb device plug/unplug #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
6dceaff
3b46f5d
06772b4
8985f83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "stm32-for-vscode.openOCDPath": false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,8 @@ | |
| # | ||
| ## Process this file with automake to produce Makefile.in | ||
|
|
||
| AM_CPPFLAGS = $(GTK_CFLAGS) | ||
| usbview_LDADD = $(GTK_LIBS) | ||
| AM_CPPFLAGS = $(GTK_CFLAGS) $(LIBUDEV_CFLAGS) | ||
|
||
| usbview_LDADD = $(GTK_LIBS) $(LIBUDEV_LIBS) | ||
|
|
||
| bin_PROGRAMS = usbview | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| * Copyright (c) 1999, 2000 by Greg Kroah-Hartman, <[email protected]> | ||
| */ | ||
| #ifdef HAVE_CONFIG_H | ||
| #include <config.h> | ||
| #include <config.h> | ||
| #endif | ||
|
|
||
| #include <stdlib.h> | ||
|
|
@@ -13,24 +13,108 @@ | |
|
|
||
| #include "usbtree.h" | ||
|
|
||
| int main (int argc, char *argv[]) | ||
| #include <libudev.h> | ||
| #include <glib-unix.h> | ||
|
|
||
| static struct udev *udev = NULL; | ||
chopin1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static struct udev_monitor *mon = NULL; | ||
| static guint udev_source_id = 0; | ||
|
|
||
| static gboolean udev_mon_cb(gint fd, GIOCondition condition, gpointer user_data) | ||
| { | ||
| GtkWidget *window1; | ||
| struct udev_device *dev; | ||
chopin1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| struct udev_device *parent_dev; | ||
| const char *action; | ||
| const char *dev_id_str; | ||
|
|
||
| dev = udev_monitor_receive_device(mon); | ||
| if (!dev) | ||
| { | ||
chopin1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| g_warning("failed to receive device from udev monitor"); | ||
| return TRUE; | ||
| } | ||
|
|
||
| action = udev_device_get_action(dev); | ||
| if (action) | ||
| { | ||
|
||
| parent_dev = udev_device_get_parent(dev); | ||
| dev_id_str = udev_device_get_property_value(dev, "ID_MODEL"); | ||
|
|
||
| const char *devtype = udev_device_get_devtype(dev); | ||
| if (devtype && strcmp(devtype, "usb_device") != 0) | ||
| { | ||
| udev_device_unref(dev); | ||
| return TRUE; | ||
| } | ||
|
|
||
| if (strncmp(action, "remove", 7) == 0) | ||
| { | ||
| g_message("a device was removed (from %s)", udev_device_get_property_value(parent_dev, "ID_MODEL")); | ||
| } | ||
| else if (strncmp(action, "add", 3) == 0) | ||
| { | ||
| g_message("add a device: > %s < (from %s)", | ||
| dev_id_str ? dev_id_str : "unknown", | ||
| udev_device_get_property_value(parent_dev, "ID_MODEL")); | ||
| } | ||
| else | ||
| { | ||
| g_debug("udev action: %s for device: %s (%s)", | ||
| action, | ||
| udev_device_get_property_value(dev, "ID_MODEL"), | ||
| parent_dev ? udev_device_get_property_value(parent_dev, "ID_MODEL") : ""); | ||
| } | ||
|
|
||
| LoadUSBTree(666); | ||
| } | ||
|
|
||
| udev_device_unref(dev); | ||
| return TRUE; | ||
| } | ||
|
|
||
| gtk_init (&argc, &argv); | ||
| static void init_udev_mon(void) | ||
| { | ||
| udev = udev_new(); | ||
| if (!udev) | ||
| { | ||
| g_warning("failed to create udev context"); | ||
| return; | ||
| } | ||
|
|
||
| initialize_stuff(); | ||
| mon = udev_monitor_new_from_netlink(udev, "udev"); | ||
| if (!mon) | ||
| { | ||
| g_warning("failed to create udev monitor"); | ||
| udev_unref(udev); | ||
| return; | ||
| } | ||
|
|
||
| /* | ||
| * The following code was added by Glade to create one of each component | ||
| * (except popup menus), just so that you see something after building | ||
| * the project. Delete any components that you don't want shown initially. | ||
| */ | ||
| window1 = create_windowMain (); | ||
| gtk_widget_show (window1); | ||
| udev_monitor_filter_add_match_subsystem_devtype(mon, "usb", NULL); | ||
| udev_monitor_enable_receiving(mon); | ||
|
|
||
| LoadUSBTree(0); | ||
| gtk_main (); | ||
| return 0; | ||
| udev_source_id = g_unix_fd_add(udev_monitor_get_fd(mon), G_IO_IN | G_IO_ERR | G_IO_HUP, | ||
| udev_mon_cb, NULL); | ||
| } | ||
|
|
||
| int main(int argc, char *argv[]) | ||
| { | ||
| GtkWidget *window1; | ||
|
|
||
| gtk_init(&argc, &argv); | ||
|
||
| // Initialize udev monitor | ||
| init_udev_mon(); | ||
|
|
||
| initialize_stuff(); | ||
|
|
||
| /* | ||
chopin1998 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * The following code was added by Glade to create one of each component | ||
| * (except popup menus), just so that you see something after building | ||
| * the project. Delete any components that you don't want shown initially. | ||
| */ | ||
| window1 = create_windowMain(); | ||
| gtk_widget_show(window1); | ||
|
|
||
| LoadUSBTree(0); | ||
| gtk_main(); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed.