6#include "dawn/prog/process.hxx"
8#include "dawn/debug.hxx"
9#include "dawn/io/common.hxx"
10#include "dawn/io/ddata.hxx"
14int CProgProcess::ioNotifierCb(
void *priv,
io_ddata_t *data)
16 SProcessBind *bind =
static_cast<SProcessBind *
>(priv);
25 bind->owner->handleCmn(bind, data);
29int CProgProcess::configureDesc(
const CDescObject &desc)
34 for (
size_t i = 0; i < desc.
getSize(); i++)
42 const size_t wpe =
sizeof(SProgStatsIOBind) / 4;
49 "Invalid config size %d, expected multiple of %zu\n", item->
cfgid.
s.
size, wpe);
54 for (b = 0; b < nbinds; b++)
56 SProgStatsIOBind *tmp =
57 reinterpret_cast<SProgStatsIOBind *
>(item->
data + b * wpe);
59 int ret = allocObject(tmp);
74 DAWNERR(
"Unsupported stats config 0x%08" PRIx32
"\n", item->
cfgid.
v);
118 handle(output, data, ioData, outputData, initsample);
121int CProgProcess::allocObject(
const SProgStatsIOBind *alloc)
123 DAWNINFO(
"allocate prog 0x%" PRIx32
" -> 0x%" PRIx32
"\n", alloc->objid.v, alloc->output.v);
129 binds.push_back({
this, *alloc});
134int CProgProcess::bindPrepare(SProcessBind *bind)
141 if (!bind->src->isNotify())
143 DAWNERR(
"Notifications not supported by IO 0x%" PRIx32
"\n", bind->src->getIdV());
147 if (!bind->src->isRead())
149 DAWNERR(
"Source IO 0x%" PRIx32
" is not readable\n", bind->src->getIdV());
155 ret = bind->src->setNotifier(ioNotifierCb, 0, bind);
158 DAWNERR(
"Set notifier failed for objId = 0x%" PRIx32
"\n", bind->src->getIdV());
164 dim = bind->src->getDataDim();
168 ret = prepareWritableTarget(bind->output, dim,
true);
171 DAWNERR(
"Failed to initialize output IO (error %d)\n", ret);
175 if (bind->output->getDataDim() != dim)
177 DAWNERR(
"Process output 0x%" PRIx32
" shape mismatch\n", bind->output->getIdV());
195 ret = configureDesc(
getDesc());
198 DAWNERR(
"Stats configure failed (error %d)\n", ret);
211 for (
auto &bind : binds)
213 bind.src =
getIO(bind.cfg.objid.v);
219 bind.output =
getIO(bind.cfg.output.v);
225 ret = bindPrepare(&bind);
231 bind.ioData = bind.src->ddata_alloc(1);
237 bind.outputData = bind.output->ddata_alloc(1);
238 if (!bind.outputData)
241 bind.ioData =
nullptr;
245 ret =
bindStateAlloc(bind.src, bind.output, bind.ioData, bind.outputData, &bind.state);
249 bind.ioData =
nullptr;
250 delete bind.outputData;
251 bind.outputData =
nullptr;
261 for (
auto &bind : binds)
264 bind.state =
nullptr;
268 bind.ioData =
nullptr;
270 delete bind.outputData;
272 bind.outputData =
nullptr;
274 bind.output =
nullptr;
286 for (
auto &bind : binds)
288 bind.initsample =
true;
297 for (
auto &bind : binds)
314 for (
auto &bind : binds)
316 bind.initsample =
true;
317 if (bind.state !=
nullptr)
CIOCommon * getIO(SObjectId::ObjectId id)
Get an I/O object by ID.
void setObjectMapItem(SObjectId::ObjectId id, CObject *obj)
Set an item in the object map.
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemNext(size_t &offset) const
Get config item at current offset and advance past it.
Base class for all I/O objects.
CDescObject & getDesc()
Get descriptor object for this object.
@ CMD_RESET
Reset object internal state.
int trigger(uint8_t cmd)
Execute a trigger command.
bool hasThread() const
Check if a background thread is active.
int init()
One-time initialize Program after bindings are resolved.
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.
int deinit()
Deinitialize Program.
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.
virtual int configureExtraCfgItem(const CDescObject &desc, const SObjectCfg::SObjectCfgItem *item, size_t &offset)
Parse program-specific config item (optional extension hook).
~CProgProcess()
Destruct the a Program.
virtual int bindStateAlloc(CIOCommon *src, CIOCommon *output, io_ddata_t *ioData, io_ddata_t *outputData, SBindState **state)
Allocate optional per-binding derived state.
int doStart()
Start the Program.
int doStop()
Stop the Program.
@ PROG_STATS_CFG_IOBIND
I/O binding configuration.
Out-of-tree user-extension hooks for Dawn.
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
Heap-allocated dynamic I/O data buffer.
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t id
Configuration identifier (bits 0-4, max 31).
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.