X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fsession.cpp;h=aa528d191fe6750958bd2cbf8491fe8bb35383d0;hb=f23c46921d031dba4c96062164cc9f3ca3c4809c;hp=e84f78042b89593e9cb96adef18ed187067e5b11;hpb=6f925ba9d6faf1077b73c5a5808259576081716a;p=pulseview.git
diff --git a/pv/session.cpp b/pv/session.cpp
index e84f7804..aa528d19 100644
--- a/pv/session.cpp
+++ b/pv/session.cpp
@@ -17,32 +17,25 @@
* along with this program; if not, see .
*/
-#ifdef _WIN32
-// Windows: Avoid boost/thread namespace pollution (which includes windows.h).
-#define NOGDI
-#define NORESOURCE
-#endif
-#include
-#include
-
#include
#include
+#include
#include
#include
#include
-#include "session.hpp"
#include "devicemanager.hpp"
+#include "session.hpp"
#include "data/analog.hpp"
#include "data/analogsegment.hpp"
+#include "data/decode/decoder.hpp"
#include "data/decoderstack.hpp"
#include "data/logic.hpp"
#include "data/logicsegment.hpp"
#include "data/signalbase.hpp"
-#include "data/decode/decoder.hpp"
#include "devices/hardwaredevice.hpp"
#include "devices/inputfile.hpp"
@@ -50,11 +43,11 @@
#include "toolbars/mainbar.hpp"
-#include "view/analogsignal.hpp"
-#include "view/decodetrace.hpp"
-#include "view/logicsignal.hpp"
-#include "view/signal.hpp"
-#include "view/view.hpp"
+#include "views/trace/analogsignal.hpp"
+#include "views/trace/decodetrace.hpp"
+#include "views/trace/logicsignal.hpp"
+#include "views/trace/signal.hpp"
+#include "views/trace/view.hpp"
#include
@@ -62,10 +55,6 @@
#include
#endif
-using boost::shared_lock;
-using boost::shared_mutex;
-using boost::unique_lock;
-
using std::bad_alloc;
using std::dynamic_pointer_cast;
using std::find_if;
@@ -81,30 +70,24 @@ using std::mutex;
using std::pair;
using std::recursive_mutex;
using std::runtime_error;
-using std::set;
using std::shared_ptr;
using std::string;
+using std::unique_ptr;
using std::unordered_set;
using std::vector;
using sigrok::Analog;
using sigrok::Channel;
-using sigrok::ChannelType;
using sigrok::ConfigKey;
using sigrok::DatafeedCallbackFunction;
using sigrok::Error;
-using sigrok::Header;
using sigrok::InputFormat;
using sigrok::Logic;
using sigrok::Meta;
-using sigrok::OutputFormat;
using sigrok::Packet;
-using sigrok::PacketPayload;
using sigrok::Session;
-using sigrok::SessionDevice;
using Glib::VariantBase;
-using Glib::Variant;
namespace pv {
Session::Session(DeviceManager &device_manager, QString name) :
@@ -621,6 +604,9 @@ const unordered_set< shared_ptr > Session::signalbases() const
#ifdef ENABLE_DECODE
bool Session::add_decoder(srd_decoder *const dec)
{
+ if (!dec)
+ return false;
+
map > channels;
shared_ptr decoder_stack;
@@ -638,7 +624,7 @@ bool Session::add_decoder(srd_decoder *const dec)
// Auto select the initial channels
for (const srd_channel *pdch : all_channels)
for (shared_ptr b : signalbases_) {
- if (b->type() == ChannelType::LOGIC) {
+ if (b->logic_data()) {
if (QString::fromUtf8(pdch->name).toLower().
contains(b->name().toLower()))
channels[pdch] = b;
@@ -652,7 +638,7 @@ bool Session::add_decoder(srd_decoder *const dec)
// Create the decode signal
shared_ptr signalbase =
- make_shared(nullptr);
+ make_shared(nullptr, data::SignalBase::DecodeChannel);
signalbase->set_decoder_stack(decoder_stack);
signalbases_.insert(signalbase);
@@ -730,7 +716,7 @@ void Session::update_signals()
unsigned int logic_channel_count = count_if(
channels.begin(), channels.end(),
[] (shared_ptr channel) {
- return channel->type() == ChannelType::LOGIC; });
+ return channel->type() == sigrok::ChannelType::LOGIC; });
// Create data containers for the logic data segments
{
@@ -748,22 +734,22 @@ void Session::update_signals()
// Make the signals list
for (shared_ptr viewbase : views_) {
- views::TraceView::View *trace_view =
- qobject_cast(viewbase.get());
+ views::trace::View *trace_view =
+ qobject_cast(viewbase.get());
if (trace_view) {
- unordered_set< shared_ptr >
+ unordered_set< shared_ptr >
prev_sigs(trace_view->signals());
trace_view->clear_signals();
for (auto channel : sr_dev->channels()) {
shared_ptr signalbase;
- shared_ptr signal;
+ shared_ptr signal;
// Find the channel in the old signals
const auto iter = find_if(
prev_sigs.cbegin(), prev_sigs.cend(),
- [&](const shared_ptr &s) {
+ [&](const shared_ptr &s) {
return s->base()->channel() == channel;
});
if (iter != prev_sigs.end()) {
@@ -780,15 +766,19 @@ void Session::update_signals()
switch(channel->type()->id()) {
case SR_CHANNEL_LOGIC:
if (!signalbase) {
- signalbase = make_shared(channel);
+ signalbase = make_shared(channel,
+ data::SignalBase::LogicChannel);
signalbases_.insert(signalbase);
all_signal_data_.insert(logic_data_);
signalbase->set_data(logic_data_);
+
+ connect(this, SIGNAL(capture_state_changed(int)),
+ signalbase.get(), SLOT(on_capture_state_changed(int)));
}
- signal = shared_ptr(
- new views::TraceView::LogicSignal(*this,
+ signal = shared_ptr(
+ new views::trace::LogicSignal(*this,
device_, signalbase));
trace_view->add_signal(signal);
break;
@@ -796,23 +786,27 @@ void Session::update_signals()
case SR_CHANNEL_ANALOG:
{
if (!signalbase) {
- signalbase = make_shared(channel);
+ signalbase = make_shared(channel,
+ data::SignalBase::AnalogChannel);
signalbases_.insert(signalbase);
shared_ptr data(new data::Analog());
all_signal_data_.insert(data);
signalbase->set_data(data);
+
+ connect(this, SIGNAL(capture_state_changed(int)),
+ signalbase.get(), SLOT(on_capture_state_changed(int)));
}
- signal = shared_ptr(
- new views::TraceView::AnalogSignal(
+ signal = shared_ptr(
+ new views::trace::AnalogSignal(
*this, signalbase));
trace_view->add_signal(signal);
break;
}
default:
- assert(0);
+ assert(false);
break;
}
}
@@ -855,13 +849,20 @@ void Session::sample_thread_proc(function error_handler)
set_capture_state(device_->session()->trigger() ?
AwaitingTrigger : Running);
- device_->run();
+ try {
+ device_->run();
+ } catch (Error e) {
+ error_handler(e.what());
+ set_capture_state(Stopped);
+ return;
+ }
+
set_capture_state(Stopped);
// Confirm that SR_DF_END was received
if (cur_logic_segment_) {
qDebug("SR_DF_END was not received.");
- assert(0);
+ assert(false);
}
// Optimize memory usage
@@ -961,7 +962,7 @@ void Session::feed_in_logic(shared_ptr logic)
// Create a new data segment
cur_logic_segment_ = make_shared(
- *logic_data_, logic, cur_samplerate_);
+ *logic_data_, logic->unit_size(), cur_samplerate_);
logic_data_->push_segment(cur_logic_segment_);
// @todo Putting this here means that only listeners querying
@@ -969,11 +970,10 @@ void Session::feed_in_logic(shared_ptr logic)
// frame_began is DecoderStack, but in future we need to signal
// this after both analog and logic sweeps have begun.
frame_began();
- } else {
- // Append to the existing data segment
- cur_logic_segment_->append_payload(logic);
}
+ cur_logic_segment_->append_payload(logic);
+
data_received();
}
@@ -984,12 +984,15 @@ void Session::feed_in_analog(shared_ptr analog)
const vector> channels = analog->channels();
const unsigned int channel_count = channels.size();
const size_t sample_count = analog->num_samples() / channel_count;
- const float *data = static_cast(analog->data_pointer());
bool sweep_beginning = false;
+ unique_ptr data(new float[analog->num_samples()]);
+ analog->get_data_as_float(data.get());
+
if (signalbases_.empty())
update_signals();
+ float *channel_data = data.get();
for (auto channel : channels) {
shared_ptr segment;
@@ -1023,7 +1026,7 @@ void Session::feed_in_analog(shared_ptr analog)
assert(segment);
// Append the samples in the segment
- segment->append_interleaved_samples(data++, sample_count,
+ segment->append_interleaved_samples(channel_data++, sample_count,
channel_count);
}
@@ -1038,7 +1041,7 @@ void Session::feed_in_analog(shared_ptr analog)
void Session::data_feed_in(shared_ptr device,
shared_ptr packet)
{
- static bool frame_began=false;
+ static bool frame_began = false;
(void)device;