Discussion:
[Libusbx-devel] [libusbx] Windows: hotplug/unplug support (#9)
Manuel Francisco Naranjo
2013-09-09 19:34:03 UTC
Permalink
Hello guys I took that branch, did some magic on top and now have some basic hotplug working on my fork, it's still a WIP and some of the commits I have there need to be rewritten, but I think it's ready to start getting some reviews.

https://github.com/manuelnaranjo/libusbx/tree/windows-hotplug

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24107860
Renaud Aubin
2013-09-09 23:16:53 UTC
Permalink
@manuelnaranjo :thumbsup: I'll check that out!

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24122511
Pete Batard
2013-09-10 17:19:56 UTC
Permalink
Sounds good.

As far as I'm concerned, it'll probably be another week or two before I am in a position to properly review your changes so I hope you're not in too much of a hurry. Also, we may apply [this](http://libusbx.1081486.n5.nabble.com/Libusbx-devel-RFC-0-3-Make-usbi-get-device-by-session-id-return-a-ref-to-the-found-device-td1898.html#a1896) as well as [this set](http://libusbx.1081486.n5.nabble.com/Libusbx-devel-RFC-Remove-fake-fds-from-Windows-backends-td1432.html) before we apply any of your changes, which may conflict with part of your proposal. As a result, we might ask you to rebase your branch after we've applied those, if that's OK.

At any rate, thanks for working on a hotplug proposal that we should be in a position to integrate.

/Pete

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24178549
Manuel Francisco Naranjo
2013-09-10 17:32:03 UTC
Permalink
Pete,

Sure there's no hurry here. Actually I wanted to start getting feedback
as I'm noticing some bugs on the implementation, and I'm sure I
introduced those as I'm not completely familiar with libusb internals.

Also I think the way usb devices on Windows get listed should be
changed, and make it more like the lib does on Linux where it starts
with the leaf nodes and starts going up, instead of trying to list the
hole tree and then finding the newly introduced leaf.

That will surely take me more time, I'm a linux guy my self, but I need
hotplug support on Windows for one of our company projects, and I don't
like the idea of sticking to such and old version of the library.

In the mean time would be nice to start getting some feedback, specially
by the people who are more familiar with the internals.

BTW I have a question what's the parent_dev of a hub supposed to be?
Right now I'm getting two nodes with VID and PID set to 0x0000 whose
win32 api path start with PCI which I assume are not the hubs, but the
hubs parent devs, and I shouldn't be seen those, but I couldn't find a
better way to solve this issue.

-Manuel
Post by Pete Batard
Sounds good.
As far as I'm concerned, it'll probably be another week or two before I
am in a position to properly review your changes so I hope you're not in
too much of a hurry. Also, we may apply this
<http://libusbx.1081486.n5.nabble.com/Libusbx-devel-RFC-0-3-Make-usbi-get-device-by-session-id-return-a-ref-to-the-found-device-td1898.html#a1896>
as well as this set
<http://libusbx.1081486.n5.nabble.com/Libusbx-devel-RFC-Remove-fake-fds-from-Windows-backends-td1432.html>
before we apply any of your changes, which may conflict with part of
your proposal. As a result, we might ask you to rebase your branch after
we've applied those, if that's OK.
At any rate, thanks for working on a hotplug proposal that we should be
in a position to integrate.
/Pete

Reply to this email directly or view it on GitHub
<https://github.com/libusbx/libusbx/issues/9#issuecomment-24178549>.
---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24179411
Manuel Francisco Naranjo
2013-09-12 15:19:15 UTC
Permalink
Please use https://github.com/manuelnaranjo/libusbx/tree/windows-hotplug-2 instead, I changed the way devices are enumerated, and got an implementation that seems to work fine.

There are a few things that still need to be tested, like I don't have any USB3.0 device so I can't tell if it works, need to test hotplug of usb hubs which I'm planning on doing today.

The basic enumeration now is first listing all usb hubs devices then looking at each device parent, with the parent path if the device is not yet registered then it will created the node, setting up hcds. Then it will enumarate usb devices and go up on the tree until it reaches the first known parent.

Not sure yet if this implementation does the right thing with composite, hid and driver less devices.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24329378
Manuel Francisco Naranjo
2013-09-12 19:09:29 UTC
Permalink
FYI I have rebased my changes on top of the master branch, which got me the usbi_get_device_by_session_id changes, after a few changes here and there my branch is again ready to be tested.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24347433
mcuee
2013-09-19 05:26:37 UTC
Permalink
I tried your tree, it caused stress test to fail.
$ ./tests/stress.exe
Failed to open null handle: 2

Interesting thing is that if I set LIBUSB_DEUG=4 and then run "./tests/stress.exe -v" it will pass the tests. In that case, it will keep printing an error message.

libusbx: error [windows_hotplug_threaded] can't register class [1410] Class already exists.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24717868
mcuee
2013-09-19 05:33:51 UTC
Permalink
A few other things.

1) Warning message

