diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-03-23 12:35:19 +0100 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2011-03-23 12:35:19 +0100 |
commit | ff7f2398283f5059e3b8e0149e0582ee7d30ad21 (patch) | |
tree | 598637736b0c8164dabad2c163b01816279f0051 /src/cameras | |
parent | 6c822e1dedff95eeb64733e8ae0f7554b01bcd17 (diff) | |
download | libuca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.tar.gz libuca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.tar.bz2 libuca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.tar.xz libuca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.zip |
Use more flexible error codes
Diffstat (limited to 'src/cameras')
-rw-r--r-- | src/cameras/dummy.c | 11 | ||||
-rw-r--r-- | src/cameras/pco.c | 62 | ||||
-rw-r--r-- | src/cameras/pf.c | 34 |
3 files changed, 54 insertions, 53 deletions
diff --git a/src/cameras/dummy.c b/src/cameras/dummy.c index 0d6c9d1..5bb609a 100644 --- a/src/cameras/dummy.c +++ b/src/cameras/dummy.c @@ -159,8 +159,9 @@ static void *uca_dummy_grab_thread(void *arg) */ static uint32_t uca_dummy_set_property(struct uca_camera *cam, enum uca_property_ids property, void *data) { + uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; if (cam->state == UCA_CAM_RECORDING) - return UCA_ERR_PROP_CAMERA_RECORDING; + return err | UCA_ERR_IS_RECORDING; switch (property) { case UCA_PROP_WIDTH: @@ -176,7 +177,7 @@ static uint32_t uca_dummy_set_property(struct uca_camera *cam, enum uca_property break; default: - return UCA_ERR_PROP_INVALID; + return err | UCA_ERR_INVALID; } return UCA_NO_ERROR; @@ -218,7 +219,7 @@ static uint32_t uca_dummy_get_property(struct uca_camera *cam, enum uca_property break; default: - return UCA_ERR_PROP_INVALID; + return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; } return UCA_NO_ERROR; } @@ -258,7 +259,7 @@ uint32_t uca_dummy_register_callback(struct uca_camera *cam, uca_cam_grab_callba cam->callback_user = user; } else - return UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED; + return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; return UCA_NO_ERROR; } @@ -266,7 +267,7 @@ uint32_t uca_dummy_register_callback(struct uca_camera *cam, uca_cam_grab_callba uint32_t uca_dummy_grab(struct uca_camera *cam, char *buffer, void *meta_data) { if (cam->callback != NULL) - return UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED; + return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; uca_dummy_memcpy(cam, buffer); cam->current_frame++; diff --git a/src/cameras/pco.c b/src/cameras/pco.c index 1cad698..1b9c8b8 100644 --- a/src/cameras/pco.c +++ b/src/cameras/pco.c @@ -14,21 +14,23 @@ static uint32_t uca_pco_set_exposure(struct uca_camera *cam, uint32_t *exposure) { + uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; uint32_t e, d; if (pco_get_delay_exposure(GET_PCO(cam), &d, &e) != PCO_NOERROR) - return UCA_ERR_PROP_GENERAL; + return err | UCA_ERR_INVALID; if (pco_set_delay_exposure(GET_PCO(cam), d, *exposure) != PCO_NOERROR) - return UCA_ERR_PROP_GENERAL; + return err | UCA_ERR_INVALID; return UCA_NO_ERROR; } static uint32_t uca_pco_set_delay(struct uca_camera *cam, uint32_t *delay) { + uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; uint32_t e, d; if (pco_get_delay_exposure(GET_PCO(cam), &d, &e) != PCO_NOERROR) - return UCA_ERR_PROP_GENERAL; + return err | UCA_ERR_INVALID; if (pco_set_delay_exposure(GET_PCO(cam), *delay, e) != PCO_NOERROR) - return UCA_ERR_PROP_GENERAL; + return err | UCA_ERR_INVALID; return UCA_NO_ERROR; } @@ -42,28 +44,29 @@ static uint32_t uca_pco_destroy(struct uca_camera *cam) static uint32_t uca_pco_set_property(struct uca_camera *cam, enum uca_property_ids property, void *data) { struct uca_grabber *grabber = cam->grabber; + uint32_t err = UCA_ERR_CAMERA | UCA_ERR_PROP; switch (property) { case UCA_PROP_WIDTH: if (grabber->set_property(grabber, UCA_GRABBER_WIDTH, (uint32_t *) data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; cam->frame_width = *((uint32_t *) data); break; case UCA_PROP_HEIGHT: if (grabber->set_property(grabber, UCA_GRABBER_HEIGHT, (uint32_t *) data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; cam->frame_height = *((uint32_t *) data); break; case UCA_PROP_X_OFFSET: if (grabber->set_property(grabber, UCA_GRABBER_OFFSET_X, (uint32_t *) data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; case UCA_PROP_Y_OFFSET: if (grabber->set_property(grabber, UCA_GRABBER_OFFSET_Y, (uint32_t *) data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; case UCA_PROP_EXPOSURE: @@ -77,11 +80,11 @@ static uint32_t uca_pco_set_property(struct uca_camera *cam, enum uca_property_i case UCA_PROP_GRAB_TIMEOUT: if (grabber->set_property(grabber, UCA_GRABBER_TIMEOUT, data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; default: - return UCA_ERR_PROP_INVALID; + return err | UCA_ERR_INVALID; } return UCA_NO_ERROR; } @@ -148,20 +151,15 @@ static uint32_t uca_pco_get_property(struct uca_camera *cam, enum uca_property_i break; case UCA_PROP_X_OFFSET: - if (grabber->get_property(grabber, UCA_GRABBER_OFFSET_X, (uint32_t *) data) != UCA_NO_ERROR) - return UCA_ERR_PROP_GENERAL; - break; + return grabber->get_property(grabber, UCA_GRABBER_OFFSET_X, (uint32_t *) data); case UCA_PROP_Y_OFFSET: - if (grabber->get_property(grabber, UCA_GRABBER_OFFSET_Y, (uint32_t *) data) != UCA_NO_ERROR) - return UCA_ERR_PROP_GENERAL; - break; + return grabber->get_property(grabber, UCA_GRABBER_OFFSET_Y, (uint32_t *) data); case UCA_PROP_DELAY: { uint32_t exposure; - if (pco_get_delay_exposure(pco, (uint32_t *) data, &exposure) != PCO_NOERROR) - return UCA_ERR_PROP_INVALID; + return pco_get_delay_exposure(pco, (uint32_t *) data, &exposure); } break; @@ -176,8 +174,7 @@ static uint32_t uca_pco_get_property(struct uca_camera *cam, enum uca_property_i case UCA_PROP_EXPOSURE: { uint32_t delay; - if (pco_get_delay_exposure(pco, &delay, (uint32_t *) data) != PCO_NOERROR) - return UCA_ERR_PROP_INVALID; + return pco_get_delay_exposure(pco, &delay, (uint32_t *) data); } break; @@ -196,31 +193,34 @@ static uint32_t uca_pco_get_property(struct uca_camera *cam, enum uca_property_i case UCA_PROP_GRAB_TIMEOUT: { uint32_t timeout; - cam->grabber->get_property(cam->grabber, UCA_GRABBER_TIMEOUT, &timeout); + uint32_t err = cam->grabber->get_property(cam->grabber, UCA_GRABBER_TIMEOUT, &timeout); + if (err != UCA_NO_ERROR) + return err; set_void(data, uint32_t, timeout); } break; default: - return UCA_ERR_PROP_INVALID; + return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; } return UCA_NO_ERROR; } uint32_t uca_pco_start_recording(struct uca_camera *cam) { + uint32_t err = UCA_ERR_CAMERA | UCA_ERR_INIT; struct pco_edge *pco = GET_PCO(cam); if (pco_arm_camera(pco) != PCO_NOERROR) - return UCA_ERR_CAM_ARM; + return err | UCA_ERR_UNCLASSIFIED; if (pco_set_rec_state(pco, 1) != PCO_NOERROR) - return UCA_ERR_CAM_RECORD; + return err | UCA_ERR_UNCLASSIFIED; return cam->grabber->acquire(cam->grabber, -1); } uint32_t uca_pco_stop_recording(struct uca_camera *cam) { if (pco_set_rec_state(GET_PCO(cam), 0) != PCO_NOERROR) - return UCA_ERR_PROP_GENERAL; + return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_UNCLASSIFIED; return UCA_NO_ERROR; } @@ -240,24 +240,24 @@ uint32_t uca_pco_register_callback(struct uca_camera *cam, uca_cam_grab_callback if (cam->callback == NULL) { cam->callback = callback; cam->callback_user = user; - cam->grabber->register_callback(cam->grabber, callback, NULL, user); - return UCA_NO_ERROR; + return cam->grabber->register_callback(cam->grabber, callback, NULL, user); } - return UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED; + return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; } uint32_t uca_pco_init(struct uca_camera **cam, struct uca_grabber *grabber) { + uint32_t err = UCA_ERR_CAMERA | UCA_ERR_INIT; if (grabber == NULL) - return UCA_ERR_CAM_NOT_FOUND; + return err | UCA_ERR_NOT_FOUND; struct pco_edge *pco = pco_init(); if (pco == NULL) - return UCA_ERR_CAM_NOT_FOUND; + return err | UCA_ERR_NOT_FOUND; if ((pco->serial_ref == NULL) || !pco_is_active(pco)) { pco_destroy(pco); - return UCA_ERR_CAM_NOT_FOUND; + return err | UCA_ERR_NOT_FOUND; } struct uca_camera *uca = uca_cam_new(); diff --git a/src/cameras/pf.c b/src/cameras/pf.c index 0bcf674..4688cd4 100644 --- a/src/cameras/pf.c +++ b/src/cameras/pf.c @@ -54,6 +54,7 @@ static uint32_t uca_pf_set_property(struct uca_camera *cam, enum uca_property_id struct uca_grabber *grabber = cam->grabber; TOKEN token = INVALID_TOKEN; int i = 0; + int err = UCA_ERR_CAMERA | UCA_ERR_PROP; /* Find a valid pf token for the property */ while (uca_to_pf[i].uca_prop != -1) { @@ -64,33 +65,33 @@ static uint32_t uca_pf_set_property(struct uca_camera *cam, enum uca_property_id i++; } if (token == INVALID_TOKEN) - return UCA_ERR_PROP_INVALID; + return err | UCA_ERR_INVALID; PFValue value; switch (property) { case UCA_PROP_WIDTH: if (grabber->set_property(grabber, UCA_GRABBER_WIDTH, data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; if (uca_pf_set_uint32_property(token, data, &cam->frame_width) < 0) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; case UCA_PROP_HEIGHT: if (grabber->set_property(grabber, UCA_GRABBER_HEIGHT, data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; if (uca_pf_set_uint32_property(token, data, &cam->frame_height) < 0) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; case UCA_PROP_X_OFFSET: if (grabber->set_property(grabber, UCA_GRABBER_OFFSET_X, data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; case UCA_PROP_Y_OFFSET: if (grabber->set_property(grabber, UCA_GRABBER_OFFSET_Y, data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; case UCA_PROP_EXPOSURE: @@ -99,16 +100,16 @@ static uint32_t uca_pf_set_property(struct uca_camera *cam, enum uca_property_id value.type = PF_FLOAT; value.value.f = (float) *((uint32_t *) data) / 1000.0; if (pfDevice_SetProperty(0, token, &value) < 0) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; case UCA_PROP_GRAB_TIMEOUT: if (grabber->set_property(grabber, UCA_GRABBER_TIMEOUT, data) != UCA_NO_ERROR) - return UCA_ERR_PROP_VALUE_OUT_OF_RANGE; + return err | UCA_ERR_OUT_OF_RANGE; break; default: - return UCA_ERR_PROP_INVALID; + return err | UCA_ERR_INVALID; } return UCA_NO_ERROR; } @@ -124,7 +125,7 @@ static uint32_t uca_pf_get_property(struct uca_camera *cam, enum uca_property_id if (uca_to_pf[i].uca_prop == property) { t = pfProperty_ParseName(0, uca_to_pf[i].pf_prop); if (t == INVALID_TOKEN || (pfDevice_GetProperty(0, t, &value) < 0)) - return UCA_ERR_PROP_INVALID; + return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; switch (value.type) { case PF_INT: @@ -171,7 +172,7 @@ static uint32_t uca_pf_get_property(struct uca_camera *cam, enum uca_property_id break; default: - return UCA_ERR_PROP_INVALID; + return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; } return UCA_NO_ERROR; } @@ -192,7 +193,7 @@ uint32_t uca_pf_grab(struct uca_camera *cam, char *buffer, void *metadata) uint32_t err = cam->grabber->grab(cam->grabber, (void **) &frame, &cam->current_frame); if (err != UCA_NO_ERROR) return err; - /* FIXME: choose according to data format */ + memcpy(buffer, frame, cam->frame_width*cam->frame_height); return UCA_NO_ERROR; } @@ -202,10 +203,9 @@ uint32_t uca_pf_register_callback(struct uca_camera *cam, uca_cam_grab_callback if (cam->callback == NULL) { cam->callback = callback; cam->callback_user = user; - cam->grabber->register_callback(cam->grabber, callback, NULL, user); - return UCA_NO_ERROR; + return cam->grabber->register_callback(cam->grabber, callback, NULL, user); } - return UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED; + return UCA_ERR_CAMERA | UCA_ERR_CALLBACK | UCA_ERR_ALREADY_REGISTERED; } static uint32_t uca_pf_destroy(struct uca_camera *cam) @@ -218,7 +218,7 @@ uint32_t uca_pf_init(struct uca_camera **cam, struct uca_grabber *grabber) { int num_ports; if ((grabber == NULL) || (pfPortInit(&num_ports) < 0) || (pfDeviceOpen(0) < 0)) - return UCA_ERR_CAM_NOT_FOUND; + return UCA_ERR_CAMERA | UCA_ERR_INIT | UCA_ERR_NOT_FOUND; /* We could check if a higher baud rate is supported, but... forget about * it. We don't need high speed configuration. */ |