using Glib::Variant;
namespace pv {
-
-// TODO: This should not be necessary
-shared_ptr<Session> SigSession::_sr_session = nullptr;
-
SigSession::SigSession(DeviceManager &device_manager) :
_device_manager(device_manager),
+ _session(device_manager.context()->create_session()),
_capture_state(Stopped)
{
- // TODO: This should not be necessary
- _sr_session = device_manager.context()->create_session();
-
set_default_device();
}
stop_capture();
}
+const shared_ptr<sigrok::Session>& SigSession::session() const
+{
+ return _session;
+}
+
shared_ptr<Device> SigSession::device() const
{
return _device;
auto prev_session_device = dynamic_pointer_cast<SessionDevice>(_device);
if (_device) {
- _sr_session->remove_datafeed_callbacks();
+ _session->remove_datafeed_callbacks();
if (!prev_session_device) {
_device->close();
- _sr_session->remove_devices();
+ _session->remove_devices();
}
}
if (session_device)
- _sr_session = session_device->parent();
+ _session = session_device->parent();
_device = device;
_decode_traces.clear();
if (device) {
if (!session_device)
{
- _sr_session = _device_manager.context()->create_session();
+ _session = _device_manager.context()->create_session();
device->open();
- _sr_session->add_device(device);
+ _session->add_device(device);
}
- _sr_session->add_datafeed_callback([=]
+ _session->add_datafeed_callback([=]
(shared_ptr<Device> device, shared_ptr<Packet> packet) {
data_feed_in(device, packet);
});
void SigSession::set_file(const string &name)
{
- _sr_session = _device_manager.context()->load_session(name);
- _device = _sr_session->devices()[0];
+ _session = _device_manager.context()->load_session(name);
+ _device = _session->devices()[0];
_decode_traces.clear();
- _sr_session->add_datafeed_callback([=]
+ _session->add_datafeed_callback([=]
(shared_ptr<Device> device, shared_ptr<Packet> packet) {
data_feed_in(device, packet);
});
void SigSession::stop_capture()
{
if (get_capture_state() != Stopped)
- _sr_session->stop();
+ _session->stop();
// Check that sampling stopped
if (_sampling_thread.joinable())
read_sample_rate(device);
try {
- _sr_session->start();
+ _session->start();
} catch(Error e) {
error_handler(e.what());
return;
}
- set_capture_state(_sr_session->trigger() ?
+ set_capture_state(_session->trigger() ?
AwaitingTrigger : Running);
- _sr_session->run();
+ _session->run();
set_capture_state(Stopped);
// Confirm that SR_DF_END was received
~SigSession();
+ const std::shared_ptr<sigrok::Session>& session() const;
+
std::shared_ptr<sigrok::Device> device() const;
/**
private:
DeviceManager &_device_manager;
+ std::shared_ptr<sigrok::Session> _session;
/**
* The device instance that will be used in the next capture session.
void data_received();
void frame_ended();
-
-public:
- // Hack. The libsigrok API now allows for multiple sessions. However,
- // sigrok::Session calls are scattered around the PV architecture and a
- // single SigSession object is being used across multiple sequential
- // sessions. This is a mess. For now just keep a single sigrok::Session
- // pointer here which we can use for all those scattered calls.
- static std::shared_ptr<sigrok::Session> _sr_session;
};
} // namespace pv
// Begin storing
try {
- auto context = _session._sr_session->context();
+ auto context = _session.session()->context();
auto output_format = context->output_formats()["srzip"];
- auto device = _session.get_device();
+ auto device = _session.device();
_output = output_format->create_output(device,
{{"filename",
Glib::Variant<Glib::ustring>::create(_file_name)}});
size_t length = end_sample - start_sample;
try {
- auto context = _session._sr_session->context();
+ auto context = _session.session()->context();
auto logic = context->create_logic_packet(data, length, unit_size);
_output->receive(logic);
} catch (Error error) {