int matchFileWithLicenses(MonkState* state, const File* file, const Licenses* licenses, const MatchCallbacks* callbacks) { GArray* matches = findAllMatchesBetween(file, licenses, MAX_ALLOWED_DIFF_LENGTH, MIN_ADJACENT_MATCHES, MAX_LEADING_DIFF); int result = processMatches(state, file, matches, callbacks); // we are done: free memory match_array_free(matches); return result; }
static PyObject *Decoder_wait(PyObject *self, PyObject *args) { int ret; unsigned int i; gboolean found_match; struct srd_decoder_inst *di; PyObject *py_pinvalues, *py_matched; if (!self || !args) return NULL; if (!(di = srd_inst_find_by_obj(NULL, self))) { PyErr_SetString(PyExc_Exception, "decoder instance not found"); Py_RETURN_NONE; } ret = set_new_condition_list(self, args); if (ret < 0) { srd_dbg("%s: %s: Aborting wait().", di->inst_id, __func__); return NULL; } if (ret == 9999) { /* Empty condition list, automatic match. */ PyObject_SetAttrString(di->py_inst, "matched", Py_None); /* Leave self.samplenum unchanged (== di->abs_cur_samplenum). */ return get_current_pinvalues(di); } while (1) { /* Wait for new samples to process, or termination request. */ g_mutex_lock(&di->data_mutex); while (!di->got_new_samples && !di->want_wait_terminate) g_cond_wait(&di->got_new_samples_cond, &di->data_mutex); /* * Check whether any of the current condition(s) match. * Arrange for termination requests to take a code path which * won't find new samples to process, pretends to have processed * previously stored samples, and returns to the main thread, * while the termination request still gets signalled. */ found_match = FALSE; ret = process_samples_until_condition_match(di, &found_match); /* If there's a match, set self.samplenum etc. and return. */ if (found_match) { /* Set self.samplenum to the (absolute) sample number that matched. */ PyObject_SetAttrString(di->py_inst, "samplenum", PyLong_FromLong(di->abs_cur_samplenum)); if (di->match_array && di->match_array->len > 0) { py_matched = PyTuple_New(di->match_array->len); for (i = 0; i < di->match_array->len; i++) PyTuple_SetItem(py_matched, i, PyBool_FromLong(di->match_array->data[i])); PyObject_SetAttrString(di->py_inst, "matched", py_matched); match_array_free(di); } else { PyObject_SetAttrString(di->py_inst, "matched", Py_None); } py_pinvalues = get_current_pinvalues(di); g_mutex_unlock(&di->data_mutex); return py_pinvalues; } /* No match, reset state for the next chunk. */ di->got_new_samples = FALSE; di->handled_all_samples = TRUE; di->abs_start_samplenum = 0; di->abs_end_samplenum = 0; di->inbuf = NULL; di->inbuflen = 0; /* Signal the main thread that we handled all samples. */ g_cond_signal(&di->handled_all_samples_cond); /* * When termination of wait() and decode() was requested, * then exit the loop after releasing the mutex. */ if (di->want_wait_terminate) { srd_dbg("%s: %s: Will return from wait().", di->inst_id, __func__); g_mutex_unlock(&di->data_mutex); return NULL; } g_mutex_unlock(&di->data_mutex); } Py_RETURN_NONE; }