delete entry.second;
}
-string Device::description()
-{
- ostringstream s;
-
- vector<string> parts =
- {vendor(), model(), version()};
-
- for (string part : parts)
- if (part.length() > 0)
- s << part;
-
- return s.str();
-}
-
string Device::vendor()
{
return valid_string(_structure->vendor);
return valid_string(_structure->version);
}
+string Device::serial_number()
+{
+ return valid_string(_structure->serial_num);
+}
+
+string Device::connection_id()
+{
+ return valid_string(_structure->connection_id);
+}
+
vector<shared_ptr<Channel>> Device::channels()
{
vector<shared_ptr<Channel>> result;
void DatafeedCallbackData::run(const struct sr_dev_inst *sdi,
const struct sr_datafeed_packet *pkt)
{
- auto device = _session->_devices[sdi];
+ auto device = _session->get_device(sdi);
auto packet = shared_ptr<Packet>(new Packet(device, pkt), Packet::Deleter());
_callback(device, packet);
}
Session::Session(shared_ptr<Context> context, string filename) :
UserOwned(_structure),
_context(context),
+ _filename(filename),
_saving(false)
{
check(sr_session_load(filename.c_str(), &_structure));
for (GSList *dev = dev_list; dev; dev = dev->next)
{
auto sdi = (struct sr_dev_inst *) dev->data;
- auto device = new SessionDevice(sdi);
- _devices[sdi] = shared_ptr<SessionDevice>(device,
- SessionDevice::Deleter());
+ _owned_devices[sdi] = new SessionDevice(sdi);
}
_context->_session = this;
}
for (auto entry : _source_callbacks)
delete entry.second;
+
+ for (auto entry : _owned_devices)
+ delete entry.second;
+}
+
+shared_ptr<Device> Session::get_device(const struct sr_dev_inst *sdi)
+{
+ if (_owned_devices.count(sdi))
+ return static_pointer_cast<Device>(
+ _owned_devices[sdi]->get_shared_pointer(this));
+ else if (_other_devices.count(sdi))
+ return _other_devices[sdi];
+ else
+ throw Error(SR_ERR_BUG);
}
void Session::add_device(shared_ptr<Device> device)
{
check(sr_session_dev_add(_structure, device->_structure));
- _devices[device->_structure] = device;
+ _other_devices[device->_structure] = device;
}
vector<shared_ptr<Device>> Session::devices()
for (GSList *dev = dev_list; dev; dev = dev->next)
{
auto sdi = (struct sr_dev_inst *) dev->data;
- result.push_back(_devices[sdi]);
+ result.push_back(get_device(sdi));
}
return result;
}
void Session::remove_devices()
{
- _devices.clear();
+ _other_devices.clear();
check(sr_session_dev_remove_all(_structure));
}
_trigger = trigger;
}
+string Session::filename()
+{
+ return _filename;
+}
+
Packet::Packet(shared_ptr<Device> device,
const struct sr_datafeed_packet *structure) :
UserOwned(structure),