blob: 4dfa4d24cf1a48efae08548bc54de27e0721e9d9 [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
65 IioChannel* GetChannel(const std::string& name) override { return nullptr; }
66
67 base::Optional<size_t> GetSampleSize() const override {
68 return base::nullopt;
69 }
70
71 bool EnableBuffer(size_t num) override { return false; }
72 bool DisableBuffer() override { return false; }
73 bool IsBufferEnabled(size_t* num = nullptr) const override { return false; }
74
75 bool ReadEvent(std::vector<uint8_t>* event) override { return false; }
76
77 private:
78 IioContextImpl* context_; // non-owned
79 iio_device* const trigger_; // non-owned
80
81 DISALLOW_COPY_AND_ASSIGN(IioDeviceTriggerImpl);
82};
83
84} // namespace libmems
85
86#endif // LIBMEMS_IIO_DEVICE_TRIGGER_IMPL_H_