blob: 2e2fcaf36c657a2ec3f6e0d8c00988577b86c0b9 [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);
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 Yang9260b662019-08-12 15:48:03 +080065 base::Optional<size_t> GetSampleSize() const override {
66 return base::nullopt;
67 }
68
69 bool EnableBuffer(size_t num) override { return false; }
70 bool DisableBuffer() override { return false; }
71 bool IsBufferEnabled(size_t* num = nullptr) const override { return false; }
72
Harvey Yange8b301b2020-05-19 14:43:03 +080073 base::Optional<int32_t> GetBufferFd() override { return base::nullopt; }
Harvey Yang34c54d52020-05-20 13:34:20 +080074 base::Optional<IioSample> ReadSample() override { return base::nullopt; }
Harvey Yang9260b662019-08-12 15:48:03 +080075
Harvey Yang98ff1b32020-10-28 14:45:35 +080076 base::TimeDelta GetPeriodForObsoleteSamplesInMilliseconds() override {
77 return base::TimeDelta::FromMilliseconds(0.0);
78 }
79
Harvey Yang9260b662019-08-12 15:48:03 +080080 private:
81 IioContextImpl* context_; // non-owned
82 iio_device* const trigger_; // non-owned
83
84 DISALLOW_COPY_AND_ASSIGN(IioDeviceTriggerImpl);
85};
86
87} // namespace libmems
88
89#endif // LIBMEMS_IIO_DEVICE_TRIGGER_IMPL_H_