From: Axel Waggershauser <awagger@web.de>

I added a LOG_ON_PTP_E mechanism similar to the LOG_ON_LIBUSB_E one.
This further increases consistency in error reporting in places where
the C_PTP_... macros could not be used. I used the macro mainly where
there have been existing checks for != PTP_RC_OK. There might be a lot
other, yet unchecked places, where this macro could be useful.

I also tuned some of the error/debug messages with the same goal (like
replacing '%x' with '%04x' in the C_PTP_ macros) or adding the
ptp_strerror where appropriate.

Please note, that both the 'inline' and the 'static' keyword in front
of the log_on_ptp_error_helper() function definition are of use here,
to make the compiler not warn about unused functions or functions
without prototype.



git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@15104 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Marcus Meissner
2014-07-22 21:08:27 +00:00
parent b06e5d1216
commit 4c8aad8d62
3 changed files with 62 additions and 77 deletions

View File

@@ -218,7 +218,7 @@ camera_prepare_canon_powershot_capture(Camera *camera, GPContext *context) {
return GP_OK;
}
if (ret != PTP_RC_OK) {
GP_LOG_D ("shooting mode resulted in 0x%04x.", ret);
GP_LOG_E ("'ptp_canon_startshootingmode (params)' failed: 0x%04x", ret);
C_PTP_REP (ret);
}
gp_port_get_timeout (camera->port, &oldtimeout);
@@ -406,7 +406,6 @@ camera_prepare_capture (Camera *camera, GPContext *context)
static int
camera_unprepare_canon_powershot_capture(Camera *camera, GPContext *context) {
uint16_t ret;
PTPParams *params = &camera->pl->params;
C_PTP (ptp_canon_endshootingmode (params));
@@ -414,9 +413,7 @@ camera_unprepare_canon_powershot_capture(Camera *camera, GPContext *context) {
if (ptp_operation_issupported(params, PTP_OC_CANON_ViewfinderOff)) {
if (params->canon_viewfinder_on) {
params->canon_viewfinder_on = 0;
ret = ptp_canon_viewfinderoff (params);
if (ret != PTP_RC_OK)
GP_LOG_E ("Canon disable viewfinder failed: %d", ret);
LOG_ON_PTP_E (ptp_canon_viewfinderoff (params));
/* ignore errors here */
}
}
@@ -2153,10 +2150,7 @@ _put_Canon_CameraOutput(CONFIG_PUT_ARGS) {
if ((u==1) || (u==2)) {
if (ptp_operation_issupported(params, PTP_OC_CANON_ViewfinderOn)) {
if (!params->canon_viewfinder_on) {
uint16_t ret = ptp_canon_viewfinderon (params);
if (ret != PTP_RC_OK)
GP_LOG_E ("Canon enable viewfinder failed: %d", ret);
else
if (LOG_ON_PTP_E (ptp_canon_viewfinderon (params)) == PTP_RC_OK);
params->canon_viewfinder_on=1;
}
}
@@ -2164,10 +2158,7 @@ _put_Canon_CameraOutput(CONFIG_PUT_ARGS) {
if (u==3) {
if (ptp_operation_issupported(params, PTP_OC_CANON_ViewfinderOff)) {
if (params->canon_viewfinder_on) {
uint16_t ret = ptp_canon_viewfinderoff (params);
if (ret != PTP_RC_OK)
GP_LOG_E ("Canon disable viewfinder failed: %d", ret);
else
if (LOG_ON_PTP_E (ptp_canon_viewfinderoff (params)) == PTP_RC_OK)
params->canon_viewfinder_on=0;
}
}
@@ -4693,20 +4684,17 @@ _put_Nikon_MFDrive(CONFIG_PUT_ARGS) {
flag = 0x2;
}
if (!xval) xval = 1;
ret = ptp_nikon_mfdrive (&camera->pl->params, flag, xval);
ret = LOG_ON_PTP_E (ptp_nikon_mfdrive (&camera->pl->params, flag, xval));
if (ret == PTP_RC_NIKON_NotLiveView) {
gp_context_error (context, _("Nikon manual focus works only in LiveView mode."));
return GP_ERROR;
}
if (ret != PTP_RC_OK) {
GP_LOG_D ("Nikon manual focus drive failed: 0x%x", ret);
return translate_ptp_result (ret);
}
if (ret != PTP_RC_OK)
return translate_ptp_result(ret);
/* The mf drive operation has started ... wait for it to
* finish. */
ret = nikon_wait_busy (&camera->pl->params, 20, 1000);
ret = LOG_ON_PTP_E (nikon_wait_busy (&camera->pl->params, 20, 1000));
if (ret == PTP_RC_NIKON_MfDriveStepEnd) {
gp_context_error (context, _("Nikon manual focus at limit."));
return GP_ERROR_CAMERA_ERROR;
@@ -5120,14 +5108,12 @@ _put_Canon_EOS_ViewFinder(CONFIG_PUT_ARGS) {
static int
_get_Nikon_ViewFinder(CONFIG_GET_ARGS) {
int val;
uint16_t ret;
PTPPropertyValue value;
PTPParams *params = &(camera->pl->params);
gp_widget_new (GP_WIDGET_TOGGLE, _(menu->label), widget);
gp_widget_set_name (*widget, menu->name);
ret = ptp_getdevicepropvalue (params, PTP_DPC_NIKON_LiveViewStatus, &value, PTP_DTC_UINT8);
if (ret != PTP_RC_OK)
if (LOG_ON_PTP_E (ptp_getdevicepropvalue (params, PTP_DPC_NIKON_LiveViewStatus, &value, PTP_DTC_UINT8) != PTP_RC_OK ))
value.u8 = 0;
val = value.u8 ? 1 : 0;
gp_widget_set_value (*widget, &val);
@@ -5137,7 +5123,6 @@ _get_Nikon_ViewFinder(CONFIG_GET_ARGS) {
static int
_put_Nikon_ViewFinder(CONFIG_PUT_ARGS) {
int val;
uint16_t res;
PTPParams *params = &(camera->pl->params);
GPContext *context = ((PTPData *) params->data)->context;
@@ -5148,24 +5133,17 @@ _put_Nikon_ViewFinder(CONFIG_PUT_ARGS) {
if (val) {
PTPPropertyValue value;
res = ptp_getdevicepropvalue (params, PTP_DPC_NIKON_LiveViewStatus, &value, PTP_DTC_UINT8);
if (res != PTP_RC_OK) {
if (LOG_ON_PTP_E (ptp_getdevicepropvalue (params, PTP_DPC_NIKON_LiveViewStatus, &value, PTP_DTC_UINT8)) != PTP_RC_OK)
value.u8 = 0;
res = PTP_RC_OK;
}
if (!value.u8) {
value.u8 = 1;
res = ptp_setdevicepropvalue (params, PTP_DPC_NIKON_RecordingMedia, &value, PTP_DTC_UINT8);
if (res != PTP_RC_OK)
GP_LOG_D ("set recordingmedia to 1 failed with 0x%04x", res);
LOG_ON_PTP_E (ptp_setdevicepropvalue (params, PTP_DPC_NIKON_RecordingMedia, &value, PTP_DTC_UINT8));
C_PTP_REP_MSG (ptp_nikon_start_liveview (params),
_("Nikon enable liveview failed"));
/* Has to put the mirror up, so takes a bit. */
res = nikon_wait_busy(params, 50, 1000);
C_PTP (nikon_wait_busy(params, 50, 1000));
}
return translate_ptp_result (res);
} else {
if (ptp_operation_issupported(params, PTP_OC_NIKON_EndLiveView))
C_PTP (ptp_nikon_end_liveview (params));
@@ -5262,9 +5240,7 @@ _put_Nikon_Movie(CONFIG_PUT_ARGS)
if (!value.u8) {
value.u8 = 1;
ret = ptp_setdevicepropvalue (params, PTP_DPC_NIKON_RecordingMedia, &value, PTP_DTC_UINT8);
if (ret != PTP_RC_OK)
GP_LOG_D ("set recordingmedia to 1 failed with 0x%04x", ret);
LOG_ON_PTP_E (ptp_setdevicepropvalue (params, PTP_DPC_NIKON_RecordingMedia, &value, PTP_DTC_UINT8));
C_PTP_REP_MSG (ptp_nikon_start_liveview (params),
_("Nikon enable liveview failed"));
C_PTP_REP_MSG (nikon_wait_busy(params, 50, 1000),
@@ -6466,7 +6442,7 @@ camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
continue;
}
if (ret != GP_OK) {
GP_LOG_D ("Failed to parse value of property '%s' / 0x%04x: ret %d", cursub->label, cursub->propid, ret);
GP_LOG_D ("Failed to parse value of property '%s' / 0x%04x: error code %d", cursub->label, cursub->propid, ret);
continue;
}
gp_widget_append (section, widget);
@@ -6481,7 +6457,7 @@ camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
ret = cursub->getfunc (camera, &widget, cursub, &dpd);
ptp_free_devicepropdesc(&dpd);
if (ret != GP_OK) {
GP_LOG_D ("Failed to parse value of property '%s' / 0x%04x: ret %d", cursub->label, cursub->propid, ret);
GP_LOG_D ("Failed to parse value of property '%s' / 0x%04x: error code %d", cursub->label, cursub->propid, ret);
continue;
}
gp_widget_append (section, widget);
@@ -6656,7 +6632,7 @@ int
camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
{
CameraWidget *section, *widget, *subwindow;
uint16_t ret2;
uint16_t ret_ptp;
unsigned int menuno, submenuno;
int ret;
PTPParams *params = &camera->pl->params;
@@ -6730,10 +6706,11 @@ camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
ret = GP_ERROR_NOT_SUPPORTED;
}
if (ret == GP_OK) {
ret2 = ptp_generic_setdevicepropvalue (params, cursub->propid, &propval, cursub->type);
if (ret2 != PTP_RC_OK) {
gp_context_error (context, _("The property '%s' / 0x%04x was not set, PTP errorcode 0x%04x."), _(cursub->label), cursub->propid, ret2);
ret = translate_ptp_result (ret2);
ret_ptp = LOG_ON_PTP_E (ptp_generic_setdevicepropvalue (params, cursub->propid, &propval, cursub->type));
if (ret_ptp != PTP_RC_OK) {
gp_context_error (context, _("The property '%s' / 0x%04x was not set (0x%04x: %s)"),
_(cursub->label), cursub->propid, ret_ptp, _(ptp_strerror(ret, params->deviceinfo.VendorExtensionID)));
ret = translate_ptp_result (ret_ptp);
}
}
ptp_free_devicepropvalue (cursub->type, &propval);
@@ -6751,13 +6728,14 @@ camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
ptp_canon_eos_getdevicepropdesc (params,cursub->propid, &dpd);
ret = cursub->putfunc (camera, widget, &propval, &dpd);
if (ret == GP_OK) {
ret2 = ptp_canon_eos_setdevicepropvalue (params, cursub->propid, &propval, cursub->type);
if (ret2 != PTP_RC_OK) {
gp_context_error (context, _("The property '%s' / 0x%04x was not set, PTP errorcode 0x%04x."), _(cursub->label), cursub->propid, ret2);
ret = translate_ptp_result (ret2);
ret_ptp = LOG_ON_PTP_E (ptp_canon_eos_setdevicepropvalue (params, cursub->propid, &propval, cursub->type));
if (ret_ptp != PTP_RC_OK) {
gp_context_error (context, _("The property '%s' / 0x%04x was not set (0x%04x: %s)."),
_(cursub->label), cursub->propid, ret_ptp, _(ptp_strerror(ret, params->deviceinfo.VendorExtensionID)));
ret = translate_ptp_result (ret_ptp);
}
} else
gp_context_error (context, _("Parsing the value of widget '%s' / 0x%04x failed with %d!"), _(cursub->label), cursub->propid, ret);
gp_context_error (context, _("Parsing the value of widget '%s' / 0x%04x failed with %d."), _(cursub->label), cursub->propid, ret);
ptp_free_devicepropdesc(&dpd);
ptp_free_devicepropvalue(cursub->type, &propval);
}
@@ -6830,9 +6808,12 @@ camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
default:
break;
}
ret = ptp_generic_setdevicepropvalue (params, propid, &propval, dpd.DataType);
/* TODO: ret is ignored here, this is inconsistent with the code above */
ret = LOG_ON_PTP_E (ptp_generic_setdevicepropvalue (params, propid, &propval, dpd.DataType));
if (ret != PTP_RC_OK) {
gp_context_error (context, _("The property '%s' / 0x%04x was not set, PTP errorcode 0x%04x."), _(label), propid, ret);
gp_context_error (context, _("The property '%s' / 0x%04x was not set (0x%04x: %s)."),
_(label), propid, ret, _(ptp_strerror(ret, params->deviceinfo.VendorExtensionID)));
ret = GP_ERROR;
}
}

View File

@@ -379,7 +379,7 @@ fixup_cached_deviceinfo (Camera *camera, PTPDeviceInfo *di) {
C_MEM (di->EventsSupported = realloc(di->EventsSupported, sizeof(di->EventsSupported[0])*(di->EventsSupported_len + events)));
j = 0; k = 0; l = 0;
for (i=0;i<xsize;i++) {
GP_LOG_E ("sony code: %x", xprops[i]);
GP_LOG_D ("sony code: %x", xprops[i]);
switch (xprops[i] & 0x7000) {
case 0x1000:
di->OperationsSupported[(k++)+di->OperationsSupported_len] = xprops[i];
@@ -2235,9 +2235,7 @@ camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
if (!value.u8) {
value.u8 = 1;
ret = ptp_setdevicepropvalue (params, PTP_DPC_NIKON_RecordingMedia, &value, PTP_DTC_UINT8);
if (ret != PTP_RC_OK)
GP_LOG_D ("set recordingmedia to 1 failed with 0x%04x", ret);
LOG_ON_PTP_E (ptp_setdevicepropvalue (params, PTP_DPC_NIKON_RecordingMedia, &value, PTP_DTC_UINT8));
C_PTP_REP_MSG (ptp_nikon_start_liveview (params),
_("Nikon enable liveview failed"));
do {
@@ -2947,9 +2945,7 @@ camera_canon_capture (Camera *camera, CameraCaptureType type, CameraFilePath *pa
free (storageids.Storage);
}
}
ret = ptp_setdevicepropvalue(params, PTP_DPC_CANON_CaptureTransferMode, &propval, PTP_DTC_UINT16);
if (ret != PTP_RC_OK)
GP_LOG_D ("setdevicepropvalue CaptureTransferMode failed, %x", ret);
LOG_ON_PTP_E (ptp_setdevicepropvalue(params, PTP_DPC_CANON_CaptureTransferMode, &propval, PTP_DTC_UINT16));
}
if (params->canon_viewfinder_on) { /* disable during capture ... reenable later on. */
@@ -3589,9 +3585,7 @@ camera_trigger_capture (Camera *camera, GPContext *context)
free (storageids.Storage);
}
}
ret = ptp_setdevicepropvalue(params, PTP_DPC_CANON_CaptureTransferMode, &propval, PTP_DTC_UINT16);
if (ret != PTP_RC_OK)
GP_LOG_D ("setdevicepropvalue CaptureTransferMode failed, %x", ret);
LOG_ON_PTP_E (ptp_setdevicepropvalue(params, PTP_DPC_CANON_CaptureTransferMode, &propval, PTP_DTC_UINT16));
}
if (params->canon_viewfinder_on) { /* disable during capture ... reenable later on. */
@@ -5028,10 +5022,8 @@ ptp_mtp_render_metadata (
gp_file_append (file, propname, n);
gp_file_append (file, ">", 1);
ret = ptp_mtp_getobjectpropdesc (params, props[j], ofc, &opd);
if (ret != PTP_RC_OK) {
fprintf (stderr," getobjectpropdesc returns 0x%x\n", ret);
} else {
ret = LOG_ON_PTP_E (ptp_mtp_getobjectpropdesc (params, props[j], ofc, &opd));
if (ret == PTP_RC_OK) {
PTPPropertyValue pv;
ret = ptp_mtp_getobjectpropvalue (params, object_id, props[j], &pv, opd.DataType);
if (ret != PTP_RC_OK) {
@@ -5134,9 +5126,8 @@ ptp_mtp_parse_metadata (
C_MEM (content = strdup(begin));
*end = '<';
GP_LOG_D ("found tag %s, content %s", propname, content);
ret = ptp_mtp_getobjectpropdesc (params, props[j], ofc, &opd);
ret = LOG_ON_PTP_E (ptp_mtp_getobjectpropdesc (params, props[j], ofc, &opd));
if (ret != PTP_RC_OK) {
GP_LOG_D (" getobjectpropdesc returns 0x%x", ret);
free (content); content = NULL;
continue;
}
@@ -6459,7 +6450,8 @@ ptp_list_folder_eos (PTPParams *params, uint32_t storage, uint32_t handle) {
handle = 0xffffffff;
}
ret = ptp_getstorageids(params, &storageids);
if (ret != PTP_RC_OK) return ret;
if (ret != PTP_RC_OK)
return ret;
} else {
storageids.n = 1;
storageids.Storage = malloc(sizeof(storageids.Storage[0]));
@@ -6469,11 +6461,9 @@ ptp_list_folder_eos (PTPParams *params, uint32_t storage, uint32_t handle) {
for (k=0;k<storageids.n;k++) {
GP_LOG_D ("reading handle %08x directory of 0x%08x", storageids.Storage[k], handle);
ret = ptp_canon_eos_getobjectinfoex (
params, storageids.Storage[k], handle ? handle : 0xffffffff, 0x100000, &tmp, &nroftmp
);
ret = LOG_ON_PTP_E (ptp_canon_eos_getobjectinfoex (
params, storageids.Storage[k], handle ? handle : 0xffffffff, 0x100000, &tmp, &nroftmp));
if (ret != PTP_RC_OK) {
GP_LOG_D ("reading directory failed: %04x", ret);
free (storageids.Storage);
return ret;
}
@@ -6945,6 +6935,7 @@ camera_init (Camera *camera, GPContext *context)
{
PTPStorageIDs storageids;
/* TODO: ret is ignored here */
ret = ptp_getstorageids(params, &storageids);
if (ret == PTP_RC_OK) {
unsigned int k;

View File

@@ -32,11 +32,23 @@ int camera_canon_eos_update_capture_target(Camera *camera, GPContext *context, i
int translate_ptp_result (uint16_t result);
int fixup_cached_deviceinfo (Camera *camera, PTPDeviceInfo*);
inline static int log_on_ptp_error_helper( int _r, const char* _func, const char* file, int line, const char* func, int vendor ) {
if (_r != PTP_RC_OK) {
const char* ptp_err_str = ptp_strerror(_r, vendor);
gp_log_with_source_location(GP_LOG_ERROR, file, line, func,
"'%s' failed: %s (0x%04x)", _func, ptp_err_str, _r);
}
return _r;
}
#define LOG_ON_PTP_E( RESULT ) \
log_on_ptp_error_helper( (RESULT), #RESULT, __FILE__, __LINE__, __func__,\
params->deviceinfo.VendorExtensionID )
#define C_PTP(RESULT) do {\
uint16_t c_ptp_ret = (RESULT);\
if (c_ptp_ret != PTP_RC_OK) {\
const char* ptp_err_str = ptp_strerror(c_ptp_ret, params->deviceinfo.VendorExtensionID);\
GP_LOG_E ("'%s' failed: %s (0x%x)", #RESULT, ptp_err_str, c_ptp_ret);\
GP_LOG_E ("'%s' failed: %s (0x%04x)", #RESULT, ptp_err_str, c_ptp_ret);\
return translate_ptp_result (c_ptp_ret);\
}\
} while(0)
@@ -46,7 +58,7 @@ int fixup_cached_deviceinfo (Camera *camera, PTPDeviceInfo*);
if (c_ptp_msg_ret != PTP_RC_OK) {\
const char* ptp_err_str = ptp_strerror(c_ptp_msg_ret, params->deviceinfo.VendorExtensionID);\
char fmt_str[256];\
snprintf(fmt_str, sizeof(fmt_str), "%s%s%s", "'%s' failed: ", MSG, " (0x%x: %s)");\
snprintf(fmt_str, sizeof(fmt_str), "%s%s%s", "'%s' failed: ", MSG, " (0x%04x: %s)");\
GP_LOG_E (fmt_str, #RESULT, ##__VA_ARGS__, c_ptp_msg_ret, ptp_err_str);\
return translate_ptp_result (c_ptp_msg_ret);\
}\
@@ -56,7 +68,7 @@ int fixup_cached_deviceinfo (Camera *camera, PTPDeviceInfo*);
uint16_t c_ptp_rep_ret = (RESULT);\
if (c_ptp_rep_ret != PTP_RC_OK) {\
const char* ptp_err_str = ptp_strerror(c_ptp_rep_ret, params->deviceinfo.VendorExtensionID);\
GP_LOG_E ("'%s' failed: '%s' (0x%x)", #RESULT, ptp_err_str, c_ptp_rep_ret);\
GP_LOG_E ("'%s' failed: '%s' (0x%04x)", #RESULT, ptp_err_str, c_ptp_rep_ret);\
gp_context_error (context, "%s", dgettext(GETTEXT_PACKAGE, ptp_err_str));\
return translate_ptp_result (c_ptp_rep_ret);\
}\
@@ -67,9 +79,9 @@ int fixup_cached_deviceinfo (Camera *camera, PTPDeviceInfo*);
if (c_ptp_rep_msg_ret != PTP_RC_OK) {\
const char* ptp_err_str = ptp_strerror(c_ptp_rep_msg_ret, params->deviceinfo.VendorExtensionID);\
char fmt_str[256];\
snprintf(fmt_str, sizeof(fmt_str), "%s%s%s", "'%s' failed: ", MSG, " (0x%x: %s)");\
snprintf(fmt_str, sizeof(fmt_str), "%s%s%s", "'%s' failed: ", MSG, " (0x%04x: %s)");\
GP_LOG_E (fmt_str, #RESULT, ##__VA_ARGS__, c_ptp_rep_msg_ret, ptp_err_str);\
snprintf(fmt_str, sizeof(fmt_str), "%s%s", MSG, " (0x%x: %s)");\
snprintf(fmt_str, sizeof(fmt_str), "%s%s", MSG, " (0x%04x: %s)");\
gp_context_error (context, fmt_str, ##__VA_ARGS__, c_ptp_rep_msg_ret, dgettext(GETTEXT_PACKAGE, ptp_err_str));\
return translate_ptp_result (c_ptp_rep_msg_ret);\
}\
@@ -83,6 +95,7 @@ int fixup_cached_deviceinfo (Camera *camera, PTPDeviceInfo*);
}\
} while (0)
struct _CameraPrivateLibrary {
PTPParams params;
int checkevents;