Harvey Yang | 9260b66 | 2019-08-12 15:48:03 +0800 | [diff] [blame] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef LIBMEMS_IIO_DEVICE_TRIGGER_IMPL_H_ |
| 6 | #define LIBMEMS_IIO_DEVICE_TRIGGER_IMPL_H_ |
| 7 | |
| 8 | #include <iio.h> |
| 9 | |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include <base/optional.h> |
| 14 | |
| 15 | #include "libmems/export.h" |
| 16 | #include "libmems/iio_device.h" |
| 17 | |
| 18 | namespace libmems { |
| 19 | |
| 20 | class IioChannel; |
| 21 | class IioContext; |
| 22 | class IioContextImpl; |
| 23 | |
| 24 | class LIBMEMS_EXPORT IioDeviceTriggerImpl : public IioDevice { |
| 25 | public: |
| 26 | // Return -1 for iio_sysfs_trigger |
| 27 | static base::Optional<int> GetIdFromString(const char* id_str); |
| 28 | // Return iio_sysfs_trigger for -1 |
| 29 | static std::string GetStringFromId(int id); |
| 30 | |
| 31 | // iio_device objects are kept alive by the IioContextImpl. |
| 32 | IioDeviceTriggerImpl(IioContextImpl* ctx, iio_device* dev); |
| 33 | ~IioDeviceTriggerImpl() override = default; |
| 34 | |
| 35 | IioContext* GetContext() const override; |
| 36 | |
| 37 | const char* GetName() const override; |
| 38 | // Return -1 for iio_sysfs_trigger |
| 39 | int GetId() const override; |
| 40 | |
| 41 | base::FilePath GetPath() const override; |
| 42 | |
| 43 | base::Optional<std::string> ReadStringAttribute( |
| 44 | const std::string& name) const override; |
| 45 | base::Optional<int64_t> ReadNumberAttribute( |
| 46 | const std::string& name) const override; |
| 47 | base::Optional<double> ReadDoubleAttribute( |
| 48 | const std::string& name) const override { |
| 49 | return base::nullopt; |
| 50 | } |
| 51 | |
| 52 | bool WriteStringAttribute(const std::string& name, |
| 53 | const std::string& value) override { |
| 54 | return false; |
| 55 | } |
| 56 | bool WriteNumberAttribute(const std::string& name, int64_t value) override; |
| 57 | bool WriteDoubleAttribute(const std::string& name, double value) override { |
| 58 | return false; |
| 59 | } |
| 60 | iio_device* GetUnderlyingIioDevice() const override { return nullptr; } |
| 61 | |
| 62 | bool SetTrigger(IioDevice* trigger_device) override { return false; } |
| 63 | IioDevice* GetTrigger() override { return nullptr; } |
| 64 | |
Harvey Yang | b0c3096 | 2019-09-17 15:00:25 +0800 | [diff] [blame] | 65 | std::vector<IioChannel*> GetAllChannels() override { |
| 66 | return std::vector<IioChannel*>(); |
| 67 | } |
Harvey Yang | 9260b66 | 2019-08-12 15:48:03 +0800 | [diff] [blame] | 68 | IioChannel* GetChannel(const std::string& name) override { return nullptr; } |
| 69 | |
| 70 | base::Optional<size_t> GetSampleSize() const override { |
| 71 | return base::nullopt; |
| 72 | } |
| 73 | |
| 74 | bool EnableBuffer(size_t num) override { return false; } |
| 75 | bool DisableBuffer() override { return false; } |
| 76 | bool IsBufferEnabled(size_t* num = nullptr) const override { return false; } |
| 77 | |
Harvey Yang | e8b301b | 2020-05-19 14:43:03 +0800 | [diff] [blame^] | 78 | base::Optional<int32_t> GetBufferFd() override { return base::nullopt; } |
Harvey Yang | 9260b66 | 2019-08-12 15:48:03 +0800 | [diff] [blame] | 79 | bool ReadEvent(std::vector<uint8_t>* event) override { return false; } |
| 80 | |
| 81 | private: |
| 82 | IioContextImpl* context_; // non-owned |
| 83 | iio_device* const trigger_; // non-owned |
| 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(IioDeviceTriggerImpl); |
| 86 | }; |
| 87 | |
| 88 | } // namespace libmems |
| 89 | |
| 90 | #endif // LIBMEMS_IIO_DEVICE_TRIGGER_IMPL_H_ |