X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdevices%2Fhardwaredevice.cpp;h=a3d84d6fadf175973fab3a2a420f190838948fc2;hp=b98b0e02f8aa9b2e43756af75835d8bae55723b4;hb=f4ab4b5c657e5613caba82feaa81a8a400e4f331;hpb=b8f99b84b701bb086e1d6edb8c32093f3047e31e diff --git a/pv/devices/hardwaredevice.cpp b/pv/devices/hardwaredevice.cpp index b98b0e0..a3d84d6 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 @@ -28,7 +27,6 @@ #include "hardwaredevice.hpp" -using std::dynamic_pointer_cast; using std::shared_ptr; using std::static_pointer_cast; using std::string; @@ -41,35 +39,43 @@ using sigrok::HardwareDevice; namespace pv { namespace devices { -HardwareDevice::HardwareDevice(const std::shared_ptr &context, - std::shared_ptr device) : +HardwareDevice::HardwareDevice(const shared_ptr &context, + shared_ptr device) : context_(context), - device_open_(false) { + device_open_(false) +{ device_ = device; } -HardwareDevice::~HardwareDevice() { - if (device_open_) - device_->close(); - - if (session_) - session_->remove_devices(); +HardwareDevice::~HardwareDevice() +{ + close(); } -string HardwareDevice::full_name() const { - vector parts = {device_->vendor(), device_->model(), - device_->version(), device_->serial_number()}; +string HardwareDevice::full_name() const +{ + vector parts = {}; + if (device_->vendor().length() > 0) + parts.push_back(device_->vendor()); + if (device_->model().length() > 0) + parts.push_back(device_->model()); + if (device_->version().length() > 0) + parts.push_back(device_->version()); + if (device_->serial_number().length() > 0) + parts.push_back("[S/N: " + device_->serial_number() + "]"); if (device_->connection_id().length() > 0) parts.push_back("(" + device_->connection_id() + ")"); 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 @@ -85,11 +91,17 @@ string HardwareDevice::display_name( dev->device_ != device_; }); - vector parts = {device_->vendor(), device_->model()}; + vector parts = {}; + if (device_->vendor().length() > 0) + parts.push_back(device_->vendor()); + if (device_->model().length() > 0) + parts.push_back(device_->model()); if (multiple_dev) { - parts.push_back(device_->version()); - parts.push_back(device_->serial_number()); + if (device_->version().length() > 0) + parts.push_back(device_->version()); + if (device_->serial_number().length() > 0) + parts.push_back("[S/N: " + device_->serial_number() + "]"); if ((device_->serial_number().length() == 0) && (device_->connection_id().length() > 0)) @@ -99,11 +111,14 @@ string HardwareDevice::display_name( return join(parts, " "); } -void HardwareDevice::create() { - // Open the device +void HardwareDevice::open() +{ + if (device_open_) + close(); + try { device_->open(); - } catch(const sigrok::Error &e) { + } catch (const sigrok::Error &e) { throw QString(e.what()); } @@ -114,5 +129,16 @@ void HardwareDevice::create() { session_->add_device(device_); } +void HardwareDevice::close() +{ + if (device_open_) + device_->close(); + + if (session_) + session_->remove_devices(); + + device_open_ = false; +} + } // namespace devices } // namespace pv