]> sigrok.org Git - pulseview.git/blobdiff - pv/storesession.cpp
RowItem: Split appart visual and layout v offsets
[pulseview.git] / pv / storesession.cpp
index d5355cba3bbe03c71aeb2bf27a2bc654f72479bb..ef1c6aad2d245317988066b65c3299033d89ebca 100644 (file)
@@ -29,6 +29,9 @@
 
 #include <libsigrok/libsigrok.hpp>
 
+using boost::shared_lock;
+using boost::shared_mutex;
+
 using std::deque;
 using std::dynamic_pointer_cast;
 using std::lock_guard;
@@ -42,6 +45,7 @@ using std::string;
 using std::thread;
 using std::vector;
 
+using sigrok::ConfigKey;
 using sigrok::Error;
 
 namespace pv {
@@ -78,8 +82,9 @@ bool StoreSession::start()
 {
        set< shared_ptr<data::SignalData> > data_set =
                _session.get_data();
-       const vector< shared_ptr<view::Signal> > sigs =
-               _session.get_signals();
+
+       shared_lock<shared_mutex> lock(_session.signals_mutex());
+       const vector< shared_ptr<view::Signal> > &sigs(_session.signals());
 
        // Check we have logic data
        if (data_set.empty() || sigs.empty()) {
@@ -94,7 +99,6 @@ bool StoreSession::start()
        }
 
        // Get the logic data
-       //shared_ptr<data::SignalData
        shared_ptr<data::Logic> data;
        if (!(data = dynamic_pointer_cast<data::Logic>(*data_set.begin()))) {
                _error = tr("PulseView currently only has support for "
@@ -114,28 +118,23 @@ bool StoreSession::start()
        const shared_ptr<data::LogicSnapshot> snapshot(snapshots.front());
        assert(snapshot);
 
-       // Make a list of channels
-       char **const channels = new char*[sigs.size() + 1];
-       for (size_t i = 0; i < sigs.size(); i++) {
-               shared_ptr<view::Signal> sig(sigs[i]);
-               assert(sig);
-               channels[i] = strdup(sig->get_name().toUtf8().constData());
-       }
-       channels[sigs.size()] = NULL;
-
        // Begin storing
        try {
-               SigSession::_sr_session->begin_save(_file_name);
+               auto context = _session.session()->context();
+               auto output_format = context->output_formats()["srzip"];
+               auto device = _session.device();
+               _output = output_format->create_output(device,
+                       {{"filename",
+                               Glib::Variant<Glib::ustring>::create(_file_name)}});
+               auto meta = context->create_meta_packet(
+                       {{ConfigKey::SAMPLERATE,
+                               Glib::Variant<guint64>::create(data->samplerate())}});
+               _output->receive(meta);
        } catch (Error error) {
                _error = tr("Error while saving.");
                return false;
        }
 
-       // Delete the channels array
-       for (size_t i = 0; i <= sigs.size(); i++)
-               free(channels[i]);
-       delete[] channels;
-
        _thread = std::thread(&StoreSession::store_proc, this, snapshot);
        return true;
 }
@@ -187,7 +186,9 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
                size_t length = end_sample - start_sample;
 
                try {
-                       SigSession::_sr_session->append(data, length, unit_size);
+                       auto context = _session.session()->context();
+                       auto logic = context->create_logic_packet(data, length, unit_size);
+                       _output->receive(logic);
                } catch (Error error) {
                        _error = tr("Error while saving.");
                        break;
@@ -197,9 +198,10 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> snapshot)
                _units_stored = start_sample >> progress_scale;
        }
 
-       _unit_count = 0;
        progress_updated();
 
+       _output.reset();
+
        delete[] data;
 }