Dawn Framework 1.0
Universal data acquisition framework for embedded systems
simple.hxx
1// dawn/include/dawn/proto/ipc/simple.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstdint>
9
10#include <poll.h>
11
12#include "dawn/common/thread.hxx"
13#include "dawn/porting/config.hxx"
14#include "dawn/proto/simplebase.hxx"
15
16namespace dawn
17{
28 : public CProtoSimpleBase
29 , protected CThreadedObject
30{
31public:
32 enum
33 {
34 PROTO_IPC_CFG_FIRST = 0,
35 PROTO_IPC_CFG_IOBIND = 1,
36 PROTO_IPC_CFG_RX_PATH = 2,
37 PROTO_IPC_CFG_TX_PATH = 3,
38 PROTO_IPC_CFG_LAST = 31
39 } typedef EProtoIpcCfg;
40
42
43 explicit CProtoIpc(CDescObject &desc)
44 : CProtoSimpleBase(desc)
45 , rxPath(CONFIG_DAWN_PROTO_IPC_RX_PATH)
46 , txPath(CONFIG_DAWN_PROTO_IPC_TX_PATH)
47 , rxfd(-1)
48 , txfd(-1)
49 , parserPos(0)
50 , parserLen(0)
51 , parserState(0)
52 {
53 }
54
55 ~CProtoIpc() override;
56
57#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
58 const char *getClassNameStr() const override
59 {
60 return "ipc";
61 }
62#endif
63
64 int configure() override;
65 int init() override;
66 int deinit() override;
67 int doStart() override;
68 int doStop() override;
69 bool hasThread() const override;
70
71 constexpr static SObjectId::ObjectId objectId(uint16_t id)
72 {
75 }
76
77 constexpr static SObjectCfg::ObjectCfgId cfgId(bool rw, uint8_t dtype, uint8_t size, uint8_t id)
78 {
81 }
82
83 constexpr static SObjectCfg::ObjectCfgId cfgIdIOBind(uint16_t size)
84 {
85 return CProtoIpc::cfgId(false, SObjectId::DTYPE_ANY, size, PROTO_IPC_CFG_IOBIND);
86 }
87
88 constexpr static SObjectCfg::ObjectCfgId cfgIdRxPath(uint16_t size)
89 {
90 return CProtoIpc::cfgId(true, SObjectId::DTYPE_CHAR, size, PROTO_IPC_CFG_RX_PATH);
91 }
92
93 constexpr static SObjectCfg::ObjectCfgId cfgIdTxPath(uint16_t size)
94 {
95 return CProtoIpc::cfgId(true, SObjectId::DTYPE_CHAR, size, PROTO_IPC_CFG_TX_PATH);
96 }
97
98private:
99 const char *rxPath;
100 const char *txPath;
101 int rxfd;
102 int txfd;
103 size_t parserPos;
104 uint16_t parserLen;
105 int parserState;
106
107 int sendFrame(uint8_t cmd, const uint8_t *payload, size_t len) override;
108
109 int configureDesc(const CDescObject &desc);
110 int ensureFifo(const char *path);
111 int fifoInit();
112 void thread();
113 int pollBefore(struct pollfd *pfds, nfds_t nfds);
114 void pollAfter(int ret);
115 int pollOnReady(struct pollfd *pfds, nfds_t nfds, int pollRet);
116
117 static int cbPollBefore(void *priv, struct pollfd *pfds, nfds_t nfds);
118 static void cbPollAfter(void *priv, struct pollfd *pfds, nfds_t nfds, int ret);
119 static int cbPollOnReady(void *priv, struct pollfd *pfds, nfds_t nfds, int pollRet);
120};
121} // Namespace dawn
Descriptor wrapper for individual object configuration.
@ PROTO_CLASS_IPC
FIFO-based local IPC protocol.
Definition common.hxx:83
Simple FIFO-based IPC transport for local Dawn communication.
Definition simple.hxx:30
int doStart()
Start implementation hook.
Definition simple.cxx:484
int deinit()
De-initialize object.
Definition simple.cxx:451
int configure()
Configure object from descriptor data.
Definition simple.cxx:409
int doStop()
Stop implementation hook.
Definition simple.cxx:500
int init()
One-time initialize object after bindings are resolved.
Definition simple.cxx:423
bool hasThread() const
Check if a background thread is active.
Definition simple.cxx:513
Shared base for simple framed protocols.
Portable thread owner abstraction for Dawn components.
Definition thread.hxx:32
static ObjectCfgId objectCfg(uint8_t type, uint16_t cls, uint8_t dtype, bool rw, uint16_t size, uint8_t id)
Construct 32-bit ConfigID from component fields.
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
Configuration for binding an I/O object to a simple protocol.
@ OBJTYPE_PROTO
Protocol object type.
Definition objectid.hxx:193
@ DTYPE_ANY
Wildcard data type (matches any actual type).
Definition objectid.hxx:68
@ DTYPE_CHAR
Character/string type (null-terminated, 4-byte aligned).
Definition objectid.hxx:144
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
static ObjectId objectId(uint8_t type, uint16_t cls, uint8_t dtype, uint8_t flags, uint16_t priv)
Construct 32-bit ObjectID from component fields.
Definition objectid.hxx:290