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)
31 SObjectCfg::SObjectCfgItem *item =
nullptr;
34 for (
size_t i = 0; i < desc.
getSize(); i++)
49 "Invalid config size %d, expected multiple of %zu\n", item->
cfgid.
s.
size, wpe);
54 for (b = 0; b < nbinds; b++)
59 int ret = allocObject(tmp);
74 DAWNERR(
"Unsupported stats config 0x%08" PRIx32
"\n", item->
cfgid.
v);
118 handle(output, data, ioData, outputData, initsample);
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#ifdef CONFIG_DAWN_IO_NOTIFY
169 bind->batch =
isBatchAware() ? bind->src->getNotifyBatch() : 1;
176 bind->outBatch = bind->batch;
184 DAWNERR(
"Failed to initialize output IO (error %d)\n", ret);
188 if (bind->output->getDataDim() != dim)
190 DAWNERR(
"Process output 0x%" PRIx32
" shape mismatch\n", bind->output->getIdV());
208 ret = configureDesc(
getDesc());
211 DAWNERR(
"Stats configure failed (error %d)\n", ret);
224 for (
auto &bind : binds)
226 bind.src =
getIO(bind.cfg.objid.v);
232 bind.output =
getIO(bind.cfg.output.v);
238 ret = bindPrepare(&bind);
244 bind.ioData = bind.src->ddata_alloc(bind.batch);
250 bind.outputData = bind.output->ddata_alloc(bind.outBatch);
251 if (!bind.outputData)
254 bind.ioData =
nullptr;
258 ret =
bindStateAlloc(bind.src, bind.output, bind.ioData, bind.outputData, &bind.state);
262 bind.ioData =
nullptr;
263 delete bind.outputData;
264 bind.outputData =
nullptr;
274 for (
auto &bind : binds)
277 bind.state =
nullptr;
281 bind.ioData =
nullptr;
283 delete bind.outputData;
285 bind.outputData =
nullptr;
287 bind.output =
nullptr;
299 for (
auto &bind : binds)
301 bind.initsample =
true;
310 for (
auto &bind : binds)
327 for (
auto &bind : binds)
329 bind.initsample =
true;
330 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.
@ IO_CLASS_VIRT
Virtual I/O.
@ CMD_RESET
Reset object internal state.
CDescObject & getDesc()
Get descriptor object for this object.
int prepareWritableTarget(CIOCommon *io, size_t dim, bool notify, size_t batch=1)
Check a writable output; shape a deferred virt output or check an already shaped one.
int trigger(uint8_t cmd)
Execute a trigger command.
bool hasThread() const
Check if a background thread is active.
@ PROG_STATS_CFG_IOBIND
I/O binding configuration.
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.
virtual bool isBatchAware() const
Whether handle() consumes every batch of a batched source.
Out-of-tree user-extension hooks for Dawn.
Configuration structure for process I/O binding.
SObjectId::UObjectId output
Output I/O object ID.
SObjectId::UObjectId objid
Source I/O object ID.
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).
struct dawn::SObjectCfg::UObjectCfgId::@334307326077356333363326153167141302007100111136 s
Bit-field structure for named member access.
uint32_t size
Configuration data size in 32-bit words (bits 5-14, max 1023).
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).