blob: 37354e13dd0955f81c71f4fb14a51549fc776ea8 [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(
Harvey Yang0c0039a2020-12-02 14:45:59 +080051 const std::string& name) const override;
Harvey Yang9260b662019-08-12 15:48:03 +080052
53 bool WriteStringAttribute(const std::string& name,
54 const std::string& value) override {
55 return false;
56 }
57 bool WriteNumberAttribute(const std::string& name, int64_t value) override;
Harvey Yang0c0039a2020-12-02 14:45:59 +080058 bool WriteDoubleAttribute(const std::string& name, double value) override;
Harvey Yang9260b662019-08-12 15:48:03 +080059 iio_device* GetUnderlyingIioDevice() const override { return nullptr; }
60
61 bool SetTrigger(IioDevice* trigger_device) override { return false; }
62 IioDevice* GetTrigger() override { return nullptr; }
63
Harvey Yang9260b662019-08-12 15:48:03 +080064 base::Optional<size_t> GetSampleSize() const override {
65 return base::nullopt;
66 }
67
68 bool EnableBuffer(size_t num) override { return false; }
69 bool DisableBuffer() override { return false; }
70 bool IsBufferEnabled(size_t* num = nullptr) const override { return false; }
71
Harvey Yange8b301b2020-05-19 14:43:03 +080072 base::Optional<int32_t> GetBufferFd() override { return base::nullopt; }
Harvey Yang34c54d52020-05-20 13:34:20 +080073 base::Optional<IioSample> ReadSample() override { return base::nullopt; }
Harvey Yang9260b662019-08-12 15:48:03 +080074
Harvey Yang98ff1b32020-10-28 14:45:35 +080075 base::TimeDelta GetPeriodForObsoleteSamplesInMilliseconds() override {
76 return base::TimeDelta::FromMilliseconds(0.0);
77 }
78
Harvey Yang9260b662019-08-12 15:48:03 +080079 private:
80 IioContextImpl* context_; // non-owned
81 iio_device* const trigger_; // non-owned
Harvey Yang3b87b1d2020-12-04 15:38:20 +080082
83 std::string log_prefix_;
Harvey Yang9260b662019-08-12 15:48:03 +080084};
85
86} // namespace libmems
87
88#endif // LIBMEMS_IIO_DEVICE_TRIGGER_IMPL_H_