C++: Correct ownership of InputDevice objects.

This commit is contained in:
Martin Ling 2014-08-24 02:00:14 +01:00 committed by Bert Vermeulen
parent ca3291e3ee
commit 6e5240f418
2 changed files with 16 additions and 8 deletions

View File

@ -361,7 +361,7 @@ Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key)
Device::Device(struct sr_dev_inst *structure) : Device::Device(struct sr_dev_inst *structure) :
Configurable(structure->driver, structure, NULL), Configurable(structure->driver, structure, NULL),
StructureWrapper<Context, struct sr_dev_inst>(structure) structure(structure)
{ {
for (GSList *entry = structure->channels; entry; entry = entry->next) 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) : HardwareDevice::HardwareDevice(Driver *driver, struct sr_dev_inst *structure) :
StructureWrapper(structure),
Device(structure), Device(structure),
driver(driver) driver(driver)
{ {
@ -1155,7 +1156,7 @@ shared_ptr<InputDevice> Input::get_device()
} }
return static_pointer_cast<InputDevice>( return static_pointer_cast<InputDevice>(
device->get_shared_pointer(context->shared_from_this())); device->get_shared_pointer(shared_from_this()));
} }
void Input::send(string data) void Input::send(string data)
@ -1173,8 +1174,10 @@ Input::~Input()
check(sr_input_free(structure)); check(sr_input_free(structure));
} }
InputDevice::InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi) : InputDevice::InputDevice(shared_ptr<Input> input,
Device(sdi), struct sr_dev_inst *structure) :
StructureWrapper(structure),
Device(structure),
input(input) input(input)
{ {
} }

View File

@ -290,8 +290,8 @@ protected:
/** A generic device, either hardware or virtual */ /** A generic device, either hardware or virtual */
class SR_API Device : class SR_API Device :
public Configurable, public enable_shared_from_this<Device>,
public StructureWrapper<Context, struct sr_dev_inst> public Configurable
{ {
public: public:
/** Description identifying this device. */ /** Description identifying this device. */
@ -314,6 +314,7 @@ protected:
Device(struct sr_dev_inst *structure); Device(struct sr_dev_inst *structure);
~Device(); ~Device();
shared_ptr<Channel> get_channel(struct sr_channel *ptr); shared_ptr<Channel> get_channel(struct sr_channel *ptr);
struct sr_dev_inst *structure;
map<struct sr_channel *, Channel *> channels; map<struct sr_channel *, Channel *> channels;
map<string, ChannelGroup *> channel_groups; map<string, ChannelGroup *> channel_groups;
/** Deleter needed to allow shared_ptr use with protected destructor. */ /** Deleter needed to allow shared_ptr use with protected destructor. */
@ -331,7 +332,9 @@ protected:
}; };
/** A real hardware device, connected via a driver */ /** A real hardware device, connected via a driver */
class SR_API HardwareDevice : public Device class SR_API HardwareDevice :
public StructureWrapper<Context, struct sr_dev_inst>,
public Device
{ {
public: public:
/** Driver providing this device. */ /** Driver providing this device. */
@ -777,7 +780,9 @@ protected:
}; };
/** A virtual device associated with an input */ /** A virtual device associated with an input */
class SR_API InputDevice : public Device class SR_API InputDevice :
public StructureWrapper<Input, struct sr_dev_inst>,
public Device
{ {
protected: protected:
InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi); InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);