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()
channels[ptr]->get_shared_pointer(this));
}
+map<string, shared_ptr<ChannelGroup>>
+Device::get_channel_groups()
+{
+ map<string, shared_ptr<ChannelGroup>> result;
+ for (auto entry: channel_groups)
+ {
+ auto name = entry.first;
+ auto channel_group = entry.second;
+ result[name] = static_pointer_cast<ChannelGroup>(
+ channel_group->get_shared_pointer(this));
+ }
+ return result;
+}
+
void Device::open()
{
check(sr_dev_open(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<Driver> HardwareDevice::get_driver()
return static_pointer_cast<Driver>(driver->get_shared_pointer(parent));
}
-map<string, shared_ptr<ChannelGroup>>
-HardwareDevice::get_channel_groups()
-{
- map<string, shared_ptr<ChannelGroup>> result;
- for (auto entry: channel_groups)
- {
- auto name = entry.first;
- auto channel_group = entry.second;
- result[name] = static_pointer_cast<ChannelGroup>(
- channel_group->get_shared_pointer(this));
- }
- return result;
-}
-
Channel::Channel(struct sr_channel *structure) :
StructureWrapper<Device, struct sr_channel>(structure),
type(ChannelType::get(structure->type))
check(sr_dev_channel_enable(parent->structure, structure->index, value));
}
-ChannelGroup::ChannelGroup(HardwareDevice *device,
+ChannelGroup::ChannelGroup(Device *device,
struct sr_channel_group *structure) :
- StructureWrapper<HardwareDevice, struct sr_channel_group>(structure),
+ StructureWrapper<Device, struct sr_channel_group>(structure),
Configurable(device->structure->driver, device->structure, structure)
{
for (GSList *entry = structure->channels; entry; entry = entry->next)
string get_version();
/** List of the channels available on this device. */
vector<shared_ptr<Channel> > get_channels();
+ /** Channel groups available on this device, indexed by name. */
+ map<string, shared_ptr<ChannelGroup> > get_channel_groups();
/** Open device. */
void open();
/** Close device. */
~Device();
shared_ptr<Channel> get_channel(struct sr_channel *ptr);
map<struct sr_channel *, Channel *> channels;
+ map<string, ChannelGroup *> channel_groups;
/** Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
{
public:
/** Driver providing this device. */
shared_ptr<Driver> get_driver();
- /** Channel groups available on this device, indexed by name. */
- map<string, shared_ptr<ChannelGroup> > get_channel_groups();
protected:
HardwareDevice(Driver *driver, struct sr_dev_inst *structure);
~HardwareDevice();
Driver *driver;
- map<string, ChannelGroup *> channel_groups;
friend class Driver;
friend class ChannelGroup;
};
/** A group of channels on a device, which share some configuration */
class SR_API ChannelGroup :
- public StructureWrapper<HardwareDevice, struct sr_channel_group>,
+ public StructureWrapper<Device, struct sr_channel_group>,
public Configurable
{
public:
/** List of the channels in this group. */
vector<shared_ptr<Channel> > get_channels();
protected:
- ChannelGroup(HardwareDevice *device, struct sr_channel_group *structure);
+ ChannelGroup(Device *device, struct sr_channel_group *structure);
~ChannelGroup();
vector<Channel *> channels;
- friend class HardwareDevice;
+ friend class Device;
};
/** A trigger configuration */
std::vector<std::shared_ptr<sigrok::Channel> >,
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<sigrok::Driver>, 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);