Dawn Framework 1.0
Universal data acquisition framework for embedded systems
process_template.hxx
1// dawn/include/dawn/prog/process_template.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include "dawn/io/ddata.hxx"
9#include "dawn/io/common.hxx"
10#include "dawn/prog/process.hxx"
11
12namespace dawn
13{
20template<typename StatsPolicy>
22{
23private:
33 template<typename T>
34 void handleTemplate(CIOCommon *output,
35 io_ddata_t *data,
36 io_ddata_t *ioData,
37 io_ddata_t *outputData,
38 bool &initsample)
39 {
40 bool update = false;
41
42 // Copy incoming sample to internal buffer.
43
44 std::memcpy(ioData->getDataPtr(), data->getDataPtr(), ioData->getDataSize());
45
46 // Initial sample processing.
47
48 if (initsample)
49 {
50 output->setData(*ioData);
51 std::memset(outputData->getDataPtr(), 0, outputData->getDataSize());
52 initsample = false;
53 }
54
55 // Apply operation to all elements.
56
57 for (size_t i = 0; i < ioData->getItems(); i++)
58 {
59 StatsPolicy::template apply<T>(i, ioData, outputData, update);
60 }
61
62 // Write updated result back to output I/O.
63
64 if (update)
65 {
66 output->setData(*outputData);
67 }
68 }
69
70protected:
81 void handle(CIOCommon *output,
82 io_ddata_t *data,
83 io_ddata_t *ioData,
84 io_ddata_t *outputData,
85 bool &initsample) override
86 {
87 switch (data->getDtype())
88 {
89#ifdef CONFIG_DAWN_DTYPE_INT8
91 {
92 this->handleTemplate<int8_t>(output, data, ioData, outputData, initsample);
93 break;
94 }
95#endif
96
97#ifdef CONFIG_DAWN_DTYPE_UINT8
99 {
100 this->handleTemplate<uint8_t>(output, data, ioData, outputData, initsample);
101 break;
102 }
103#endif
104
105#ifdef CONFIG_DAWN_DTYPE_INT16
107 {
108 this->handleTemplate<int16_t>(output, data, ioData, outputData, initsample);
109 break;
110 }
111#endif
112
113#ifdef CONFIG_DAWN_DTYPE_UINT16
115 {
116 this->handleTemplate<uint16_t>(output, data, ioData, outputData, initsample);
117 break;
118 }
119#endif
120
121#ifdef CONFIG_DAWN_DTYPE_INT32
123 {
124 this->handleTemplate<int32_t>(output, data, ioData, outputData, initsample);
125 break;
126 }
127#endif
128
129#ifdef CONFIG_DAWN_DTYPE_UINT32
131 {
132 this->handleTemplate<uint32_t>(output, data, ioData, outputData, initsample);
133 break;
134 }
135#endif
136
137#ifdef CONFIG_DAWN_DTYPE_INT64
139 {
140 this->handleTemplate<int64_t>(output, data, ioData, outputData, initsample);
141 break;
142 }
143#endif
144
145#ifdef CONFIG_DAWN_DTYPE_UINT64
147 {
148 this->handleTemplate<uint64_t>(output, data, ioData, outputData, initsample);
149 break;
150 }
151#endif
152
153#ifdef CONFIG_DAWN_DTYPE_FLOAT
155 {
156 this->handleTemplate<float>(output, data, ioData, outputData, initsample);
157 break;
158 }
159#endif
160
161#ifdef CONFIG_DAWN_DTYPE_DOUBLE
163 {
164 this->handleTemplate<double>(output, data, ioData, outputData, initsample);
165 break;
166 }
167#endif
168
169 default:
170 {
171 DAWNERR("process: unsupported dtype %d\n", data->getDtype());
172 }
173 }
174 }
175
176public:
184 : CProgProcess(desc)
185 {
186 }
187};
188
189} // namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:27
int setData(IODataCmn &data, size_t offset=0)
Set data for I/O (public interface with stats tracking).
Definition common.hxx:392
Policy-based template for sample processing implementations.
void handle(CIOCommon *output, io_ddata_t *data, io_ddata_t *ioData, io_ddata_t *outputData, bool &initsample)
Process incoming sample.
CProgProcessTemplate(CDescObject &desc)
Construct the template-based processing Program.
Base class for callback-driven sample processing Program objects.
Definition process.hxx:28
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ DTYPE_FLOAT
IEEE 754 single-precision floating point (32-bit).
Definition objectid.hxx:112
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
Definition objectid.hxx:92
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
Definition objectid.hxx:80
@ DTYPE_INT16
Signed 16-bit integer (-32768 to 32767).
Definition objectid.hxx:84
@ DTYPE_INT8
Signed 8-bit integer (-128 to 127).
Definition objectid.hxx:76
@ DTYPE_UINT64
Unsigned 64-bit integer.
Definition objectid.hxx:104
@ DTYPE_UINT16
Unsigned 16-bit integer (0 to 65535).
Definition objectid.hxx:88
@ DTYPE_DOUBLE
IEEE 754 double-precision floating point (64-bit).
Definition objectid.hxx:120
@ DTYPE_INT64
Signed 64-bit integer.
Definition objectid.hxx:100
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
Heap-allocated dynamic I/O data buffer.
Definition ddata.hxx:21
uint8_t getDtype() const
Get data type enum for introspection.
Definition ddata.hxx:217
size_t getDataSize()
Get data size in bytes.
Definition ddata.hxx:153
void * getDataPtr(size_t batch=0)
Get pointer to data only (skips timestamp if present).
Definition ddata.hxx:180
size_t getItems()
Get number of items per batch.
Definition ddata.hxx:128