Dawn Framework 1.0
Universal data acquisition framework for embedded systems
virt.hxx
1// dawn/include/dawn/io/virt.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <mutex>
9#include <vector>
10
11#include "dawn/io/common.hxx"
12#include "dawn/porting/config.hxx"
13
14namespace dawn
15{
24 : public CIOCommon
25 , public IIONotifier
26{
27public:
28 typedef void (*virtCB)(CIOVirt *io, void *priv);
29
30 explicit CIOVirt(CDescObject &desc)
31 : CIOCommon(desc)
32 , iodata(nullptr)
33 , set_cb(nullptr)
34 , get_cb(nullptr)
35 , set_cb_priv(nullptr)
36 , get_cb_priv(nullptr)
37 , dlen(0)
38 , blen(1)
39 , tlen(getDtypeSize())
40#ifdef CONFIG_DAWN_IO_TIMESTAMP
41 , ts(0)
42#endif
43 , noteSupport(false)
44 {
45 }
46
47 ~CIOVirt() override;
48
49 CIOVirt(const CIOVirt &) = delete;
50 CIOVirt &operator=(const CIOVirt &) = delete;
51
52#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
53 const char *getClassNameStr() const override
54 {
55 return "virt";
56 }
57#endif
58
59 int configure() override;
60 int init() override;
61 int deinit() override;
62 int getDataImpl(IODataCmn &data, size_t len) override;
63 int setDataImpl(IODataCmn &data) override;
64
65#ifdef CONFIG_DAWN_IO_NOTIFY
66 int getFd() const override;
67#endif
68
69 size_t getDataSize() const override;
70 size_t getDataDim() const override;
71
72 bool isRead() const override
73 {
74 return true;
75 };
76
77 bool isWrite() const override
78 {
79 return true;
80 };
81
82 bool isNotify() const override
83 {
84 return this->noteSupport;
85 };
86
87 bool isBatch() const override
88 {
89 return this->blen > 1;
90 };
91
92 int regNotifier(SIONotifier n) override;
93 int unregNotifier(const SIONotifier &n);
94
95 int initialize(size_t dim, size_t batch = 1, bool note = false);
96 int setCallbackSet(virtCB cb, void *priv);
97 int setCallbackGet(virtCB cb, void *priv);
98 int setVal(const void *v, size_t d);
99 int getVal(void *v, size_t d);
100
101 using ObjectIdHelper =
103
104 constexpr static SObjectId::ObjectId objectId(SObjectId::EObjectDataType dtype,
105 bool ts,
106 uint16_t inst)
107 {
108 return ObjectIdHelper::create(dtype, ts, inst);
109 }
110
111private:
112 std::mutex mutex;
113 io_ddata_t *iodata;
114 virtCB set_cb;
115 virtCB get_cb;
116 void *set_cb_priv;
117 void *get_cb_priv;
118 size_t dlen;
119 size_t blen;
120 size_t tlen;
121#ifdef CONFIG_DAWN_IO_TIMESTAMP
122 uint64_t ts;
123#endif
124 bool noteSupport;
125#ifdef CONFIG_DAWN_IO_NOTIFY
126 std::vector<SIONotifier> vnote;
127 std::mutex pfdsLock;
128#endif
129
130 void copyBatches(uint8_t *dst, size_t dstStride, const uint8_t *src, size_t srcStride, size_t n);
131 size_t batchStride(IODataCmn &data);
132 int store(const void *src, size_t stride, IODataCmn *tsSrc);
133
134#ifdef CONFIG_DAWN_IO_NOTIFY
135 void sendNotify(io_ddata_t *data);
136#endif
137};
138} // Namespace dawn
Descriptor wrapper for individual object configuration.
Template helper for creating ObjectIDs for I/O types.
Definition common.hxx:262
static SObjectId::ObjectId create(bool ts, uint16_t inst)
Create ObjectID with default data type.
Definition common.hxx:272
Base class for all I/O objects.
Definition common.hxx:27
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:451
Virtual I/O type for user-provided data and callbacks.
Definition virt.hxx:26
bool isBatch() const
Check if IO supports batch operations.
Definition virt.hxx:87
size_t getDataSize() const
Get data size in bytes.
Definition virt.cxx:224
int regNotifier(SIONotifier n)
Register I/O notification callback.
Definition virt.cxx:239
bool isNotify() const
Check if IO supports notifications.
Definition virt.hxx:82
int configure()
Configure object from descriptor data.
Definition virt.cxx:41
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition virt.cxx:180
int deinit()
De-initialize object.
Definition virt.cxx:51
bool isWrite() const
Check if IO supports write operations.
Definition virt.hxx:77
size_t getDataDim() const
Get data vector dimension.
Definition virt.cxx:231
bool isRead() const
Check if IO supports read operations.
Definition virt.hxx:72
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition virt.cxx:56
int init()
One-time initialize object after bindings are resolved.
Definition virt.cxx:46
size_t getDtypeSize() const
Get size of this object's data type.
Definition object.cxx:195
Abstract interface for registering asynchronous I/O notification.
Definition inotifier.hxx:25
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
EObjectDataType
Data types supported by Dawn framework.
Definition objectid.hxx:61
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44