6#include "dawn/prog/iodemux.hxx"
10#include "dawn/debug.hxx"
11#include "dawn/io/common.hxx"
12#include "dawn/io/sdata.hxx"
29CProgIODemux::~CProgIODemux()
36 outputIds.push_back(ioId);
37 outputs.push_back(
nullptr);
42int CProgIODemux::configureDesc(
const CDescObject &desc)
48 for (
size_t i = 0; i < desc.
getSize(); i++)
52 if (item->
cfgid.
s.
cls != CProgCommon::PROG_CLASS_IODEMUX)
54 DAWNERR(
"iodemux: unsupported cfg class 0x%" PRIx32
"\n", item->
cfgid.
v);
60 case PROG_IODEMUX_CFG_CONTROL:
64 DAWNERR(
"iodemux: CONTROL must have one item\n");
73 case PROG_IODEMUX_CFG_INPUT:
77 DAWNERR(
"iodemux: INPUT must have one item\n");
86 case PROG_IODEMUX_CFG_OUTPUTS:
90 DAWNERR(
"iodemux: OUTPUTS must not be empty\n");
94 for (
size_t j = 0; j < item->
cfgid.
s.
size; j++)
96 int ret = allocOutput(ids[j].v);
106 DAWNERR(
"iodemux: unsupported cfg id %u\n", item->
cfgid.
s.
id);
111 if (controlId == 0 || inputId == 0 || outputs.empty())
113 DAWNERR(
"iodemux: control, input and outputs are required\n");
122 return configureDesc(
getDesc());
125int CProgIODemux::validateShape(
CIOCommon *io)
const
127 if (io ==
nullptr || input ==
nullptr)
143 control =
getIO(controlId);
144 if (control ==
nullptr || !control->
isRead() || !control->
isNotify() ||
147 DAWNERR(
"iodemux: control 0x%" PRIx32
" must be scalar uint32 notify IO\n", controlId);
151 input =
getIO(inputId);
154 DAWNERR(
"iodemux: input 0x%" PRIx32
" is not readable notify IO\n", inputId);
158 for (
size_t i = 0; i < outputIds.size(); i++)
160 outputs[i] =
getIO(outputIds[i]);
161 if (outputs[i] ==
nullptr)
163 DAWNERR(
"iodemux: output IO 0x%" PRIx32
" not found\n", outputIds[i]);
167 int ret = prepareWritableTarget(outputs[i], input->
getDataDim(),
true);
170 DAWNERR(
"iodemux: output prepare failed %d\n", ret);
174 ret = validateShape(outputs[i]);
177 DAWNERR(
"iodemux: output 0x%" PRIx32
" incompatible\n", outputIds[i]);
183 if (dataBuf ==
nullptr)
205int CProgIODemux::controlNotifierCb(
void *priv,
io_ddata_t *data)
210 if (self ==
nullptr || !self->active || data ==
nullptr || data->
getItems() < 1)
215 std::memcpy(&index, data->
getDataPtr(),
sizeof(index));
216 self->routeIndex(index);
220int CProgIODemux::inputNotifierCb(
void *priv,
io_ddata_t *data)
226 if (self ==
nullptr || !self->active)
231 self->routeIndex(
static_cast<uint32_t
>(self->currentIndex));
241 ret = control->setNotifier(controlNotifierCb, 0,
this);
244 DAWNERR(
"iodemux: control setNotifier failed %d\n", ret);
248 ret = input->setNotifier(inputNotifierCb, 0,
this);
251 DAWNERR(
"iodemux: input setNotifier failed %d\n", ret);
260 if (control->
getData(ctrlData, 1) == OK)
262 routeIndex(ctrlData(0));
271 if (control !=
nullptr)
273 control->setNotifier(
nullptr, 0,
nullptr);
275 if (input !=
nullptr)
277 input->setNotifier(
nullptr, 0,
nullptr);
291void CProgIODemux::routeIndex(uint32_t index)
293 if (index >= outputs.size() || dataBuf ==
nullptr)
298 currentIndex = index;
299 if (input->
getData(*dataBuf, 1) != OK)
304 int ret = outputs[index]->setData(*dataBuf);
307 DAWNERR(
"iodemux: output setData 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 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.
bool isTimestamp() const
Check if I/O supports timestamp.
virtual size_t getDataDim() const =0
Get data vector dimension.
io_ddata_t * ddata_alloc(size_t batch, size_t chunk_size=0)
Allocate data buffer for this I/O.
virtual size_t getDataSize() const =0
Get data size in bytes.
virtual bool isRead() const =0
Check if IO supports read operations.
CDescObject & getDesc()
Get descriptor object for this object.
uint8_t getDtype() const
Get data type field.
Base class for all PROG (processing) objects.
IO demultiplexer: routes one input to the selected output.
int doStop()
Stop implementation hook.
int doStart()
Start implementation hook.
int configure()
Configure object from descriptor data.
int init()
One-time initialize object after bindings are resolved.
bool hasThread() const
Check if a background thread is active.
int deinit()
De-initialize object.
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).
uint32_t ObjectId
ObjectID type - single 32-bit value.
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).