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 | |
parent | 6c822e1dedff95eeb64733e8ae0f7554b01bcd17 (diff) | |
download | uca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.tar.gz uca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.tar.bz2 uca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.tar.xz uca-ff7f2398283f5059e3b8e0149e0582ee7d30ad21.zip |
Use more flexible error codes
-rw-r--r-- | src/cameras/dummy.c | 11 | ||||
-rw-r--r-- | src/cameras/pco.c | 62 | ||||
-rw-r--r-- | src/cameras/pf.c | 34 | ||||
-rw-r--r-- | src/grabbers/me4.c | 33 | ||||
-rw-r--r-- | src/uca.c | 6 | ||||
-rw-r--r-- | src/uca.h | 53 | ||||
-rw-r--r-- | test/control.c | 2 | ||||
-rw-r--r-- | test/enum.c | 6 |
8 files changed, 116 insertions, 91 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. */ diff --git a/src/grabbers/me4.c b/src/grabbers/me4.c index 6cd72ae..01b908d 100644 --- a/src/grabbers/me4.c +++ b/src/grabbers/me4.c @@ -72,9 +72,10 @@ static struct uca_sisofg_map_t *uca_me4_find_property(enum uca_grabber_constants uint32_t uca_me4_set_property(struct uca_grabber *grabber, enum uca_grabber_constants property, void *data) { + uint32_t err = UCA_ERR_GRABBER | UCA_ERR_PROP; struct uca_sisofg_map_t *fg_prop = uca_me4_find_property(property); if (fg_prop == NULL) - return UCA_ERR_PROP_INVALID; + return err | UCA_ERR_INVALID; switch (property) { case UCA_GRABBER_TIMEOUT: @@ -91,21 +92,25 @@ uint32_t uca_me4_set_property(struct uca_grabber *grabber, enum uca_grabber_cons * the map. */ struct uca_sisofg_map_t *constant = uca_me4_find_property(*((uint32_t *) data)); if (constant != NULL) - return Fg_setParameter(GET_FG(grabber), fg_prop->fg_id, &constant->fg_id, PORT_A) == FG_OK ? UCA_NO_ERROR : UCA_ERR_PROP_INVALID; - return UCA_ERR_PROP_INVALID; + return Fg_setParameter(GET_FG(grabber), fg_prop->fg_id, &constant->fg_id, PORT_A) == FG_OK ? \ + UCA_NO_ERROR : err | UCA_ERR_INVALID; + return err | UCA_ERR_INVALID; } else - return Fg_setParameter(GET_FG(grabber), fg_prop->fg_id, data, PORT_A) == FG_OK ? UCA_NO_ERROR : UCA_ERR_PROP_GENERAL; + return Fg_setParameter(GET_FG(grabber), fg_prop->fg_id, data, PORT_A) == FG_OK ? \ + UCA_NO_ERROR : err | UCA_ERR_INVALID; } uint32_t uca_me4_get_property(struct uca_grabber *grabber, enum uca_grabber_constants property, void *data) { + uint32_t err = UCA_ERR_GRABBER | UCA_ERR_PROP; struct uca_sisofg_map_t *fg_prop = uca_me4_find_property(property); if (fg_prop == NULL) - return UCA_ERR_PROP_INVALID; + return err | UCA_ERR_INVALID; /* FIXME: translate data back to UCA_ normalized constants */ - return Fg_getParameter(GET_FG(grabber), fg_prop->fg_id, data, PORT_A) == FG_OK ? UCA_NO_ERROR : UCA_ERR_PROP_GENERAL; + return Fg_getParameter(GET_FG(grabber), fg_prop->fg_id, data, PORT_A) == FG_OK ? \ + UCA_NO_ERROR : err | UCA_ERR_INVALID; } uint32_t uca_me4_alloc(struct uca_grabber *grabber, uint32_t pixel_size, uint32_t n_buffers) @@ -125,27 +130,27 @@ uint32_t uca_me4_alloc(struct uca_grabber *grabber, uint32_t pixel_size, uint32_ ((struct fg_apc_data *) grabber->user)->mem = mem; return UCA_NO_ERROR; } - return UCA_ERR_PROP_GENERAL; + return UCA_ERR_GRABBER | UCA_ERR_NO_MEMORY; } uint32_t uca_me4_acquire(struct uca_grabber *grabber, int32_t n_frames) { if (GET_MEM(grabber) == NULL) - return UCA_ERR_GRABBER_NOMEM; + return UCA_ERR_GRABBER | UCA_ERR_NO_MEMORY; int flag = grabber->asynchronous ? ACQ_STANDARD : ACQ_BLOCK; n_frames = n_frames < 0 ? GRAB_INFINITE : n_frames; if (Fg_AcquireEx(GET_FG(grabber), 0, n_frames, flag, GET_MEM(grabber)) == FG_OK) return UCA_NO_ERROR; - return UCA_ERR_GRABBER_ACQUIRE; + return UCA_ERR_GRABBER | UCA_ERR_ACQUIRE; } uint32_t uca_me4_stop_acquire(struct uca_grabber *grabber) { if (GET_MEM(grabber) != NULL) if (Fg_stopAcquireEx(GET_FG(grabber), 0, GET_MEM(grabber), STOP_SYNC) != FG_OK) - return UCA_ERR_PROP_GENERAL; + return UCA_ERR_GRABBER | UCA_ERR_ACQUIRE; return UCA_NO_ERROR; } @@ -160,7 +165,7 @@ uint32_t uca_me4_grab(struct uca_grabber *grabber, void **buffer, uint64_t *fram last_frame = Fg_getLastPicNumberBlockingEx(me4->fg, last_frame+1, PORT_A, me4->timeout, me4->mem); if (last_frame <= 0) - return UCA_ERR_PROP_GENERAL; + return UCA_ERR_GRABBER | UCA_ERR_FRAME_TRANSFER; *frame_number = (uint64_t) last_frame; *buffer = Fg_getImagePtrEx(me4->fg, last_frame, PORT_A, me4->mem); @@ -191,10 +196,10 @@ uint32_t uca_me4_register_callback(struct uca_grabber *grabber, uca_cam_grab_cal ctrl.timeout = 1; if (Fg_registerApcHandler(GET_FG(grabber), PORT_A, &ctrl, FG_APC_CONTROL_BASIC) != FG_OK) - return UCA_ERR_GRABBER_CALLBACK_REGISTRATION_FAILED; + return UCA_ERR_GRABBER | UCA_ERR_CALLBACK; } else - return UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED; + return UCA_ERR_GRABBER | UCA_ERR_CALLBACK; return UCA_NO_ERROR; } @@ -203,7 +208,7 @@ uint32_t uca_me4_init(struct uca_grabber **grabber) { Fg_Struct *fg = Fg_Init("libFullAreaGray8.so", 0); if (fg == NULL) - return UCA_ERR_GRABBER_NOT_FOUND; + return UCA_ERR_GRABBER | UCA_ERR_NOT_FOUND; struct uca_grabber *uca = (struct uca_grabber *) malloc(sizeof(struct uca_grabber)); memset(uca, 0, sizeof(struct uca_grabber)); @@ -138,7 +138,7 @@ struct uca *uca_init(const char *config_filename) while (grabber_inits[i] != NULL) { uca_grabber_init init = grabber_inits[i]; /* FIXME: we don't only want to take the first one */ - if (init(&grabber) != UCA_ERR_GRABBER_NOT_FOUND) + if (init(&grabber) == UCA_NO_ERROR) break; i++; } @@ -159,7 +159,7 @@ struct uca *uca_init(const char *config_filename) while (cam_inits[i] != NULL) { struct uca_camera *cam = NULL; uca_cam_init init = cam_inits[i]; - if (init(&cam, grabber) != UCA_ERR_CAM_NOT_FOUND) { + if (init(&cam, grabber) == UCA_NO_ERROR) { if (current == NULL) g_uca->cameras = current = cam; else { @@ -214,7 +214,7 @@ enum uca_property_ids uca_get_property_id(const char *property_name) return i; i++; } - return UCA_ERR_PROP_INVALID; + return UCA_ERR_CAMERA | UCA_ERR_PROP | UCA_ERR_INVALID; } struct uca_property *uca_get_full_property(enum uca_property_ids property_id) @@ -199,23 +199,42 @@ typedef struct uca_property { extern const char *uca_unit_map[]; /**< maps unit numbers to corresponding strings */ -enum uca_errors { - UCA_NO_ERROR = 0, - UCA_ERR_GRABBER_NOT_FOUND, - UCA_ERR_CAM_NOT_FOUND, /**< camera probing or initialization failed */ - UCA_ERR_PROP_INVALID, /**< the requested property is not supported by the camera */ - UCA_ERR_PROP_GENERAL, /**< error occured reading/writing the property */ - UCA_ERR_PROP_VALUE_OUT_OF_RANGE, /**< error occured writing the property */ - UCA_ERR_PROP_CAMERA_RECORDING, /**< cannot set/get property because camera is recording */ - - UCA_ERR_CAM_ARM, /**< camera is not armed */ - UCA_ERR_CAM_RECORD, /**< could not record */ - - UCA_ERR_GRABBER_ACQUIRE, /**< grabber couldn't acquire a frame */ - UCA_ERR_GRABBER_NOMEM, /**< no memory was allocated using uca_grabber->alloc() */ - UCA_ERR_GRABBER_CALLBACK_REGISTRATION_FAILED, - UCA_ERR_GRABBER_CALLBACK_ALREADY_REGISTERED -}; + +/* + * 16 bits error code + * 4 bits error source + * 4 bits error class + * 4 bits reserved + * 4 bits error level + */ + +#define UCA_NO_ERROR 0x00000000 + +#define UCA_ERR_MASK_CODE 0x0000FFFF +#define UCA_ERR_MASK_SOURCE 0x000F0000 +#define UCA_ERR_MASK_TYPE 0x00F00000 +#define UCA_ERR_MASK_RESRV 0x0F000000 +#define UCA_ERR_MASK_LEVEL 0xF0000000 + +#define UCA_ERR_GRABBER 0x00010000 +#define UCA_ERR_CAMERA 0x00020000 + +#define UCA_ERR_INIT 0x00100000 /**< error during initialization */ +#define UCA_ERR_PROP 0x00200000 /**< error while setting/getting property */ +#define UCA_ERR_CALLBACK 0x00300000 /**< callback-related errors */ + +#define UCA_ERR_FAILURE 0x10000000 +#define UCA_ERR_WARNING 0x20000000 + +#define UCA_ERR_UNCLASSIFIED 0x10000001 +#define UCA_ERR_NOT_FOUND 0x10000002 +#define UCA_ERR_INVALID 0x10000003 +#define UCA_ERR_NO_MEMORY 0x10000004 +#define UCA_ERR_OUT_OF_RANGE 0x10000005 +#define UCA_ERR_ACQUIRE 0x10000006 +#define UCA_ERR_IS_RECORDING 0x10000007 /**< error because device is recording */ +#define UCA_ERR_FRAME_TRANSFER 0x10000008 +#define UCA_ERR_ALREADY_REGISTERED 0x10000009 /** * Keeps a list of cameras and grabbers. diff --git a/test/control.c b/test/control.c index 2d954f9..47c2fab 100644 --- a/test/control.c +++ b/test/control.c @@ -262,7 +262,7 @@ void fill_tree_store(GtkTreeStore *tree_store, struct uca_camera *cam) get_first_level_root(tree_store, &iter, tokens[0]); find_recursively(tree_store, &iter, &child, tokens, 1); - if (result == UCA_ERR_PROP_INVALID) + if (result != UCA_NO_ERROR) g_sprintf(value_string, "n/a"); int count = 0; diff --git a/test/enum.c b/test/enum.c index 954b734..f28bf9b 100644 --- a/test/enum.c +++ b/test/enum.c @@ -42,21 +42,21 @@ int main(int argc, char *argv[]) printf("%s = ", prop->name); switch (prop->type) { case uca_string: - if (cam->get_property(cam, i, string_value, num_bytes) != UCA_ERR_PROP_INVALID) { + if (cam->get_property(cam, i, string_value, num_bytes) == UCA_NO_ERROR) { printf("%s ", string_value); } else printf("n/a"); break; case uca_uint32t: - if (cam->get_property(cam, i, &uint32_value, 0) != UCA_ERR_PROP_INVALID) { + if (cam->get_property(cam, i, &uint32_value, 0) == UCA_NO_ERROR) { printf("%i %s", uint32_value, uca_unit_map[prop->unit]); } else printf("n/a"); break; case uca_uint8t: - if (cam->get_property(cam, i, &uint8_value, 0) != UCA_ERR_PROP_INVALID) { + if (cam->get_property(cam, i, &uint8_value, 0) == UCA_NO_ERROR) { printf("%i %s", uint8_value, uca_unit_map[prop->unit]); } else |