blob: d1bec8c92d009809b9518c3ea77628a2b9e3decc [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_CHANNEL_IMPL_H_
6#define LIBMEMS_IIO_CHANNEL_IMPL_H_
Enrico Granata60a818d2019-05-09 09:56:09 -07007
8#include <iio.h>
9
10#include <memory>
Harvey Yang96029cb2019-06-03 17:26:14 +080011#include <string>
Enrico Granata60a818d2019-05-09 09:56:09 -070012
Enrico Granata51cdb942019-06-18 16:40:17 -070013#include "libmems/export.h"
14#include "libmems/iio_channel.h"
Enrico Granata60a818d2019-05-09 09:56:09 -070015
Enrico Granata51cdb942019-06-18 16:40:17 -070016namespace libmems {
Enrico Granata60a818d2019-05-09 09:56:09 -070017
18class IioDevice;
19
Enrico Granata51cdb942019-06-18 16:40:17 -070020class LIBMEMS_EXPORT IioChannelImpl : public IioChannel {
Enrico Granata60a818d2019-05-09 09:56:09 -070021 public:
22 // iio_channel objects are kept alive by the IioContextImpl.
23 explicit IioChannelImpl(iio_channel* channel);
24 ~IioChannelImpl() override = default;
25
26 const char* GetId() const override;
27
28 bool IsEnabled() const override;
29 bool SetEnabled(bool en) override;
30
Harvey Yang96029cb2019-06-03 17:26:14 +080031 base::Optional<std::string> ReadStringAttribute(
32 const std::string& name) const override;
33 base::Optional<int64_t> ReadNumberAttribute(
34 const std::string& name) const override;
35
Harvey Yang34c54d52020-05-20 13:34:20 +080036 base::Optional<int64_t> Convert(const uint8_t* src) const;
37 base::Optional<uint64_t> Length() const;
38
Enrico Granata60a818d2019-05-09 09:56:09 -070039 private:
40 iio_channel* const channel_; // non-owned
41
42 DISALLOW_COPY_AND_ASSIGN(IioChannelImpl);
43};
44
Enrico Granata51cdb942019-06-18 16:40:17 -070045} // namespace libmems
Enrico Granata60a818d2019-05-09 09:56:09 -070046
Enrico Granata51cdb942019-06-18 16:40:17 -070047#endif // LIBMEMS_IIO_CHANNEL_IMPL_H_