Lines Matching defs:poll_cb
73 * @poll_cb : ptr to poll thread object
80 static int32_t mm_camera_poll_sig_async(mm_camera_poll_thread_t *poll_cb,
91 pthread_mutex_lock(&poll_cb->mutex);
93 poll_cb->status = FALSE;
96 len = write(poll_cb->pfds[1], &cmd_evt, sizeof(cmd_evt));
100 pthread_mutex_unlock(&poll_cb->mutex);
104 pthread_mutex_unlock(&poll_cb->mutex);
118 * @poll_cb : ptr to poll thread object
125 static int32_t mm_camera_poll_sig(mm_camera_poll_thread_t *poll_cb,
136 pthread_mutex_lock(&poll_cb->mutex);
138 poll_cb->status = FALSE;
141 len = write(poll_cb->pfds[1], &cmd_evt, sizeof(cmd_evt));
145 pthread_mutex_unlock(&poll_cb->mutex);
150 if (FALSE == poll_cb->status) {
152 pthread_cond_wait(&poll_cb->cond_v, &poll_cb->mutex);
155 pthread_mutex_unlock(&poll_cb->mutex);
166 * @poll_cb : ptr to poll thread object
170 static void mm_camera_poll_sig_done(mm_camera_poll_thread_t *poll_cb)
172 pthread_mutex_lock(&poll_cb->mutex);
173 poll_cb->status = TRUE;
174 pthread_cond_signal(&poll_cb->cond_v);
176 pthread_mutex_unlock(&poll_cb->mutex);
185 * @poll_cb : ptr to poll thread object
190 static void mm_camera_poll_set_state(mm_camera_poll_thread_t *poll_cb,
193 poll_cb->state = state;
202 * @poll_cb : ptr to poll thread object
206 static void mm_camera_poll_proc_pipe(mm_camera_poll_thread_t *poll_cb)
211 read_len = read(poll_cb->pfds[0], &cmd_evt, sizeof(cmd_evt));
213 __func__, poll_cb->pfds[0], (int)read_len, (int)sizeof(cmd_evt), cmd_evt.cmd);
218 poll_cb->num_fds = 0;
219 poll_cb->poll_fds[poll_cb->num_fds].fd = poll_cb->pfds[0];
220 poll_cb->poll_fds[poll_cb->num_fds].events = POLLIN|POLLRDNORM|POLLPRI;
221 poll_cb->num_fds++;
223 if (MM_CAMERA_POLL_TYPE_EVT == poll_cb->poll_type) {
224 if (poll_cb->poll_entries[0].fd > 0) {
226 poll_cb->poll_fds[poll_cb->num_fds].fd = poll_cb->poll_entries[0].fd;
227 poll_cb->poll_fds[poll_cb->num_fds].events = POLLIN|POLLRDNORM|POLLPRI;
228 poll_cb->num_fds++;
230 } else if (MM_CAMERA_POLL_TYPE_DATA == poll_cb->poll_type) {
232 if(poll_cb->poll_entries[i].fd > 0) {
234 poll_cb->poll_fds[poll_cb->num_fds].fd = poll_cb->poll_entries[i].fd;
235 poll_cb->poll_fds[poll_cb->num_fds].events = POLLIN|POLLRDNORM|POLLPRI;
236 poll_cb->num_fds++;
245 poll_cb->poll_fds[poll_cb->num_fds].fd = -1;
246 poll_cb->poll_fds[poll_cb->num_fds].events = 0;
247 poll_cb->num_fds++;
252 mm_camera_poll_sig_done(poll_cb);
257 mm_camera_poll_set_state(poll_cb, MM_CAMERA_POLL_TASK_STATE_STOPPED);
258 mm_camera_poll_sig_done(poll_cb);
269 * @poll_cb : ptr to poll thread object
273 static void *mm_camera_poll_fn(mm_camera_poll_thread_t *poll_cb)
277 CDBG("%s: poll type = %d, num_fd = %d poll_cb = %p\n",
278 __func__, poll_cb->poll_type, poll_cb->num_fds,poll_cb);
280 for(i = 0; i < poll_cb->num_fds; i++) {
281 poll_cb->poll_fds[i].events = POLLIN|POLLRDNORM|POLLPRI;
284 rc = poll(poll_cb->poll_fds, poll_cb->num_fds, poll_cb->timeoutms);
286 if ((poll_cb->poll_fds[0].revents & POLLIN) &&
287 (poll_cb->poll_fds[0].revents & POLLRDNORM)) {
290 mm_camera_poll_proc_pipe(poll_cb);
292 for(i=1; i<poll_cb->num_fds; i++) {
294 if ((poll_cb->poll_type == MM_CAMERA_POLL_TYPE_EVT) &&
295 (poll_cb->poll_fds[i].revents & POLLPRI)) {
297 if (NULL != poll_cb->poll_entries[i-1].notify_cb) {
298 poll_cb->poll_entries[i-1].notify_cb(poll_cb->poll_entries[i-1].user_data);
302 if ((MM_CAMERA_POLL_TYPE_DATA == poll_cb->poll_type) &&
303 (poll_cb->poll_fds[i].revents & POLLIN) &&
304 (poll_cb->poll_fds[i].revents & POLLRDNORM)) {
306 if (NULL != poll_cb->poll_entries[i-1].notify_cb) {
307 poll_cb->poll_entries[i-1].notify_cb(poll_cb->poll_entries[i-1].user_data);
317 } while (poll_cb->state == MM_CAMERA_POLL_TASK_STATE_POLL);
334 mm_camera_poll_thread_t *poll_cb = (mm_camera_poll_thread_t *)data;
337 poll_cb->poll_fds[poll_cb->num_fds++].fd = poll_cb->pfds[0];
339 mm_camera_poll_sig_done(poll_cb);
340 mm_camera_poll_set_state(poll_cb, MM_CAMERA_POLL_TASK_STATE_POLL);
341 return mm_camera_poll_fn(poll_cb);
351 * @poll_cb : ptr to poll thread object
355 int32_t mm_camera_poll_thread_notify_entries_updated(mm_camera_poll_thread_t * poll_cb)
358 return mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED);
367 * @poll_cb : ptr to poll thread object
377 int32_t mm_camera_poll_thread_add_poll_fd(mm_camera_poll_thread_t * poll_cb,
387 if (MM_CAMERA_POLL_TYPE_DATA == poll_cb->poll_type) {
396 poll_cb->poll_entries[idx].fd = fd;
397 poll_cb->poll_entries[idx].handler = handler;
398 poll_cb->poll_entries[idx].notify_cb = notify_cb;
399 poll_cb->poll_entries[idx].user_data = userdata;
402 rc = mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED);
404 rc = mm_camera_poll_sig_async(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED_ASYNC );
419 * @poll_cb : ptr to poll thread object
425 int32_t mm_camera_poll_thread_del_poll_fd(mm_camera_poll_thread_t * poll_cb,
432 if (MM_CAMERA_POLL_TYPE_DATA == poll_cb->poll_type) {
441 (handler == poll_cb->poll_entries[idx].handler)) {
443 poll_cb->poll_entries[idx].fd = -1; /* set fd to invalid */
444 poll_cb->poll_entries[idx].handler = 0;
445 poll_cb->poll_entries[idx].notify_cb = NULL;
449 rc = mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED);
451 rc = mm_camera_poll_sig_async(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED_ASYNC );
463 int32_t mm_camera_poll_thread_launch(mm_camera_poll_thread_t * poll_cb,
470 poll_cb->poll_type = poll_type;
472 poll_cb->pfds[0] = 0;
473 poll_cb->pfds[1] = 0;
474 rc = pipe(poll_cb->pfds);
481 poll_cb->timeoutms = -1; /* Infinite seconds */
484 __func__, poll_cb->poll_type,
485 poll_cb->pfds[0], poll_cb->pfds[1],poll_cb->timeoutms);
487 pthread_mutex_init(&poll_cb->mutex, NULL);
488 pthread_cond_init(&poll_cb->cond_v, NULL);
491 pthread_mutex_lock(&poll_cb->mutex);
492 poll_cb->status = 0;
493 pthread_create(&poll_cb->pid, NULL, mm_camera_poll_thread, (void *)poll_cb);
494 if(!poll_cb->status) {
495 pthread_cond_wait(&poll_cb->cond_v, &poll_cb->mutex);
497 pthread_mutex_unlock(&poll_cb->mutex);
503 int32_t mm_camera_poll_thread_release(mm_camera_poll_thread_t *poll_cb)
509 if(MM_CAMERA_POLL_TASK_STATE_STOPPED == poll_cb->state) {
515 mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_EXIT);
517 if (pthread_join(poll_cb->pid, NULL) != 0) {
522 if(poll_cb->pfds[0]) {
523 close(poll_cb->pfds[0]);
525 if(poll_cb->pfds[1]) {
526 close(poll_cb->pfds[1]);
529 pthread_mutex_destroy(&poll_cb->mutex);
530 pthread_cond_destroy(&poll_cb->cond_v);
531 memset(poll_cb, 0, sizeof(mm_camera_poll_thread_t));