X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=inline;f=pv%2Fdevices%2Fhardwaredevice.cpp;h=591c756ba84519abce9b2e0eed39e41f07b83763;hb=53bb2e1de75f5cca9244efc83c4e77a222e322f4;hp=6374dafe6e03aaddb219a05c1fa4c3a21ab71dd5;hpb=b485408f20c39ae8d05372a5faffe15653c74705;p=pulseview.git
diff --git a/pv/devices/hardwaredevice.cpp b/pv/devices/hardwaredevice.cpp
index 6374daf..591c756 100644
--- 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
- * 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 .
*/
#include
@@ -43,17 +42,19 @@ namespace devices {
HardwareDevice::HardwareDevice(const std::shared_ptr &context,
std::shared_ptr device) :
- context_(context) {
+ context_(context),
+ device_open_(false)
+{
device_ = device;
}
-HardwareDevice::~HardwareDevice() {
- device_->close();
- if (session_)
- session_->remove_devices();
+HardwareDevice::~HardwareDevice()
+{
+ close();
}
-string HardwareDevice::full_name() const {
+string HardwareDevice::full_name() const
+{
vector parts = {device_->vendor(), device_->model(),
device_->version(), device_->serial_number()};
if (device_->connection_id().length() > 0)
@@ -61,12 +62,14 @@ string HardwareDevice::full_name() const {
return join(parts, " ");
}
-shared_ptr HardwareDevice::hardware_device() const {
+shared_ptr HardwareDevice::hardware_device() const
+{
return static_pointer_cast(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
@@ -96,17 +99,33 @@ string HardwareDevice::display_name(
return join(parts, " ");
}
-void HardwareDevice::create() {
- // Open the device
- try {
- device_->open();
- } catch(const sigrok::Error &e) {
- throw QString(e.what());
- }
-
- // Set up the session
- session_ = context_->create_session();
- session_->add_device(device_);
+void HardwareDevice::open()
+{
+ if (device_open_)
+ close();
+
+ try {
+ device_->open();
+ } catch (const sigrok::Error &e) {
+ throw QString(e.what());
+ }
+
+ device_open_ = true;
+
+ // Set up the session
+ session_ = context_->create_session();
+ session_->add_device(device_);
+}
+
+void HardwareDevice::close()
+{
+ if (device_open_)
+ device_->close();
+
+ if (session_)
+ session_->remove_devices();
+
+ device_open_ = false;
}
} // namespace devices