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 , tlen(getDtypeSize())
39#ifdef CONFIG_DAWN_IO_TIMESTAMP
40 , ts(0)
41#endif
42 , noteSupport(false)
43 {
44 }
45
46 ~CIOVirt() override;
47
48 CIOVirt(const CIOVirt &) = delete;
49 CIOVirt &operator=(const CIOVirt &) = delete;
50
51#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
52 const char *getClassNameStr() const override
53 {
54 return "virt";
55 }
56#endif
57
58 int configure() override;
59 int init() override;
60 int deinit() override;
61 int getDataImpl(IODataCmn &data, size_t len) override;
62 int setDataImpl(IODataCmn &data) override;
63
64#ifdef CONFIG_DAWN_IO_NOTIFY
65 int getFd() const override;
66#endif
67
68 size_t getDataSize() const override;
69 size_t getDataDim() const override;
70
71 bool isRead() const override
72 {
73 return true;
74 };
75
76 bool isWrite() const override
77 {
78 return true;
79 };
80
81 bool isNotify() const override
82 {
83 return this->noteSupport;
84 };
85
86 bool isBatch() const override
87 {
88 return false;
89 };
90
91 int regNotifier(SIONotifier n) override;
92 int unregNotifier(const SIONotifier &n);
93
94 int initialize(size_t dim, size_t batch = 1, bool note = false);
95 int setCallbackSet(virtCB cb, void *priv);
96 int setCallbackGet(virtCB cb, void *priv);
97 int setVal(const void *v, size_t d);
98 int getVal(void *v, size_t d);
99
100 using ObjectIdHelper =
102
103 constexpr static SObjectId::ObjectId objectId(SObjectId::EObjectDataType dtype,
104 bool ts,
105 uint16_t inst)
106 {
107 return ObjectIdHelper::create(dtype, ts, inst);
108 }
109
110private:
111 std::mutex mutex;
112 io_ddata_t *iodata;
113 virtCB set_cb;
114 virtCB get_cb;
115 void *set_cb_priv;
116 void *get_cb_priv;
117 size_t dlen;
118 size_t tlen;
119#ifdef CONFIG_DAWN_IO_TIMESTAMP
120 uint64_t ts;
121#endif
122 bool noteSupport;
123#ifdef CONFIG_DAWN_IO_NOTIFY
124 std::vector<SIONotifier> vnote;
125 std::mutex pfdsLock;
126#endif
127
128#ifdef CONFIG_DAWN_IO_NOTIFY
129 void sendNotify(io_ddata_t *data);
130#endif
131};
132} // Namespace dawn
Descriptor wrapper for individual object configuration.
Template helper for creating ObjectIDs for I/O types.
Definition common.hxx:236
static SObjectId::ObjectId create(bool ts, uint16_t inst)
Create ObjectID with default data type.
Definition common.hxx:246
Base class for all I/O objects.
Definition common.hxx:27
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:425
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:86
size_t getDataSize() const
Get data size in bytes.
Definition virt.cxx:127
int regNotifier(SIONotifier n)
Register I/O notification callback.
Definition virt.cxx:142
bool isNotify() const
Check if IO supports notifications.
Definition virt.hxx:81
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:92
int deinit()
De-initialize object.
Definition virt.cxx:51
bool isWrite() const
Check if IO supports write operations.
Definition virt.hxx:76
size_t getDataDim() const
Get data vector dimension.
Definition virt.cxx:134
bool isRead() const
Check if IO supports read operations.
Definition virt.hxx:71
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