Lines Matching defs:poll_cb
64 static int32_t mm_camera_poll_sig(mm_camera_poll_thread_t *poll_cb,
75 pthread_mutex_lock(&poll_cb->mutex);
77 poll_cb->status = false;
80 len = write(poll_cb->pfds[1], &cmd_evt, sizeof(cmd_evt));
86 if (false == poll_cb->status) {
88 pthread_cond_wait(&poll_cb->cond_v, &poll_cb->mutex);
91 pthread_mutex_unlock(&poll_cb->mutex);
96 static void mm_camera_poll_sig_done(mm_camera_poll_thread_t *poll_cb)
98 pthread_mutex_lock(&poll_cb->mutex);
99 poll_cb->status = true;
100 pthread_cond_signal(&poll_cb->cond_v);
102 pthread_mutex_unlock(&poll_cb->mutex);
105 static void mm_camera_poll_set_state(mm_camera_poll_thread_t *poll_cb,
108 poll_cb->state = state;
111 static void mm_camera_poll_proc_pipe(mm_camera_poll_thread_t *poll_cb)
116 read_len = read(poll_cb->pfds[0], &cmd_evt, sizeof(cmd_evt));
118 __func__, poll_cb->pfds[0], (int)read_len, (int)sizeof(cmd_evt), cmd_evt.cmd);
122 poll_cb->num_fds = 0;
123 poll_cb->poll_fds[poll_cb->num_fds].fd = poll_cb->pfds[0];
124 poll_cb->poll_fds[poll_cb->num_fds].events = POLLIN|POLLRDNORM|POLLPRI;
125 poll_cb->num_fds++;
127 if (MM_CAMERA_POLL_TYPE_EVT == poll_cb->poll_type) {
128 if (poll_cb->poll_entries[0].fd > 0) {
130 poll_cb->poll_fds[poll_cb->num_fds].fd = poll_cb->poll_entries[0].fd;
131 poll_cb->poll_fds[poll_cb->num_fds].events = POLLIN|POLLRDNORM|POLLPRI;
132 poll_cb->num_fds++;
134 } else if (MM_CAMERA_POLL_TYPE_CH == poll_cb->poll_type) {
136 if(poll_cb->poll_entries[i].fd > 0) {
138 poll_cb->poll_fds[poll_cb->num_fds].fd = poll_cb->poll_entries[i].fd;
139 poll_cb->poll_fds[poll_cb->num_fds].events = POLLIN|POLLRDNORM|POLLPRI;
140 poll_cb->num_fds++;
149 poll_cb->poll_fds[poll_cb->num_fds].fd = -1;
150 poll_cb->poll_fds[poll_cb->num_fds].events = 0;
151 poll_cb->num_fds++;
155 mm_camera_poll_sig_done(poll_cb);
160 mm_camera_poll_set_state(poll_cb, MM_CAMERA_POLL_TASK_STATE_STOPPED);
161 mm_camera_poll_sig_done(poll_cb);
166 static void *mm_camera_poll_fn(mm_camera_poll_thread_t *poll_cb)
170 CDBG("%s: poll type = %d, num_fd = %d poll_cb = %p\n",
171 __func__, poll_cb->poll_type, poll_cb->num_fds,poll_cb);
173 for(i = 0; i < poll_cb->num_fds; i++) {
174 poll_cb->poll_fds[i].events = POLLIN|POLLRDNORM|POLLPRI;
177 rc = poll(poll_cb->poll_fds, poll_cb->num_fds, poll_cb->timeoutms);
179 if ((poll_cb->poll_fds[0].revents & POLLIN) &&
180 (poll_cb->poll_fds[0].revents & POLLRDNORM)) {
183 mm_camera_poll_proc_pipe(poll_cb);
185 for(i=1; i<poll_cb->num_fds; i++) {
187 if ((poll_cb->poll_type == MM_CAMERA_POLL_TYPE_EVT) &&
188 (poll_cb->poll_fds[i].revents & POLLPRI)) {
190 if (NULL != poll_cb->poll_entries[i-1].notify_cb) {
191 poll_cb->poll_entries[i-1].notify_cb(poll_cb->poll_entries[i-1].user_data);
195 if ((poll_cb->poll_type == MM_CAMERA_POLL_TYPE_CH) &&
196 (poll_cb->poll_fds[i].revents & POLLIN) &&
197 (poll_cb->poll_fds[i].revents & POLLRDNORM)) {
199 if (NULL != poll_cb->poll_entries[i-1].notify_cb) {
200 poll_cb->poll_entries[i-1].notify_cb(poll_cb->poll_entries[i-1].user_data);
210 } while (poll_cb->state == MM_CAMERA_POLL_TASK_STATE_POLL);
219 mm_camera_poll_thread_t *poll_cb = (mm_camera_poll_thread_t *)data;
222 poll_cb->poll_fds[poll_cb->num_fds++].fd = poll_cb->pfds[0];
224 //poll_cb->poll_fds[poll_cb->num_fds++].fd = (((mm_camera_obj_t *)poll_cb->my_obj)->ctrl_fd);
226 mm_camera_poll_sig_done(poll_cb);
227 mm_camera_poll_set_state(poll_cb, MM_CAMERA_POLL_TASK_STATE_POLL);
228 ret = mm_camera_poll_fn(poll_cb);
232 int32_t mm_camera_poll_thread_notify_entries_updated(mm_camera_poll_thread_t * poll_cb)
235 return mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED);
238 int32_t mm_camera_poll_thread_add_poll_fd(mm_camera_poll_thread_t * poll_cb,
247 if (MM_CAMERA_POLL_TYPE_CH == poll_cb->poll_type) {
256 poll_cb->poll_entries[idx].fd = fd;
257 poll_cb->poll_entries[idx].handler = handler;
258 poll_cb->poll_entries[idx].notify_cb = notify_cb;
259 poll_cb->poll_entries[idx].user_data = userdata;
261 rc = mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED);
269 int32_t mm_camera_poll_thread_del_poll_fd(mm_camera_poll_thread_t * poll_cb,
275 if (MM_CAMERA_POLL_TYPE_CH == poll_cb->poll_type) {
284 (handler == poll_cb->poll_entries[idx].handler)) {
286 poll_cb->poll_entries[idx].fd = -1; /* set fd to invalid */
287 poll_cb->poll_entries[idx].handler = 0;
288 poll_cb->poll_entries[idx].notify_cb = NULL;
291 rc = mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_POLL_ENTRIES_UPDATED);
300 int32_t mm_camera_poll_thread_launch(mm_camera_poll_thread_t * poll_cb,
304 poll_cb->poll_type = poll_type;
306 poll_cb->pfds[0] = 0;
307 poll_cb->pfds[1] = 0;
308 rc = pipe(poll_cb->pfds);
314 poll_cb->timeoutms = -1; /* Infinite seconds */
317 __func__, poll_cb->poll_type,
318 poll_cb->pfds[0], poll_cb->pfds[1],poll_cb->timeoutms);
320 pthread_mutex_init(&poll_cb->mutex, NULL);
321 pthread_cond_init(&poll_cb->cond_v, NULL);
324 pthread_mutex_lock(&poll_cb->mutex);
325 poll_cb->status = 0;
326 pthread_create(&poll_cb->pid, NULL, mm_camera_poll_thread, (void *)poll_cb);
327 if(!poll_cb->status) {
328 pthread_cond_wait(&poll_cb->cond_v, &poll_cb->mutex);
330 pthread_mutex_unlock(&poll_cb->mutex);
335 int32_t mm_camera_poll_thread_release(mm_camera_poll_thread_t *poll_cb)
338 if(MM_CAMERA_POLL_TASK_STATE_STOPPED == poll_cb->state) {
344 mm_camera_poll_sig(poll_cb, MM_CAMERA_PIPE_CMD_EXIT);
346 if (pthread_join(poll_cb->pid, NULL) != 0) {
351 if(poll_cb->pfds[0]) {
352 close(poll_cb->pfds[0]);
354 if(poll_cb->pfds[1]) {
355 close(poll_cb->pfds[1]);
358 pthread_mutex_destroy(&poll_cb->mutex);
359 pthread_cond_destroy(&poll_cb->cond_v);
360 memset(poll_cb, 0, sizeof(mm_camera_poll_thread_t));