]> sigrok.org Git - libsigrok.git/commitdiff
C++: Add SessionDevice class for devices owned by loaded sessions.
authorMartin Ling <redacted>
Sat, 6 Sep 2014 15:06:00 +0000 (16:06 +0100)
committerUwe Hermann <redacted>
Mon, 8 Sep 2014 17:27:38 +0000 (19:27 +0200)
bindings/cxx/classes.cpp
bindings/cxx/include/libsigrok/libsigrok.hpp
bindings/swig/classes.i

index 76d3e8ecfed5c9a32d22967016e0adde7901ac63..3043ba51b318caf15d37aa5aab2be6e0be190247 100644 (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;
 }
 
index 29d6c73638fa7780253e7287ec1c97faac2eec6d..2a819b09c9649ff0a16636ac2296e936b60c7be8 100644 (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>
 {
index cc4aa7429bdc6f973ba9cbacbb013de3fbda3718..fe89952c611bde5bc64795a96bdbce22596380a3 100644 (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);