$ ./examples/listdevs.exe
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID of HCD hu
b from '\\.\USB#VID_413C&PID_2513#6&2DA13301&0&2'
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID of HCD hu
b from '\\.\USB#VID_8087&PID_0020#5&1302ECA6&0&1'
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID of HCD hu
b from '\\.\USB#VID_8087&PID_0020#5&1302ECA6&0&1'
413c:3012 (bus 3, device 7) path: 1.4
413c:2003 (bus 3, device 6) path: 1.2
0a5c:5800 (bus 7, device 3) path: 1.8
0483:3748 (bus 3, device 8) path: 1.3
046d:c52f (bus 7, device 2) path: 1.1
8087:0020 (bus 7, device 5) path: 1
8087:0020 (bus 6, device 3) path: 1
1d6b:0001 (bus 5, device 1) path: 2
1d6b:0001 (bus 4, device 1) path: 1
1d6b:0001 (bus 3, device 1) path: 1
8086:3b3c (bus 2, device 1)
8086:3b34 (bus 1, device 1)

2) You seem to change the behavior of hotplugtest so that it does not quit.

$ ./examples/hotplugtest.exe 0x0483 0x3748
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID of HCD hub from '\\.\USB#VID_413C&PID_2513#6&2DA13301&0&2'
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID of HCD hub from '\\.\USB#VID_8087&PID_0020#5&1302ECA6&0&1'
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID of HCD hub from '\\.\USB#VID_8087&PID_0020#5&1302ECA6&0&1'
Waiting for events
libusbx: error [message_callback_handle_device_change] dbt_arrival 5
Callback Device detached: 0483:3748
libusbx: error [message_callback_handle_device_change] dbt_arrival 5
Callback Device attached: 0483:3748
libusbx: error [message_callback_handle_device_change] dbt_arrival 5
Callback Device detached: 0483:3748
libusbx: error [message_callback_handle_device_change] dbt_arrival 5
Callback Device attached: 0483:3748
libusbx: error [message_callback_handle_device_change] dbt_arrival 5
Callback Device detached: 0483:3748
libusbx: error [message_callback_handle_device_change] dbt_arrival 5
Callback Device attached: 0483:3748
...

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24718065
Pete Batard
2013-09-20 01:35:20 UTC
Permalink
OK, a few preliminary remarks:

