Dawn Framework 1.0
Universal data acquisition framework for embedded systems
process.hxx
1// dawn/include/dawn/prog/process.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <vector>
9
10#include "dawn/porting/config.hxx"
11#include "dawn/prog/common.hxx"
12
13namespace dawn
14{
15class CIOCommon;
16class IIOCommon;
17class io_ddata_t;
18
26
28{
29public:
31
32 enum
33 {
37 };
38
40
46
52
54 : CProgCommon(desc)
55 {
56 }
57
63
64 ~CProgProcess() override;
65
71
72 int configure() override;
73
79
80 int init() override;
81
87
88 int deinit() override;
89
95
96 int doStart() override;
97
103
104 int doStop() override;
105
111
112 bool hasThread() const override;
113
120
121 int trigger(uint8_t cmd) override;
122
123protected:
124 struct SBindState
125 {
126 virtual ~SBindState() = default;
127
128 virtual void reset()
129 {
130 }
131 };
132
133private:
135
136 struct SProcessBind
137 {
138 CProgProcess *owner = nullptr;
139 SProgStatsIOBind cfg = {};
140 CIOCommon *src = nullptr;
141 CIOCommon *output = nullptr;
142 io_ddata_t *ioData = nullptr;
143 io_ddata_t *outputData = nullptr;
144 SBindState *state = nullptr;
145 size_t batch = 1;
146 size_t outBatch = 1;
147 bool initsample = false;
148 bool active = false;
149 };
150
152
153 std::vector<SProcessBind> binds;
154
162
163 static int ioNotifierCb(void *priv, io_ddata_t *data);
164
171
172 int configureDesc(const CDescObject &desc);
173
180
181 int allocObject(const SProgStatsIOBind *alloc);
182
188
189 int bindPrepare(SProcessBind *bind);
190
191protected:
197
198 virtual int configureExtraCfgItem(const CDescObject &desc,
199 const SObjectCfg::SObjectCfgItem *item,
200 size_t &offset);
201
208
209 virtual bool isBatchAware() const
210 {
211 return false;
212 }
213
223
224 virtual void handle(CIOCommon *output,
225 io_ddata_t *data,
226 io_ddata_t *ioData,
227 io_ddata_t *outputData,
228 bool &initsample) = 0;
229
237
238 virtual int bindStateAlloc(CIOCommon *src,
239 CIOCommon *output,
240 io_ddata_t *ioData,
241 io_ddata_t *outputData,
242 SBindState **state);
243
249
250 virtual void handleWithState(CIOCommon *output,
251 io_ddata_t *data,
252 io_ddata_t *ioData,
253 io_ddata_t *outputData,
254 bool &initsample,
255 void *state);
256
266 {
267 if (!binds.empty())
268 {
269 return binds[0].output;
270 }
271 return nullptr;
272 }
273
283 {
284 if (!binds.empty())
285 {
286 return binds[0].src;
287 }
288 return nullptr;
289 }
290
297
298 void handleCmn(SProcessBind *bind, io_ddata_t *data)
299 {
300 DAWNASSERT(bind != nullptr, "nullptr pointer");
301 DAWNASSERT(data != nullptr, "nullptr pointer");
302
303 // Handle by derived processing implementation
304
305 this->handleWithState(
306 bind->output, data, bind->ioData, bind->outputData, bind->initsample, bind->state);
307 };
308};
309} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all I/O objects.
Definition common.hxx:30
CProgCommon(CDescObject &desc)
Constructor.
Definition common.cxx:17
CProgProcess(CDescObject &desc)
Construct a a Program from descriptor.
Definition process.hxx:53
int trigger(uint8_t cmd)
Execute a trigger command.
Definition process.cxx:323
bool hasThread() const
Check if a background thread is active.
Definition process.cxx:318
CIOCommon * getOutputIO() const
Get the output IO for the first bind.
Definition process.hxx:265
@ PROG_STATS_CFG_FIRST
First config ID.
Definition process.hxx:34
@ PROG_STATS_CFG_IOBIND
I/O binding configuration.
Definition process.hxx:35
@ PROG_STATS_CFG_LAST
Last config ID.
Definition process.hxx:36
int init()
One-time initialize Program after bindings are resolved.
Definition process.cxx:220
CIOCommon * getSourceIO() const
Get the source IO for the first bind.
Definition process.hxx:282
virtual void handle(CIOCommon *output, io_ddata_t *data, io_ddata_t *ioData, io_ddata_t *outputData, bool &initsample)=0
Process incoming sample.
int configure()
Configure Program from descriptor.
Definition process.cxx:202
int deinit()
Deinitialize Program.
Definition process.cxx:272
virtual void handleWithState(CIOCommon *output, io_ddata_t *data, io_ddata_t *ioData, io_ddata_t *outputData, bool &initsample, void *state)
Process incoming sample with optional per-binding state.
Definition process.cxx:110
virtual int configureExtraCfgItem(const CDescObject &desc, const SObjectCfg::SObjectCfgItem *item, size_t &offset)
Parse program-specific config item (optional extension hook).
Definition process.cxx:85
~CProgProcess()
Destruct the a Program.
Definition process.cxx:197
virtual int bindStateAlloc(CIOCommon *src, CIOCommon *output, io_ddata_t *ioData, io_ddata_t *outputData, SBindState **state)
Allocate optional per-binding derived state.
Definition process.cxx:95
void handleCmn(SProcessBind *bind, io_ddata_t *data)
Common callback wrapper.
Definition process.hxx:298
int doStart()
Start the Program.
Definition process.cxx:295
int doStop()
Stop the Program.
Definition process.cxx:308
virtual bool isBatchAware() const
Whether handle() consumes every batch of a batched source.
Definition process.hxx:209
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
Configuration structure for process I/O binding.
Definition process.hxx:42
SObjectId::UObjectId output
Output I/O object ID.
Definition process.hxx:44
SObjectId::UObjectId objid
Source I/O object ID.
Definition process.hxx:43
Heap-allocated dynamic I/O data buffer.
Definition ddata.hxx:21
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218