projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
DeviceManager: Added const context accessor
[pulseview.git]
/
pv
/
devicemanager.cpp
diff --git
a/pv/devicemanager.cpp
b/pv/devicemanager.cpp
index ee6a01232e73e365a1dc399da73f3ddc04a99f14..326cbca80f5daa0bb278ff388478fb1776d96dda 100644
(file)
--- a/
pv/devicemanager.cpp
+++ b/
pv/devicemanager.cpp
@@
-18,8
+18,8
@@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "devicemanager.h"
-#include "s
igsession.h
"
+#include "devicemanager.h
pp
"
+#include "s
ession.hpp
"
#include <cassert>
#include <stdexcept>
#include <cassert>
#include <stdexcept>
@@
-27,14
+27,16
@@
#include <string>
#include <vector>
#include <string>
#include <vector>
-#include <libsigrok
/libsigrok
.hpp>
+#include <libsigrok
cxx/libsigrokcxx
.hpp>
+#include <boost/algorithm/string/join.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem.hpp>
+using boost::algorithm::join;
+
using std::dynamic_pointer_cast;
using std::list;
using std::map;
using std::dynamic_pointer_cast;
using std::list;
using std::map;
-using std::ostringstream;
using std::remove_if;
using std::runtime_error;
using std::shared_ptr;
using std::remove_if;
using std::runtime_error;
using std::shared_ptr;
@@
-53,7
+55,7
@@
using sigrok::SessionDevice;
namespace pv {
DeviceManager::DeviceManager(shared_ptr<Context> context) :
namespace pv {
DeviceManager::DeviceManager(shared_ptr<Context> context) :
-
_context
(context)
+
context_
(context)
{
for (auto entry : context->drivers())
driver_scan(entry.second, map<const ConfigKey *, VariantBase>());
{
for (auto entry : context->drivers())
driver_scan(entry.second, map<const ConfigKey *, VariantBase>());
@@
-63,14
+65,19
@@
DeviceManager::~DeviceManager()
{
}
{
}
+const std::shared_ptr<sigrok::Context>& DeviceManager::context() const
+{
+ return context_;
+}
+
shared_ptr<Context> DeviceManager::context()
{
shared_ptr<Context> DeviceManager::context()
{
- return
_context
;
+ return
context_
;
}
const list< shared_ptr<HardwareDevice> >& DeviceManager::devices() const
{
}
const list< shared_ptr<HardwareDevice> >& DeviceManager::devices() const
{
- return
_devices
;
+ return
devices_
;
}
list< shared_ptr<HardwareDevice> > DeviceManager::driver_scan(
}
list< shared_ptr<HardwareDevice> > DeviceManager::driver_scan(
@@
-82,7
+89,7
@@
list< shared_ptr<HardwareDevice> > DeviceManager::driver_scan(
// Remove any device instances from this driver from the device
// list. They will not be valid after the scan.
// Remove any device instances from this driver from the device
// list. They will not be valid after the scan.
-
_devices
.remove_if([&](shared_ptr<HardwareDevice> device) {
+
devices_
.remove_if([&](shared_ptr<HardwareDevice> device) {
return device->driver() == driver; });
// Do the scan
return device->driver() == driver; });
// Do the scan
@@
-90,21
+97,21
@@
list< shared_ptr<HardwareDevice> > DeviceManager::driver_scan(
driver_devices.insert(driver_devices.end(), devices.begin(), devices.end());
// Add the scanned devices to the main list, set display names and sort.
driver_devices.insert(driver_devices.end(), devices.begin(), devices.end());
// Add the scanned devices to the main list, set display names and sort.
-
_devices.insert(_devices
.end(), driver_devices.begin(),
+
devices_.insert(devices_
.end(), driver_devices.begin(),
driver_devices.end());
driver_devices.end());
- for (shared_ptr<Device> device :
_devices
)
-
_display_names[device] =
build_display_name(device);
+ for (shared_ptr<Device> device :
devices_
)
+ build_display_name(device);
-
_devices
.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
+
devices_
.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
{ return compare_devices(a, b); });
{ return compare_devices(a, b); });
- // As the display names depend on the complete
_devices
list,
+ // As the display names depend on the complete
devices_
list,
// we need to recompute them. However, there is no need to
// we need to recompute them. However, there is no need to
- // recomute all names of the
_devices
list since only the
+ // recomute all names of the
devices_
list since only the
// devices that use the given driver can be affected.
for (shared_ptr<Device> device : driver_devices)
// devices that use the given driver can be affected.
for (shared_ptr<Device> device : driver_devices)
-
_display_names[device] =
build_display_name(device);
+ build_display_name(device);
driver_devices.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
{ return compare_devices(a, b); });
driver_devices.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
{ return compare_devices(a, b); });
@@
-141,7
+148,7
@@
const shared_ptr<HardwareDevice> DeviceManager::find_device_from_info(
last_resort_dev = NULL;
last_resort_dev = NULL;
- for (shared_ptr<HardwareDevice> dev :
_devices
) {
+ for (shared_ptr<HardwareDevice> dev :
devices_
) {
assert(dev);
dev_info = get_device_info(dev);
assert(dev);
dev_info = get_device_info(dev);
@@
-184,30
+191,41
@@
const shared_ptr<HardwareDevice> DeviceManager::find_device_from_info(
return last_resort_dev;
}
return last_resort_dev;
}
-
const string
DeviceManager::build_display_name(shared_ptr<Device> device)
+
void
DeviceManager::build_display_name(shared_ptr<Device> device)
{
auto session_device = dynamic_pointer_cast<SessionDevice>(device);
auto hardware_device = dynamic_pointer_cast<HardwareDevice>(device);
{
auto session_device = dynamic_pointer_cast<SessionDevice>(device);
auto hardware_device = dynamic_pointer_cast<HardwareDevice>(device);
- if (session_device)
- return boost::filesystem::path(
+ if (session_device) {
+ full_names_[device] = display_names_[device] =
+ boost::filesystem::path(
session_device->parent()->filename()).filename().string();
session_device->parent()->filename()).filename().string();
+ return;
+ }
+
+ // First, build the device's full name. It always contains all
+ // possible information.
+ vector<string> parts = {device->vendor(), device->model(),
+ device->version(), device->serial_number()};
- ostringstream s;
+ if (device->connection_id().length() > 0)
+ parts.push_back("("+device->connection_id()+")");
- bool multiple_dev = false;
+ full_names_[device] = join(parts, " ");
+
+ // Next, build the display name. It only contains fields as required.
// If we can find another device with the same model/vendor then
// we have at least two such devices and need to distinguish them.
// If we can find another device with the same model/vendor then
// we have at least two such devices and need to distinguish them.
- if (hardware_device)
-
multiple_dev = any_of(_devices.begin(), _devices
.end(),
-
[&](shared_ptr<HardwareDevice> dev) {
+ const bool multiple_dev = hardware_device && any_of(
+
devices_.begin(), devices_
.end(),
+ [&](shared_ptr<HardwareDevice> dev) {
return (dev->vendor() == hardware_device->vendor() &&
return (dev->vendor() == hardware_device->vendor() &&
- dev->model() == hardware_device->model()) &&
- dev != hardware_device;
-
} );
+
dev->model() == hardware_device->model()) &&
+
dev != hardware_device;
+ } );
-
vector<string>
parts = {device->vendor(), device->model()};
+ parts = {device->vendor(), device->model()};
if (multiple_dev) {
parts.push_back(device->version());
if (multiple_dev) {
parts.push_back(device->version());
@@
-218,27
+236,22
@@
const string DeviceManager::build_display_name(shared_ptr<Device> device)
parts.push_back("("+device->connection_id()+")");
}
parts.push_back("("+device->connection_id()+")");
}
- for (size_t i = 0; i < parts.size(); i++)
- {
- if (parts[i].length() > 0)
- {
- if (i != 0)
- s << " ";
- s << parts[i];
- }
- }
-
- return s.str();
+ display_names_[device] = join(parts, " ");
}
const std::string DeviceManager::get_display_name(std::shared_ptr<sigrok::Device> dev)
{
}
const std::string DeviceManager::get_display_name(std::shared_ptr<sigrok::Device> dev)
{
- return _display_names[dev];
+ return display_names_[dev];
+}
+
+const std::string DeviceManager::get_full_name(std::shared_ptr<sigrok::Device> dev)
+{
+ return full_names_[dev];
}
void DeviceManager::update_display_name(std::shared_ptr<sigrok::Device> dev)
{
}
void DeviceManager::update_display_name(std::shared_ptr<sigrok::Device> dev)
{
-
_display_names[dev] =
build_display_name(dev);
+ build_display_name(dev);
}
bool DeviceManager::compare_devices(shared_ptr<Device> a,
}
bool DeviceManager::compare_devices(shared_ptr<Device> a,
@@
-247,7
+260,7
@@
bool DeviceManager::compare_devices(shared_ptr<Device> a,
assert(a);
assert(b);
assert(a);
assert(b);
- return
_display_names[a].compare(_display_names
[b]) < 0;
+ return
display_names_[a].compare(display_names_
[b]) < 0;
}
} // namespace pv
}
} // namespace pv