X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Finclude%2Flibsigrokcxx%2Flibsigrokcxx.hpp;h=a83600aa99753d9b4a5baf83ce95a4c4b7de5eaa;hb=21d1bec60e6d69f6f2ef6f3dc3e07219153285c0;hp=f10ae9559d70296d78d1931b65a16285faed2e3a;hpb=4c9208a799064a4eb3c76701edf3a007811dbc85;p=libsigrok.git diff --git a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp index f10ae955..a83600aa 100644 --- a/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp +++ b/bindings/cxx/include/libsigrokcxx/libsigrokcxx.hpp @@ -130,6 +130,17 @@ public: template class SR_API ParentOwned { +private: + /* Weak pointer for shared_from_this() implementation. */ + weak_ptr _weak_this; + + static void reset_parent(Class *object) + { + if (!object->_parent) + throw Error(SR_ERR_BUG); + object->_parent.reset(); + } + protected: /* Parent object which owns this child object's underlying structure. @@ -146,8 +157,12 @@ protected: references to both the parent and all its children are gone. */ shared_ptr _parent; - /* Weak pointer for shared_from_this() implementation. */ - weak_ptr _weak_this; + Struct *_structure; + + explicit ParentOwned(Struct *structure) : + _structure(structure) + { + } public: /* Get parent object that owns this object. */ @@ -184,20 +199,6 @@ public: 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; - - explicit ParentOwned(Struct *structure) : - _structure(structure) - { - } }; /* Base template for classes whose resources are owned by the user. */ @@ -314,7 +315,7 @@ public: * @param header Initial data from stream. */ shared_ptr open_stream(string header); map serials(shared_ptr driver) const; -protected: +private: map _drivers; map _input_formats; map _output_formats; @@ -376,7 +377,7 @@ public: * @param options Mapping of (ConfigKey, value) pairs. */ vector > scan( const map &options = {}); -protected: +private: bool _initialized; vector _devices; explicit Driver(struct sr_dev_driver *structure); @@ -413,8 +414,10 @@ protected: ~Device(); virtual shared_ptr get_shared_from_this() = 0; shared_ptr get_channel(struct sr_channel *ptr); + struct sr_dev_inst *_structure; map _channels; +private: map _channel_groups; /** Deleter needed to allow shared_ptr use with protected destructor. */ class Deleter @@ -438,7 +441,7 @@ class SR_API HardwareDevice : public: /** Driver providing this device. */ shared_ptr driver(); -protected: +private: HardwareDevice(shared_ptr driver, struct sr_dev_inst *structure); ~HardwareDevice(); shared_ptr get_shared_from_this(); @@ -462,7 +465,7 @@ class SR_API UserDevice : public: /** Add a new channel to this device. */ shared_ptr add_channel(unsigned int index, const ChannelType *type, string name); -protected: +private: UserDevice(string vendor, string model, string version); ~UserDevice(); shared_ptr get_shared_from_this(); @@ -495,7 +498,7 @@ public: void set_enabled(bool value); /** Get the index number of this channel. */ unsigned int index() const; -protected: +private: explicit Channel(struct sr_channel *structure); ~Channel(); const ChannelType * const _type; @@ -517,7 +520,7 @@ public: string name() const; /** List of the channels in this group. */ vector > channels(); -protected: +private: ChannelGroup(Device *device, struct sr_channel_group *structure); ~ChannelGroup(); vector _channels; @@ -534,7 +537,7 @@ public: vector > stages(); /** Add a new stage to this trigger. */ shared_ptr add_stage(); -protected: +private: Trigger(shared_ptr context, string name); ~Trigger(); shared_ptr _context; @@ -562,7 +565,7 @@ public: * @param type TriggerMatchType to apply. * @param value Threshold value. */ void add_match(shared_ptr channel, const TriggerMatchType *type, float value); -protected: +private: vector _matches; explicit TriggerStage(struct sr_trigger_stage *structure); ~TriggerStage(); @@ -580,7 +583,7 @@ public: const TriggerMatchType *type() const; /** Threshold value. */ float value() const; -protected: +private: TriggerMatch(struct sr_trigger_match *structure, shared_ptr channel); ~TriggerMatch(); shared_ptr _channel; @@ -600,7 +603,7 @@ class SR_PRIV DatafeedCallbackData public: void run(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *pkt); -protected: +private: DatafeedCallbackFunction _callback; DatafeedCallbackData(Session *session, DatafeedCallbackFunction callback); @@ -613,7 +616,7 @@ class SR_API SessionDevice : public ParentOwned, public Device { -protected: +private: explicit SessionDevice(struct sr_dev_inst *sdi); ~SessionDevice(); shared_ptr get_shared_from_this(); @@ -662,7 +665,7 @@ public: void set_trigger(shared_ptr trigger); /** Get filename this session was loaded from. */ string filename() const; -protected: +private: explicit Session(shared_ptr context); Session(shared_ptr context, string filename); ~Session(); @@ -688,7 +691,7 @@ public: const PacketType *type() const; /** Payload of this packet. */ shared_ptr payload(); -protected: +private: Packet(shared_ptr device, const struct sr_datafeed_packet *structure); ~Packet(); @@ -712,12 +715,7 @@ protected: PacketPayload(); virtual ~PacketPayload() = 0; virtual shared_ptr 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; friend class Packet; friend class Output; @@ -733,7 +731,7 @@ public: int feed_version() const; /* Start time of this session. */ Glib::TimeVal start_time() const; -protected: +private: explicit Header(const struct sr_datafeed_header *structure); ~Header(); shared_ptr get_shared_pointer(Packet *parent); @@ -748,7 +746,7 @@ class SR_API Meta : public: /* Mapping of (ConfigKey, value) pairs. */ map config() const; -protected: +private: explicit Meta(const struct sr_datafeed_meta *structure); ~Meta(); shared_ptr get_shared_pointer(Packet *parent); @@ -768,7 +766,7 @@ public: size_t data_length() const; /* Size of each sample in bytes. */ unsigned int unit_size() const; -protected: +private: explicit Logic(const struct sr_datafeed_logic *structure); ~Logic(); shared_ptr get_shared_pointer(Packet *parent); @@ -793,7 +791,7 @@ public: const Unit *unit() const; /** Measurement flags associated with the samples in this packet. */ vector mq_flags() const; -protected: +private: explicit Analog(const struct sr_datafeed_analog *structure); ~Analog(); shared_ptr get_shared_pointer(Packet *parent); @@ -817,7 +815,7 @@ public: /** Create an input using this input format. * @param options Mapping of (option name, value) pairs. */ shared_ptr create_input(const map &options = {}); -protected: +private: explicit InputFormat(const struct sr_input_module *structure); ~InputFormat(); friend class Context; @@ -836,7 +834,7 @@ public: void send(void *data, size_t length); /** Signal end of input data. */ void end(); -protected: +private: Input(shared_ptr context, const struct sr_input *structure); ~Input(); shared_ptr _context; @@ -851,7 +849,7 @@ class SR_API InputDevice : public ParentOwned, public Device { -protected: +private: InputDevice(shared_ptr input, struct sr_dev_inst *sdi); ~InputDevice(); shared_ptr get_shared_from_this(); @@ -873,7 +871,7 @@ public: Glib::VariantBase default_value() const; /** Possible values for this option, if a limited set. */ vector values() const; -protected: +private: Option(const struct sr_option *structure, shared_ptr structure_array); ~Option(); @@ -917,7 +915,7 @@ public: * @see sr_output_flags */ bool test_flag(const OutputFlag *flag) const; -protected: +private: explicit OutputFormat(const struct sr_output_module *structure); ~OutputFormat(); friend class Context; @@ -931,7 +929,7 @@ public: /** Update output with data from the given packet. * @param packet Packet to handle. */ string receive(shared_ptr packet); -protected: +private: Output(shared_ptr format, shared_ptr device); Output(shared_ptr format, shared_ptr device, const map &options); @@ -982,6 +980,7 @@ protected: ~EnumValue() { } +private: static const std::map _values; const Enum _id; const string _name;