]> sigrok.org Git - pulseview.git/commitdiff
Session: Simplified logic of set_device
authorJoel Holdsworth <redacted>
Mon, 2 Feb 2015 03:18:46 +0000 (20:18 -0700)
committerJoel Holdsworth <redacted>
Thu, 28 May 2015 14:59:04 +0000 (15:59 +0100)
pv/session.cpp

index 70637437e08b5ad1ea867e58ae4573956cc30bb9..5f2bc8ea0544de070b62ff33fd9b5f2d66d06c30 100644 (file)
@@ -123,30 +123,26 @@ void Session::set_device(shared_ptr<Device> device)
        // Ensure we are not capturing before setting the device
        stop_capture();
 
-       // Are we setting a session device?
-       const auto session_device =
-               dynamic_pointer_cast<SessionDevice>(device);
-
-       // Did we have a session device selected previously?
-       const auto prev_session_device =
-               dynamic_pointer_cast<SessionDevice>(device_);
-
        if (device_) {
                session_->remove_datafeed_callbacks();
-               if (!prev_session_device) {
+
+               // Did we have a hardware device selected previously?
+               if (!dynamic_pointer_cast<HardwareDevice>(device_)) {
                        device_->close();
                        session_->remove_devices();
                }
        }
 
-       if (session_device)
-               session_ = session_device->parent();
-
        decode_traces_.clear();
 
        if (device) {
-               if (!session_device)
-               {
+               // Are we setting a session device?
+               const auto session_device =
+                       dynamic_pointer_cast<SessionDevice>(device);
+
+               if (session_device)
+                       session_ = session_device->parent();
+               else {
                        session_ = device_manager_.context()->create_session();
 
                        try {