Dawn Framework 1.0
Universal data acquisition framework for embedded systems
inspector.cxx
1// dawn/src/dev/inspector.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/dev/inspector.hxx"
7
8#ifdef CONFIG_DAWN_INSPECT
9
10# include "dawn/common/object.hxx"
11# include "dawn/io/common.hxx"
12# include "dawn/io/handler.hxx"
13# include "dawn/prog/common.hxx"
14# include "dawn/prog/handler.hxx"
15# include "dawn/proto/common.hxx"
16# include "dawn/proto/handler.hxx"
17
18using namespace dawn;
19
20//***************************************************************************
21// Private Data
22//***************************************************************************
23
24CDevInspector *CDevInspector::singleton = nullptr;
25
26//***************************************************************************
27// Public Functions
28//***************************************************************************
29
31{
32 io_handler = handler;
33}
34
36{
37 prog_handler = handler;
38}
39
41{
42 proto_handler = handler;
43}
44
46{
47 if (io_handler == nullptr)
48 {
49 return 0;
50 }
51
52 return io_handler->getObjects().size();
53}
54
56{
57 if (prog_handler == nullptr)
58 {
59 return 0;
60 }
61
62 return prog_handler->getObjects().size();
63}
64
66{
67 if (proto_handler == nullptr)
68 {
69 return 0;
70 }
71
72 return proto_handler->getObjects().size();
73}
74
75const CIOCommon *CDevInspector::getIO(size_t index) const
76{
77 if (io_handler == nullptr)
78 {
79 return nullptr;
80 }
81
82 const auto &objects = io_handler->getObjects();
83
84 if (index >= objects.size())
85 {
86 return nullptr;
87 }
88
89 return objects[index];
90}
91
92const CObject *CDevInspector::getProg(size_t index) const
93{
94 if (prog_handler == nullptr)
95 {
96 return nullptr;
97 }
98
99 const auto &objects = prog_handler->getObjects();
100
101 if (index >= objects.size())
102 {
103 return nullptr;
104 }
105
106 return objects[index];
107}
108
109const CObject *CDevInspector::getProto(size_t index) const
110{
111 if (proto_handler == nullptr)
112 {
113 return nullptr;
114 }
115
116 const auto &objects = proto_handler->getObjects();
117
118 if (index >= objects.size())
119 {
120 return nullptr;
121 }
122
123 return objects[index];
124}
125
126const CObject *CDevInspector::findObject(uint32_t objid) const
127{
128 const CObject *obj;
130
131 uobjid.v = objid;
132
133 // Check IO handler
134
135 if (io_handler != nullptr)
136 {
137 obj = io_handler->getObjectById(uobjid);
138 if (obj != nullptr)
139 {
140 return obj;
141 }
142 }
143
144 // Check PROG handler
145
146 if (prog_handler != nullptr)
147 {
148 obj = prog_handler->getObjectById(uobjid);
149 if (obj != nullptr)
150 {
151 return obj;
152 }
153 }
154
155 // Check PROTO handler
156
157 if (proto_handler != nullptr)
158 {
159 obj = proto_handler->getObjectById(uobjid);
160 if (obj != nullptr)
161 {
162 return obj;
163 }
164 }
165
166 return nullptr;
167}
168
169size_t CDevInspector::getProgIOBindings(size_t prog_index,
170 const CIOCommon **io_list,
171 size_t max_size) const
172{
173 const CObject *prog;
174 const CProgCommon *prog_common;
175 const std::map<SObjectId::ObjectId, CIOCommon *> *io_map;
176 size_t count;
177
178 prog = getProg(prog_index);
179 if (prog == nullptr)
180 {
181 return 0;
182 }
183
184 prog_common = static_cast<const CProgCommon *>(prog);
185 io_map = &prog_common->getIOMap();
186
187 if (io_map->empty())
188 {
189 return 0;
190 }
191
192 count = 0;
193 for (const auto &pair : *io_map)
194 {
195 if (count >= max_size)
196 {
197 break;
198 }
199
200 io_list[count] = pair.second;
201 count++;
202 }
203
204 return count;
205}
206
207size_t CDevInspector::getProtoBindings(size_t proto_index,
208 const CObject **obj_list,
209 size_t max_size) const
210{
211 const CObject *proto;
212 const CProtoCommon *proto_common;
213 const std::map<SObjectId::ObjectId, CIOCommon *> *obj_map;
214 size_t count;
215
216 proto = getProto(proto_index);
217 if (proto == nullptr)
218 {
219 return 0;
220 }
221
222 proto_common = static_cast<const CProtoCommon *>(proto);
223 obj_map = &proto_common->getIOMap();
224
225 if (obj_map->empty())
226 {
227 return 0;
228 }
229
230 count = 0;
231 for (const auto &pair : *obj_map)
232 {
233 if (count >= max_size)
234 {
235 break;
236 }
237
238 obj_list[count] = pair.second;
239 count++;
240 }
241
242 return count;
243}
244
245#endif // CONFIG_DAWN_INSPECT
const std::map< SObjectId::ObjectId, CIOCommon * > & getIOMap() const
Get the I/O map for this object.
Definition bindable.cxx:18
Global registry for object inspection.
Definition inspector.hxx:38
size_t getProtoBindings(size_t proto_index, const CObject **obj_list, size_t max_size) const
Get object bindings for PROTO object.
size_t getProtoCount() const
Get number of PROTO objects.
Definition inspector.cxx:65
size_t getProgCount() const
Get number of PROG objects.
Definition inspector.cxx:55
void registerProgHandler(const CProgHandler *handler)
Register PROG handler.
Definition inspector.cxx:35
const CObject * getProg(size_t index) const
Get PROG object by index.
Definition inspector.cxx:92
const CObject * findObject(uint32_t objid) const
Find object by ID.
const CIOCommon * getIO(size_t index) const
Get IO object by index.
Definition inspector.cxx:75
void registerIOHandler(const CIOHandler *handler)
Register IO handler.
Definition inspector.cxx:30
size_t getProgIOBindings(size_t prog_index, const CIOCommon **io_list, size_t max_size) const
Get IO bindings for PROG object.
void registerProtoHandler(const CProtoHandler *handler)
Register PROTO handler.
Definition inspector.cxx:40
size_t getIOCount() const
Get number of IO objects.
Definition inspector.cxx:45
const CObject * getProto(size_t index) const
Get PROTO object by index.
const std::vector< T * > & getObjects() const
Get read-only access to all objects.
T * getObjectById(const SObjectId::UObjectId &id) const
Get object by ObjectID.
Base class for all I/O objects.
Definition common.hxx:27
Manages I/O object lifecycle and dispatch.
Definition handler.hxx:37
Base class for all Dawn objects (IOs, Programs, Protocols).
Definition object.hxx:28
Base class for all PROG (processing) objects.
Definition common.hxx:27
Manages Programs object lifecycle and dispatch.
Definition handler.hxx:28
Base class for all protocol implementations.
Definition common.hxx:23
Manages PROTO object lifecycle and dispatch.
Definition handler.hxx:28
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
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