#include "device.hpp"
+using std::map;
+using std::set;
+
+using sigrok::ConfigKey;
+using sigrok::Error;
+
+using Glib::VariantBase;
+using Glib::Variant;
+
namespace pv {
namespace devices {
return device_;
}
+template
+uint64_t Device::read_config(const sigrok::ConfigKey*,
+ const uint64_t);
+
+template<typename T>
+T Device::read_config(const ConfigKey *key, const T default_value)
+{
+ assert(key);
+ map< const ConfigKey*, set<sigrok::Capability> > keys;
+
+ if (!device_)
+ return default_value;
+
+ try {
+ keys = device_->config_keys(ConfigKey::DEVICE_OPTIONS);
+ } catch (const Error) {
+ return default_value;
+ }
+
+ const auto iter = keys.find(key);
+ if (iter == keys.end() ||
+ (*iter).second.find(sigrok::GET) != (*iter).second.end())
+ return default_value;
+
+ return VariantBase::cast_dynamic<Variant<T>>(
+ device_->config_get(ConfigKey::SAMPLERATE)).get();
+}
+
void Device::run() {
assert(device_);
assert(session_);
#include <string>
namespace sigrok {
+class ConfigKey;
class Device;
class Session;
} // namespace sigrok
std::shared_ptr<sigrok::Device> device() const;
+ template<typename T>
+ T read_config(const sigrok::ConfigKey *key, const T default_value = 0);
+
/**
* Builds the full name. It only contains all the fields.
*/
return shared_ptr<view::Signal>();
}
-void Session::read_sample_rate(shared_ptr<sigrok::Device> device)
-{
- assert(device);
- map< const ConfigKey*, set<sigrok::Capability> > keys;
-
- try {
- keys = device->config_keys(ConfigKey::DEVICE_OPTIONS);
- } catch (const Error) {}
-
- const auto iter = keys.find(ConfigKey::SAMPLERATE);
- cur_samplerate_ = (iter != keys.end() &&
- (*iter).second.find(sigrok::GET) != (*iter).second.end()) ?
- VariantBase::cast_dynamic<Variant<guint64>>(
- device->config_get(ConfigKey::SAMPLERATE)).get() : 0;
-}
-
void Session::sample_thread_proc(shared_ptr<devices::Device> device,
function<void (const QString)> error_handler)
{
assert(device);
assert(error_handler);
- const std::shared_ptr<sigrok::Device> sr_dev = device->device();
- assert(sr_dev);
- read_sample_rate(sr_dev);
+ cur_samplerate_ = device_->read_config<uint64_t>(ConfigKey::SAMPLERATE);
try {
device_->session()->start();
void Session::feed_in_header()
{
- read_sample_rate(device_->device());
+ cur_samplerate_ = device_->read_config<uint64_t>(ConfigKey::SAMPLERATE);
}
void Session::feed_in_meta(shared_ptr<Meta> meta)
std::shared_ptr<view::Signal> signal_from_channel(
std::shared_ptr<sigrok::Channel> channel) const;
- void read_sample_rate(std::shared_ptr<sigrok::Device> device);
-
private:
void sample_thread_proc(std::shared_ptr<devices::Device> device,
std::function<void (const QString)> error_handler);