{
auto name = entry.first;
auto driver = entry.second;
- result[name] = driver->get_shared_pointer(this);
+ result[name] = driver->get_shared_pointer(shared_from_this());
}
return result;
}
{
auto name = entry.first;
auto input_format = entry.second;
- result[name] = input_format->get_shared_pointer(this);
+ result[name] = input_format->get_shared_pointer(shared_from_this());
}
return result;
}
{
auto name = entry.first;
auto output_format = entry.second;
- result[name] = output_format->get_shared_pointer(this);
+ result[name] = output_format->get_shared_pointer(shared_from_this());
}
return result;
}
{
vector<shared_ptr<TriggerStage>> result;
for (auto stage : _stages)
- result.push_back(stage->get_shared_pointer(this));
+ result.push_back(stage->get_shared_pointer(shared_from_this()));
return result;
}
{
auto stage = new TriggerStage(sr_trigger_stage_add(_structure));
_stages.push_back(stage);
- return stage->get_shared_pointer(this);
+ return stage->get_shared_pointer(shared_from_this());
}
TriggerStage::TriggerStage(struct sr_trigger_stage *structure) :
{
vector<shared_ptr<TriggerMatch>> result;
for (auto match : _matches)
- result.push_back(match->get_shared_pointer(this));
+ result.push_back(match->get_shared_pointer(shared_from_this()));
return result;
}
{
if (_owned_devices.count(sdi))
return static_pointer_cast<Device>(
- _owned_devices[sdi]->get_shared_pointer(this));
+ _owned_devices[sdi]->get_shared_pointer(shared_from_this()));
else if (_other_devices.count(sdi))
return _other_devices[sdi];
else
shared_ptr<PacketPayload> Packet::payload()
{
if (_payload)
- return _payload->get_shared_pointer(this);
+ return _payload->get_shared_pointer(shared_from_this());
else
throw Error(SR_ERR_NA);
}
{
}
-shared_ptr<PacketPayload> Header::get_shared_pointer(Packet *_parent)
+shared_ptr<PacketPayload> Header::get_shared_pointer(shared_ptr<Packet> _parent)
{
return static_pointer_cast<PacketPayload>(
ParentOwned::get_shared_pointer(_parent));
{
}
-shared_ptr<PacketPayload> Meta::get_shared_pointer(Packet *_parent)
+shared_ptr<PacketPayload> Meta::get_shared_pointer(shared_ptr<Packet> _parent)
{
return static_pointer_cast<PacketPayload>(
ParentOwned::get_shared_pointer(_parent));
{
}
-shared_ptr<PacketPayload> Logic::get_shared_pointer(Packet *_parent)
+shared_ptr<PacketPayload> Logic::get_shared_pointer(shared_ptr<Packet> _parent)
{
return static_pointer_cast<PacketPayload>(
ParentOwned::get_shared_pointer(_parent));
{
}
-shared_ptr<PacketPayload> Analog::get_shared_pointer(Packet *_parent)
+shared_ptr<PacketPayload> Analog::get_shared_pointer(shared_ptr<Packet> _parent)
{
return static_pointer_cast<PacketPayload>(
ParentOwned::get_shared_pointer(_parent));
auto input = sr_input_new(_structure, map_to_hash_variant(options));
if (!input)
throw Error(SR_ERR_ARG);
- return shared_ptr<Input>(
- new Input(_parent->shared_from_this(), input), Input::Deleter());
+ return shared_ptr<Input>(new Input(_parent, input), Input::Deleter());
}
Input::Input(shared_ptr<Context> context, const struct sr_input *structure) :
{
}
-public:
- /* Get parent object that owns this object. */
- shared_ptr<Parent> parent()
- {
- return _parent;
- }
-
/* Note, this implementation will create a new smart_ptr if none exists. */
shared_ptr<Class> shared_from_this()
{
- shared_ptr<Class> shared;
+ shared_ptr<Class> shared = _weak_this.lock();
- if (!(shared = _weak_this.lock()))
+ if (!shared)
{
- shared = shared_ptr<Class>(static_cast<Class *>(this), reset_parent);
+ shared.reset(static_cast<Class *>(this), &reset_parent);
_weak_this = shared;
}
return shared_from_this();
}
- shared_ptr<Class> get_shared_pointer(Parent *parent)
+public:
+ /* Get parent object that owns this object. */
+ shared_ptr<Parent> parent()
{
- if (!parent)
- throw Error(SR_ERR_BUG);
- return get_shared_pointer(parent->shared_from_this());
+ return _parent;
}
};
template <class Class, typename Struct>
class SR_API UserOwned : public enable_shared_from_this<Class>
{
-public:
- shared_ptr<Class> shared_from_this()
- {
- auto shared = enable_shared_from_this<Class>::shared_from_this();
- if (!shared)
- throw Error(SR_ERR_BUG);
- return shared;
- }
protected:
Struct *_structure;
{
}
+ shared_ptr<Class> shared_from_this()
+ {
+ auto shared = enable_shared_from_this<Class>::shared_from_this();
+ if (!shared)
+ throw Error(SR_ERR_BUG);
+ return shared;
+ }
+
/* Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
{
protected:
PacketPayload();
virtual ~PacketPayload() = 0;
- virtual shared_ptr<PacketPayload> get_shared_pointer(Packet *parent) = 0;
+private:
+ virtual shared_ptr<PacketPayload> get_shared_pointer(shared_ptr<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;
private:
explicit Header(const struct sr_datafeed_header *structure);
~Header();
- shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
+ shared_ptr<PacketPayload> get_shared_pointer(shared_ptr<Packet> parent);
friend class Packet;
};
private:
explicit Meta(const struct sr_datafeed_meta *structure);
~Meta();
- shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
+ shared_ptr<PacketPayload> get_shared_pointer(shared_ptr<Packet> parent);
map<const ConfigKey *, Glib::VariantBase> _config;
friend class Packet;
};
private:
explicit Logic(const struct sr_datafeed_logic *structure);
~Logic();
- shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
+ shared_ptr<PacketPayload> get_shared_pointer(shared_ptr<Packet> parent);
friend class Packet;
};
private:
explicit Analog(const struct sr_datafeed_analog *structure);
~Analog();
- shared_ptr<PacketPayload> get_shared_pointer(Packet *parent);
+ shared_ptr<PacketPayload> get_shared_pointer(shared_ptr<Packet> parent);
friend class Packet;
};