/alps/ipecamera

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/ipecamera

« back to all changes in this revision

Viewing changes to events.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-08-06 01:08:42 UTC
  • Revision ID: csa@suren.me-20150806010842-pdy8up1ro75gcd1a
Use new locking subsystem to ensure integrity

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include "private.h"
20
20
#include "events.h"
21
21
 
 
22
#define LOCK(lock_name) \
 
23
    err = pcilib_lock(ctx->lock_name##_lock); \
 
24
    if (err) { \
 
25
        pcilib_error("IPECamera is busy"); \
 
26
        return PCILIB_ERROR_BUSY; \
 
27
    } \
 
28
    ctx->lock_name##_locked = 1;
 
29
 
 
30
#define UNLOCK(lock_name) \
 
31
    if (ctx->lock_name##_locked) { \
 
32
        pcilib_unlock(ctx->lock_name##_lock); \
 
33
        ctx->lock_name##_locked = 0; \
 
34
    }
 
35
 
22
36
int ipecamera_stream(pcilib_context_t *vctx, pcilib_event_callback_t callback, void *user) {
23
37
    int run_flag = 1;
24
38
    int res, err = 0;
34
48
 
35
49
    ipecamera_debug(API, "ipecamera: start streaming");
36
50
 
 
51
    LOCK(stream);
 
52
 
37
53
    ctx->streaming = 1;
38
54
    ctx->run_streamer = 1;
39
55
 
79
95
 
80
96
    ctx->streaming = 0;
81
97
 
 
98
    UNLOCK(stream);
 
99
 
82
100
    ipecamera_debug(API, "ipecamera: streaming finished");
83
101
 
84
102
    if (do_stop) {
89
107
}
90
108
 
91
109
int ipecamera_next_event(pcilib_context_t *vctx, pcilib_timeout_t timeout, pcilib_event_id_t *evid, size_t info_size, pcilib_event_info_t *info) {
 
110
    int err;
92
111
    struct timeval tv;
93
112
    ipecamera_t *ctx = (ipecamera_t*)vctx;
94
113
 
109
128
 
110
129
    ipecamera_debug(API, "ipecamera: next_event");
111
130
 
 
131
    LOCK(stream);
 
132
 
112
133
#ifdef IPECAMERA_ANNOUNCE_READY
113
134
    if (((!ctx->preproc)&&(ctx->reported_id == ctx->event_id))||((ctx->preproc)&&(ctx->reported_id == ctx->preproc_id))) {
114
135
#else /* IPECAMERA_ANNOUNCE_READY */
138
159
        }
139
160
        
140
161
        if (ctx->reported_id == ctx->event_id) {
 
162
            UNLOCK(stream);
141
163
            ipecamera_debug(API, "ipecamera: next_event timed out");
142
164
            return PCILIB_ERROR_TIMEOUT;
143
165
        }
156
178
        else if (info_size >= sizeof(pcilib_event_info_t))
157
179
            memcpy(info, ctx->frame + ((ctx->reported_id-1)%ctx->buffer_size), sizeof(pcilib_event_info_t));
158
180
        else {
 
181
            UNLOCK(stream);
159
182
            ipecamera_debug(API, "ipecamera: next_event returned a error");
160
183
            return PCILIB_ERROR_INVALID_ARGUMENT;
161
184
        }
163
186
 
164
187
    if ((ctx->event_id - ctx->reported_id) >= ctx->buffer_size) goto retry;
165
188
 
 
189
    UNLOCK(stream);
 
190
 
166
191
    ipecamera_debug(API, "ipecamera: next_event returned");
167
192
 
168
193
    return 0;