blob: 5088baf25631f56899835ac8a08a4289eb4d085e [file] [log] [blame]
Enrico Granata60a818d2019-05-09 09:56:09 -07001// 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 MEMS_SETUP_IIO_DEVICE_IMPL_H_
6#define MEMS_SETUP_IIO_DEVICE_IMPL_H_
7
8#include <iio.h>
9
10#include <map>
11#include <memory>
12#include <string>
13
14#include <base/optional.h>
15
16#include "mems_setup/iio_device.h"
17
18namespace mems_setup {
19
20class IioChannelImpl;
21class IioContext;
22class IioContextImpl;
23
24class IioDeviceImpl : public IioDevice {
25 public:
26 // iio_device objects are kept alive by the IioContextImpl.
27 IioDeviceImpl(IioContextImpl* ctx, iio_device* dev);
28 ~IioDeviceImpl() override = default;
29
30 IioContext* GetContext() const override;
31
32 const char* GetName() const override;
33 const char* GetId() const override;
34
35 base::FilePath GetPath() const override;
36
37 base::Optional<std::string> ReadStringAttribute(
38 const std::string& name) const override;
39 base::Optional<int64_t> ReadNumberAttribute(
40 const std::string& name) const override;
41
42 bool WriteStringAttribute(const std::string& name,
43 const std::string& value) override;
44 bool WriteNumberAttribute(const std::string& name, int64_t value) override;
45
46 iio_device* GetUnderlyingIioDevice() const override;
47
48 bool SetTrigger(IioDevice* trigger_device) override;
49 IioDevice* GetTrigger() override;
50
51 IioChannel* GetChannel(const std::string& name) override;
52
53 bool EnableBuffer(size_t num) override;
54 bool DisableBuffer() override;
55 bool IsBufferEnabled(size_t* num = nullptr) const override;
56
57 private:
58 IioContextImpl* context_; // non-owned
59 iio_device* const device_; // non-owned
60 std::map<std::string, std::unique_ptr<IioChannelImpl>> channels_;
61 DISALLOW_COPY_AND_ASSIGN(IioDeviceImpl);
62};
63
64} // namespace mems_setup
65
66#endif // MEMS_SETUP_IIO_DEVICE_IMPL_H_