{
DevInst::use(owner);
- sr_session_new();
+ sr_session_new(&SigSession::_sr_session);
assert(_sdi);
sr_dev_open(_sdi);
- if (sr_session_dev_add(_sdi) != SR_OK)
+ if (sr_session_dev_add(SigSession::_sr_session, _sdi) != SR_OK)
throw QString(tr("Failed to use device."));
}
{
if (_owner) {
DevInst::release();
- sr_session_destroy();
+ sr_session_destroy(SigSession::_sr_session);
}
sr_dev_close(_sdi);
void DevInst::start()
{
- if (sr_session_start() != SR_OK)
+ if (sr_session_start(SigSession::_sr_session) != SR_OK)
throw tr("Failed to start session.");
}
void DevInst::run()
{
- sr_session_run();
+ sr_session_run(SigSession::_sr_session);
}
} // device
struct sr_channel;
struct sr_channel_group;
-namespace pv {
+#include <pv/sigsession.h>
-class SigSession;
+namespace pv {
namespace device {
File* File::create(const string &name)
{
- if (sr_session_load(name.c_str()) == SR_OK) {
+ if (sr_session_load(name.c_str(), &SigSession::_sr_session) == SR_OK) {
GSList *devlist = NULL;
- sr_session_dev_list(&devlist);
- sr_session_destroy();
+ sr_session_dev_list(SigSession::_sr_session, &devlist);
+ sr_session_destroy(SigSession::_sr_session);
if (devlist) {
sr_dev_inst *const sdi = (sr_dev_inst*)devlist->data;
_input = load_input_file_format(_path, NULL);
File::use(owner);
- sr_session_new();
+ sr_session_new(&SigSession::_sr_session);
- if (sr_session_dev_add(_input->sdi) != SR_OK)
+ if (sr_session_dev_add(SigSession::_sr_session, _input->sdi) != SR_OK)
throw tr("Failed to add session device.");
}
assert(_input);
File::release();
sr_dev_close(_input->sdi);
- sr_session_destroy();
+ sr_session_destroy(SigSession::_sr_session);
_input = NULL;
}
{
assert(!_sdi);
- if (sr_session_load(_path.c_str()) != SR_OK)
+ if (sr_session_load(_path.c_str(), &SigSession::_sr_session) != SR_OK)
throw tr("Failed to open file.\n");
GSList *devlist = NULL;
- sr_session_dev_list(&devlist);
+ sr_session_dev_list(SigSession::_sr_session, &devlist);
if (!devlist || !devlist->data) {
if (devlist)
File::release();
sr_dev_close(_sdi);
sr_dev_clear(_sdi->driver);
- sr_session_destroy();
+ sr_session_destroy(SigSession::_sr_session);
_sdi = NULL;
}
// TODO: This should not be necessary
SigSession* SigSession::_session = NULL;
+// TODO: This should not be necessary
+struct sr_session *SigSession::_sr_session = NULL;
+
SigSession::SigSession(DeviceManager &device_manager) :
_device_manager(device_manager),
_capture_state(Stopped)
stop_capture();
if (_dev_inst) {
- sr_session_datafeed_callback_remove_all();
+ sr_session_datafeed_callback_remove_all(_sr_session);
_dev_inst->release();
}
if (dev_inst) {
dev_inst->use(this);
- sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
+ sr_session_datafeed_callback_add(_sr_session, data_feed_in_proc, NULL);
update_signals(dev_inst);
}
}
void SigSession::stop_capture()
{
if (get_capture_state() != Stopped)
- sr_session_stop();
+ sr_session_stop(_sr_session);
// Check that sampling stopped
if (_sampling_thread.joinable())
return;
}
- set_capture_state(sr_session_trigger_get() ?
+ set_capture_state(sr_session_trigger_get(_sr_session) ?
AwaitingTrigger : Running);
dev_inst->run();
// sessions should should be supported and it should be
// possible to associate a pointer with a sr_session.
static SigSession *_session;
+
+public:
+ // TODO: Even more of a hack. The libsigrok API now allows for
+ // multiple sessions. However sr_session_* calls are scattered
+ // around the PV architecture and a single SigSession object is
+ // being used across multiple sequential sessions, which are
+ // created and destroyed in other classes in pv::device. This
+ // is a mess. For now just keep a single sr_session pointer here
+ // which we can use for all those scattered calls.
+ static struct sr_session *_sr_session;
};
} // namespace pv
probes[sigs.size()] = NULL;
// Begin storing
- if (sr_session_save_init(_file_name.c_str(),
+ if (sr_session_save_init(SigSession::_sr_session, _file_name.c_str(),
data->samplerate(), probes) != SR_OK) {
_error = tr("Error while saving.");
return false;
start_sample + samples_per_block, sample_count);
snapshot->get_samples(data, start_sample, end_sample);
- if(sr_session_append(_file_name.c_str(), data, unit_size,
- end_sample - start_sample) != SR_OK)
+ if(sr_session_append(SigSession::_sr_session, _file_name.c_str(), data,
+ unit_size, end_sample - start_sample) != SR_OK)
{
_error = tr("Error while saving.");
break;
/* Populate this channel's trigger setting with whatever we
* find in the current session trigger, if anything. */
_trigger_match = 0;
- if ((trigger = sr_session_trigger_get())) {
+ if ((trigger = sr_session_trigger_get(SigSession::_sr_session))) {
for (l = trigger->stages; l && !_trigger_match; l = l->next) {
stage = (struct sr_trigger_stage *)l->data;
for (m = stage->matches; m && !_trigger_match; m = m->next) {