kopia lustrzana https://gitlab.com/sane-project/backends
add sanei_usb_exit() function
- create a sanei_usb_exit() function to free allocated resources during use of sanei_usb functions by a backendmerge-requests/1/head
rodzic
caf4614f61
commit
52ba4844ca
|
@ -182,6 +182,13 @@ struct sanei_usb_dev_descriptor
|
||||||
*/
|
*/
|
||||||
extern void sanei_usb_init (void);
|
extern void sanei_usb_init (void);
|
||||||
|
|
||||||
|
/** End sanei_usb use, freeing resources when needed.
|
||||||
|
*
|
||||||
|
* When the use count of sanei_usb reach 0, free resources and end
|
||||||
|
* sanei_usb use.
|
||||||
|
*/
|
||||||
|
extern void sanei_usb_exit (void);
|
||||||
|
|
||||||
/** Search for USB devices.
|
/** Search for USB devices.
|
||||||
*
|
*
|
||||||
* Search USB busses for scanner devices.
|
* Search USB busses for scanner devices.
|
||||||
|
|
|
@ -519,6 +519,53 @@ sanei_usb_init (void)
|
||||||
sanei_usb_scan_devices();
|
sanei_usb_scan_devices();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sanei_usb_exit (void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* check we have really some work to do */
|
||||||
|
if(initialized==0)
|
||||||
|
{
|
||||||
|
DBG (1, "%s: sanei_usb in not initialized!\n", __func__);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* decrement the use count */
|
||||||
|
initialized--;
|
||||||
|
|
||||||
|
/* if we reach 0, free allocated resources */
|
||||||
|
if(initialized==0)
|
||||||
|
{
|
||||||
|
/* free allocated resources */
|
||||||
|
DBG (4, "%s: freeing resources\n", __func__);
|
||||||
|
for (i = 0; i < device_number; i++)
|
||||||
|
{
|
||||||
|
if (devices[i].devname != NULL)
|
||||||
|
{
|
||||||
|
DBG (5, "%s: freeing device %02d\n", __func__, i);
|
||||||
|
free(devices[i].devname);
|
||||||
|
devices[i].devname=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef HAVE_LIBUSB_1_0
|
||||||
|
if (sanei_usb_ctx)
|
||||||
|
{
|
||||||
|
libusb_exit (sanei_usb_ctx);
|
||||||
|
/* reset libusb-1.0 context */
|
||||||
|
sanei_usb_ctx=NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* reset device_number */
|
||||||
|
device_number=0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DBG (4, "%s: not freeing resources since use count is %d\n", __func__, initialized);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_USBCALLS
|
#ifdef HAVE_USBCALLS
|
||||||
/** scan for devices through usbcall method
|
/** scan for devices through usbcall method
|
||||||
* Check for devices using OS/2 USBCALLS Interface
|
* Check for devices using OS/2 USBCALLS Interface
|
||||||
|
|
Ładowanie…
Reference in New Issue