Skip to content

Commit

Permalink
remove code duplication in ptp_check_event
Browse files Browse the repository at this point in the history
  • Loading branch information
axxel authored and msmeissn committed Sep 25, 2024
1 parent 8d4975f commit da7dead
Showing 1 changed file with 22 additions and 42 deletions.
64 changes: 22 additions & 42 deletions camlibs/ptp2/ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3664,53 +3664,33 @@ ptp_check_event (PTPParams *params)
uint16_t ret;

if (params->deviceinfo.VendorExtensionID == PTP_VENDOR_NIKON) {
unsigned int evtcnt = 0, i;
PTPContainer *xevent = NULL;
if (ptp_operation_issupported(params, PTP_OC_NIKON_GetEventEx)) {
unsigned int evtcnt = 0, i;
PTPContainer *xevent = NULL;

ret = ptp_nikon_check_eventex(params, &xevent, &evtcnt);
if (ret != PTP_RC_OperationNotSupported)
CHECK_PTP_RC(ret);

if (evtcnt) {
for (i = 0; i < evtcnt; i++)
handle_event_internal (params, &xevent[i]);
params->events = realloc(params->events, sizeof(PTPContainer)*(evtcnt+params->nrofevents));
memcpy (&params->events[params->nrofevents],xevent,evtcnt*sizeof(PTPContainer));
params->nrofevents += evtcnt;
params->event90c7works = 1;
}
free (xevent);
if (params->event90c7works)
return PTP_RC_OK;
/* fall through to generic event handling */
} else {
} else if (ptp_operation_issupported(params, PTP_OC_NIKON_GetEvent)) {
/* Method offered by Nikon DSLR, Nikon 1, and some older Nikon Coolpix P*
* The Nikon Coolpix P2 however does not return anything. So if we never get
* events from here, use the ptp "interrupt" method */
if (ptp_operation_issupported(params, PTP_OC_NIKON_GetEvent)) {
unsigned int evtcnt = 0, i;
PTPContainer *xevent = NULL;

ret = ptp_nikon_check_event(params, &xevent, &evtcnt);
if (ret != PTP_RC_OperationNotSupported)
CHECK_PTP_RC(ret);

if (evtcnt) {
for (i = 0; i < evtcnt; i++)
handle_event_internal (params, &xevent[i]);
params->events = realloc(params->events, sizeof(PTPContainer)*(evtcnt+params->nrofevents));
memcpy (&params->events[params->nrofevents],xevent,evtcnt*sizeof(PTPContainer));
params->nrofevents += evtcnt;
params->event90c7works = 1;
}
free (xevent);
if (params->event90c7works)
return PTP_RC_OK;
/* fall through to generic event handling */
}
ret = ptp_nikon_check_event(params, &xevent, &evtcnt);
} else {
ret = PTP_RC_OperationNotSupported;
}
if (ret != PTP_RC_OperationNotSupported)
CHECK_PTP_RC(ret);

if (evtcnt) {
ptp_add_events(params, xevent, evtcnt);
for (i = 0; i < evtcnt; i++)
handle_event_internal (params, &xevent[i]);
params->event90c7works = 1;
}
free (xevent);
if (params->event90c7works)
return PTP_RC_OK;
/* fall through to generic event handling */
}

/* should not get here ... EOS has no normal PTP events and another queue handling. */
if ( (params->deviceinfo.VendorExtensionID == PTP_VENDOR_CANON) &&
ptp_operation_issupported(params, PTP_OC_CANON_EOS_GetEvent)
Expand Down Expand Up @@ -3742,6 +3722,8 @@ ptp_check_event (PTPParams *params)
return PTP_RC_OK;
#endif
}

/* check the (USB) interrupt based event queue */
ret = params->event_check(params,&event);

store_event:
Expand All @@ -3750,8 +3732,6 @@ ptp_check_event (PTPParams *params)
ptp_add_event (params, &event);

handle_event_internal (params, &event);


}
if (ret == PTP_ERROR_TIMEOUT) /* ok, just new events */
ret = PTP_RC_OK;
Expand Down

0 comments on commit da7dead

Please sign in to comment.