1. TCHAR: No. Just no. Please get rid of this atrocity. Either you use an UTF-8 char* string (or you use a wchar_t if you must need UTF-16). Your use of TCHAR completely breaks VS2012 compilation right now and despite what Microsoft wants to make everybody believe, there is no justification for using TCHAR ever (except for letting Redmond get away with not doing [what they should have done about 15 years ago](http://www.utf8everywhere.org/))

2. Be mindful that
```
int a;
a = 1;
int b;
b = a+1;
```
Will not work on MS compilers. All the variable declarations must be at the top.
Thus windows_usb.c lines 584 & 2366 also break MSVC compilation.

3. b9eae35836855367a0e779c349ae333db8564a3b => nope, not gonna work. MSVC doesn't have named initializers (and that's not limited to MSVC6). You need to revert this whole patch.

4. When the __existing__ code uses something like
```
int func(int a, int b, int c);
```
It's very bad manner to disregard the previous styling convention and introduce your new code with
```
int newfunc(int d,
int e,
int f)
```
Whoever was first to create a source gets to decide the styling convention, and everyone who comes after follows. Now, if you create a new sourcefile, you get to pick whatever you like (as long as it's not too wild), but if you add to an existing one, you just spend some time looking around at the existing style, and follow it.
Same goes for using spaces in code addons where spaces are used. I see quite a few of these.
Please use an editor that displays whitespace symbols and address your spaces vs tabs issues. Also, a proper git UI (such as TortoiseGit on Windows) is very efficient at letting you know when you're introducing whitespace issues and it's as annoying for a maintainer as it is for a submitter to see one's patch shot down simply because they didn't bother paying attention to whitespace issues.

5. f3dd52c02212c62e154972093d832f1b83f794f1 - I'm not sure how I feel about having emacs defs introduced to Windows specific files that __most__ people are going to edit on Windows, with editors that aren't emacs and that have their styling sensibly set __globally__ without a requirement to have it def'd within the file itself (ugh! Besides vi > emacs anyway ;)). Can you imagine if every editor out there insisted on doing the same? We'd end up with a whole set of /* Joe's editor */ .... /* Bob's editor */ ... /* Bill's editor */ sections that'd end up taking more space than the actual payload of the file. Now, if you __must__ have it, and since OS X has already started doing some of that, I'll let it slide, but really, who in their right mind can justify that merging and multiplying editor specific presentation config data in each source of a project is a good idea.

6. If you don't have a Windows machine at hand, __strongly__ suggest that you install Wine and the latest __standalone__ WDK (I think [this](http://www.microsoft.com/en-us/download/details.aspx?id=11800) link should do), so that you can pick up on all the annoyances that the MS compiler is going to throw at you. If you have a Windows test machine (which I guess you probably do, since I don't see why you'd want to spend time on a Windows hp implementation in the first place), then it's even easier - just install the WDK, and run ddk_build.cmd in the msvc directory. By the way the WDK is free and is as close as you can get to MSVC if you can't afford the hefty Visual Studio license.
It's also a good idea to test both cygwin & MinGW compilation if you can. Basically, the first thing I'm going to do is check whatever errors and warnings come out out of MSVC (either WDK or VS2012), MinGW (one of 32 or 64 depending on how the stars are aligned) and cygwin. If either one of those doesn't compile cleanly, I'll ask you to make it so (and yeah, this kind of multiplies your amount of testing by 3 - welcome to not time consuming at all libusb Windows backend development!).

If you try to address the above, I'll try to get a more serious look at your actual implementation (though it may be a couple more weeks before I actually do so).

/Pete

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24785359
Manuel Francisco Naranjo
2013-09-20 01:57:10 UTC
Permalink
Post by Pete Batard
1.
TCHAR: No. Just no. Please get rid of this atrocity. Either you use
an UTF-8 char* string (or you use a wchar_t if you must need
UTF-16). Your use of TCHAR completely breaks VS2012 compilation
right now and despite what Microsoft wants to make everybody
believe, there is no justification for using TCHAR ever (except for
letting Redmond get away with not doing what they should have done
about 15 years ago <http://www.utf8everywhere.org/>)\
Yeah I don't like TCHAR either, but as msdn was using it, I had no idea
what to replace it with, and was kind of lazy.
Post by Pete Batard
2.
Be mindful that
|int a;
a = 1;
int b;
b = a+1;
|
Will not work on MS compilers. All the variable declarations must be
at the top.
Thus windows_usb.c lines 584 & 2366 also break MSVC compilation.
Really? Is that stupid?
Post by Pete Batard
3.
b9eae35
<https://github.com/libusbx/libusbx/commit/b9eae35836855367a0e779c349ae333db8564a3b>
=> nope, not gonna work. MSVC doesn't have named initializers (and
that's not limited to MSVC6). You need to revert this whole patch.
Ok no problem, someone from inside the company noticed the same, I've
been using mingw and cygwin only.
Post by Pete Batard
4.
When the *existing* code uses something like
|int func(int a, int b, int c);
|
It's very bad manner to disregard the previous styling convention
and introduce your new code with
|int newfunc(int d,
int e,
int f)
|
Whoever was first to create a source gets to decide the styling
convention, and everyone who comes after follows. Now, if you create
a new sourcefile, you get to pick whatever you like (as long as it's
not too wild), but if you add to an existing one, you just spend
some time looking around at the existing style, and follow it.
Same goes for using spaces in code addons where spaces are used. I
see quite a few of these.
Please use an editor that displays whitespace symbols and address
your spaces vs tabs issues. Also, a proper git UI (such as
TortoiseGit on Windows) is very efficient at letting you know when
you're introducing whitespace issues and it's as annoying for a
maintainer as it is for a submitter to see one's patch shot down
simply because they didn't bother paying attention to whitespace issues.
Yes sorry my fault, it's just that I'm using linux for development with
emacs and those lines are just too long to actually be readable (yes I'm
doing 80 chars here!). I got used to some linux kernel development long
time ago and now can't leave it behind as I really like it. But I can
fix that no problem.

I did paid attention to the tabs/whitespace nightmare in libusb, what
did I miss? Did I introduce any spaces where there should be tabs? I'll
review my changes again.

BTW shouldn't there be just one code guideline for the hole project?
Post by Pete Batard
5.
f3dd52c
<https://github.com/libusbx/libusbx/commit/f3dd52c02212c62e154972093d832f1b83f794f1>
- I'm not sure how I feel about having emacs defs introduced to
Windows specific files that *most* people are going to edit on
Windows, with editors that aren't emacs and that have their styling
sensibly set *globally* without a requirement to have it def'd
within the file itself (ugh! Besides vi > emacs anyway ;)). Can you
imagine if every editor out there insisted on doing the same? We'd
end up with a whole set of /* Joe's editor // .... // Bob's editor
// ... // Bill's editor */ sections that'd end up taking more space
than the actual payload of the file. Now, if you *must* have it, and
since OS X has already started doing some of that, I'll let it
slide, but really, who in their right mind can justify that merging
and multiplying editor specific presentation config data in each so
urce of a project is a good idea.
Ok I will look if there's any way I can set this up without interfering
with my global settings. My setup is linux+emacs with a vm running win7 64b.
Post by Pete Batard
6.
If you don't have a Windows machine at hand, *strongly* suggest that
you install Wine and the latest *standalone* WDK (I think this
<http://www.microsoft.com/en-us/download/details.aspx?id=11800> link
should do), so that you can pick up on all the annoyances that the
MS compiler is going to throw at you. If you have a Windows test
machine (which I guess you probably do, since I don't see why you'd
want to spend time on a Windows hp implementation in the first
place), then it's even easier - just install the WDK, and run
ddk_build.cmd in the msvc directory. By the way the WDK is free and
is as close as you can get to MSVC if you can't afford the hefty
Visual Studio license.
It's also a good idea to test both cygwin & MinGW compilation if you
can. Basically, the first thing I'm going to do is check whatever
errors and warnings come out out of MSVC (either WDK or VS2012),
MinGW (one of 32 or 64 depending on how the stars are aligned) and
cygwin. If either one of those doesn't compile cleanly, I'll ask you
to make it so (and yeah, this kind of multiplies your amount of
testing by 3 - welcome to not time consuming at all libusb Windows
backend development!).
I will go ahead and test with WDK, I have it somewhere. I think I may
have MSVC somewhere. MinGW does build and run as that's my main
compiler, only I'm using SCons for building the project, I tried with
cygwin as well, and it was working long time ago.
Post by Pete Batard
If you try to address the above, I'll try to get a more serious look at
your actual implementation (though it may be a couple more weeks before
I actually do so).
Sure I can do that, sometime next week I think.

Let me refactor the code and I send a more clean code.

-Manuel

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24785995
Tim Roberts
2013-09-20 18:15:47 UTC
Permalink
Post by Manuel Francisco Naranjo
Post by Pete Batard
Be mindful that
|int a;
a = 1;
int b;
b = a+1;
|
Will not work on MS compilers. All the variable declarations must be
at the top.
Thus windows_usb.c lines 584 & 2366 also break MSVC compilation.
Really? Is that stupid?
No, it's smart, it's just smart C89. Microsoft has not implemented C99,
and has not given a timeline for doing so. Virtually all important
Windows code is done in C# or C++.

On a related note, I've never understood why the Linux world clings so
tightly to C. Many of the improvements in C99 were introduced because
of C++. In the C++ world, the delta between MSVC and gcc is very, very
small. You don't have to dive hip-deep into templates and
metaprogramming and inheritance; it's quite viable to use C++ as a
better C. In my experience, most programming solutions are more clearly
expressed in C++ than in C.
--
Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
Manuel Francisco Naranjo
2013-09-20 02:02:25 UTC
Permalink
Post by mcuee
$ ./examples/listdevs.exe
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID
of HCD hub from '\.\USB#VID_413C&PID_2513#6&2DA13301&0&2'
Ok that's weird! I'll look into the code, I think I haven't changed that
function, but I did so many changes that I can't remember now.
Post by mcuee
2) You seem to change the behavior of hotplugtest so that it does not quit.
Yes in my branch it exists after 20 events, and it doesn't try opening
the device.
Post by mcuee
$ ./examples/hotplugtest.exe 0x0483 0x3748
libusbx: warning [force_hcd_device_descriptor] could not infer VID/PID
of HCD hub from '\.\USB#VID_413C&PID_2513#6&2DA13301&0&2'
This is the same as before.
Post by mcuee
libusbx: error [message_callback_handle_device_change] dbt_arrival 5
I'll look into this, I remember taking that log message out, but maybe I
didn't took it out and used the error function instead of verbose
debugging, anyway that line is not a real error but rather normal behavior.

-Manuel

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24786152
Manuel Francisco Naranjo
2013-09-20 01:59:14 UTC
Permalink
Post by mcuee
I tried your tree, it caused stress test to fail.
$ ./tests/stress.exe
Failed to open null handle: 2
Interesting thing is that if I set LIBUSB_DEUG=4 and then run
"./tests/stress.exe -v" it will pass the tests. In that case, it will
keep printing an error message.
libusbx: error [windows_hotplug_threaded] can't register class [1410]
Class already exists.
I think I know where the problem is been generated. I need to register a
new class to create a fake hidden window, stress calls usb_init multiple
times? My fault I thought that would actually be doing things wrong.
I'll look into this.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24786053
litghost
2013-09-22 16:14:31 UTC
Permalink
I've tested tested the hotplug on USB 3.0 with a Windows Intel XCHI controller, and it appears to work. I built with VS 2012, and was required to make some assorted fixes to get it to build https://github.com/manuelnaranjo/libusbx/pull/1 .

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24884941
Pete Batard
2013-09-23 01:06:05 UTC
Permalink
Yes sorry my fault, it's just that I'm using linux for development with emacs and those lines are just too long to actually be readable (yes I'm doing 80 chars here!).
You poor soul. You know they have invented high resolution monitors and editors with nice UI interfaces, where one can be fairly productive, since the 1990s, right? ;)
I got used to some linux kernel development long time ago and now can't leave it behind as I really like it. But I can fix that no problem. I did paid attention to the tabs/whitespace nightmare in libusb, what did I miss? Did I introduce any spaces where there should be tabs? I'll review my changes again.
Since you have a Windows machine to test with, my advice would be to install TortoiseGit (note you'll need to install msysgit first) and fetch your repo. The diff has a very nice UI that will make it very explicit where spaces are used in lieu of tabs, by displaying dots vs arrows. For what is worth, pretty much all the lines you introduced in edde05c45ba7052b01fb25394d0a7267bad4c878 use space in lieu of tabs. There's also some weird stuff where you introduce tabs in comments in d2612f119ab6dc969084e55fa122a66d998826cf. 16f11affc63fe6593036799111c8a4f86011cde4 also has spaces instead of tabs.
BTW shouldn't there be just one code guideline for the hole project?
Some people may insist on rigid project-wide guidelines, but I personally don't see that as a necessity, as too constraining. My take is that if you create a new source, you get to pick your styling (as long as it's not too wild). If you follow a source, you follow the styling used by the original author. Especially on a project such as libusb(x), this can help with keeping people who want to introduce a new backend happy for not having to depart from the style they are comfortable with (even if it's something as historical as 80 chars emacs...)

I'm not going to comment on MS vs C standards, since I would only have some very negative things to say, and that won't change the fact that, at the end of the day, we have no choice but to deal with how restrictive MSVC is in that respect.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-24894839
Manuel Francisco Naranjo
2013-10-09 01:34:01 UTC
Permalink
@mcuee is '\\.\USB#VID_413C&PID_2513#6&2DA13301&0&2' a USB hub attached to a PCI hub? Or is it a composite device? I'm trying to figure out if I broke something here

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-25941104
Tim Roberts
2013-10-09 04:12:40 UTC
Permalink
On Oct 8, 2013, at 6:34 PM, Manuel Francisco Naranjo <***@github.com<mailto:***@github.com>> wrote:

@mcuee<https://github.com/mcuee> is '\.\USB#VID_413C&PID_2513#6&2DA13301&0&2' a USB hub attached to a PCI hub? Or is it a composite device? I'm trying to figure out if I broke something here


Google is your friend.

That's the ID of the internal USB hub in Dell's port replicator.
--
Tim Roberts, ***@probo.com<mailto:***@probo.com>
Providenza & Boekelheide, Inc.
naranjo.manuel
2013-10-09 10:53:40 UTC
Permalink
Post by Tim Roberts
@mcuee <https://github.com/mcuee> is
'\.\USB#VID_413C&PID_2513#6&2DA13301&0&2' a USB hub attached to a PCI
hub? Or is it a composite device? I'm trying to figure out if I broke
something here
Google is your friend.
That's the ID of the internal USB hub in Dell's port replicator.
I was kind of tired when sending the email, didn't though about using
that :S. Anyway so it's a weird usb hub inside a computer. Is it a
regression that you get that warning now? I don't see how former code
would show the right vid and pid. Unless it was picking up as a usb
device attached to another HCD.

-Manuel




--
View this message in context: http://libusbx.1081486.n5.nabble.com/Re-Libusbx-devel-libusbx-Windows-hotplug-unplug-support-9-tp2051p2061.html
Sent from the libusbx mailing list archive at Nabble.com.
Manuel Francisco Naranjo
2013-10-09 02:49:30 UTC
Permalink
Pete and the rest,

I have updated my branch according to your comments, you can find it at [1]. I splitted the changes so that commits don't impact more than one file, except when it's totally necessary, also squashed commits so it's cleaner to understand what the changes are.

I took out TCHAR as char was enough. Same with tabs vs spaces things, and line with, I compiled with mingw, cygwin and VS2005.

Let me know if there's anything else I need to fix before doing the pull request.

Cheers,

-Manuel

[1] https://github.com/manuelnaranjo/libusbx/tree/windows-hotplug-3

PS: For mingw I needed to modify config.h manually to set WINVER and _WIN32_WINNT, I didn't wanted to put this into my branch, is anyone else getting this issues?

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-25943385
litghost
2013-10-09 03:43:06 UTC
Permalink
The VS2012 projects still use UNICODE, so some structs are the wide-char versions. Update the VS projects to use mutlibyte-char? For example, DEV_BROADCAST_DEVICEINTERFACE is DEV_BROADCAST_DEVICEINTERFACEW when UNICODE is set, and DEV_BROADCAST_DEVICEINTERFACE_A when it is not.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-25944836
Manuel Francisco Naranjo
2013-10-09 10:49:24 UTC
Permalink
@litghost I don't have VS2012 installed, I guess I could try looking for it and giving it a try. I've been using mingw most of the time, I'm way more familiar with GCC. Problem that I see is that in we are forcing to use some ANSI functions (that was the former case so I kept it), and not bothering about unicode ones. My guess here is that either before or after adding hotplug support all code should be normalized to either let the compiler decide or force using ANSI. But that's up to the core developers to decide not me.

-Manuel

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-25961944
litghost
2013-10-09 13:03:39 UTC
Permalink
It free, http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-25968972
Pete Batard
2013-10-09 22:07:21 UTC
Permalink
Thanks Manuel.

* b8d13f2d0d40ffa3addd38f12b0152d942135661: Please don't try to squeeze your styling when I specifically warned you about it. There are way too many styling issues with this commit: I'm seeing double spaces converted to tabs in printf's that are unrelated to your patch, braces at the end of an if statement that are missing the leading space, and I also said not to split,
mutilple,
arguments,
over,
multiple,
lines.
Sorry but, while I'm still willing to believe these are honest mistakes, I can't let style slide. Multistlyled code is a pain for everybody, not just the maintainers. Unless you created a new source from scratch, you just pay attention to whatever existing style was used and follow it, starting with the very first commit you want us to integrate. I already have 19 lines to fix [just for the styling of this one patch](https://github.com/pbatard/libusbx-hp/commit/96b0255c2aab77d82a09717b568c3524e92377ae), and I don't really want to have to spend time fixing styling issues.
* b3f0ac528457e9da19039aa8c5cf855002a93dbd: would have to track why we did this in the first place, which I'm not gonna do, so no objection on removing this cast and letting time tell if it was actually needed in the first place.
* 7b4eaa9855f307465c29649564af5157a7a12d7e: I don't really see anything that needs fixing there. We're setting `usbi_default_context` to NULL but ctx is still perfectly valid. Plus you're modifying `usbi_default_context` outside of its mutex lock (not a good idea), and what's more, splitting the message that says we're destroying the default context (which we're not really doing here) from the part where we're removing the user reference. Unless you've experienced a real issue there, which we'll need to analyse better, this commit is NO_GO.
* b86964ace5f2f9c088d56b17c56ffa603ef5d9f3: Don't really care, if Toby is also OK with this.
* 17d05f567c04868406ca6402b1a5d378d687a171: No real issue with that either. I'd prefer to see inline helper calls towards the top of a source rather than added at the bottom, but that's minor and I'm not going to force you to redo that one.
* 3de7d1d9cb4299fc9cfd10abcd16416289a5640c: If we still need to have direct reference to the abomination that is a T-string in our code, then something is very wrong. And indeed something still is. Microsoft wasn't as foolish as have any of their __A__ calls take a `PCTSTR`/`PTSTR`, and your def should be:
```
LL_DECLARE_PREFIXED(WINAPI, HDEVINFO, p, SetupDiGetClassDevsExA, (const GUID*, PCSTR, HWND, DWORD, HDEVINFO, PCSTR, PVOID));
DLL_DECLARE_PREFIXED(WINAPI, BOOL, p, SetupDiGetDeviceInstanceIdA, (HDEVINFO, PSP_DEVINFO_DATA, PSTR, DWORD, PDWORD));
```
While we're on the subject, the informal rule I've tried to follow is: for anything that returns strings that we're pretty sure is never going to see any localized character (GUID, Device Interface Path, etc.), use an explicit __A__ call. For items that may see a localized string (eg. directory path) use the __W__ call and convert the string to UTF-8 if we need to feed it to other parts of the library. Or, to put it more simply, just consider that everything is UTF-8 everywhere, as long as Microsoft doesn't provide us with any other choice but to use __W__.
That's not to say I haven't missed a few calls where __A__ should have been explicitly specified explicitly in `windows_usb.c`. If that's the case, we'll need to fix that as well.
* 327aac878e127a7b2ec7b82977bbd7dea05b5133: I'll review the bulk of the hotplug patch when I have more time in front of me
* a3f315d4b35ba34955a1ecf9900032b92e8f5578: We have a lowercase `bool` and that's what we (try to) use everywhere where Microsoft doesn't forces us otherwise. Please use that to preserve styling. You also have,
frigging,
parameters,
on,
separate,
lines, in this commit and the previous one. I'm going to be a pain, but not having to spend half a comment complaining about styling inconsistencies is what I'd prefer, so it would be nice if these were to be eliminated.
* dfa1d55947ae6cc3433de5b610f849993fd7fb79: You're gonna have to merge that with 327aac878e127a7b2ec7b82977bbd7dea05b5133. `TCHAR` is not OK ever, even temporarily.
* c94f9d5dbe74473938e66c8ac5fa847eb2c960b2: Likewise, would be better merged with the earlier patches.

I hope I'm not sounding too harsh, because I do appreciate the work you put in so far, and if it achieves what we want, I very much want to see your patch integrated one way or the other.
Still, I'd rather get all the styling and grouping/merging issues out of the way, to ensure that we can review what actually matters, as well as have commits that could actually be integrated as is, if we think the code behind them is sound.

/Pete

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26013240
Manuel Francisco Naranjo
2013-10-10 01:02:34 UTC
Permalink
Pete,

Don't worry on sounding harsh, I agree with the styling issues, my bad I missed those changes while reviewing what to stage and what not, btw I discovered git add -p, git commit -p and git stash -p thanks to this, very powerful, that's why you are seen those style issues.

- b8d13f2 : don't worry about this one, I will check the style on this commit, and also in any other missing, I only worried about windows_usb.{c,h}
- 7b4eaa9 : this was necessary to keep tracing library cleanup when not creating a different context, I agree this shouldn't be part of the branch, but it was a feature I needed to figure out where I was leaking devices while still writting the code that's why it was still there. I think this is a different conversation.
- b86964a : it was necessary for mingw building when using my own build tools, as I didn't wanted to pass those values through compiler arguments, it makes more sense to use the autogenerated config.h
- 3de7d1d : declaring those type values was necessary to get mingw building as WINVER and _WIN_WINNT aren't defined, but you are right as I'm referencing the A version and not the subfixed one I can just rely on PTSTR which should be defined.
- a3f315d : I can change to bool, about the arguments you mean lines like 981, 982 on the resulting code? You prefer code without argument comments? If so I can make those one line, otherwise how you want me to put the comments?
- dfa1d55 and c94f9d5 : ok makes sense, just wanted to keep track on the changes someone suggested for VS2012.

I'll do the suggested fixes and get back to you by the end of the week.

Regards,
Manuel


---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26021911
tobygray
2013-10-11 08:21:02 UTC
Permalink
Hi Manuel,

Regarding the addition of config.h into the testlib.c in b86964a
<https://github.com/libusbx/libusbx/commit/b86964a>, what values were
you needing to pass? Was it just _WIN32?

Regards,

Toby
Post by Manuel Francisco Naranjo
Pete,
Don't worry on sounding harsh, I agree with the styling issues, my bad
I missed those changes while reviewing what to stage and what not, btw
I discovered git add -p, git commit -p and git stash -p thanks to
this, very powerful, that's why you are seen those style issues.
don't worry about this one, I will check the style on this commit,
and also in any other missing, I only worried about windows_usb.{c,h}
* 7b4eaa9 <https://github.com/libusbx/libusbx/commit/7b4eaa9> : this
was necessary to keep tracing library cleanup when not creating a
different context, I agree this shouldn't be part of the branch,
but it was a feature I needed to figure out where I was leaking
devices while still writting the code that's why it was still
there. I think this is a different conversation.
* b86964a <https://github.com/libusbx/libusbx/commit/b86964a> : it
was necessary for mingw building when using my own build tools, as
I didn't wanted to pass those values through compiler arguments,
it makes more sense to use the autogenerated config.h
declaring those type values was necessary to get mingw building as
WINVER and /WIN/WINNT aren't defined, but you are right as I'm
referencing the A version and not the subfixed one I can just rely
on PTSTR which should be defined.
* a3f315d <https://github.com/libusbx/libusbx/commit/a3f315d> : I
can change to bool, about the arguments you mean lines like 981,
982 on the resulting code? You prefer code without argument
comments? If so I can make those one line, otherwise how you want
me to put the comments?
* dfa1d55 <https://github.com/libusbx/libusbx/commit/dfa1d55> and
c94f9d5 <https://github.com/libusbx/libusbx/commit/c94f9d5> : ok
makes sense, just wanted to keep track on the changes someone
suggested for VS2012.
I'll do the suggested fixes and get back to you by the end of the week.
Regards,
Manuel

Reply to this email directly or view it on GitHub
<https://github.com/libusbx/libusbx/issues/9#issuecomment-26021911>.
---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26121465
Manuel Francisco Naranjo
2013-10-11 11:57:57 UTC
Permalink
@tobygray yes indeed, yet it wasn't related to make stress test fail. That happens because I need to register a new class so I can create my own window, and I don't do proper cleanup on the exit mechanism, simply because I have no track on the registered class, I'll be looking into this today.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26131734
Matthias Bolte
2013-10-11 12:24:07 UTC
Permalink
You could use GetClassInfoExA to check if the window class already exist any only register it if it's not existing yet.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26133039
tobygray
2013-10-11 12:54:17 UTC
Permalink
@manuelnaranjo shouldn't the #define checks then be changed to OS_WINDOWS and OS_WINCE?

Also wouldn't mingw provide a unistd.h which provides the required defines? How are you compiling with mingw and what compiler error does it produce without including config.h?

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26134617
Manuel Francisco Naranjo
2013-10-11 19:18:49 UTC
Permalink
@tobygray you are right, we don't need config.h in test lib, but we do need config.h to set WINVER and _WINNT_WIN32 to get some winapi structures defined when building for mingw. I'm updating the branch with those changes in.

@photron thanks for the suggestion, what I ended up doing I think it's more proper, now when the thread exits it will kill it's own window, unregister the class, etc.

Now stress.exe works fine in my VM (slow though)

-Manuel

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26164250
Manuel Francisco Naranjo
2013-10-11 19:21:46 UTC
Permalink
Guys after last round of suggestions I got, I did more fixes into my branch[1], many commits had been squashed now, formatting should be correct, library is initialized and cleaned up correctly and unicode/ansi works fine.

I think we are getting close, hopefully soon this can be merged.

-Manuel

[1] https://github.com/manuelnaranjo/libusbx/tree/windows-hotplug-4

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26164495
Matthias Bolte
2013-10-11 20:11:22 UTC
Permalink
Well, using UnregisterClassA is dangerous because it requires that the hotplug thread always exits correctly and that you are not starting a new hotplug thread before the old one has ended. And this is where the problems are:

In the error path of windows_init you're just terminated the hotplug thread using TerminateThread. This can result in killing the hotplug thread after the window class was registered but before the thread had a chance to unregister it again. The next call to windows_init will try to start the hotplug thread again, this will fail because the window class is still registered from the last attempt. You cannot just terminate a thread right away, this will just create trouble.

Also you're not doing any handshaking with the hotplug thread in windows_init. You just hope that it'll work. If there is an error in starting the hotplug thread then windows_init will just succeed but hotplug doesn't work, because the hotplug thread exited early. The clock_gettime thread uses a semaphore to handshake between the thread and windows_init. The hotplug thread should do the same.

Looking at windows_exit I see that you only ask the hotplug thread to exit if it managed to create the message window yet. But if the hotplug thread didn't manage to create the message window yet (due to the missing handshake in windows_init and unfortunate thread scheduling) you're not going to end it. The next call to windows_init will create a second hotplug thread which will then exit early due to the inability to register the window class a second time, as the first hotplug thread is still running.

So I suggest that you add handshaking to the hotplug thread and make windows_init wait until the hotplug thread has created the message window so that you can always ask the hotplug thread to exit via WM_QUIT. Basically use the same pattern as the clock_gettime thread.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26168408
Manuel Francisco Naranjo
2013-10-12 02:58:18 UTC
Permalink
@photron You are right good catch, I will implement it that way then. I will look into clock code and re-use it's design pattern.

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-26189632
Chris Dickens
2014-01-17 02:14:45 UTC
Permalink
Hi All,

I have been needing hotplug support on Windows for quite some time, so I
was eager to start testing this code. I've finally had the chance to, and I
think it's a great start (thanks Manuel for your groundwork!!). Here's my
preliminary findings:

1) The way that the hubs are enumerated is broken, with respect to the bus
number. Every hub is assigned its own bus number. This is fine if there
were only root hubs present but does not work otherwise.
2) The session id for a device is indiscriminately based on the calculated
hash of the device interface path in some places and the device instance ID
in other places, and the two values are never the same. This is therefore
broken.
3) Composite and HID devices are not enumerated correctly. The individual
interfaces of these devices are never discovered and assigned to the parent
device. These devices are discovered and presented in the device list, but
none of their interfaces are usable.
4) The hotplug thread only receives notifications for devices. This may be
fine in most cases, but it will not be when hubs or host controllers are
introduced or taken away.

