]> sigrok.org Git - pulseview.git/blobdiff - pv/devices/device.cpp
Added InputFile
[pulseview.git] / pv / devices / device.cpp
index 004749c9462f5bee93bd983901151737d5ea3337..4027a1c2d820a35ba248e312f3d066af789df620 100644 (file)
 
 #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 {
 
@@ -43,6 +52,39 @@ std::shared_ptr<sigrok::Device> Device::device() const {
        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::start() {
+       assert(session_);
+       session_->start();
+}
+
 void Device::run() {
        assert(device_);
        assert(session_);