X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=bindings%2Fcxx%2Finclude%2Flibsigrok%2Flibsigrok.hpp;h=6b4fbfc175fb364c57b87c437f0ab00ba9ef51e1;hb=9fa5b426ec7c0a77eb9401f3dd10ad463a8d1ac7;hp=972bde883d523fccec8f7324a9dc05dea06f6972;hpb=a4e47454580b83972f052b5ace8e687d54d9425c;p=libsigrok.git diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index 972bde88..6b4fbfc1 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -77,6 +77,7 @@ raised, which provides access to the error code and description. #include #include #include +#include namespace sigrok { @@ -113,6 +114,7 @@ class SR_API InputDevice; class SR_API Output; class SR_API DataType; class SR_API Option; +class SR_API UserDevice; /** Exception thrown when an error code is returned by any libsigrok call. */ class SR_API Error: public exception @@ -148,6 +150,12 @@ protected: weak_ptr _weak_this; public: + /* Get parent object that owns this object. */ + shared_ptr parent() + { + return _parent; + } + /* Note, this implementation will create a new smart_ptr if none exists. */ shared_ptr shared_from_this() { @@ -256,6 +264,9 @@ public: void set_log_callback_default(); /** Create a new session. */ shared_ptr create_session(); + /** Create a new user device. */ + shared_ptr create_user_device( + string vendor, string model, string version); /** Load a saved session. * @param filename File name string. */ shared_ptr load_session(string filename); @@ -281,6 +292,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 +313,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 config_keys(const ConfigKey *key); + map > 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: @@ -339,14 +356,16 @@ protected: class SR_API Device : public Configurable { public: - /** Description identifying this device. */ - 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 > channels(); /** Channel groups available on this device, indexed by name. */ @@ -401,6 +420,28 @@ protected: friend class ChannelGroup; }; +/** A virtual device, created by the user */ +class SR_API UserDevice : + public UserOwned, + public Device +{ +public: + /** Add a new channel to this device. */ + shared_ptr add_channel(unsigned int index, const ChannelType *type, string name); +protected: + UserDevice(string vendor, string model, string version); + ~UserDevice(); + shared_ptr get_shared_from_this(); + /** Deleter needed to allow shared_ptr use with protected destructor. */ + class Deleter + { + public: + void operator()(UserDevice *device) { delete device; } + }; + friend class Context; + friend class Deleter; +}; + /** A channel on a device */ class SR_API Channel : public ParentOwned @@ -425,6 +466,7 @@ protected: ~Channel(); const ChannelType * const _type; friend class Device; + friend class UserDevice; friend class ChannelGroup; friend class Session; friend class TriggerStage; @@ -653,14 +695,19 @@ public: /** Set trigger setting. * @param trigger Trigger object to use. */ void set_trigger(shared_ptr trigger); + /** Get filename this session was loaded from. */ + string filename(); protected: Session(shared_ptr context); Session(shared_ptr context, string filename); ~Session(); + shared_ptr get_device(const struct sr_dev_inst *sdi); const shared_ptr _context; - map > _devices; + map _owned_devices; + map > _other_devices; vector _datafeed_callbacks; map, SourceCallbackData *> _source_callbacks; + string _filename; bool _saving; bool _save_initialized; string _save_filename; @@ -669,6 +716,7 @@ protected: friend class Deleter; friend class Context; friend class DatafeedCallbackData; + friend class SessionDevice; }; /** A packet on the session datafeed */ @@ -821,6 +869,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, const struct sr_input *structure); ~Input(); @@ -912,17 +962,44 @@ protected: }; /** Base class for objects which wrap an enumeration value from libsigrok */ -template class SR_API EnumValue +template class SR_API EnumValue { public: - /** The enum constant associated with this value. */ - T id() const { return _id; } + /** The integer constant associated with this value. */ + int id() const + { + return static_cast(_id); + } /** The name associated with this value. */ - string name() const { return _name; } + string name() const + { + return _name; + } + /** Get value associated with a given integer constant. */ + static const Class *get(int id) + { + auto key = static_cast(id); + if (_values.find(key) == _values.end()) + throw Error(SR_ERR_ARG); + return _values.at(key); + } + /** Get possible values. */ + static std::vector values() + { + std::vector result; + for (auto entry : _values) + result.push_back(entry.second); + return result; + } protected: - EnumValue(T id, const char name[]) : _id(id), _name(name) {} - ~EnumValue() {} - const T _id; + EnumValue(Enum id, const char name[]) : _id(id), _name(name) + { + } + ~EnumValue() + { + } + static const std::map _values; + const Enum _id; const string _name; };