for (GSList *entry = structure->channels; entry; entry = entry->next)
{
auto channel = (struct sr_channel *) entry->data;
- channels.push_back(new Channel(channel));
+ channels[channel] = new Channel(channel);
}
}
Device::~Device()
{
- for (auto channel : channels)
- delete channel;
+ for (auto entry : channels)
+ delete entry.second;
}
string Device::get_vendor()
vector<shared_ptr<Channel>> Device::get_channels()
{
vector<shared_ptr<Channel>> result;
- for (auto channel : channels)
+ for (auto entry : channels)
result.push_back(static_pointer_cast<Channel>(
- channel->get_shared_pointer(this)));
+ entry.second->get_shared_pointer(this)));
return result;
}
+shared_ptr<Channel> Device::get_channel(struct sr_channel *ptr)
+{
+ return static_pointer_cast<Channel>(
+ channels[ptr]->get_shared_pointer(this));
+}
+
void Device::open()
{
check(sr_dev_open(structure));
Configurable(device->structure->driver, device->structure, structure)
{
for (GSList *entry = structure->channels; entry; entry = entry->next)
- {
- auto channel = (struct sr_channel *) entry->data;
- for (auto device_channel : device->channels)
- if (channel == device_channel->structure)
- channels.push_back(device_channel);
- }
+ channels.push_back(device->channels[(struct sr_channel *)entry->data]);
}
ChannelGroup::~ChannelGroup()
protected:
Device(struct sr_dev_inst *structure);
~Device();
- vector<Channel *> channels;
+ shared_ptr<Channel> get_channel(struct sr_channel *ptr);
+ map<struct sr_channel *, Channel *> channels;
/** Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
{