mirror of
https://github.com/DreamSourceLab/DSView.git
synced 2025-01-23 13:42:55 +08:00
The step 4 of code refactoring for v2.0
This commit is contained in:
parent
78a2ac0a50
commit
9a63adf86d
@ -47,8 +47,9 @@ const int64_t DecoderStack::DecodeChunkLength = 4 * 1024;
|
|||||||
const unsigned int DecoderStack::DecodeNotifyPeriod = 1024;
|
const unsigned int DecoderStack::DecodeNotifyPeriod = 1024;
|
||||||
|
|
||||||
DecoderStack::DecoderStack(SigSession *session,
|
DecoderStack::DecoderStack(SigSession *session,
|
||||||
const srd_decoder *const dec, DecoderStatus *decoder_status) :
|
const srd_decoder *dec, DecoderStatus *decoder_status) :
|
||||||
_session(session)
|
_session(session),
|
||||||
|
m_decoder(dec)
|
||||||
{
|
{
|
||||||
assert(session);
|
assert(session);
|
||||||
assert(dec);
|
assert(dec);
|
||||||
@ -164,10 +165,12 @@ void DecoderStack::build_row()
|
|||||||
std::map<const decode::Row, bool>::const_iterator iter = _rows_gshow.find(row);
|
std::map<const decode::Row, bool>::const_iterator iter = _rows_gshow.find(row);
|
||||||
if (iter == _rows_gshow.end()) {
|
if (iter == _rows_gshow.end()) {
|
||||||
_rows_gshow[row] = true;
|
_rows_gshow[row] = true;
|
||||||
|
|
||||||
if (row.title().contains("bit", Qt::CaseInsensitive) ||
|
if (row.title().contains("bit", Qt::CaseInsensitive) ||
|
||||||
row.title().contains("warning", Qt::CaseInsensitive)) {
|
row.title().contains("warning", Qt::CaseInsensitive)) {
|
||||||
_rows_lshow[row] = false;
|
_rows_lshow[row] = false;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
_rows_lshow[row] = true;
|
_rows_lshow[row] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,7 +348,6 @@ bool DecoderStack::list_annotation(dsv::decode::Annotation &ann,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool DecoderStack::list_row_title(int row, QString &title)
|
bool DecoderStack::list_row_title(int row, QString &title)
|
||||||
{
|
{
|
||||||
for (auto i = _rows.begin();i != _rows.end(); i++) {
|
for (auto i = _rows.begin();i != _rows.end(); i++) {
|
||||||
@ -780,6 +782,13 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *self)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pdata->pdo->di->decoder != d->m_decoder){
|
||||||
|
// dsv_err("ERROR:Is a invalid decoder instance.%p,%p",
|
||||||
|
// pdata->pdo->di->decoder,
|
||||||
|
// d->m_decoder);
|
||||||
|
// assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
Annotation *a = new Annotation(pdata, d->_decoder_status);
|
Annotation *a = new Annotation(pdata, d->_decoder_status);
|
||||||
if (a == NULL){
|
if (a == NULL){
|
||||||
d->_no_memory = true;
|
d->_no_memory = true;
|
||||||
@ -790,7 +799,7 @@ void DecoderStack::annotation_callback(srd_proto_data *pdata, void *self)
|
|||||||
assert(pdata->pdo);
|
assert(pdata->pdo);
|
||||||
assert(pdata->pdo->di);
|
assert(pdata->pdo->di);
|
||||||
const srd_decoder *const decc = pdata->pdo->di->decoder;
|
const srd_decoder *const decc = pdata->pdo->di->decoder;
|
||||||
assert(decc);
|
assert(decc);
|
||||||
|
|
||||||
auto row_iter = d->_rows.end();
|
auto row_iter = d->_rows.end();
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
DecoderStack(SigSession *_session,
|
DecoderStack(SigSession *_session,
|
||||||
const srd_decoder *const decoder, DecoderStatus *decoder_status);
|
const srd_decoder *decoder, DecoderStatus *decoder_status);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -213,6 +213,7 @@ private:
|
|||||||
bool _is_capture_end;
|
bool _is_capture_end;
|
||||||
int _progress;
|
int _progress;
|
||||||
bool _is_decoding;
|
bool _is_decoding;
|
||||||
|
const srd_decoder *m_decoder;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace data
|
} // namespace data
|
||||||
|
@ -457,10 +457,14 @@ static int get_annotations(struct srd_decoder *dec)
|
|||||||
|
|
||||||
if (PyTuple_Size(py_ann) == 3) {
|
if (PyTuple_Size(py_ann) == 3) {
|
||||||
ann_type = 0;
|
ann_type = 0;
|
||||||
for (j = 0; j < strlen(annpair[0]); j++)
|
|
||||||
|
for (j = 0; j < strlen(annpair[0]); j++){
|
||||||
ann_type = ann_type * 10 + (annpair[0][j] - '0');
|
ann_type = ann_type * 10 + (annpair[0][j] - '0');
|
||||||
|
}
|
||||||
|
|
||||||
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
|
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
|
||||||
} else if (PyTuple_Size(py_ann) == 2) {
|
}
|
||||||
|
else if (PyTuple_Size(py_ann) == 2) {
|
||||||
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
|
dec->ann_types = g_slist_append(dec->ann_types, GINT_TO_POINTER(ann_type));
|
||||||
ann_type++;
|
ann_type++;
|
||||||
}
|
}
|
||||||
|
@ -347,7 +347,8 @@ struct srd_proto_data {
|
|||||||
};
|
};
|
||||||
struct srd_proto_data_annotation {
|
struct srd_proto_data_annotation {
|
||||||
int ann_class;
|
int ann_class;
|
||||||
int ann_type;
|
int ann_type;
|
||||||
|
int ann_row_index;
|
||||||
char str_number_hex[DECODE_NUM_HEX_MAX_LEN]; //numerical value hex format string
|
char str_number_hex[DECODE_NUM_HEX_MAX_LEN]; //numerical value hex format string
|
||||||
long long numberic_value;
|
long long numberic_value;
|
||||||
char **ann_text; //text string lines
|
char **ann_text; //text string lines
|
||||||
|
@ -178,17 +178,16 @@ err:
|
|||||||
@obj is the fourth param from python calls put()
|
@obj is the fourth param from python calls put()
|
||||||
*/
|
*/
|
||||||
static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj,
|
static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj,
|
||||||
struct srd_proto_data *pdata)
|
struct srd_proto_data_annotation *pda)
|
||||||
{
|
{
|
||||||
PyObject *py_tmp;
|
PyObject *py_tmp;
|
||||||
struct srd_proto_data_annotation *pda;
|
|
||||||
int ann_class;
|
int ann_class;
|
||||||
char **ann_text;
|
char **ann_text;
|
||||||
gpointer ann_type_ptr;
|
gpointer ann_type_ptr;
|
||||||
PyGILState_STATE gstate;
|
PyGILState_STATE gstate;
|
||||||
int ann_size;
|
int ann_size;
|
||||||
|
|
||||||
pda = pdata->data;
|
assert(pda);
|
||||||
|
|
||||||
gstate = PyGILState_Ensure();
|
gstate = PyGILState_Ensure();
|
||||||
|
|
||||||
@ -256,6 +255,8 @@ static int convert_annotation(struct srd_decoder_inst *di, PyObject *obj,
|
|||||||
pda->ann_type = GPOINTER_TO_INT(ann_type_ptr);
|
pda->ann_type = GPOINTER_TO_INT(ann_type_ptr);
|
||||||
pda->ann_text = ann_text;
|
pda->ann_text = ann_text;
|
||||||
|
|
||||||
|
//srd_info("class:%d, type:%d", ann_class, pda->ann_type);
|
||||||
|
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
|
|
||||||
return SRD_OK;
|
return SRD_OK;
|
||||||
@ -458,9 +459,11 @@ static void release_meta(GVariant *gvar)
|
|||||||
g_variant_unref(gvar);
|
g_variant_unref(gvar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//param list: start_sample, end_sample, output_type, [ann_class,[data]]
|
||||||
static PyObject *Decoder_put(PyObject *self, PyObject *args)
|
static PyObject *Decoder_put(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
GSList *l;
|
GSList *l;
|
||||||
|
GSList *l2;
|
||||||
PyObject *py_data, *py_res;
|
PyObject *py_data, *py_res;
|
||||||
struct srd_decoder_inst *di, *next_di;
|
struct srd_decoder_inst *di, *next_di;
|
||||||
struct srd_pd_output *pdo;
|
struct srd_pd_output *pdo;
|
||||||
@ -468,9 +471,13 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
|
|||||||
struct srd_proto_data_annotation pda;
|
struct srd_proto_data_annotation pda;
|
||||||
struct srd_proto_data_binary pdb;
|
struct srd_proto_data_binary pdb;
|
||||||
uint64_t start_sample, end_sample;
|
uint64_t start_sample, end_sample;
|
||||||
int output_id;
|
int output_id; //The output type index.
|
||||||
struct srd_pd_callback *cb;
|
struct srd_pd_callback *cb;
|
||||||
PyGILState_STATE gstate;
|
PyGILState_STATE gstate;
|
||||||
|
struct srd_decoder_annotation_row *ann_row = NULL;
|
||||||
|
gpointer ann_row_index_ptr = 0;
|
||||||
|
int row_index;
|
||||||
|
int ann_class_tmp;
|
||||||
|
|
||||||
py_data = NULL; //the fourth param from python
|
py_data = NULL; //the fourth param from python
|
||||||
|
|
||||||
@ -518,10 +525,42 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
|
|||||||
if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) {
|
if ((cb = srd_pd_output_callback_find(di->sess, pdo->output_type))) {
|
||||||
pdata.data = &pda;
|
pdata.data = &pda;
|
||||||
/* Convert from PyDict to srd_proto_data_annotation. */
|
/* Convert from PyDict to srd_proto_data_annotation. */
|
||||||
if (convert_annotation(di, py_data, &pdata) != SRD_OK) {
|
if (convert_annotation(di, py_data, &pda) != SRD_OK) {
|
||||||
/* An error was already logged. */
|
/* An error was already logged. */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get the row index.
|
||||||
|
pda.ann_row_index = -1;
|
||||||
|
row_index = 0;
|
||||||
|
|
||||||
|
for (l = di->decoder->annotation_rows; l; l = l->next)
|
||||||
|
{
|
||||||
|
ann_row = l->data;
|
||||||
|
|
||||||
|
for (l2 = ann_row->ann_classes; l2; l2 = l2->next)
|
||||||
|
{
|
||||||
|
ann_class_tmp = GPOINTER_TO_INT(l2->data);
|
||||||
|
|
||||||
|
if (ann_class_tmp == pda.ann_class){
|
||||||
|
pda.ann_row_index = row_index;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
row_index++;
|
||||||
|
|
||||||
|
if (pda.ann_row_index != -1){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pda.ann_row_index == -1){
|
||||||
|
srd_err("\n\nERROR:The annotation have no row index!decoder:%s,ann-class:%d\n\n",
|
||||||
|
di->decoder->id, pda.ann_class);
|
||||||
|
release_annotation(pdata.data);
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
cb->cb(&pdata, cb->cb_data);
|
cb->cb(&pdata, cb->cb_data);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
@ -601,7 +640,7 @@ err:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
return output info index
|
Returns the output type index
|
||||||
*/
|
*/
|
||||||
static PyObject *Decoder_register(PyObject *self, PyObject *args,
|
static PyObject *Decoder_register(PyObject *self, PyObject *args,
|
||||||
PyObject *kwargs)
|
PyObject *kwargs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user