With these discoveries, I forked the branch and started playing around.
I've made some significant progress in getting towards a fully working
solution. All of the above issues have been addressed, and the library is
now fully functional in most cases. There are a couple issues that need
remain to be addressed:

1) Since the hotplug thread can only receive notifications for registered
device interfaces, trouble arises with composite devices. If there is no
driver installed on any one of its interfaces, the interface path can't be
found when the device is enumerated. If the driver for any interface is
installed after the device has been enumerated, the hotplug thread will not
receive any notifications of this. The solution may be a just-in-time
approach where the interface path isn't searched for until the interface is
attempted to be used.
2) The bus numbering scheme is and always has been flaky in the Windows
backend. The bus number was previously derived from the position of the
host controller in the devinfo set. The order in which Windows will provide
the host controllers in this set is unknown, and add/removing host
controllers will obviously change this set. For example, let's say a system
has three host controllers, and let's say there are two libsusb contexts, A
and B. Two host controllers are functional, and one is missing a driver.
Context A is initialized and enumerates the hubs and find the two busses.
Now let's say the driver for the host controller is installed. Context B is
now initialized, and it enumerates the hubs and finds three busses. Windows
may present this host controller at index 0, 1, or 2 in the devinfo set.
Therefore the same devices on bus number 1 in context A may not be on the
same bus number in context B. The bus number is simply a book-keeping
thing, but it would be useful to ensure consistency. I have a potential
solution for this.

