void translator::process_data(const audio_record &data) { try{ std::string cmdname = m_r->recognize(data); boost::shared_ptr<cmd::command> p = contnr->get_by_name(cmdname); manip::manipulator* wnd_man = manip_creator.create(); p->execute(*wnd_man); push_result(true); } catch (ANN_based_recognizer::cmd_not_found& exc) { push_result(false); } }
void push_result(const std::string & result) { push_result(dispatch_result(result, -1)); }
static inline void push_waiting(int cli) { static int len; static char *eos, *pos; static int wait_idx; while (1) { eos = (char *)memchr(in_buffer[cli].newline, '\n', in_buffer[cli].len + in_buffer[cli].buf - in_buffer[cli].newline); if (eos == NULL) { in_buffer[cli].newline = in_buffer[cli].buf + in_buffer[cli].len; return; } in_buffer[cli].newline = eos; wait_idx = waiting.avai; if (wait_idx == -1) { fputs("push_waiting: waiting list full\n", stderr); return; } waiting.avai = waiting.item[wait_idx].next; *eos = '\0'; waiting.item[wait_idx].cli = cli; errno = 0; waiting.item[wait_idx].seq = strtol(in_buffer[cli].buf, &pos, 10); if (errno == ERANGE || *pos != ' ') goto ignore; ++pos; waiting.item[wait_idx].type = *pos - '0'; ++pos; if (*pos != ' ') goto ignore; ++pos; /* it's at least a testing url now */ waiting.item[wait_idx].cli_prev = -1; waiting.item[wait_idx].cli_next = pending[cli].in; if (pending[cli].in >= 0) waiting.item[pending[cli].in].cli_prev = wait_idx; pending[cli].in = wait_idx; len = eos - pos; if (waiting.item[wait_idx].type == HK_TYPE1) { if ((waiting.item[wait_idx].url = malloc(len + HH_ADD_LEN - 2)) == NULL) goto error; eos = waiting.item[wait_idx].url; memcpy(eos, "GET http://", HH_PRE_LEN); eos += HH_PRE_LEN; memcpy(eos, pos, len); eos += len; memcpy(eos, " HTTP/1.1\n\n", HH_PST_LEN - 2); waiting.item[wait_idx].len = len + HH_ADD_LEN - 2; } else if (waiting.item[wait_idx].type == HK_TYPE2) { if ((waiting.item[wait_idx].url = malloc(len + HH_ADD_LEN)) == NULL) goto error; eos = waiting.item[wait_idx].url; memcpy(eos, "GET http://", HH_PRE_LEN); eos += HH_PRE_LEN; memcpy(eos, pos, len); eos += len; memcpy(eos, " HTTP/1.1\r\n\r\n", HH_PST_LEN); waiting.item[wait_idx].len = len + HH_ADD_LEN; } else goto error; pos += len + 1; in_buffer[cli].len = in_buffer[cli].len - (pos - in_buffer[cli].buf); in_buffer[cli].newline = in_buffer[cli].buf; memmove(in_buffer[cli].buf, pos, in_buffer[cli].len); /* it's a waiting for test url now */ waiting.item[wait_idx].next = -1; if (waiting.head < 0) { waiting.head = wait_idx; waiting.item[wait_idx].prev = -1; } else { waiting.item[waiting.tail].next = wait_idx; waiting.item[wait_idx].prev = waiting.tail; } waiting.tail = wait_idx; continue; ignore: pos = eos + 1; in_buffer[cli].len = in_buffer[cli].len - (pos - in_buffer[cli].buf); in_buffer[cli].newline = in_buffer[cli].buf; memmove(in_buffer[cli].buf, pos, in_buffer[cli].len); waiting.item[wait_idx].next = waiting.avai; waiting.avai = wait_idx; continue; error: /* report the format error result */ push_result(NULL, GUK_QUERY_FORMAT_ERROR, waiting.item + wait_idx); continue; } }