#include "datasnapshot.h"
-DataSnapshot::DataSnapshot() :
- _sample_count(0)
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+DataSnapshot::DataSnapshot(int unit_size) :
+ _data(NULL),
+ _data_length(0),
+ _unit_size(unit_size)
+{
+ assert(_unit_size > 0);
+}
+
+DataSnapshot::~DataSnapshot()
{
+ free(_data);
}
uint64_t DataSnapshot::get_sample_count()
{
- return _sample_count;
+ return _data_length / _unit_size;
+}
+
+void DataSnapshot::append_data(void *data, uint64_t length)
+{
+ _data = realloc(_data, _data_length + length);
+ memcpy((uint8_t*)_data + _data_length, data, length);
+ _data_length += length;
}
class DataSnapshot
{
public:
- DataSnapshot();
+ DataSnapshot(int unit_size);
+
+ virtual ~DataSnapshot();
uint64_t get_sample_count();
protected:
- uint64_t _sample_count;
+ void append_data(void *data, uint64_t length);
+
+protected:
+ void *_data;
+ uint64_t _data_length;
+ int _unit_size;
};
{
}
+int LogicData::get_num_probes() const
+{
+ return _num_probes;
+}
+
void LogicData::push_snapshot(
boost::shared_ptr<LogicDataSnapshot> &snapshot)
{
public:
LogicData(const sr_datafeed_meta_logic &meta);
+ int get_num_probes() const;
+
void push_snapshot(
boost::shared_ptr<LogicDataSnapshot> &snapshot);
private:
- int _num_probes;
+ const int _num_probes;
};
#include "logicdatasnapshot.h"
+#include <assert.h>
+
#include <QDebug>
+LogicDataSnapshot::LogicDataSnapshot(
+ const sr_datafeed_logic &logic) :
+ DataSnapshot(logic.unitsize)
+{
+ append_payload(logic);
+}
+
void LogicDataSnapshot::append_payload(
const sr_datafeed_logic &logic)
{
+ assert(_unit_size == logic.unitsize);
+
qDebug() << "SR_DF_LOGIC (length =" << logic.length
<< ", unitsize = " << logic.unitsize << ")";
+
+ append_data(logic.data, logic.length);
}
class LogicDataSnapshot : public DataSnapshot
{
public:
+ LogicDataSnapshot(const sr_datafeed_logic &logic);
void append_payload(const sr_datafeed_logic &logic);
};
if(!_logic_data)
break;
- // Add an empty data snapshot
- shared_ptr<LogicDataSnapshot> snapshot(
- new LogicDataSnapshot());
- _logic_data->push_snapshot(snapshot);
- _cur_logic_snapshot = snapshot;
-
break;
}
case SR_DF_LOGIC:
+
assert(packet->payload);
- assert(_cur_logic_snapshot);
- if(_cur_logic_snapshot)
+ if(!_cur_logic_snapshot)
+ {
+ // Create a new data snapshot
+ _cur_logic_snapshot = shared_ptr<LogicDataSnapshot>(
+ new LogicDataSnapshot(
+ *(sr_datafeed_logic*)packet->payload));
+ _logic_data->push_snapshot(_cur_logic_snapshot);
+ }
+ else
+ {
+ // Append to the existing data snapshot
_cur_logic_snapshot->append_payload(
*(sr_datafeed_logic*)packet->payload);
+ }
+
break;
case SR_DF_END: