]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
C++: Add SessionDevice class for devices owned by loaded sessions.
[libsigrok.git] / bindings / cxx / classes.cpp
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;
 }