blob: 9d855dc2eb17b95584fcbe7ba63fee18c558ebb1 [file] [log] [blame]
Harvey Yang9260b662019-08-12 15:48:03 +08001// 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
18namespace libmems {
19
20class IioChannel;
21class IioContext;
22class IioContextImpl;
23
24class 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);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090033 IioDeviceTriggerImpl(const IioDeviceTriggerImpl&) = delete;
34 IioDeviceTriggerImpl& operator=(const IioDeviceTriggerImpl&) = delete;
35
Harvey Yang9260b662019-08-12 15:48:03 +080036 ~IioDeviceTriggerImpl() override = default;
37
38 IioContext* GetContext() const override;
39
40 const char* GetName() const override;
41 // Return -1 for iio_sysfs_trigger
42 int GetId() const override;
43
44 base::FilePath GetPath() const override;
45
46 base::Optional<std::string> ReadStringAttribute(
47 const std::string& name) const override;
48 base::Optional<int64_t> ReadNumberAttribute(
49 const std::string& name) const override;
50 base::Optional<double> ReadDoubleAttribute(
51 const std::string& name) const override {
52 return base::nullopt;
53 }
54
55 bool WriteStringAttribute(const std::string& name,
56 const std::string& value) override {
57 return false;
58 }
59 bool WriteNumberAttribute(const std::string& name, int64_t value) override;
60 bool WriteDoubleAttribute(const std::string& name, double value) override {
61 return false;
62 }
63 iio_device* GetUnderlyingIioDevice() const override { return nullptr; }
64
65 bool SetTrigger(IioDevice* trigger_device) override { return false; }
66 IioDevice* GetTrigger() override { return nullptr; }
67
Harvey Yang9260b662019-08-12 15:48:03 +080068 base::Optional<size_t> GetSampleSize() const override {
69 return base::nullopt;
70 }
71
72 bool EnableBuffer(size_t num) override { return false; }
73 bool DisableBuffer() override { return false; }
74 bool IsBufferEnabled(size_t* num = nullptr) const override { return false; }
75
Harvey Yange8b301b2020-05-19 14:43:03 +080076 base::Optional<int32_t> GetBufferFd() override { return base::nullopt; }
Harvey Yang34c54d52020-05-20 13:34:20 +080077 base::Optional<IioSample> ReadSample() override { return base::nullopt; }
Harvey Yang9260b662019-08-12 15:48:03 +080078
Harvey Yang98ff1b32020-10-28 14:45:35 +080079 base::TimeDelta GetPeriodForObsoleteSamplesInMilliseconds() override {
80 return base::TimeDelta::FromMilliseconds(0.0);
81 }
82
Harvey Yang9260b662019-08-12 15:48:03 +080083 private:
84 IioContextImpl* context_; // non-owned
85 iio_device* const trigger_; // non-owned
Harvey Yang9260b662019-08-12 15:48:03 +080086};
87
88} // namespace libmems
89
90#endif // LIBMEMS_IIO_DEVICE_TRIGGER_IMPL_H_