Dawn Framework 1.0
Universal data acquisition framework for embedded systems
handler.cxx
1// dawn/src/prog/handler.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/prog/handler.hxx"
7
8#include "dawn/debug.hxx"
9#include "dawn/io/common.hxx"
10
11#ifdef CONFIG_DAWN_INSPECT
12# include "dawn/dev/inspector.hxx"
13#endif
14
15using namespace dawn;
16
17void CProgHandler::objallocPriv(CHandler &obj, CDescObject &desc)
18{
19 // Allocate object
20
22 {
23 CProgHandler &t = static_cast<CProgHandler &>(obj);
24 CProgCommon *tmp = nullptr;
25
26 tmp = t.create(desc);
27 if (tmp == nullptr)
28 {
29 DAWNERR("Failed to create PROG object 0x%" PRIx32 "\n", desc.getObjectIdV());
30 t.allocError = -ENOMEM;
31 return;
32 }
33
34 DAWNINFO("created PROG: 0x%" PRIx32 " %p\n", desc.getObjectIdV(), tmp);
35 if (t.registerObject(tmp) < 0)
36 {
37 return;
38 }
39 }
40}
41
42CProgCommon *CProgHandler::create(CDescObject &desc)
43{
44 // User factory has priority
45
46 if (userFactory != nullptr)
47 {
48 CProgCommon *ret = nullptr;
49
50 ret = userFactory->create(desc);
51 if (ret != nullptr)
52 {
53 return ret;
54 }
55 }
56
57 return factory.create(desc);
58}
59
60CIOCommon *CProgHandler::getIO(SObjectId::ObjectId id)
61{
63 uid.v = id;
64 return ioHandler->getIO(uid);
65}
66
67int CProgHandler::objalloc(CDescriptor &desc)
68{
69 return CGenericHandler<CProgCommon>::objalloc(desc, objallocPriv);
70}
71
73{
74 int ret;
75
76 // Set user factory
77 userFactory = f;
78
79 // Connect handler
80 ioHandler = io;
81
82 // Allocate objects from descriptor
83 ret = objalloc(desc);
84 if (ret < 0)
85 {
86 return ret;
87 }
88
89#ifdef CONFIG_DAWN_INSPECT
90 // Register with global inspector for debugging
91
93 inspector->registerProgHandler(this);
94#endif
95
96 return OK;
97}
98
100{
101 // Configure all registered programs using base class
103 if (ret != OK)
104 {
105 return ret;
106 }
107
108 // Bind IOs to programs
109 for (size_t i = 0; i < getObjectCount(); i++)
110 {
111 CProgCommon *prog = getObjectAt(i);
112 if (prog == nullptr)
113 {
114 continue;
115 }
116
117 // Collect IOs for this program
118 for (auto const &[id, io] : prog->getIOMap())
119 {
120 CObject *resolvedIO = static_cast<CObject *>(getIO(id));
121 prog->setObjectMapItem(id, resolvedIO);
122 }
123 }
124
125 // Run one-time init after bindings are resolved
127}
128
133
135{
137 uid.v = id;
138 return reinterpret_cast<CObject *>(getProg(uid));
139}
140
void setObjectMapItem(SObjectId::ObjectId id, CObject *obj)
Set an item in the object map.
Definition bindable.cxx:23
const std::map< SObjectId::ObjectId, CIOCommon * > & getIOMap() const
Get the I/O map for this object.
Definition bindable.cxx:18
Descriptor wrapper for individual object configuration.
SObjectId::ObjectId getObjectIdV() const
Get object identifier as raw 32-bit value.
SObjectId::UObjectId & getObjectId() const
Get object identifier as union structure.
Binary device descriptor manager.
Global registry for object inspection.
Definition inspector.hxx:38
void registerProgHandler(const CProgHandler *handler)
Register PROG handler.
Definition inspector.cxx:35
static CDevInspector * getInst()
Get singleton instance.
Definition inspector.hxx:59
int initAll()
Run one-time init() for all configured objects.
size_t getObjectCount() const
Get total number of registered objects.
int registerObject(T *obj)
Register object.
T * getObjectById(const SObjectId::UObjectId &id) const
Get object by ObjectID.
int configureAll()
Configure all objects managed by this handler.
int objalloc(CDescriptor &desc, CDescriptor::allocobj_func_t func)
Allocate objects from descriptor.
CProgCommon * getObjectAt(size_t index) const
Get object at index.
Base implementation of IHandler interface.
Definition handler.hxx:110
Base class for all I/O objects.
Definition common.hxx:27
Manages I/O object lifecycle and dispatch.
Definition handler.hxx:37
CIOCommon * getIO(SObjectId::UObjectId &id) const
Get I/O object by ObjectID as CIOCommon*.
Definition handler.cxx:181
Base class for all Dawn objects (IOs, Programs, Protocols).
Definition object.hxx:28
Base class for all PROG (processing) objects.
Definition common.hxx:27
CProgCommon * create(CDescObject &desc)
Create a PROG object from descriptor.
Definition factory.cxx:136
Manages Programs object lifecycle and dispatch.
Definition handler.hxx:28
bool isObjectValid(SObjectId::UObjectId &obj) const
Validate object ID in handler collection.
Definition handler.cxx:129
CObject * getObject(const SObjectId::ObjectId id)
Get a Programs object by object ID.
Definition handler.cxx:134
int initAll()
Configure, bind, and initialize all Program objects.
Definition handler.cxx:99
int init(CDescriptor &desc, CIOHandler *io, IProgFactory *f)
Initialize the Programs handler.
Definition handler.cxx:72
CProgCommon * getProg(SObjectId::UObjectId &id) const
Get a Programs object by object ID (type-safe).
Definition handler.cxx:141
Abstract factory interface for PROG object creation.
Definition factory.hxx:20
virtual CProgCommon * create(CDescObject &desc)=0
Create a PROG object from descriptor.
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
static bool objectIsProg(const UObjectId &objid)
Check if object is Program type (raw 32-bit version).
Definition objectid.hxx:411
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).
Definition objectid.hxx:221