From: Martin Ling Date: Sun, 24 Aug 2014 01:00:14 +0000 (+0100) Subject: C++: Correct ownership of InputDevice objects. X-Git-Tag: libsigrok-0.4.0~1097 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=6e5240f418a8e021a8d1272b6255a8c0f10b5af6 C++: Correct ownership of InputDevice objects. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 986b2c1e..edd68bd4 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -361,7 +361,7 @@ Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key) Device::Device(struct sr_dev_inst *structure) : Configurable(structure->driver, structure, NULL), - StructureWrapper(structure) + structure(structure) { for (GSList *entry = structure->channels; entry; entry = entry->next) { @@ -453,6 +453,7 @@ void Device::close() } HardwareDevice::HardwareDevice(Driver *driver, struct sr_dev_inst *structure) : + StructureWrapper(structure), Device(structure), driver(driver) { @@ -1155,7 +1156,7 @@ shared_ptr Input::get_device() } return static_pointer_cast( - device->get_shared_pointer(context->shared_from_this())); + device->get_shared_pointer(shared_from_this())); } void Input::send(string data) @@ -1173,8 +1174,10 @@ Input::~Input() check(sr_input_free(structure)); } -InputDevice::InputDevice(shared_ptr input, struct sr_dev_inst *sdi) : - Device(sdi), +InputDevice::InputDevice(shared_ptr input, + struct sr_dev_inst *structure) : + StructureWrapper(structure), + Device(structure), input(input) { } diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index 546a4502..cc57d1a0 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -290,8 +290,8 @@ protected: /** A generic device, either hardware or virtual */ class SR_API Device : - public Configurable, - public StructureWrapper + public enable_shared_from_this, + public Configurable { public: /** Description identifying this device. */ @@ -314,6 +314,7 @@ protected: Device(struct sr_dev_inst *structure); ~Device(); shared_ptr get_channel(struct sr_channel *ptr); + struct sr_dev_inst *structure; map channels; map channel_groups; /** Deleter needed to allow shared_ptr use with protected destructor. */ @@ -331,7 +332,9 @@ protected: }; /** A real hardware device, connected via a driver */ -class SR_API HardwareDevice : public Device +class SR_API HardwareDevice : + public StructureWrapper, + public Device { public: /** Driver providing this device. */ @@ -777,7 +780,9 @@ protected: }; /** A virtual device associated with an input */ -class SR_API InputDevice : public Device +class SR_API InputDevice : + public StructureWrapper, + public Device { protected: InputDevice(shared_ptr input, struct sr_dev_inst *sdi);