Chris


On Fri, Oct 11, 2013 at 7:58 PM, Manuel Francisco Naranjo <
@photron <https://github.com/photron> You are right good catch, I will
implement it that way then. I will look into clock code and re-use it's
design pattern.
—
Reply to this email directly or view it on GitHub<https://github.com/libusbx/libusbx/issues/9#issuecomment-26189632>
.
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
https://lists.sourceforge.net/lists/listinfo/libusbx-devel
mcuee
2014-01-17 07:40:02 UTC
Permalink
@Chirs: Nice. Where do you keep you code?

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-32585532
Chris Dickens
2014-01-22 10:27:12 UTC
Permalink
Sorry for the delayed reply. Been battling some harsh illness in my
household.

You can find my code here:
https://github.com/dickens/libusbx-hp/tree/windows-hotplug-3
@Chirs <https://github.com/Chirs>: Nice. Where do you keep you code?
—
Reply to this email directly or view it on GitHub<https://github.com/libusbx/libusbx/issues/9#issuecomment-32585532>
.
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
libusbx-devel mailing list
https://lists.sourceforge.net/lists/listinfo/libusbx-devel
user83
2014-07-02 21:07:39 UTC
Permalink
What is the current state of hotplug/unplug support on windows? Is there any idea when it might be moved into the main branch (or whatever its called)? I am not familiar with the libusb code base, but if there is anything I could do to help (testing or whatever) it would be worth me putting a few days into this to get it working soon. Thanks

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-47836830
Pete Batard
2014-07-03 21:35:46 UTC
Permalink
Hi,

