-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiio_context_impl.h
67 lines (50 loc) · 1.96 KB
/
iio_context_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2019 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LIBMEMS_IIO_CONTEXT_IMPL_H_
#define LIBMEMS_IIO_CONTEXT_IMPL_H_
#include <iio.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "libmems/export.h"
#include "libmems/iio_context.h"
#include "libmems/iio_device.h"
#include "libmems/iio_device_impl.h"
#include "libmems/iio_device_trigger_impl.h"
namespace libmems {
class LIBMEMS_EXPORT IioContextImpl : public IioContext {
public:
IioContextImpl();
IioContextImpl(const IioContextImpl&) = delete;
IioContextImpl& operator=(const IioContextImpl&) = delete;
~IioContextImpl() override = default;
iio_context* GetCurrentContext() const override;
void Reload() override;
bool SetTimeout(uint32_t timeout) override;
std::vector<IioDevice*> GetDevicesByName(const std::string& name) override;
IioDevice* GetDeviceById(int id) override;
std::vector<IioDevice*> GetAllDevices() override;
std::vector<IioDevice*> GetTriggersByName(const std::string& name) override;
IioDevice* GetTriggerById(int id) override;
std::vector<IioDevice*> GetAllTriggers() override;
private:
using ContextUniquePtr =
std::unique_ptr<iio_context, decltype(&iio_context_destroy)>;
template <typename T>
IioDevice* GetById(int id, std::map<int, std::unique_ptr<T>>* devices_map);
template <typename T>
std::vector<IioDevice*> GetByName(
const std::string& name, std::map<int, std::unique_ptr<T>>* devices_map);
template <typename T>
std::vector<IioDevice*> GetAll(
std::map<int, std::unique_ptr<T>>* devices_map);
std::vector<ContextUniquePtr> context_;
// device id to IioDevice
std::map<int, std::unique_ptr<IioDeviceImpl>> devices_;
// trigger id to IioDevice
std::map<int, std::unique_ptr<IioDeviceTriggerImpl>> triggers_;
};
} // namespace libmems
#endif // LIBMEMS_IIO_CONTEXT_IMPL_H_