libfxlink: return status from fxlink_device_start_bulk_{IN,OUT}

This commit is contained in:
Lephenixnoir 2023-03-27 19:47:08 +02:00
parent 1573db3860
commit 1251ca23ee
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
2 changed files with 14 additions and 11 deletions

View File

@ -438,15 +438,15 @@ static void bulk_IN_callback(struct libusb_transfer *transfer)
}
}
void fxlink_device_start_bulk_IN(struct fxlink_device *fdev)
bool fxlink_device_start_bulk_IN(struct fxlink_device *fdev)
{
if(!fdev->comm || !fdev->comm->claimed || fdev->comm->tr_bulk_IN)
return;
return false;
fdev->comm->tr_bulk_IN = libusb_alloc_transfer(0);
if(!fdev->comm->tr_bulk_IN) {
elog("allocation of bulk IN transfer failed\n");
return;
return false;
}
libusb_fill_bulk_transfer(fdev->comm->tr_bulk_IN,
@ -462,11 +462,12 @@ void fxlink_device_start_bulk_IN(struct fxlink_device *fdev)
if(rc < 0) {
elog_libusb(rc, "bulk IN transfer failed to submit");
fdev->status = FXLINK_FDEV_STATUS_ERROR;
return;
return false;
}
// hlog("calculators %s", fxlink_device_id(fdev));
// log_("submitted new IN transfer (no timeout)\n");
return true;
}
struct fxlink_message *fxlink_device_finish_bulk_IN(struct fxlink_device *fdev)
@ -552,26 +553,26 @@ static void bulk_OUT_callback(struct libusb_transfer *transfer)
}
}
void fxlink_device_start_bulk_OUT(struct fxlink_device *fdev,
bool fxlink_device_start_bulk_OUT(struct fxlink_device *fdev,
char const *app, char const *type, void const *data, int size,
bool own_data)
{
struct fxlink_comm *comm = fdev->comm;
if(!comm || !comm->claimed || comm->ftransfer_OUT)
return;
return false;
comm->ftransfer_OUT =
fxlink_transfer_make_OUT(app, type, data, size, own_data);
if(!comm->ftransfer_OUT) {
elog("allocation of OUT transfer (protocol) failed\n");
return;
return false;
}
comm->tr_bulk_OUT = libusb_alloc_transfer(0);
if(!comm->tr_bulk_OUT) {
elog("allocation of bulk OUT transfer (libusb) failed\n");
free(comm->ftransfer_OUT);
return;
return false;
}
libusb_fill_bulk_transfer(comm->tr_bulk_OUT, fdev->dh,
@ -588,8 +589,10 @@ void fxlink_device_start_bulk_OUT(struct fxlink_device *fdev,
if(rc < 0) {
elog_libusb(rc, "bulk OUT transfer failed to submit");
fdev->status = FXLINK_FDEV_STATUS_ERROR;
return;
return false;
}
return true;
}
//---

View File

@ -201,7 +201,7 @@ bool fxlink_device_claim_fxlink(struct fxlink_device *fdev);
/* Start an IN transfer on the device if none is currently running, so that the
device structure is always ready to receive data from the calculator. */
void fxlink_device_start_bulk_IN(struct fxlink_device *fdev);
bool fxlink_device_start_bulk_IN(struct fxlink_device *fdev);
/* Finish an IN transfer and obtain the completed message. This function should
be checked every frame as it will return a non-NULL pointer as soon as the
@ -212,7 +212,7 @@ struct fxlink_message *fxlink_device_finish_bulk_IN(
/* Start an OUT transfer on the device. If `own_data` is set, the transfer will
free(data) when it completes. */
void fxlink_device_start_bulk_OUT(struct fxlink_device *fdev,
bool fxlink_device_start_bulk_OUT(struct fxlink_device *fdev,
char const *app, char const *type, void const *data, int size,
bool own_data);