template <class Parent, typename Struct> class SR_API StructureWrapper :
public enable_shared_from_this<StructureWrapper<Parent, Struct> >
{
-public:
+protected:
/* Parent object which owns this child object's underlying structure.
This shared pointer will be null when this child is unused, but
the parent are called at the correct time, i.e. only when all
references to both the parent and all its children are gone. */
shared_ptr<Parent> parent;
+
+public:
+ shared_ptr<StructureWrapper<Parent, Struct> >
+ get_shared_pointer(Parent *parent)
+ {
+ this->parent = static_pointer_cast<Parent>(parent->shared_from_this());
+ return shared_ptr<StructureWrapper<Parent, Struct> >(
+ this, reset_parent);
+ }
+ shared_ptr<StructureWrapper<Parent, Struct> >
+ get_shared_pointer(shared_ptr<Parent> parent)
+ {
+ this->parent = parent;
+ return shared_ptr<StructureWrapper<Parent, Struct> >(
+ this, reset_parent);
+ }
protected:
+ static void reset_parent(StructureWrapper<Parent, Struct> *object)
+ {
+ object->parent.reset();
+ }
+
Struct *structure;
StructureWrapper<Parent, Struct>(Struct *structure) :
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. */
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;
+ map<string, ChannelGroup *> channel_groups;
/** Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
{
friend class Channel;
friend class ChannelGroup;
friend class Output;
+ friend class Analog;
};
/** A real hardware device, connected via a driver */
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 */
};
/** A packet on the session datafeed */
-class SR_API Packet
+class SR_API Packet : public enable_shared_from_this<Packet>
{
public:
/** Type of this packet. */
const PacketType *get_type();
/** Payload of this packet. */
- PacketPayload *get_payload();
+ shared_ptr<PacketPayload> get_payload();
protected:
- Packet(const struct sr_datafeed_packet *structure);
+ Packet(shared_ptr<Device> device,
+ const struct sr_datafeed_packet *structure);
~Packet();
const struct sr_datafeed_packet *structure;
+ shared_ptr<Device> device;
PacketPayload *payload;
/** Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
friend class Session;
friend class Output;
friend class DatafeedCallbackData;
+ friend class Header;
+ friend class Meta;
+ friend class Logic;
+ friend class Analog;
};
/** Abstract base class for datafeed packet payloads */
protected:
PacketPayload();
virtual ~PacketPayload() = 0;
- virtual void *get_data() = 0;
- virtual size_t get_data_size() = 0;
+ shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) {
+ return static_pointer_cast<PacketPayload>(get_shared_pointer(parent));
+ }
+ /** Deleter needed to allow shared_ptr use with protected destructor. */
+ class Deleter
+ {
+ public:
+ void operator()(PacketPayload *payload) { delete payload; }
+ };
+ friend class Deleter;
friend class Packet;
friend class Output;
};
+/** Payload of a datafeed header packet */
+class SR_API Header : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_header>
+{
+public:
+ int get_feed_version();
+ Glib::TimeVal get_start_time();
+protected:
+ Header(const struct sr_datafeed_header *structure);
+ ~Header();
+ const struct sr_datafeed_header *structure;
+ friend class Packet;
+};
+
+/** Payload of a datafeed metadata packet */
+class SR_API Meta : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_meta>
+{
+public:
+ map<const ConfigKey *, Glib::VariantBase> get_config();
+protected:
+ Meta(const struct sr_datafeed_meta *structure);
+ ~Meta();
+ const struct sr_datafeed_meta *structure;
+ map<const ConfigKey *, Glib::VariantBase> config;
+ friend class Packet;
+};
+
/** Payload of a datafeed packet with logic data */
-class SR_API Logic : public PacketPayload
+class SR_API Logic : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_logic>
{
+public:
+ /* Pointer to data. */
+ void *get_data_pointer();
+ /* Data length in bytes. */
+ size_t get_data_length();
+ /* Size of each sample in bytes. */
+ unsigned int get_unit_size();
protected:
Logic(const struct sr_datafeed_logic *structure);
~Logic();
const struct sr_datafeed_logic *structure;
- vector<uint8_t> data;
- void *get_data();
- size_t get_data_size();
friend class Packet;
};
/** Payload of a datafeed packet with analog data */
-class SR_API Analog : public PacketPayload
+class SR_API Analog : public PacketPayload,
+ public StructureWrapper<Packet, const struct sr_datafeed_analog>
{
public:
+ /** Pointer to data. */
+ float *get_data_pointer();
/** Number of samples in this packet. */
unsigned int get_num_samples();
+ /** Channels for which this packet contains data. */
+ vector<shared_ptr<Channel> > get_channels();
/** Measured quantity of the samples in this packet. */
const Quantity *get_mq();
/** Unit of the samples in this packet. */
Analog(const struct sr_datafeed_analog *structure);
~Analog();
const struct sr_datafeed_analog *structure;
- void *get_data();
- size_t get_data_size();
friend class Packet;
};