From: Martin Ling Date: Thu, 24 Jul 2014 11:41:49 +0000 (+0100) Subject: bindings: Support get_channel_groups() on base Device class. X-Git-Tag: libsigrok-0.4.0~1201 X-Git-Url: http://sigrok.org/gitweb/?a=commitdiff_plain;ds=inline;h=6be7a7f287a5567361f1dadf41a9d11b828a9101;hp=2928f47d6404e51c2dda1842c43db578cb1d6cdd;p=libsigrok.git bindings: Support get_channel_groups() on base Device class. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 2ae0f298..889c996e 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -346,12 +346,20 @@ Device::Device(struct sr_dev_inst *structure) : auto channel = (struct sr_channel *) entry->data; channels[channel] = new Channel(channel); } + + for (GSList *entry = structure->channel_groups; entry; entry = entry->next) + { + auto group = (struct sr_channel_group *) entry->data; + channel_groups[group->name] = new ChannelGroup(this, group); + } } Device::~Device() { for (auto entry : channels) delete entry.second; + for (auto entry : channel_groups) + delete entry.second; } string Device::get_vendor() @@ -384,6 +392,20 @@ shared_ptr Device::get_channel(struct sr_channel *ptr) channels[ptr]->get_shared_pointer(this)); } +map> +Device::get_channel_groups() +{ + map> result; + for (auto entry: channel_groups) + { + auto name = entry.first; + auto channel_group = entry.second; + result[name] = static_pointer_cast( + channel_group->get_shared_pointer(this)); + } + return result; +} + void Device::open() { check(sr_dev_open(structure)); @@ -398,17 +420,10 @@ HardwareDevice::HardwareDevice(Driver *driver, struct sr_dev_inst *structure) : Device(structure), driver(driver) { - for (GSList *entry = structure->channel_groups; entry; entry = entry->next) - { - auto group = (struct sr_channel_group *) entry->data; - channel_groups[group->name] = new ChannelGroup(this, group); - } } HardwareDevice::~HardwareDevice() { - for (auto entry : channel_groups) - delete entry.second; } shared_ptr HardwareDevice::get_driver() @@ -416,20 +431,6 @@ shared_ptr HardwareDevice::get_driver() return static_pointer_cast(driver->get_shared_pointer(parent)); } -map> -HardwareDevice::get_channel_groups() -{ - map> result; - for (auto entry: channel_groups) - { - auto name = entry.first; - auto channel_group = entry.second; - result[name] = static_pointer_cast( - channel_group->get_shared_pointer(this)); - } - return result; -} - Channel::Channel(struct sr_channel *structure) : StructureWrapper(structure), type(ChannelType::get(structure->type)) @@ -465,9 +466,9 @@ void Channel::set_enabled(bool value) check(sr_dev_channel_enable(parent->structure, structure->index, value)); } -ChannelGroup::ChannelGroup(HardwareDevice *device, +ChannelGroup::ChannelGroup(Device *device, struct sr_channel_group *structure) : - StructureWrapper(structure), + StructureWrapper(structure), Configurable(device->structure->driver, device->structure, structure) { for (GSList *entry = structure->channels; entry; entry = entry->next) diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index 32045597..c4150904 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -284,6 +284,8 @@ public: string get_version(); /** List of the channels available on this device. */ vector > get_channels(); + /** Channel groups available on this device, indexed by name. */ + map > get_channel_groups(); /** Open device. */ void open(); /** Close device. */ @@ -293,6 +295,7 @@ protected: ~Device(); shared_ptr get_channel(struct sr_channel *ptr); map channels; + map channel_groups; /** Deleter needed to allow shared_ptr use with protected destructor. */ class Deleter { @@ -313,13 +316,10 @@ class SR_API HardwareDevice : public Device public: /** Driver providing this device. */ shared_ptr get_driver(); - /** Channel groups available on this device, indexed by name. */ - map > get_channel_groups(); protected: HardwareDevice(Driver *driver, struct sr_dev_inst *structure); ~HardwareDevice(); Driver *driver; - map channel_groups; friend class Driver; friend class ChannelGroup; }; @@ -350,7 +350,7 @@ protected: /** A group of channels on a device, which share some configuration */ class SR_API ChannelGroup : - public StructureWrapper, + public StructureWrapper, public Configurable { public: @@ -359,10 +359,10 @@ public: /** List of the channels in this group. */ vector > get_channels(); protected: - ChannelGroup(HardwareDevice *device, struct sr_channel_group *structure); + ChannelGroup(Device *device, struct sr_channel_group *structure); ~ChannelGroup(); vector channels; - friend class HardwareDevice; + friend class Device; }; /** A trigger configuration */ diff --git a/bindings/swig/classes.i b/bindings/swig/classes.i index 445fdfbb..7c6b60c6 100644 --- a/bindings/swig/classes.i +++ b/bindings/swig/classes.i @@ -188,14 +188,14 @@ typedef std::map std::vector >, channels, get_channels); +%attributeval(sigrok::Device, map_string_ChannelGroup, + channel_groups, get_channel_groups); + /* Using %attributestring for shared_ptr attribute. See http://sourceforge.net/p/swig/mailman/message/31832070/ */ %attributestring(sigrok::HardwareDevice, std::shared_ptr, driver, get_driver); -%attributeval(sigrok::HardwareDevice, map_string_ChannelGroup, - channel_groups, get_channel_groups); - %attributestring(sigrok::Channel, std::string, name, get_name, set_name); %attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled); %attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type);