The status, really, is that the libusb Windows backend is in need of a new maintainer.

As the hopefully soon to be ex-libusb Windows backend maintainer, I've been wanting to look into this and other things for about a year now... However, doing proper review and testing requires time (more than a few days as far as I'm concerned), which is difficult to prioritize right now.

Now, the reasoning behind libusb having lower priority than some of the other FLOSS projects I am involved with, is that, as opposed to those, with, libusb is aimed at developers and as a consequence I expect that, if a group of developers is inconvenienced enough, one of them will rise to the challenge and take matter in their own hands. This is pretty much what happened in the past.

TL;DR: Maintainers of FLOSS projects such as libusb rarely have the luxury of spending their full time on a single project and have to choose their battles. The result of which is that work doesn't get done...

Regards,

/Pete

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-47987579
Chris Dickens
2014-07-06 04:31:30 UTC
Permalink
Hi,

If this is a matter of stepping up and volunteering, I would be more than
willing to. I've been using libusb with my hotplug implementation on
Windows for over 6 months now. It's on a cross-platform utility in which
hotplug functionality is the single most important feature, where multiple
devices are expected to come and go and triggering off this event is
crucial.

I'm happy to help with libusb in any way I can, and right now I have the
time to dedicate to it.

Regards,
Chris
Post by Pete Batard
Hi,
The status, really, is that the libusb Windows backend is in need of a new maintainer.
As the hopefully soon to be ex-libusb Windows backend maintainer, I've
been wanting to look into this and other things for about a year now...
However, doing proper review and testing requires time (more than a few
days as far as I'm concerned), which is difficult to prioritize right now.
Now, the reasoning behind libusb having lower priority than some of the
other FLOSS projects I am involved with, is that, as opposed to those,
with, libusb is aimed at developers and as a consequence I expect that, if
a group of developers is inconvenienced enough, one of them will rise to
the challenge and take matter in their own hands. This is pretty much what
happened in the past.
TL;DR: Maintainers of FLOSS projects such as libusb rarely have the luxury
of spending their full time on a single project and have to choose their
battles. The result of which is that work doesn't get done...
Regards,
/Pete
—
Reply to this email directly or view it on GitHub
<https://github.com/libusbx/libusbx/issues/9#issuecomment-47987579>.
Pete Batard
2014-07-06 20:18:25 UTC
Permalink
Hi Chris,

No objection from me. ;)

You've been around our lists long enough, have been doing plenty of good work already, and crucially, you indicate that you have some time for it, so if you want the Windows maintainer job, since I'm pretty sure other maintainers will feel the same way I do, consider it yours!

I have now added you to the list of github maintainers for the project, and if you send one of us your SourceForge username, we can also add you to the project there (which is required for file uploads, etc.)

I should also point out that, I'm not planning to drop off the libusb map altogether, so I'll continue to try to help where I can (feel free to drop me an e-mail anytime).
Of course, you have my thanks for volunteering to take the Windows maintenance over!

Regards,

/Pete

---
Reply to this email directly or view it on GitHub:
https://github.com/libusbx/libusbx/issues/9#issuecomment-48125032
Loading...