aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Walleij <triad@df.lth.se>2007-09-16 19:49:48 +0000
committerLinus Walleij <triad@df.lth.se>2007-09-16 19:49:48 +0000
commitff01cb1638a3dab0be15a2012ab4f895ab615d3e (patch)
treee04628c5ce746292d0582ca03cccece98fe916ba /src
parentd7bcab5dec1ab5f4601618f20089061d65bda891 (diff)
downloadlibmtp-ff01cb1638a3dab0be15a2012ab4f895ab615d3e.tar.gz
Better transaction cancel code structure (bringing upstream)
Diffstat (limited to 'src')
-rw-r--r--src/libusb-glue.c34
-rw-r--r--src/ptp.c26
-rw-r--r--src/ptp.h3
3 files changed, 32 insertions, 31 deletions
diff --git a/src/libusb-glue.c b/src/libusb-glue.c
index 0bb99e4..167a3eb 100644
--- a/src/libusb-glue.c
+++ b/src/libusb-glue.c
@@ -930,10 +930,6 @@ ptp_read_func (
ptp_usb->current_transfer_total,
ptp_usb->current_transfer_callback_data);
if (ret != 0) {
- uint16_t sub_ret = ptp_usb_control_cancel_request (ptp_usb->params, ptp_usb->params->transaction_id);
- if (sub_ret != PTP_RC_OK) {
- return sub_ret;
- }
return PTP_ERROR_CANCEL;
}
}
@@ -1022,10 +1018,6 @@ ptp_write_func (
ptp_usb->current_transfer_total,
ptp_usb->current_transfer_callback_data);
if (ret != 0) {
- uint16_t sub_ret = ptp_usb_control_cancel_request (ptp_usb->params, ptp_usb->params->transaction_id);
- if (sub_ret != PTP_RC_OK) {
- return sub_ret;
- }
return PTP_ERROR_CANCEL;
}
}
@@ -1180,13 +1172,10 @@ ptp_usb_sendreq (PTPParams* params, PTPContainer* req)
&written
);
ptp_exit_send_memory_handler (&memhandler);
- if (ret!=PTP_RC_OK) {
+ if (ret!=PTP_RC_OK && ret!=PTP_ERROR_CANCEL) {
ret = PTP_ERROR_IO;
-/* ptp_error (params,
- "PTP: request code 0x%04x sending req error 0x%04x",
- req->Code,ret); */
}
- if (written != towrite) {
+ if (written != towrite && ret != PTP_ERROR_CANCEL) {
ptp_error (params,
"PTP: request code 0x%04x sending req wrote only %ld bytes instead of %d",
req->Code, written, towrite
@@ -1235,10 +1224,6 @@ ptp_usb_senddata (PTPParams* params, PTPContainer* ptp,
ret = ptp_write_func(wlen, &memhandler, params->data, &written);
ptp_exit_send_memory_handler (&memhandler);
if (ret!=PTP_RC_OK) {
- ret = PTP_ERROR_IO;
-/* ptp_error (params,
- "PTP: request code 0x%04x sending data error 0x%04x",
- ptp->Code,ret);*/
return ret;
}
if (size <= datawlen) return ret;
@@ -1255,7 +1240,7 @@ ptp_usb_senddata (PTPParams* params, PTPContainer* ptp,
}
bytes_left_to_transfer -= written;
}
- if (ret!=PTP_RC_OK)
+ if (ret!=PTP_RC_OK && ret!=PTP_ERROR_CANCEL)
ret = PTP_ERROR_IO;
return ret;
}
@@ -1325,8 +1310,8 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
&readdata,
0
);
- if (xret == -1)
- return PTP_ERROR_IO;
+ if (xret != PTP_RC_OK)
+ return ret;
if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ)
break;
}
@@ -1415,16 +1400,9 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
params->data, &rlen, 1);
if (ret!=PTP_RC_OK) {
- ret = PTP_ERROR_IO;
break;
}
} while (0);
- /*
- if (ret!=PTP_RC_OK) {
- ptp_error (params,
- "PTP: request code 0x%04x getting data error 0x%04x",
- ptp->Code, ret);
- }*/
return ret;
}
@@ -1543,6 +1521,7 @@ ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) {
int ret;
unsigned char buffer[6];
+ printf("Request cancel of transaction %d\n", transactionid);
htod16a(&buffer[0],PTP_EC_CancelTransaction);
htod32a(&buffer[2],transactionid);
ret = usb_control_msg(ptp_usb->handle,
@@ -1563,6 +1542,7 @@ static int init_ptp_usb (PTPParams* params, PTP_USB* ptp_usb, struct usb_device*
params->senddata_func=ptp_usb_senddata;
params->getresp_func=ptp_usb_getresp;
params->getdata_func=ptp_usb_getdata;
+ params->cancelreq_func=ptp_usb_control_cancel_request;
params->data=ptp_usb;
params->transaction_id=0;
/*
diff --git a/src/ptp.c b/src/ptp.c
index 316e156..2eb3ae0 100644
--- a/src/ptp.c
+++ b/src/ptp.c
@@ -49,7 +49,7 @@
# define N_(String) (String)
#endif
-#define CHECK_PTP_RC(result) {uint16_t r=(result); if (r!=PTP_RC_OK && r!=PTP_ERROR_CANCEL) return r;}
+#define CHECK_PTP_RC(result) {uint16_t r=(result); if (r!=PTP_RC_OK) return r;}
#define PTP_CNT_INIT(cnt) {memset(&cnt,0,sizeof(cnt));}
@@ -147,11 +147,29 @@ ptp_transaction_new (PTPParams* params, PTPContainer* ptp,
/* is there a dataphase? */
switch (flags&PTP_DP_DATA_MASK) {
case PTP_DP_SENDDATA:
- CHECK_PTP_RC(params->senddata_func(params, ptp,
- sendlen, handler));
+ {
+ uint16_t ret;
+ ret = params->senddata_func(params, ptp,
+ sendlen, handler);
+ if (ret == PTP_ERROR_CANCEL) {
+ ret = params->cancelreq_func(params,
+ params->transaction_id-1);
+ }
+ if (ret != PTP_RC_OK)
+ return ret;
+ }
break;
case PTP_DP_GETDATA:
- CHECK_PTP_RC(params->getdata_func(params, ptp, handler));
+ {
+ uint16_t ret;
+ ret = params->getdata_func(params, ptp, handler);
+ if (ret == PTP_ERROR_CANCEL) {
+ ret = params->cancelreq_func(params,
+ params->transaction_id-1);
+ }
+ if (ret != PTP_RC_OK)
+ return ret;
+ }
break;
case PTP_DP_NODATA:
break;
diff --git a/src/ptp.h b/src/ptp.h
index 0cabce6..ce34590 100644
--- a/src/ptp.h
+++ b/src/ptp.h
@@ -1473,6 +1473,8 @@ typedef uint16_t (* PTPIOSendData) (PTPParams* params, PTPContainer* ptp,
typedef uint16_t (* PTPIOGetResp) (PTPParams* params, PTPContainer* resp);
typedef uint16_t (* PTPIOGetData) (PTPParams* params, PTPContainer* ptp,
PTPDataHandler *putter);
+typedef uint16_t (* PTPIOCancelReq) (PTPParams* params, uint32_t transaction_id);
+
/* debug functions */
typedef void (* PTPErrorFunc) (void *data, const char *format, va_list args)
#if (__GNUC__ >= 3)
@@ -1497,6 +1499,7 @@ struct _PTPParams {
PTPIOGetData getdata_func;
PTPIOGetResp event_check;
PTPIOGetResp event_wait;
+ PTPIOCancelReq cancelreq_func;
/* Custom error and debug function */
PTPErrorFunc error_func;