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 7a016d1bd985090c9b89a2db880253e3cbce73f7..326cbca80f5daa0bb278ff388478fb1776d96dda 100644
(file)
--- a/
pv/devicemanager.cpp
+++ b/
pv/devicemanager.cpp
@@
-19,7
+19,7
@@
*/
#include "devicemanager.hpp"
*/
#include "devicemanager.hpp"
-#include "s
igs
ession.hpp"
+#include "session.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;
@@
-63,6
+65,11
@@
DeviceManager::~DeviceManager()
{
}
{
}
+const std::shared_ptr<sigrok::Context>& DeviceManager::context() const
+{
+ return context_;
+}
+
shared_ptr<Context> DeviceManager::context()
{
return context_;
shared_ptr<Context> DeviceManager::context()
{
return context_;
@@
-94,7
+101,7
@@
list< shared_ptr<HardwareDevice> > DeviceManager::driver_scan(
driver_devices.end());
for (shared_ptr<Device> device : devices_)
driver_devices.end());
for (shared_ptr<Device> device : devices_)
-
display_names_[device] =
build_display_name(device);
+ build_display_name(device);
devices_.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
{ return compare_devices(a, b); });
devices_.sort([&](shared_ptr<Device> a, shared_ptr<Device> b)
{ return compare_devices(a, b); });
@@
-104,7
+111,7
@@
list< shared_ptr<HardwareDevice> > DeviceManager::driver_scan(
// 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)
// 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)
-
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); });
@@
-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()+")");
+
+ full_names_[device] = join(parts, " ");
- bool multiple_dev = false;
+ // 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,17
+236,7
@@
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)
@@
-236,9
+244,14
@@
const std::string DeviceManager::get_display_name(std::shared_ptr<sigrok::Device
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,