void ParseWordRecognizedArray(std::vector<WordConfidencePair>& results, const AL::ALValue& value, float recognitionThreshold) { // unexpected data if (value.getType() != AL::ALValue::TypeArray) MODULE_ERROR("invalid array type"); // unexpected data if (value.getSize() % 2 != 0) MODULE_ERROR("invalid array size"); for (int i = 0; i < (int)value.getSize(); i += 2) { AL::ALValue wordValue = value[i]; AL::ALValue confidenceValue = value[i + 1]; float confidence = confidenceValue.operator float &(); if (confidence >= recognitionThreshold) { WordConfidencePair pair = { wordValue.toString(), confidence }; results.push_back(pair); } } std::sort(results.begin(), results.end(), WordConfidencePairComparison()); }
const char *errstr (error_t _error) { static bool initialized = false; module_t module_id = MODULE_ID (_error); int error_id = MODULE_ERROR (_error); if (0 == initialized) { errstr_init (); initialized = true; } if (0 == _error) { return "SUCCESS"; } if (_error > 0) { return "ERROR_ERRSTR_NOT_NEGATIVE"; } if (module_id > MODULE_LAST) { return "ERROR_ERRSTR_INVALID_MODULEID"; } if (!g_errstr_array [module_id].available_) { return "ERROR_ERRSTR_NOT_AVAILABLE"; } if (error_id > g_errstr_array [module_id].last_error_) { return "ERROR_ERRSTR_OUT_OF_LAST"; } if (0 == g_errstr_array [module_id].error_array_ [error_id]) { return "ERROR_ERRSTR_NOT_DEFINED"; } return g_errstr_array [module_id].error_array_ [error_id]; }
error_t event_receive (event_set_t _expected, event_set_handle_t _received, msecond_t _timeout, event_option_t _option) { interrupt_level_t level; event_option_t wait_option = EVENT_WAIT_ALL | EVENT_WAIT_ANY; event_option_t return_option = EVENT_RETURN_ALL | EVENT_RETURN_EXPECTED; task_handle_t p_task; if (is_in_interrupt ()) { return ERROR_T (ERROR_EVENT_RECV_INVCONTEXT); } if (0 == _expected) { return 0; } if (null == _received) { return ERROR_T (ERROR_EVENT_RECV_INVPTR); } if ((wait_option == (wait_option & _option)) || (0 == (int)(wait_option & _option)) || (return_option == (return_option & _option)) || (0 == (int)(return_option & _option))) { return ERROR_T (ERROR_EVENT_RECV_INVOPT); } level = global_interrupt_disable (); p_task = task_self (); if (is_invalid_task (p_task)) { global_interrupt_enable (level); return ERROR_T (ERROR_EVENT_RECV_INVCONTEXT); } again: // if expected event(s) is/are available, return it if (EVENT_WAIT_ALL == (_option & EVENT_WAIT_ALL)) { if ((_expected & p_task->event_received_) == _expected) { if (EVENT_RETURN_ALL == (_option & EVENT_RETURN_ALL)) { *_received = p_task->event_received_; } else { *_received = _expected; p_task->event_received_ &= ~(*_received); } global_interrupt_enable (level); return 0; } } else { if ((_expected & p_task->event_received_) != 0) { if (EVENT_RETURN_ALL == (_option & EVENT_RETURN_ALL)) { *_received = p_task->event_received_; } else { *_received = _expected & p_task->event_received_; p_task->event_received_ &= ~(*_received); } global_interrupt_enable (level); return 0; } } // run here it means we need to block the task p_task->timeout_ = _timeout; (void) task_state_change (p_task, TASK_STATE_WAITING); p_task->ecode_ = 0; p_task->event_expected_ = _expected; p_task->event_option_ = _option; global_interrupt_enable (level); task_schedule (null); level = global_interrupt_disable (); p_task->event_option_ = (event_option_t) 0; if (0 == p_task->ecode_) { // event(s) has/have received and need to return the event(s) expected goto again; } global_interrupt_enable (level); //lint -e{650} if (ERROR_TASK_WAIT_TIMEOUT == MODULE_ERROR (p_task->ecode_)) { p_task->ecode_ = ERROR_T (ERROR_EVENT_RECV_TIMEOUT); } return p_task->ecode_; }