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