6#include "dawn/prog/selector.hxx"
11#include "dawn/debug.hxx"
12#include "dawn/io/common.hxx"
13#include "dawn/io/ddata.hxx"
14#include "dawn/io/sdata.hxx"
31CProgSelector::~CProgSelector()
36int CProgSelector::configureDesc(
const CDescObject &desc)
45 for (ii = 0; ii < desc.
getSize(); ii++)
49 if (item->
cfgid.
s.
cls != CProgCommon::PROG_CLASS_SELECTOR)
51 DAWNERR(
"selector: unsupported cfg class 0x%" PRIx32
"\n", item->
cfgid.
v);
57 case PROG_SELECTOR_CFG_CONTROL:
61 DAWNERR(
"selector: CONTROL must have 1 entry\n");
70 case PROG_SELECTOR_CFG_DATA:
75 DAWNERR(
"selector: DATA must have at least 1 entry\n");
79 for (
size_t j = 0; j < n; j++)
81 dataIds.push_back(ids[j].v);
82 dataIos.push_back(
nullptr);
86 dataBinds.push_back(db);
92 case PROG_SELECTOR_CFG_TARGET:
96 DAWNERR(
"selector: TARGET must have 1 entry\n");
107 DAWNERR(
"selector: unsupported cfg id %u\n", item->
cfgid.
s.
id);
113 if (ctrlId == 0 || dataIds.empty() || targetId == 0)
115 DAWNERR(
"selector: missing control, data, or target config\n");
124 return configureDesc(
getDesc());
139 DAWNERR(
"selector: control IO 0x%" PRIx32
" not found\n", ctrlId);
144 DAWNERR(
"selector: control IO 0x%" PRIx32
" is not readable\n", ctrlId);
149 DAWNERR(
"selector: control IO 0x%" PRIx32
" must be scalar uint32\n", ctrlId);
154 for (i = 0; i < dataIds.size(); i++)
156 io =
getIO(dataIds[i]);
159 DAWNERR(
"selector: data IO 0x%" PRIx32
" not found\n", dataIds[i]);
164 DAWNERR(
"selector: data IO 0x%" PRIx32
" is not readable\n", dataIds[i]);
170 dataDim = dataIos[0]->getDataDim();
171 dataSize = dataIos[0]->getDtypeSize();
172 dataDtype = dataIos[0]->getDtype();
174 for (i = 1; i < dataIos.size(); i++)
176 if (dataIos[i]->getDataDim() != dataDim || dataIos[i]->
getDtypeSize() != dataSize ||
177 dataIos[i]->
getDtype() != dataDtype)
179 DAWNERR(
"selector: data IO 0x%" PRIx32
" shape mismatch with first data input\n",
185 target =
getIO(targetId);
188 DAWNERR(
"selector: target 0x%" PRIx32
" not found\n", targetId);
192 ret = prepareWritableTarget(target, dataDim,
true);
195 DAWNERR(
"selector: target prepare failed %d\n", ret);
199 iodata =
new (std::nothrow)
io_ddata_t(dataSize, dataDim, 1, dataDtype);
200 if (!iodata || !iodata->isAllocated())
204 DAWNERR(
"selector: iodata allocation failed\n");
224int CProgSelector::ctrlNotifierCb(
void *priv,
io_ddata_t *data)
229 if (!data || data->
getItems() < 1 || !sel->active)
234 std::memcpy(&idx, data->
getDataPtr(),
sizeof(idx));
235 sel->applyRoute(idx);
239int CProgSelector::dataNotifierCb(
void *priv,
io_ddata_t *data)
241 SDataBind *bind =
static_cast<SDataBind *
>(priv);
246 if (!bind->owner || !bind->owner->active)
251 if (bind->owner->ctrlIo)
255 if (bind->owner->ctrlIo->getData(ctrlData, 1) == OK)
258 if (index < bind->owner->dataIos.size())
260 bind->owner->currentIndex =
static_cast<size_t>(index);
266 if (bind->index == bind->owner->currentIndex)
268 bind->owner->applyRoute(
static_cast<uint32_t
>(bind->index));
284 ret = ctrlIo->setNotifier(ctrlNotifierCb, 0,
this);
287 DAWNERR(
"selector: setNotifier on control failed %d\n", ret);
293 for (i = 0; i < dataIos.size(); i++)
295 if (dataIos[i] && dataIos[i]->isNotify())
297 ret = dataIos[i]->setNotifier(dataNotifierCb, 0, &dataBinds[i]);
300 DAWNERR(
"selector: setNotifier on data[%zu] failed %d\n", i, ret);
315 if (ctrlIo->
getData(ctrlData, 1) == OK)
331 ctrlIo->setNotifier(
nullptr, 0,
nullptr);
334 for (
size_t i = 0; i < dataIos.size(); i++)
336 if (dataIos[i] && dataIos[i]->isNotify())
338 dataIos[i]->setNotifier(
nullptr, 0,
nullptr);
354void CProgSelector::applyRoute(uint32_t index)
358 if (index >= dataIos.size() || !dataIos[index] || !iodata || !target)
363 currentIndex =
static_cast<size_t>(index);
365 ret = dataIos[index]->getData(*iodata, 1);
368 DAWNERR(
"selector: getData from data[%" PRIu32
"] failed %d\n", index, ret);
372 ret = target->
setData(*iodata);
375 DAWNERR(
"selector: setData to target failed %d\n", ret);
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.
int setData(IODataCmn &data, size_t offset=0)
Set data for I/O (public interface with stats tracking).
int getData(IODataCmn &data, size_t len, size_t offset=0)
Get data from I/O (public interface with stats tracking).
virtual bool isNotify() const =0
Check if IO supports notifications.
virtual size_t getDataDim() const =0
Get data vector dimension.
virtual bool isRead() const =0
Check if IO supports read operations.
CDescObject & getDesc()
Get descriptor object for this object.
size_t getDtypeSize() const
Get size of this object's data type.
uint8_t getDtype() const
Get data type field.
Base class for all PROG (processing) objects.
Data selector: routes one of N data inputs to a target IO based on the value of a control input.
int init()
One-time initialize object after bindings are resolved.
int configure()
Configure object from descriptor data.
int deinit()
De-initialize object.
int doStop()
Stop implementation hook.
int doStart()
Start implementation hook.
bool hasThread() const
Check if a background thread is active.
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).
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Heap-allocated dynamic I/O data buffer.
void * getDataPtr(size_t batch=0)
Get pointer to data only (skips timestamp if present).
size_t getItems()
Get number of items per batch.
Static (compile-time) I/O data buffer (no timestamp).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
uint32_t cls
Object class (bits 21-29, max 511).
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.
32-bit encoded object identifier (union with bit field).
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).