]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/include/libsigrok/libsigrok.hpp
bindings: Add Session::filename() and corresponding SWIG attribute.
[libsigrok.git] / bindings / cxx / include / libsigrok / libsigrok.hpp
index 15509c9c5803ac805956a8f7f648fe98502e95a1..3e49bd5986defbc4cbabc789c0adf0be2c08a9f6 100644 (file)
@@ -77,6 +77,7 @@ raised, which provides access to the error code and description.
 #include <memory>
 #include <vector>
 #include <map>
+#include <set>
 
 namespace sigrok
 {
@@ -148,6 +149,12 @@ protected:
        weak_ptr<Class> _weak_this;
 
 public:
+       /* Get parent object that owns this object. */
+       shared_ptr<Parent> parent()
+       {
+               return _parent;
+       }
+
        /* Note, this implementation will create a new smart_ptr if none exists. */
        shared_ptr<Class> shared_from_this()
        {
@@ -281,6 +288,12 @@ protected:
        friend class Driver;
 };
 
+enum Capability {
+       GET = SR_CONF_GET,
+       SET = SR_CONF_SET,
+       LIST = SR_CONF_LIST
+};
+
 /** An object that can be configured. */
 class SR_API Configurable
 {
@@ -296,7 +309,7 @@ public:
         * @param key ConfigKey to enumerate values for. */
        Glib::VariantContainerBase config_list(const ConfigKey *key);
        /** Enumerate available keys, according to a given index key. */
-       vector<const ConfigKey *> config_keys(const ConfigKey *key);
+       map<const ConfigKey *, set<Capability> > config_keys(const ConfigKey *key);
        /** Check for a key in the list from a given index key. */
        bool config_check(const ConfigKey *key, const ConfigKey *index_key);
 protected:
@@ -323,7 +336,8 @@ public:
        /** 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> options =
+                       map<const ConfigKey *, Glib::VariantBase>());
 protected:
        bool _initialized;
        vector<HardwareDevice *> _devices;
@@ -339,13 +353,17 @@ class SR_API Device : public Configurable
 {
 public:
        /** Description identifying this device. */
-       string description();
+       virtual string description();
        /** Vendor name for this device. */
        string vendor();
        /** Model name for this device. */
        string model();
        /** Version string for this device. */
        string version();
+       /** Serial number for this device. */
+       string serial_number();
+       /** Connection ID for this device. */
+       string connection_id();
        /** List of the channels available on this device. */
        vector<shared_ptr<Channel> > channels();
        /** Channel groups available on this device, indexed by name. */
@@ -378,17 +396,24 @@ protected:
 
 /** A real hardware device, connected via a driver */
 class SR_API HardwareDevice :
-       public ParentOwned<HardwareDevice, Context, struct sr_dev_inst>,
+       public UserOwned<HardwareDevice, struct sr_dev_inst>,
        public Device
 {
 public:
        /** Driver providing this device. */
        shared_ptr<Driver> driver();
 protected:
-       HardwareDevice(Driver *driver, struct sr_dev_inst *structure);
+       HardwareDevice(shared_ptr<Driver> driver, struct sr_dev_inst *structure);
        ~HardwareDevice();
        shared_ptr<Device> get_shared_from_this();
-       Driver *_driver;
+       shared_ptr<Driver> _driver;
+       /** Deleter needed to allow shared_ptr use with protected destructor. */
+       class Deleter
+       {
+       public:
+               void operator()(HardwareDevice *device) { delete device; }
+       };
+       friend class Deleter;
        friend class Driver;
        friend class ChannelGroup;
 };
@@ -590,6 +615,8 @@ class SR_API SessionDevice :
        public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
        public Device
 {
+       /** Description identifying this device. */
+       string description();
 protected:
        SessionDevice(struct sr_dev_inst *sdi);
        ~SessionDevice();
@@ -645,14 +672,19 @@ public:
        /** Set trigger setting.
         * @param trigger Trigger object to use. */
        void set_trigger(shared_ptr<Trigger> trigger);
+       /** Get filename this session was loaded from. */
+       string filename();
 protected:
        Session(shared_ptr<Context> context);
        Session(shared_ptr<Context> context, string filename);
        ~Session();
+       shared_ptr<Device> get_device(const struct sr_dev_inst *sdi);
        const shared_ptr<Context> _context;
-       map<const struct sr_dev_inst *, shared_ptr<Device> > _devices;
+       map<const struct sr_dev_inst *, SessionDevice *> _owned_devices;
+       map<const struct sr_dev_inst *, shared_ptr<Device> > _other_devices;
        vector<DatafeedCallbackData *> _datafeed_callbacks;
        map<shared_ptr<EventSource>, SourceCallbackData *> _source_callbacks;
+       string _filename;
        bool _saving;
        bool _save_initialized;
        string _save_filename;
@@ -661,6 +693,7 @@ protected:
        friend class Deleter;
        friend class Context;
        friend class DatafeedCallbackData;
+       friend class SessionDevice;
 };
 
 /** A packet on the session datafeed */
@@ -795,7 +828,8 @@ public:
        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 = {});
+       shared_ptr<Input> create_input(map<string, Glib::VariantBase> options =
+               map<string, Glib::VariantBase>());
 protected:
        InputFormat(const struct sr_input_module *structure);
        ~InputFormat();
@@ -812,6 +846,8 @@ public:
        /** Send next stream data.
         * @param data Next stream data. */
        void send(string data);
+       /** Signal end of input data. */
+       void end();
 protected:
        Input(shared_ptr<Context> context, const struct sr_input *structure);
        ~Input();
@@ -827,6 +863,9 @@ class SR_API InputDevice :
        public ParentOwned<InputDevice, Input, struct sr_dev_inst>,
        public Device
 {
+public:
+       /** Description identifying this device. */
+       string description();
 protected:
        InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
        ~InputDevice();
@@ -874,7 +913,8 @@ public:
         * @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> options =
+                       map<string, Glib::VariantBase>());
 protected:
        OutputFormat(const struct sr_output_module *structure);
        ~OutputFormat();