-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiio_context.h
98 lines (78 loc) · 3.69 KB
/
iio_context.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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_H_
#define LIBMEMS_IIO_CONTEXT_H_
#include <iio.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <base/macros.h>
#include "libmems/export.h"
namespace libmems {
class IioDevice;
// The IioContext is the root of the tree of IIO devices on the system.
// A context is - at its core - a container of devices, which can be
// retrieved via GetDevicesByName, GetDeviceById and GetAllDevices, providing
// the devices's name, id or nothing as input.
class LIBMEMS_EXPORT IioContext {
public:
virtual ~IioContext() = default;
// Returns the iio_context object underlying this object, if any is available.
// Returns nullptr if no iio_device exists.
virtual iio_context* GetCurrentContext() const = 0;
// libiio loads the device list at context creation time, and does not
// have a way to update it as new devices appear on the system.
// This is a helper that allows a rescan of the system to find new devices
// dynamically at runtime. It should be called after any actions that cause
// new devices of interest to show up.
virtual void Reload() = 0;
// Sets |timeout| in milliseconds for I/O operations, mainly for reading
// events. Sets |timeout| as 0 to specify that no timeout should occur.
// Default for network/unix_socket backend: 5000 milliseconds.
// Default for local backend: 1000 millisecond.
// Returns true if success.
virtual bool SetTimeout(uint32_t timeout) = 0;
// Returns IioDevices as a vector given the device's name. Only devices with
// id having "iio:device" as the prefix would be available.
// Returns an empty vector if no device can be found.
// The device objects are guaranteed to stay valid as long as this context
// object is valid.
virtual std::vector<IioDevice*> GetDevicesByName(const std::string& name) = 0;
// Returns an IioDevice given the device's ID by int. Real id in string would
// be "iio:device|id|".
// Returns nullptr if the device cannot be found. The
// device object is guaranteed to stay valid as long as this context object is
// valid.
virtual IioDevice* GetDeviceById(int id) = 0;
// Returns all IioDevices as a vector. Only devices with id having
// "iio:device" as the prefix would be available.
// Returns an empty vector if no device can be found.
// The device objects are guaranteed to stay valid as long as this context
// object is valid.
virtual std::vector<IioDevice*> GetAllDevices() = 0;
// Returns triggers as a vector given the trigger's name.
// Returns an empty vector if no device can be found.
// The trigger objects are guaranteed to stay valid as long as this context
// object is valid.
virtual std::vector<IioDevice*> GetTriggersByName(
const std::string& name) = 0;
// Returns an IioDevice given the trigger's ID by int. Real id in string would
// be "trigger|id|". If |id| is -1, trigger iio_sysfs_trigger is returned.
// Returns nullptr if the device cannot be found. The
// device object is guaranteed to stay valid as long as this context object is
// valid.
virtual IioDevice* GetTriggerById(int id) = 0;
// Returns all triggers as a vector.
// Returns an empty vector if no device can be found.
// The device objects are guaranteed to stay valid as long as this context
// object is valid.
virtual std::vector<IioDevice*> GetAllTriggers() = 0;
protected:
IioContext() = default;
IioContext(const IioContext&) = delete;
IioContext& operator=(const IioContext&) = delete;
};
} // namespace libmems
#endif // LIBMEMS_IIO_CONTEXT_H_