projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Confirm with user when trying to close sessions with unsaved data
[pulseview.git]
/
pv
/
devices
/
hardwaredevice.cpp
diff --git
a/pv/devices/hardwaredevice.cpp
b/pv/devices/hardwaredevice.cpp
index b98b0e02f8aa9b2e43756af75835d8bae55723b4..591c756ba84519abce9b2e0eed39e41f07b83763 100644
(file)
--- a/
pv/devices/hardwaredevice.cpp
+++ b/
pv/devices/hardwaredevice.cpp
@@
-14,8
+14,7
@@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/algorithm/string/join.hpp>
*/
#include <boost/algorithm/string/join.hpp>
@@
-44,19
+43,18
@@
namespace devices {
HardwareDevice::HardwareDevice(const std::shared_ptr<sigrok::Context> &context,
std::shared_ptr<sigrok::HardwareDevice> device) :
context_(context),
HardwareDevice::HardwareDevice(const std::shared_ptr<sigrok::Context> &context,
std::shared_ptr<sigrok::HardwareDevice> device) :
context_(context),
- device_open_(false) {
+ device_open_(false)
+{
device_ = device;
}
device_ = device;
}
-HardwareDevice::~HardwareDevice() {
- if (device_open_)
- device_->close();
-
- if (session_)
- session_->remove_devices();
+HardwareDevice::~HardwareDevice()
+{
+ close();
}
}
-string HardwareDevice::full_name() const {
+string HardwareDevice::full_name() const
+{
vector<string> parts = {device_->vendor(), device_->model(),
device_->version(), device_->serial_number()};
if (device_->connection_id().length() > 0)
vector<string> parts = {device_->vendor(), device_->model(),
device_->version(), device_->serial_number()};
if (device_->connection_id().length() > 0)
@@
-64,12
+62,14
@@
string HardwareDevice::full_name() const {
return join(parts, " ");
}
return join(parts, " ");
}
-shared_ptr<sigrok::HardwareDevice> HardwareDevice::hardware_device() const {
+shared_ptr<sigrok::HardwareDevice> HardwareDevice::hardware_device() const
+{
return static_pointer_cast<sigrok::HardwareDevice>(device_);
}
string HardwareDevice::display_name(
return static_pointer_cast<sigrok::HardwareDevice>(device_);
}
string HardwareDevice::display_name(
- const DeviceManager &device_manager) const {
+ const DeviceManager &device_manager) const
+{
const auto hw_dev = hardware_device();
// If we can find another device with the same model/vendor then
const auto hw_dev = hardware_device();
// If we can find another device with the same model/vendor then
@@
-99,11
+99,14
@@
string HardwareDevice::display_name(
return join(parts, " ");
}
return join(parts, " ");
}
-void HardwareDevice::create() {
- // Open the device
+void HardwareDevice::open()
+{
+ if (device_open_)
+ close();
+
try {
device_->open();
try {
device_->open();
- } catch(const sigrok::Error &e) {
+ } catch
(const sigrok::Error &e) {
throw QString(e.what());
}
throw QString(e.what());
}
@@
-114,5
+117,16
@@
void HardwareDevice::create() {
session_->add_device(device_);
}
session_->add_device(device_);
}
+void HardwareDevice::close()
+{
+ if (device_open_)
+ device_->close();
+
+ if (session_)
+ session_->remove_devices();
+
+ device_open_ = false;
+}
+
} // namespace devices
} // namespace pv
} // namespace devices
} // namespace pv