From: Joel Holdsworth Date: Wed, 19 Feb 2014 22:50:07 +0000 (+0000) Subject: Added pv::device::Device X-Git-Tag: pulseview-0.2.0~56 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=921b90c0b3ae0cf44247da3d87bd7dc0612e9681 Added pv::device::Device --- diff --git a/CMakeLists.txt b/CMakeLists.txt index aaed2d61..58c86c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,7 @@ set(pulseview_SOURCES pv/data/logicsnapshot.cpp pv/data/signaldata.cpp pv/data/snapshot.cpp + pv/device/device.cpp pv/device/devinst.cpp pv/dialogs/about.cpp pv/dialogs/connect.cpp diff --git a/pv/device/device.cpp b/pv/device/device.cpp new file mode 100644 index 00000000..ca18fc13 --- /dev/null +++ b/pv/device/device.cpp @@ -0,0 +1,64 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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 + */ + +#include + +#include + +#include "device.h" + +using std::ostringstream; +using std::string; + +namespace pv { +namespace device { + +Device::Device(sr_dev_inst *sdi) : + DevInst(sdi) +{ +} + +std::string Device::format_device_title() const +{ + ostringstream s; + + assert(_sdi); + + if (_sdi->vendor && _sdi->vendor[0]) { + s << _sdi->vendor; + if ((_sdi->model && _sdi->model[0]) || + (_sdi->version && _sdi->version[0])) + s << ' '; + } + + if (_sdi->model && _sdi->model[0]) { + s << _sdi->model; + if (_sdi->version && _sdi->version[0]) + s << ' '; + } + + if (_sdi->version && _sdi->version[0]) + s << _sdi->version; + + return s.str(); +} + +} // device +} // pv diff --git a/pv/device/device.h b/pv/device/device.h new file mode 100644 index 00000000..fe91a6cb --- /dev/null +++ b/pv/device/device.h @@ -0,0 +1,40 @@ +/* + * This file is part of the PulseView project. + * + * Copyright (C) 2014 Joel Holdsworth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * 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 + */ + +#ifndef PULSEVIEW_PV_DEVICE_DEVICE_H +#define PULSEVIEW_PV_DEVICE_DEVICE_H + +#include "devinst.h" + +namespace pv { +namespace device { + +class Device : public DevInst +{ +public: + Device(sr_dev_inst *dev_inst); + + std::string format_device_title() const; +}; + +} // device +} // pv + +#endif // PULSVIEW_PV_DEVICE_DEVICE_H diff --git a/pv/device/devinst.cpp b/pv/device/devinst.cpp index a5f96808..5fe29517 100644 --- a/pv/device/devinst.cpp +++ b/pv/device/devinst.cpp @@ -19,7 +19,6 @@ */ #include -#include #include @@ -27,9 +26,6 @@ #include "devinst.h" -using std::ostringstream; -using std::string; - namespace pv { namespace device { @@ -44,31 +40,6 @@ sr_dev_inst* DevInst::dev_inst() const return _sdi; } -string DevInst::format_device_title() const -{ - ostringstream s; - - assert(_sdi); - - if (_sdi->vendor && _sdi->vendor[0]) { - s << _sdi->vendor; - if ((_sdi->model && _sdi->model[0]) || - (_sdi->version && _sdi->version[0])) - s << ' '; - } - - if (_sdi->model && _sdi->model[0]) { - s << _sdi->model; - if (_sdi->version && _sdi->version[0]) - s << ' '; - } - - if (_sdi->version && _sdi->version[0]) - s << _sdi->version; - - return s.str(); -} - GVariant* DevInst::get_config(const sr_probe_group *group, int key) { GVariant *data = NULL; diff --git a/pv/device/devinst.h b/pv/device/devinst.h index 073813f2..6e81f49c 100644 --- a/pv/device/devinst.h +++ b/pv/device/devinst.h @@ -42,12 +42,13 @@ class DevInst : public QObject { Q_OBJECT -public: +protected: DevInst(sr_dev_inst *sdi); +public: sr_dev_inst* dev_inst() const; - std::string format_device_title() const; + virtual std::string format_device_title() const = 0; GVariant* get_config(const sr_probe_group *group, int key); @@ -68,7 +69,7 @@ public: signals: void config_changed(); -private: +protected: sr_dev_inst *const _sdi; }; diff --git a/pv/devicemanager.cpp b/pv/devicemanager.cpp index 11a5fe3c..b854c050 100644 --- a/pv/devicemanager.cpp +++ b/pv/devicemanager.cpp @@ -19,7 +19,7 @@ */ #include "devicemanager.h" -#include "device/devinst.h" +#include "device/device.h" #include "sigsession.h" #include @@ -102,7 +102,7 @@ list< shared_ptr > DeviceManager::driver_scan( GSList *const devices = sr_driver_scan(driver, drvopts); for (GSList *l = devices; l; l = l->next) driver_devices.push_back(shared_ptr( - new device::DevInst((sr_dev_inst*)l->data))); + new device::Device((sr_dev_inst*)l->data))); g_slist_free(devices); driver_devices.sort(compare_devices); diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 622bf8d2..4469a3ee 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -25,7 +25,7 @@ #include "sigsession.h" #include "devicemanager.h" -#include "device/devinst.h" +#include "device/device.h" #include "data/analog.h" #include "data/analogsnapshot.h" @@ -127,7 +127,7 @@ void SigSession::load_file(const string &name, } shared_ptr dev_inst( - new device::DevInst((sr_dev_inst*)devlist->data)); + new device::Device((sr_dev_inst*)devlist->data)); g_slist_free(devlist); _decode_traces.clear(); @@ -147,7 +147,7 @@ void SigSession::load_file(const string &name, _decode_traces.clear(); update_signals(shared_ptr( - new device::DevInst(in->sdi))); + new device::Device(in->sdi))); read_sample_rate(in->sdi); _sampling_thread = boost::thread( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 27d42f91..5e064a02 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -57,6 +57,7 @@ set(pulseview_TEST_SOURCES ${PROJECT_SOURCE_DIR}/pv/data/logicsnapshot.cpp ${PROJECT_SOURCE_DIR}/pv/data/snapshot.cpp ${PROJECT_SOURCE_DIR}/pv/data/signaldata.cpp + ${PROJECT_SOURCE_DIR}/pv/device/device.cpp ${PROJECT_SOURCE_DIR}/pv/device/devinst.cpp ${PROJECT_SOURCE_DIR}/pv/prop/int.cpp ${PROJECT_SOURCE_DIR}/pv/prop/property.cpp