Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Copy link
Owner

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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"stm32-for-vscode.openOCDPath": false
}
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document somewhere in the commit message that you are adding the requirement of libudev please.

usbview_LDADD = $(GTK_LIBS) $(LIBUDEV_LIBS)

bin_PROGRAMS = usbview

Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ AM_CONDITIONAL(ICONS,[test x${icons} = xyes])

AC_SEARCH_LIBS([strerror],[cposix])
PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.0])
PKG_CHECK_MODULES([LIBUDEV], [libudev])
AC_SUBST([GTK_FLAGS])
AC_SUBST([GTK_LIBS])

Expand Down
114 changes: 99 additions & 15 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
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;
struct udev_device *parent_dev;
const char *action;
const char *dev_id_str;

dev = udev_monitor_receive_device(mon);
if (!dev)
{
g_warning("failed to receive device from udev monitor");
return TRUE;
}

action = udev_device_get_action(dev);
if (action)
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proper kernel coding style please.

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You turned tabs into spaces :(

// Initialize udev monitor
init_udev_mon();

initialize_stuff();

/*
* 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;
}