Dawn Framework 1.0
Universal data acquisition framework for embedded systems
object.hxx
1// dawn/include/dawn/common/object.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstdint>
9
10#include "dawn/common/descobject.hxx"
11#include "dawn/common/objectcfg.hxx"
12#include "dawn/common/objectid.hxx"
13#include "dawn/porting/config.hxx"
14
15#ifndef CONFIG_DAWN_OBJECT_NAME_SIZE
16# define CONFIG_DAWN_OBJECT_NAME_SIZE 16
17#endif
18
19namespace dawn
20{
28{
29public:
32 enum
33 {
35 STATE_RUNNING = 1
36 } typedef EObjectState;
37
40 enum
41 {
45 CMD_TRIGGER3 = 3
46 };
47
54 explicit CObject(CDescObject &desc)
55 : started(false)
56 , objdesc(desc)
57 , uobjid(desc.getObjectId())
58 {
59 }
60
61 virtual ~CObject() = default;
62
73 virtual int configure()
74 {
75 return OK;
76 };
77
87 virtual int init()
88 {
89 return OK;
90 };
91
100 virtual int deinit()
101 {
102 return OK;
103 };
104
116 int start()
117 {
118 int ret;
119
120 if (started)
121 {
122 return OK;
123 }
124
125 ret = doStart();
126 if (ret == OK)
127 {
128 started = true;
129 }
130
131 return ret;
132 };
133
145 int stop()
146 {
147 int ret;
148
149 if (!started)
150 {
151 return OK;
152 }
153
154 ret = doStop();
155 started = false;
156 return ret;
157 };
158
169 virtual bool hasThread() const
170 {
171 return false;
172 }
173
183 virtual EObjectState getState() const
184 {
185 return started ? STATE_RUNNING : STATE_STOPPED;
186 }
187
195 virtual int trigger(uint8_t cmd)
196 {
197 UNUSED(cmd);
198 return -ENOTSUP;
199 }
200
208
216
223 bool getCfgFlag() const;
224
231 uint8_t getType() const;
232
239 uint16_t getCls() const;
240
247 uint8_t getDtype() const;
248
255 uint8_t getFlags() const;
256
263 uint16_t getPriv() const;
264
272
279 size_t getDtypeSize() const;
280
292 int setObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len);
293
305 int getObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len);
306
314 enum
315 {
316 DESCVALID_ERR_LEN_ALIGN = -1,
317 DESCVALID_ERR_NO_OBJSIZE = -2,
318 DESCVALID_ERR_NO_CFG_HEADER = -3,
319 DESCVALID_ERR_CFG_TRUNCATED = -4,
320 DESCVALID_ERR_CFG_DATA = -6
321 };
322
334 static int descValidDefault(const uint32_t *data, size_t len);
335
346 static int validateDesc(const uint32_t *desc, size_t len);
347
348#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
358 virtual const char *getClassNameStr() const = 0;
359
369 const char *getName() const;
370#endif // CONFIG_DAWN_OBJECT_HAS_NAME
371
372protected:
386 virtual int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
387 {
388 UNUSED(objcfg);
389 UNUSED(data);
390 UNUSED(len);
391 return OK;
392 }
393
402 virtual int doStart()
403 {
404 return OK;
405 }
406
415 virtual int doStop()
416 {
417 return OK;
418 }
419
420#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
429 mutable char name[CONFIG_DAWN_OBJECT_NAME_SIZE] = {};
430#endif
431
432private:
433 bool started; // Operational started state, set by start()/stop() wrappers.
434 CDescObject &objdesc;
435 SObjectId::UObjectId uobjid;
436};
437
438} // Namespace dawn
Descriptor wrapper for individual object configuration.
Base class for all Dawn objects (IOs, Programs, Protocols).
Definition object.hxx:28
virtual int init()
One-time initialize object after bindings are resolved.
Definition object.hxx:87
uint8_t getType() const
Get object type field.
Definition object.cxx:165
virtual int trigger(uint8_t cmd)
Execute a trigger command.
Definition object.hxx:195
uint16_t getPriv() const
Get instance/private data field.
Definition object.cxx:185
virtual int doStart()
Start implementation hook.
Definition object.hxx:402
uint16_t getCls() const
Get object class field.
Definition object.cxx:170
EObjectState
Object operational state returned by getState()
Definition object.hxx:33
@ STATE_STOPPED
Object is stopped.
Definition object.hxx:34
@ STATE_RUNNING
Object is running.
Definition object.hxx:35
uint8_t getFlags() const
Get type-specific flags field.
Definition object.cxx:180
int stop()
Stop object.
Definition object.hxx:145
virtual int doStop()
Stop implementation hook.
Definition object.hxx:415
virtual bool hasThread() const
Check if a background thread is active.
Definition object.hxx:169
static int descValidDefault(const uint32_t *data, size_t len)
Default descriptor validation method.
Definition object.cxx:42
virtual EObjectState getState() const
Get current operational state.
Definition object.hxx:183
virtual int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Pre-update hook for runtime configuration writes.
Definition object.hxx:386
virtual int deinit()
De-initialize object.
Definition object.hxx:100
SObjectId::ObjectId getIdV() const
Get object identifier as raw 32-bit value.
Definition object.cxx:155
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
size_t getDtypeSize() const
Get size of this object's data type.
Definition object.cxx:195
int getObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Get object configuration item.
Definition object.cxx:240
SObjectId::UObjectId getId() const
Get object identifier as union structure.
Definition object.cxx:150
CObject(CDescObject &desc)
Construct a CObject from a descriptor.
Definition object.hxx:54
virtual int configure()
Configure object from descriptor data.
Definition object.hxx:73
int setObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
Set object configuration item.
Definition object.cxx:200
uint8_t getDtype() const
Get data type field.
Definition object.cxx:175
@ CMD_RESET
Reset object internal state.
Definition object.hxx:42
@ CMD_TRIGGER3
Object-specific trigger slot 3.
Definition object.hxx:45
@ CMD_TRIGGER2
Object-specific trigger slot 2.
Definition object.hxx:44
@ CMD_TRIGGER1
Object-specific trigger slot 1.
Definition object.hxx:43
static int validateDesc(const uint32_t *desc, size_t len)
Validate entire descriptor.
Definition object.cxx:123
bool getCfgFlag() const
Check if configuration flag is set.
Definition object.cxx:160
int start()
Start object.
Definition object.hxx:116
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
Definition objectcfg.hxx:60
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
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218