//-------------------------------------------------------------------------------------------------- void le_event_ClearFdHandlerByEventType ( le_event_FdMonitorRef_t monitorRef, ///< [in] Reference to the File Descriptor Monitor object. le_event_FdEventType_t eventType ///< [in] The type of event to clear the handler for. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(eventType < LE_EVENT_NUM_FD_EVENT_TYPES); // Look up the File Descriptor Monitor object using the safe reference provided. // Note that the safe reference map is shared by all threads in the process, so it // must be protected using the mutex. The File Descriptor Monitor objects, on the other // hand, are only allowed to be accessed by the one thread that created them, so it is // safe to unlock the mutex after doing the safe reference lookup. LOCK FdMonitor_t* monitorPtr = le_ref_Lookup(FdMonitorRefMap, monitorRef); UNLOCK LE_FATAL_IF(monitorPtr == NULL, "File Descriptor Monitor %p doesn't exist!", monitorRef); LE_FATAL_IF(thread_GetEventRecPtr() != monitorPtr->threadRecPtr, "FD Monitor '%s' (fd %d) is owned by another thread.", monitorPtr->name, monitorPtr->fd); // Get a pointer to the Handler object in the appropriate spot for this type of event in the // FD Monitor's array of handlers. Handler_t* handlerPtr = &(monitorPtr->handlerArray[eventType]); LE_CRIT_IF(handlerPtr->handlerFunc == NULL, "Handler cleared when not set for FD Monitor '%s' (fd %d), event type %d.", monitorPtr->name, monitorPtr->fd, eventType); // Clear the Handler object. handlerPtr->handlerFunc = NULL; handlerPtr->contextPtr = NULL; LOCK le_ref_DeleteRef(HandlerRefMap, handlerPtr->safeRef); UNLOCK handlerPtr->safeRef = NULL; // Disable the monitoring of this event. DisableFdMonitoring(monitorPtr, eventType); }
//-------------------------------------------------------------------------------------------------- void properties_DeleteIter ( properties_Iter_Ref_t iteratorRef ///< [IN] Reference to the iterator. ) { // Close the file. int r; do { r = fclose(iteratorRef->streamPtr); } while ( (r != 0) && (errno == EINTR) ); LE_CRIT_IF(r != 0, "Failed to close file %s. %m.", iteratorRef->fileName); // Release the memory. le_mem_Release(iteratorRef); }
//-------------------------------------------------------------------------------------------------- void fdMon_Report ( void* safeRef, ///< [in] Safe Reference for the FD Monitor object for the fd. uint32_t eventFlags ///< [in] OR'd together event flags from epoll_wait(). ) //-------------------------------------------------------------------------------------------------- { // Queue up function calls for any flags set in epoll's event. if (eventFlags & EPOLLIN) { le_event_QueueFunction(DispatchToHandler, safeRef, (void*)LE_EVENT_FD_READABLE); } if (eventFlags & EPOLLPRI) { le_event_QueueFunction(DispatchToHandler, safeRef, (void*)LE_EVENT_FD_READABLE_URGENT); } if (eventFlags & EPOLLOUT) { le_event_QueueFunction(DispatchToHandler, safeRef, (void*)LE_EVENT_FD_WRITEABLE); } if (eventFlags & EPOLLHUP) { le_event_QueueFunction(DispatchToHandler, safeRef, (void*)LE_EVENT_FD_WRITE_HANG_UP); } if (eventFlags & EPOLLRDHUP) { le_event_QueueFunction(DispatchToHandler, safeRef, (void*)LE_EVENT_FD_READ_HANG_UP); } if (eventFlags & EPOLLERR) { le_event_QueueFunction(DispatchToHandler, safeRef, (void*)LE_EVENT_FD_ERROR); } LE_CRIT_IF(eventFlags & ~(EPOLLIN | EPOLLPRI | EPOLLOUT | EPOLLHUP | EPOLLRDHUP | EPOLLERR), "Extra flags found in fd event report. (%xd)", eventFlags); }
//-------------------------------------------------------------------------------------------------- static void* PlayAmrThread ( void* contextPtr ) { MediaAmrContext_t * amrCtxtPtr = (MediaAmrContext_t *) contextPtr; LE_DEBUG("PlayAmrThread"); while (1) { uint8_t outBuffer[amrCtxtPtr->paAmrDecoderCtxPtr->bufferSize]; /* Decode the packet */ if ( pa_media_DecodeAmrFrames( amrCtxtPtr->paAmrDecoderCtxPtr, amrCtxtPtr->fd_in, outBuffer ) == LE_OK ) { write(amrCtxtPtr->fd_pipe_input, outBuffer, amrCtxtPtr->paAmrDecoderCtxPtr->bufferSize); } else { break; } } // close can be interrupted by a signal, retry if it is the case int result; do { result = close(amrCtxtPtr->fd_pipe_input); } while ((result == -1) && (errno == EINTR)); LE_CRIT_IF(result == -1, "Failed to close audio input pipe (%m)."); pa_media_ReleaseAmrDecoder(amrCtxtPtr->paAmrDecoderCtxPtr); LE_DEBUG("PlayAmrThread end"); return NULL; }