+private:
+ /* Weak pointer for shared_from_this() implementation. */
+ weak_ptr<Class> _weak_this;
+
+ static void reset_parent(Class *object)
+ {
+ if (!object->_parent)
+ throw Error(SR_ERR_BUG);
+ object->_parent.reset();
+ }
+
/* Note, this implementation will create a new smart_ptr if none exists. */
shared_ptr<Class> shared_from_this()
{
/* Note, this implementation will create a new smart_ptr if none exists. */
shared_ptr<Class> shared_from_this()
{
- shared_ptr<Class> get_shared_pointer(Parent *parent)
- {
- if (!parent)
- throw Error(SR_ERR_BUG);
- return get_shared_pointer(parent->shared_from_this());
- }
-protected:
- static void reset_parent(Class *object)
- {
- if (!object->_parent)
- throw Error(SR_ERR_BUG);
- object->_parent.reset();
- }
-
- Struct *_structure;
-
- ParentOwned<Class, Parent, Struct>(Struct *structure) :
- _structure(structure)
+public:
+ /* Get parent object that owns this object. */
+ shared_ptr<Parent> parent()
shared_ptr<Class> shared_from_this()
{
auto shared = enable_shared_from_this<Class>::shared_from_this();
shared_ptr<Class> shared_from_this()
{
auto shared = enable_shared_from_this<Class>::shared_from_this();
virtual size_t read(const struct sr_resource *res, void *buf, size_t count) = 0;
static SR_PRIV int open_callback(struct sr_resource *res,
virtual size_t read(const struct sr_resource *res, void *buf, size_t count) = 0;
static SR_PRIV int open_callback(struct sr_resource *res,
{
public:
/** Create new context */
static shared_ptr<Context> create();
/** libsigrok package version. */
{
public:
/** Create new context */
static shared_ptr<Context> create();
/** libsigrok package version. */
/** Available hardware drivers, indexed by name. */
map<string, shared_ptr<Driver> > drivers();
/** Available input formats, indexed by name. */
/** Available hardware drivers, indexed by name. */
map<string, shared_ptr<Driver> > drivers();
/** Available input formats, indexed by name. */
/** Available output formats, indexed by name. */
map<string, shared_ptr<OutputFormat> > output_formats();
/** Current log level. */
/** Available output formats, indexed by name. */
map<string, shared_ptr<OutputFormat> > output_formats();
/** Current log level. */
shared_ptr<Packet> create_logic_packet(
void *data_pointer, size_t data_length, unsigned int unit_size);
/** Create an analog packet. */
shared_ptr<Packet> create_logic_packet(
void *data_pointer, size_t data_length, unsigned int unit_size);
/** Create an analog packet. */
vector<shared_ptr<Channel> > channels,
float *data_pointer, unsigned int num_samples, const Quantity *mq,
const Unit *unit, vector<const QuantityFlag *> mqflags);
vector<shared_ptr<Channel> > channels,
float *data_pointer, unsigned int num_samples, const Quantity *mq,
const Unit *unit, vector<const QuantityFlag *> mqflags);
/** Open an input stream based on header data.
* @param header Initial data from stream. */
shared_ptr<Input> open_stream(string header);
/** Open an input stream based on header data.
* @param header Initial data from stream. */
shared_ptr<Input> open_stream(string header);
- map<string, string> serials(shared_ptr<Driver> driver);
-protected:
- map<string, Driver *> _drivers;
- map<string, InputFormat *> _input_formats;
- map<string, OutputFormat *> _output_formats;
+ map<string, string> serials(shared_ptr<Driver> driver) const;
+private:
+ struct sr_context *_structure;
+ map<string, unique_ptr<Driver> > _drivers;
+ map<string, unique_ptr<InputFormat> > _input_formats;
+ map<string, unique_ptr<OutputFormat> > _output_formats;
/** Set configuration for the given key to a specified value.
* @param key ConfigKey to set.
* @param value Value to set. */
/** Set configuration for the given key to a specified value.
* @param key ConfigKey to set.
* @param value Value to set. */
/** Enumerate available values for the given configuration key.
* @param key ConfigKey to enumerate values for. */
/** Enumerate available values for the given configuration key.
* @param key ConfigKey to enumerate values for. */
/** Scan for devices and return a list of devices found.
* @param options Mapping of (ConfigKey, value) pairs. */
/** Scan for devices and return a list of devices found.
* @param options Mapping of (ConfigKey, value) pairs. */
- vector<shared_ptr<HardwareDevice> > scan(
- map<const ConfigKey *, Glib::VariantBase> options =
- map<const ConfigKey *, Glib::VariantBase>());
-protected:
+ vector<shared_ptr<HardwareDevice> > scan(map<const ConfigKey *, Glib::VariantBase>
+ options = map<const ConfigKey *, Glib::VariantBase>());
+private:
+ struct sr_dev_driver *_structure;
/** List of the channels available on this device. */
vector<shared_ptr<Channel> > channels();
/** Channel groups available on this device, indexed by name. */
/** List of the channels available on this device. */
vector<shared_ptr<Channel> > channels();
/** Channel groups available on this device, indexed by name. */
~Device();
virtual shared_ptr<Device> get_shared_from_this() = 0;
shared_ptr<Channel> get_channel(struct sr_channel *ptr);
~Device();
virtual shared_ptr<Device> get_shared_from_this() = 0;
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:
- void operator()(Device *device) { delete device; }
- };
- friend class Deleter;
+ map<struct sr_channel *, unique_ptr<Channel> > _channels;
+private:
+ map<string, unique_ptr<ChannelGroup> > _channel_groups;
+
};
/** A real hardware device, connected via a driver */
class SR_API HardwareDevice :
};
/** A real hardware device, connected via a driver */
class SR_API HardwareDevice :
HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
~HardwareDevice();
shared_ptr<Device> get_shared_from_this();
shared_ptr<Driver> _driver;
HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
~HardwareDevice();
shared_ptr<Device> get_shared_from_this();
shared_ptr<Driver> _driver;
};
/** A virtual device, created by the user */
class SR_API UserDevice :
};
/** A virtual device, created by the user */
class SR_API UserDevice :
public Device
{
public:
/** Add a new channel to this device. */
shared_ptr<Channel> add_channel(unsigned int index, const ChannelType *type, string name);
public Device
{
public:
/** Add a new channel to this device. */
shared_ptr<Channel> add_channel(unsigned int index, const ChannelType *type, string name);
UserDevice(string vendor, string model, string version);
~UserDevice();
shared_ptr<Device> get_shared_from_this();
UserDevice(string vendor, string model, string version);
~UserDevice();
shared_ptr<Device> get_shared_from_this();
/** Set the name of this channel. *
* @param name Name string to set. */
void set_name(string name);
/** Type of this channel. */
/** Set the name of this channel. *
* @param name Name string to set. */
void set_name(string name);
/** Type of this channel. */
/** Set the enabled status of this channel.
* @param value Boolean value to set. */
void set_enabled(bool value);
/** Get the index number of this channel. */
/** Set the enabled status of this channel.
* @param value Boolean value to set. */
void set_enabled(bool value);
/** Get the index number of this channel. */
};
/** A group of channels on a device, which share some configuration */
class SR_API ChannelGroup :
};
/** A group of channels on a device, which share some configuration */
class SR_API ChannelGroup :
- public ParentOwned<ChannelGroup, Device, struct sr_channel_group>,
+ public ParentOwned<ChannelGroup, Device>,
/** List of the stages in this trigger. */
vector<shared_ptr<TriggerStage> > stages();
/** Add a new stage to this trigger. */
shared_ptr<TriggerStage> add_stage();
/** List of the stages in this trigger. */
vector<shared_ptr<TriggerStage> > stages();
/** Add a new stage to this trigger. */
shared_ptr<TriggerStage> add_stage();
/** List of match conditions on this stage. */
vector<shared_ptr<TriggerMatch> > matches();
/** Add a new match condition to this stage.
/** List of match conditions on this stage. */
vector<shared_ptr<TriggerMatch> > matches();
/** Add a new match condition to this stage.
* @param type TriggerMatchType to apply.
* @param value Threshold value. */
void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type, float value);
* @param type TriggerMatchType to apply.
* @param value Threshold value. */
void add_match(shared_ptr<Channel> channel, const TriggerMatchType *type, float value);
-protected:
- vector<TriggerMatch *> _matches;
- TriggerStage(struct sr_trigger_stage *structure);
+private:
+ struct sr_trigger_stage *_structure;
+ vector<unique_ptr<TriggerMatch> > _matches;
+ explicit TriggerStage(struct sr_trigger_stage *structure);
public:
void run(const struct sr_dev_inst *sdi,
const struct sr_datafeed_packet *pkt);
public:
void run(const struct sr_dev_inst *sdi,
const struct sr_datafeed_packet *pkt);
DatafeedCallbackFunction _callback;
DatafeedCallbackData(Session *session,
DatafeedCallbackFunction callback);
DatafeedCallbackFunction _callback;
DatafeedCallbackData(Session *session,
DatafeedCallbackFunction callback);
- public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
+ public ParentOwned<SessionDevice, Session>,
* @param trigger Trigger object to use. */
void set_trigger(shared_ptr<Trigger> trigger);
/** Get filename this session was loaded from. */
* @param trigger Trigger object to use. */
void set_trigger(shared_ptr<Trigger> trigger);
/** Get filename this session was loaded from. */
Session(shared_ptr<Context> context, string filename);
~Session();
shared_ptr<Device> get_device(const struct sr_dev_inst *sdi);
Session(shared_ptr<Context> context, string filename);
~Session();
shared_ptr<Device> get_device(const struct sr_dev_inst *sdi);
Packet(shared_ptr<Device> device,
const struct sr_datafeed_packet *structure);
~Packet();
Packet(shared_ptr<Device> device,
const struct sr_datafeed_packet *structure);
~Packet();
- virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0;
- /** Deleter needed to allow shared_ptr use with protected destructor. */
- class Deleter
- {
- public:
- void operator()(PacketPayload *payload) { delete payload; }
- };
- friend class Deleter;
+private:
+ virtual shared_ptr<PacketPayload> share_owned_by(shared_ptr<Packet> parent) = 0;
+
- public ParentOwned<Header, Packet, const struct sr_datafeed_header>,
+ public ParentOwned<Header, Packet>,
- public ParentOwned<Meta, Packet, const struct sr_datafeed_meta>,
+ public ParentOwned<Meta, Packet>,
- map<const ConfigKey *, Glib::VariantBase> config();
-protected:
- Meta(const struct sr_datafeed_meta *structure);
+ map<const ConfigKey *, Glib::VariantBase> config() const;
+private:
+ explicit Meta(const struct sr_datafeed_meta *structure);
- public ParentOwned<Logic, Packet, const struct sr_datafeed_logic>,
+ public ParentOwned<Logic, Packet>,
-class SR_API AnalogOld :
- public ParentOwned<AnalogOld, Packet, const struct sr_datafeed_analog_old>,
+class SR_API Analog :
+ public ParentOwned<Analog, Packet>,
/** Channels for which this packet contains data. */
vector<shared_ptr<Channel> > channels();
/** Measured quantity of the samples in this packet. */
/** Channels for which this packet contains data. */
vector<shared_ptr<Channel> > channels();
/** Measured quantity of the samples in this packet. */
- vector<const QuantityFlag *> mq_flags();
-protected:
- AnalogOld(const struct sr_datafeed_analog_old *structure);
- ~AnalogOld();
- shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
+ vector<const QuantityFlag *> mq_flags() const;
+private:
+ explicit Analog(const struct sr_datafeed_analog *structure);
+ ~Analog();
+ shared_ptr<PacketPayload> share_owned_by(shared_ptr<Packet> parent);
+
+ const struct sr_datafeed_analog *_structure;
+
/** A list of preferred file name extensions for this file format.
* @note This list is a recommendation only. */
/** A list of preferred file name extensions for this file format.
* @note This list is a recommendation only. */
/** Options supported by this input format. */
map<string, shared_ptr<Option> > options();
/** Create an input using this input format.
* @param options Mapping of (option name, value) pairs. */
/** Options supported by this input format. */
map<string, shared_ptr<Option> > options();
/** Create an input using this input format.
* @param options Mapping of (option name, value) pairs. */
- shared_ptr<Input> create_input(map<string, Glib::VariantBase> options =
- map<string, Glib::VariantBase>());
-protected:
- InputFormat(const struct sr_input_module *structure);
+ shared_ptr<Input> create_input(map<string, Glib::VariantBase>
+ options = map<string, Glib::VariantBase>());
+private:
+ explicit InputFormat(const struct sr_input_module *structure);
void send(void *data, size_t length);
/** Signal end of input data. */
void end();
void send(void *data, size_t length);
/** Signal end of input data. */
void end();
- public ParentOwned<InputDevice, Input, struct sr_dev_inst>,
+ public ParentOwned<InputDevice, Input>,
InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
~InputDevice();
shared_ptr<Device> get_shared_from_this();
shared_ptr<Input> _input;
friend class Input;
InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
~InputDevice();
shared_ptr<Device> get_shared_from_this();
shared_ptr<Input> _input;
friend class Input;
Option(const struct sr_option *structure,
shared_ptr<const struct sr_option *> structure_array);
~Option();
Option(const struct sr_option *structure,
shared_ptr<const struct sr_option *> structure_array);
~Option();
/** A list of preferred file name extensions for this file format.
* @note This list is a recommendation only. */
/** A list of preferred file name extensions for this file format.
* @note This list is a recommendation only. */
/** Options supported by this output format. */
map<string, shared_ptr<Option> > options();
/** Create an output using this format.
* @param device Device to output for.
* @param options Mapping of (option name, value) pairs. */
/** Options supported by this output format. */
map<string, shared_ptr<Option> > options();
/** Create an output using this format.
* @param device Device to output for.
* @param options Mapping of (option name, value) pairs. */
- shared_ptr<Output> create_output(
- shared_ptr<Device> device,
- map<string, Glib::VariantBase> options =
- map<string, Glib::VariantBase>());
+ shared_ptr<Output> create_output(shared_ptr<Device> device,
+ map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
/** Create an output using this format.
* @param filename Name of destination file.
* @param device Device to output for.
* @param options Mapping of (option name, value) pairs. */
shared_ptr<Output> create_output(string filename,
shared_ptr<Device> device,
/** Create an output using this format.
* @param filename Name of destination file.
* @param device Device to output for.
* @param options Mapping of (option name, value) pairs. */
shared_ptr<Output> create_output(string filename,
shared_ptr<Device> device,
- map<string, Glib::VariantBase> options =
- map<string, Glib::VariantBase>());
+ map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
/**
* Checks whether a given flag is set.
* @param flag Flag to check
* @return true if flag is set for this module
* @see sr_output_flags
*/
/**
* Checks whether a given flag is set.
* @param flag Flag to check
* @return true if flag is set for this module
* @see sr_output_flags
*/
- bool test_flag(const OutputFlag *flag);
-protected:
- OutputFormat(const struct sr_output_module *structure);
+ bool test_flag(const OutputFlag *flag) const;
+private:
+ explicit OutputFormat(const struct sr_output_module *structure);
{
public:
/** Update output with data from the given packet.
* @param packet Packet to handle. */
string receive(shared_ptr<Packet> packet);
{
public:
/** Update output with data from the given packet.
* @param packet Packet to handle. */
string receive(shared_ptr<Packet> packet);
Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device);
Output(shared_ptr<OutputFormat> format,
shared_ptr<Device> device, map<string, Glib::VariantBase> options);
Output(string filename, shared_ptr<OutputFormat> format,
shared_ptr<Device> device, map<string, Glib::VariantBase> options);
~Output();
Output(shared_ptr<OutputFormat> format, shared_ptr<Device> device);
Output(shared_ptr<OutputFormat> format,
shared_ptr<Device> device, map<string, Glib::VariantBase> options);
Output(string filename, shared_ptr<OutputFormat> format,
shared_ptr<Device> device, map<string, Glib::VariantBase> options);
~Output();
const shared_ptr<OutputFormat> _format;
const shared_ptr<Device> _device;
const map<string, Glib::VariantBase> _options;
const shared_ptr<OutputFormat> _format;
const shared_ptr<Device> _device;
const map<string, Glib::VariantBase> _options;