Add hid_get_path to API resolves #163
This resolves the ability to get the device path from hid_device pointer issue in #163
Add a new hid_get_path function to the API. This adds a new path member to the opaque structure of each hid implementation. The path is dynamically allocated and populated in the respective hid_open_path functions. The function returns a const char pointer to this path string.
- Add path string to each hid_device_ structure in hid.c files
- Add hid_get_path function to hidapi.h and hid.c files
- Add init and free code for dev->path to hid.c files
- Allocate and populate dev->path in hid_open_path in hid.c files
- Add example of hid_get_path usage in test.c
This PR does have a significant caveat:
I don't have the ability to test this on anything other than windows at the moment. The use of char * may not be appropriate on some implementations (I am thinking of linux with UTF-8 capable filesystems). Please let me know if you can test this on other hidapi implementations.
After getting my hands on a linux machine. I can say that the libusb and hidraw implementations also appear to work correctly. The limitation on this may be the fact that this linux machine was set up to be en_US.UTF-8.
TODO: somehow test on a mac
What's on to of my mind - replace calloc + strcpy with strdup
I'll check everything closely a bit later
I'm probably going to spend some more time on this. I think it is possible to postpone initialization of the "path" variable until it is first time called (at least for some backends).
I haven't forgot about this one, but I remember I wanted to perform some kind of optimisation, at least for one of the platforms, before merging it.