/alps/ipecamera

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to event.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-12-12 04:45:35 UTC
  • Revision ID: csa@dside.dyndns.org-20111212044535-6no1q7g230i8uvlv
multithread preprocessing of ipecamera frames and code reorganization

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
pcilib_event_t pcilib_find_event(pcilib_t *ctx, const char *event) {
31
31
    int i;
32
 
    pcilib_register_bank_t res;
33
 
    unsigned long addr;
34
 
    
 
32
 
35
33
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
36
34
    pcilib_event_description_t *events = model_info->events;
37
 
    
 
35
 
38
36
    for (i = 0; events[i].name; i++) {
39
37
        if (!strcasecmp(events[i].name, event)) return events[i].evid;
40
38
    }
44
42
 
45
43
pcilib_event_data_type_t pcilib_find_event_data_type(pcilib_t *ctx, pcilib_event_t event, const char *data_type) {
46
44
    int i;
47
 
    pcilib_register_bank_t res;
48
 
    unsigned long addr;
49
45
    
50
46
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
51
47
    pcilib_event_data_type_description_t *data_types = model_info->data_types;
193
189
}
194
190
*/
195
191
 
196
 
int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, pcilib_event_info_t **info) {
197
 
    int err;
 
192
int pcilib_get_next_event(pcilib_t *ctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, size_t info_size, pcilib_event_info_t *info) {
198
193
    pcilib_event_api_description_t *api;
199
194
//    pcilib_return_event_callback_context_t user;
200
195
    
207
202
    }
208
203
 
209
204
    if (api->next_event) 
210
 
        return api->next_event(ctx->event_ctx, timeout, evid, info);
 
205
        return api->next_event(ctx->event_ctx, timeout, evid, info_size, info);
211
206
 
212
207
/*      
213
208
    if (api->stream) {
245
240
 
246
241
 
247
242
void *pcilib_get_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t *size) {
 
243
    int err;
 
244
    void *res = NULL;
248
245
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
249
246
 
250
247
    pcilib_event_api_description_t *api = model_info->event_api;
251
248
    if (!api) {
 
249
        if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED;
252
250
        pcilib_error("Event API is not supported by the selected model");
253
251
        return NULL;
254
252
    }
255
253
 
256
 
    if (api->get_data) 
257
 
        return api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, size, NULL);
258
 
 
 
254
    if (api->get_data) {
 
255
        err = api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, size, &res);
 
256
        if (err) {
 
257
            if (size) *size = (size_t)err;
 
258
            return NULL;
 
259
        }
 
260
        return res;
 
261
    }
 
262
    
 
263
    if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED;
259
264
    return NULL;
260
265
}
261
266
 
262
267
int pcilib_copy_data_with_argument(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t arg_size, void *arg, size_t size, void *buf, size_t *retsize) {
263
 
    void *res;
 
268
    int err;
 
269
    void *res = buf;
264
270
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
265
271
 
266
272
    pcilib_event_api_description_t *api = model_info->event_api;
270
276
    }
271
277
 
272
278
    if (api->get_data) {
273
 
        res = api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, &size, buf);
274
 
        if (!res) return PCILIB_ERROR_FAILED;
 
279
        err = api->get_data(ctx->event_ctx, event_id, data_type, arg_size, arg, &size, &res);
 
280
        if (err) return err;
 
281
        
 
282
        if (buf != res) memcpy(buf, res, size);
275
283
        
276
284
        if (retsize) *retsize = size;
277
285
        return 0;
282
290
 
283
291
 
284
292
void *pcilib_get_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t *size) {
 
293
    int err;
 
294
    void *res = NULL;
285
295
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
286
296
 
287
297
    pcilib_event_api_description_t *api = model_info->event_api;
288
298
    if (!api) {
289
299
        pcilib_error("Event API is not supported by the selected model");
 
300
        if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED;
290
301
        return NULL;
291
302
    }
292
303
 
293
 
    if (api->get_data) 
294
 
        return api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, size, NULL);
 
304
    if (api->get_data) {
 
305
        err = api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, size, &res);
 
306
        if (err) {
 
307
            if (size) *size = (size_t)err;
 
308
            return NULL;
 
309
        }
 
310
        return res;
 
311
    }
295
312
 
 
313
    if (size) *size = (size_t)PCILIB_ERROR_NOTSUPPORTED;
296
314
    return NULL;
297
315
}
298
316
 
299
317
int pcilib_copy_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t size, void *buf, size_t *ret_size) {
300
 
    void *res;
 
318
    int err;
 
319
    void *res = buf;
301
320
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
302
321
 
303
322
    pcilib_event_api_description_t *api = model_info->event_api;
307
326
    }
308
327
 
309
328
    if (api->get_data) {
310
 
        res = api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, &size, buf);
311
 
        if (!res) return PCILIB_ERROR_FAILED;
 
329
        err = api->get_data(ctx->event_ctx, event_id, data_type, 0, NULL, &size, &res);
 
330
        if (err) return err;
312
331
        
 
332
        if (buf != res) memcpy(buf, res, size);
 
333
 
313
334
        if (ret_size) *ret_size = size;
314
335
        return 0;
315
336
    }
317
338
    return PCILIB_ERROR_NOTSUPPORTED;
318
339
}
319
340
 
320
 
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, void *data) {
 
341
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, void *data) {
321
342
    pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
322
343
    
323
344
    pcilib_event_api_description_t *api = model_info->event_api;
327
348
    }
328
349
 
329
350
    if (api->return_data) 
330
 
        return api->return_data(ctx->event_ctx, event_id, data);
 
351
        return api->return_data(ctx->event_ctx, event_id, data_type, data);
331
352
 
332
353
    return 0;
333
354
}
352
373
    data = pcilib_get_data(user->ctx, event_id, PCILIB_EVENT_DATA, &size);
353
374
    if (!data) {
354
375
        pcilib_error("Error getting event data");
355
 
        return PCILIB_ERROR_FAILED;
 
376
        return -(int)size;
356
377
    }
357
378
    
358
379
    if (*(user->data)) {
359
380
        if ((user->size)&&(*(user->size) < size)) {
360
381
            pcilib_error("The supplied buffer does not have enough space to hold the event data. Buffer size is %z, but %z is required", user->size, size);
361
 
            return PCILIB_ERROR_MEMORY;
 
382
            return -PCILIB_ERROR_MEMORY;
362
383
        }
363
384
 
364
385
        *(user->size) = size;
366
387
        *(user->data) = malloc(size);
367
388
        if (!*(user->data)) {
368
389
            pcilib_error("Memory allocation (%i bytes) for event data is failed");
369
 
            return PCILIB_ERROR_MEMORY;
 
390
            return -PCILIB_ERROR_MEMORY;
370
391
        }
371
392
        if (*(user->size)) *(user->size) = size;
372
393
        allocated = 1;
374
395
    
375
396
    memcpy(*(user->data), data, size);
376
397
    
377
 
    err = pcilib_return_data(user->ctx, event_id, data);
 
398
    err = pcilib_return_data(user->ctx, event_id, PCILIB_EVENT_DATA, data);
378
399
    if (err) {
379
400
        if (allocated) {
380
401
            free(*(user->data));
381
402
            *(user->data) = NULL;
382
403
        }
383
404
        pcilib_error("The event data had been overwritten before it was returned, data corruption may occur");
384
 
        return err;
 
405
        return -err;
385
406
    }
386
407
    
387
 
    return 0;
 
408
    return PCILIB_STREAMING_CONTINUE;
388
409
}
389
410
 
390
411
int pcilib_grab(pcilib_t *ctx, pcilib_event_t event_mask, size_t *size, void **data, pcilib_timeout_t timeout) {
391
412
    int err;
392
 
    struct timespec ts;
393
413
    pcilib_event_id_t eid;
394
414
    
395
415
    pcilib_grab_callback_user_data_t user = {ctx, size, data};
397
417
    err = pcilib_start(ctx, event_mask, PCILIB_EVENT_FLAGS_DEFAULT);
398
418
    if (!err) err = pcilib_trigger(ctx, event_mask, 0, NULL);
399
419
    if (!err) {
400
 
        err = pcilib_get_next_event(ctx, timeout, &eid, NULL);
 
420
        err = pcilib_get_next_event(ctx, timeout, &eid, 0, NULL);
401
421
        if (!err) pcilib_grab_callback(event_mask, eid, &user);
402
422
    }
403
423
    pcilib_stop(ctx, PCILIB_EVENT_FLAGS_DEFAULT);