C++: Fix shared pointer handling for Device base class.
This commit is contained in:
parent
f1830b225d
commit
d01d231487
|
@ -419,14 +419,14 @@ vector<shared_ptr<Channel>> Device::get_channels()
|
||||||
vector<shared_ptr<Channel>> result;
|
vector<shared_ptr<Channel>> result;
|
||||||
for (auto entry : channels)
|
for (auto entry : channels)
|
||||||
result.push_back(static_pointer_cast<Channel>(
|
result.push_back(static_pointer_cast<Channel>(
|
||||||
entry.second->get_shared_pointer(this)));
|
entry.second->get_shared_pointer(get_shared_from_this())));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_ptr<Channel> Device::get_channel(struct sr_channel *ptr)
|
shared_ptr<Channel> Device::get_channel(struct sr_channel *ptr)
|
||||||
{
|
{
|
||||||
return static_pointer_cast<Channel>(
|
return static_pointer_cast<Channel>(
|
||||||
channels[ptr]->get_shared_pointer(this));
|
channels[ptr]->get_shared_pointer(get_shared_from_this()));
|
||||||
}
|
}
|
||||||
|
|
||||||
map<string, shared_ptr<ChannelGroup>>
|
map<string, shared_ptr<ChannelGroup>>
|
||||||
|
@ -438,7 +438,7 @@ Device::get_channel_groups()
|
||||||
auto name = entry.first;
|
auto name = entry.first;
|
||||||
auto channel_group = entry.second;
|
auto channel_group = entry.second;
|
||||||
result[name] = static_pointer_cast<ChannelGroup>(
|
result[name] = static_pointer_cast<ChannelGroup>(
|
||||||
channel_group->get_shared_pointer(this));
|
channel_group->get_shared_pointer(get_shared_from_this()));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -464,6 +464,12 @@ HardwareDevice::~HardwareDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<Device> HardwareDevice::get_shared_from_this()
|
||||||
|
{
|
||||||
|
return static_pointer_cast<Device>(
|
||||||
|
static_pointer_cast<HardwareDevice>(shared_from_this()));
|
||||||
|
}
|
||||||
|
|
||||||
shared_ptr<Driver> HardwareDevice::get_driver()
|
shared_ptr<Driver> HardwareDevice::get_driver()
|
||||||
{
|
{
|
||||||
return static_pointer_cast<Driver>(driver->get_shared_pointer(parent));
|
return static_pointer_cast<Driver>(driver->get_shared_pointer(parent));
|
||||||
|
@ -735,9 +741,6 @@ vector<shared_ptr<Device>> Session::get_devices()
|
||||||
for (GSList *dev = dev_list; dev; dev = dev->next)
|
for (GSList *dev = dev_list; dev; dev = dev->next)
|
||||||
{
|
{
|
||||||
auto sdi = (struct sr_dev_inst *) dev->data;
|
auto sdi = (struct sr_dev_inst *) dev->data;
|
||||||
if (devices.count(sdi) == 0)
|
|
||||||
devices[sdi] = shared_ptr<Device>(
|
|
||||||
new Device(sdi), Device::Deleter());
|
|
||||||
result.push_back(devices[sdi]);
|
result.push_back(devices[sdi]);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -1199,6 +1202,12 @@ InputDevice::~InputDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<Device> InputDevice::get_shared_from_this()
|
||||||
|
{
|
||||||
|
return static_pointer_cast<Device>(
|
||||||
|
static_pointer_cast<InputDevice>(shared_from_this()));
|
||||||
|
}
|
||||||
|
|
||||||
Option::Option(const struct sr_option *structure,
|
Option::Option(const struct sr_option *structure,
|
||||||
shared_ptr<const struct sr_option *> structure_array) :
|
shared_ptr<const struct sr_option *> structure_array) :
|
||||||
structure(structure),
|
structure(structure),
|
||||||
|
|
|
@ -289,9 +289,7 @@ 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 Configurable
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** Description identifying this device. */
|
/** Description identifying this device. */
|
||||||
|
@ -313,6 +311,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
Device(struct sr_dev_inst *structure);
|
Device(struct sr_dev_inst *structure);
|
||||||
~Device();
|
~Device();
|
||||||
|
virtual shared_ptr<Device> get_shared_from_this() = 0;
|
||||||
shared_ptr<Channel> get_channel(struct sr_channel *ptr);
|
shared_ptr<Channel> get_channel(struct sr_channel *ptr);
|
||||||
struct sr_dev_inst *structure;
|
struct sr_dev_inst *structure;
|
||||||
map<struct sr_channel *, Channel *> channels;
|
map<struct sr_channel *, Channel *> channels;
|
||||||
|
@ -342,6 +341,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
HardwareDevice(Driver *driver, struct sr_dev_inst *structure);
|
HardwareDevice(Driver *driver, struct sr_dev_inst *structure);
|
||||||
~HardwareDevice();
|
~HardwareDevice();
|
||||||
|
shared_ptr<Device> get_shared_from_this();
|
||||||
Driver *driver;
|
Driver *driver;
|
||||||
friend class Driver;
|
friend class Driver;
|
||||||
friend class ChannelGroup;
|
friend class ChannelGroup;
|
||||||
|
@ -765,6 +765,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
Input(shared_ptr<Context> context, const struct sr_input *structure);
|
Input(shared_ptr<Context> context, const struct sr_input *structure);
|
||||||
~Input();
|
~Input();
|
||||||
|
shared_ptr<Device> get_shared_from_this();
|
||||||
const struct sr_input *structure;
|
const struct sr_input *structure;
|
||||||
shared_ptr<Context> context;
|
shared_ptr<Context> context;
|
||||||
InputDevice *device;
|
InputDevice *device;
|
||||||
|
@ -787,6 +788,7 @@ class SR_API InputDevice :
|
||||||
protected:
|
protected:
|
||||||
InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
|
InputDevice(shared_ptr<Input> input, struct sr_dev_inst *sdi);
|
||||||
~InputDevice();
|
~InputDevice();
|
||||||
|
shared_ptr<Device> get_shared_from_this();
|
||||||
shared_ptr<Input> input;
|
shared_ptr<Input> input;
|
||||||
/** Deleter needed to allow shared_ptr use with protected destructor. */
|
/** Deleter needed to allow shared_ptr use with protected destructor. */
|
||||||
class Deleter
|
class Deleter
|
||||||
|
|
Loading…
Reference in New Issue