]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
bindings: Use getters now that 'struct sr_dev_inst' is opaque.
[libsigrok.git] / bindings / cxx / classes.cpp
index 9013e41ae9d44ad004cfe2a9b218e742a719432e..83f1fbf73567f9ab2a5460e3a73f2668680645de 100644 (file)
@@ -413,16 +413,16 @@ bool Configurable::config_check(const ConfigKey *key,
 }
 
 Device::Device(struct sr_dev_inst *structure) :
-       Configurable(structure->driver, structure, NULL),
+       Configurable(sr_dev_inst_driver_get(structure), structure, NULL),
        _structure(structure)
 {
-       for (GSList *entry = structure->channels; entry; entry = entry->next)
+       for (GSList *entry = sr_dev_inst_channels_get(structure); entry; entry = entry->next)
        {
                auto channel = (struct sr_channel *) entry->data;
                _channels[channel] = new Channel(channel);
        }
 
-       for (GSList *entry = structure->channel_groups; entry; entry = entry->next)
+       for (GSList *entry = sr_dev_inst_channel_groups_get(structure); entry; entry = entry->next)
        {
                auto group = (struct sr_channel_group *) entry->data;
                _channel_groups[group->name] = new ChannelGroup(this, group);
@@ -437,58 +437,35 @@ Device::~Device()
                delete entry.second;
 }
 
-string Device::description()
-{
-       ostringstream s;
-
-       vector<string> parts =
-               {vendor(), model(), version(), serial_number()};
-
-       for (size_t i = 0; i < parts.size(); i++)
-       {
-               if (parts[i].length() > 0)
-               {
-                       if (i != 0)
-                               s << " ";
-                       s << parts[i];
-               }
-       }
-
-       if (serial_number().length() == 0 && connection_id().length() > 0)
-               s << " " << connection_id();
-
-       return s.str();
-}
-
 string Device::vendor()
 {
-       return valid_string(_structure->vendor);
+       return valid_string(sr_dev_inst_vendor_get(_structure));
 }
 
 string Device::model()
 {
-       return valid_string(_structure->model);
+       return valid_string(sr_dev_inst_model_get(_structure));
 }
 
 string Device::version()
 {
-       return valid_string(_structure->version);
+       return valid_string(sr_dev_inst_version_get(_structure));
 }
 
 string Device::serial_number()
 {
-       return valid_string(_structure->serial_num);
+       return valid_string(sr_dev_inst_sernum_get(_structure));
 }
 
 string Device::connection_id()
 {
-       return valid_string(_structure->connection_id);
+       return valid_string(sr_dev_inst_connid_get(_structure));
 }
 
 vector<shared_ptr<Channel>> Device::channels()
 {
        vector<shared_ptr<Channel>> result;
-       for (auto channel = _structure->channels; channel; channel = channel->next)
+       for (auto channel = sr_dev_inst_channels_get(_structure); channel; channel = channel->next)
                result.push_back(
                        _channels[(struct sr_channel *) channel->data]->get_shared_pointer(
                                get_shared_from_this()));
@@ -589,7 +566,7 @@ unsigned int Channel::index()
 ChannelGroup::ChannelGroup(Device *device,
                struct sr_channel_group *structure) :
        ParentOwned(structure),
-       Configurable(device->_structure->driver, device->_structure, structure)
+       Configurable(sr_dev_inst_driver_get(device->_structure), device->_structure, structure)
 {
        for (GSList *entry = structure->channels; entry; entry = entry->next)
                _channels.push_back(device->_channels[(struct sr_channel *)entry->data]);
@@ -789,11 +766,6 @@ SessionDevice::~SessionDevice()
 {
 }
 
-string SessionDevice::description()
-{
-       return _parent->_filename;
-}
-
 shared_ptr<Device> SessionDevice::get_shared_from_this()
 {
        return static_pointer_cast<Device>(shared_from_this());
@@ -871,16 +843,6 @@ vector<shared_ptr<Device>> Session::devices()
 
 void Session::remove_devices()
 {
-       for (auto entry : _owned_devices)
-       {
-               // We own this device. Make sure it's not referenced.
-               auto device = entry.second;
-               auto ptr = device->get_shared_pointer(this);
-               if (ptr.use_count() > 1)
-                       throw Error(SR_ERR_BUG);
-               delete device;
-       }
-       _owned_devices.clear();
        _other_devices.clear();
        check(sr_session_dev_remove_all(_structure));
 }
@@ -935,7 +897,7 @@ void Session::append(shared_ptr<Packet> packet)
                        {
                                GVariant *samplerate;
 
-                               check(sr_config_get(packet->_device->_structure->driver,
+                               check(sr_config_get(sr_dev_inst_driver_get(packet->_device->_structure),
                                        packet->_device->_structure, NULL, SR_CONF_SAMPLERATE,
                                        &samplerate));
 
@@ -1081,6 +1043,11 @@ void Session::set_trigger(shared_ptr<Trigger> trigger)
        _trigger = trigger;
 }
 
+string Session::filename()
+{
+       return _filename;
+}
+
 Packet::Packet(shared_ptr<Device> device,
        const struct sr_datafeed_packet *structure) :
        UserOwned(structure),
@@ -1370,11 +1337,6 @@ InputDevice::~InputDevice()
 {
 }
 
-string InputDevice::description()
-{
-       return "<input data>";
-}
-
 shared_ptr<Device> InputDevice::get_shared_from_this()
 {
        return static_pointer_cast<Device>(shared_from_this());