C++: Add SessionDevice class for devices owned by loaded sessions.

This commit is contained in:
Martin Ling 2014-09-06 16:06:00 +01:00 committed by Uwe Hermann
parent be43d5d584
commit cac58676e9
3 changed files with 44 additions and 0 deletions

View File

@ -745,6 +745,21 @@ EventSource::~EventSource()
{
}
SessionDevice::SessionDevice(struct sr_dev_inst *structure) :
ParentOwned(structure),
Device(structure)
{
}
SessionDevice::~SessionDevice()
{
}
shared_ptr<Device> SessionDevice::get_shared_from_this()
{
return static_pointer_cast<Device>(shared_from_this());
}
Session::Session(shared_ptr<Context> context) :
UserOwned(structure),
context(context), saving(false)
@ -758,6 +773,15 @@ Session::Session(shared_ptr<Context> context, string filename) :
context(context), saving(false)
{
check(sr_session_load(filename.c_str(), &structure));
GSList *dev_list;
check(sr_session_dev_list(structure, &dev_list));
for (GSList *dev = dev_list; dev; dev = dev->next)
{
auto sdi = (struct sr_dev_inst *) dev->data;
auto device = new SessionDevice(sdi);
devices[sdi] = shared_ptr<SessionDevice>(device,
SessionDevice::Deleter());
}
context->session = this;
}

View File

@ -585,6 +585,25 @@ protected:
friend class SourceCallbackData;
};
/** A virtual device associated with a stored session */
class SR_API SessionDevice :
public ParentOwned<SessionDevice, Session, struct sr_dev_inst>,
public Device
{
protected:
SessionDevice(struct sr_dev_inst *sdi);
~SessionDevice();
shared_ptr<Device> get_shared_from_this();
/** Deleter needed to allow shared_ptr use with protected destructor. */
class Deleter
{
public:
void operator()(SessionDevice *device) { delete device; }
};
friend class Deleter;
friend class Session;
};
/** A sigrok session */
class SR_API Session : public UserOwned<Session, struct sr_session>
{

View File

@ -68,6 +68,7 @@ template< class T > class enable_shared_from_this;
%shared_ptr(sigrok::ChannelGroup);
%shared_ptr(sigrok::EventSource);
%shared_ptr(sigrok::Session);
%shared_ptr(sigrok::SessionDevice);
%shared_ptr(sigrok::Packet);
%shared_ptr(sigrok::PacketPayload);
%shared_ptr(sigrok::Header);