Dawn Framework 1.0
Universal data acquisition framework for embedded systems
fileio.hxx
1// dawn/include/dawn/io/fileio.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <limits.h>
9
10#include "dawn/io/common.hxx"
11#include "dawn/porting/config.hxx"
12
13namespace dawn
14{
27class CIOFile : public CIOCommon
28{
29public:
30 enum
31 {
36 };
37
38 enum
39 {
40 IO_FILE_CFG_FIRST = 0,
43 IO_FILE_CFG_LAST = 31
44 };
45
46 explicit CIOFile(CDescObject &desc)
47 : CIOCommon(desc)
48 , fd(-1)
49 , fsize(0)
50 , perm(IO_FILE_PERM_READ)
51 , writeOnceLocked(false)
52 , devNode(false)
53 {
54 }
55
56 ~CIOFile() override;
57
58#ifdef CONFIG_DAWN_OBJECT_HAS_NAME
59 const char *getClassNameStr() const override
60 {
61 return "file";
62 }
63#endif
64
65 int configure() override;
66 int deinit() override;
67 int getDataImpl(IODataCmn &data, size_t len) override;
68 int setDataImpl(IODataCmn &data) override;
69 int getDataAtImpl(IODataCmn &data, size_t len, size_t offset) override;
70 int setDataAtImpl(IODataCmn &data, size_t offset) override;
71
72#ifdef CONFIG_DAWN_IO_NOTIFY
73 int getFd() const override;
74#endif
75
76 size_t getDataSize() const override;
77 size_t getDataDim() const override;
78 bool isRead() const override;
79 bool isWrite() const override;
80
81 bool isNotify() const override
82 {
83 return false;
84 }
85
86 bool isBatch() const override
87 {
88 return false;
89 }
90
91 bool isSeekable() const override
92 {
93 return true;
94 }
95
97
98 constexpr static SObjectId::ObjectId objectId(uint16_t inst)
99 {
100 return ObjectIdHelper::create(inst);
101 }
102
103 constexpr static SObjectCfg::ObjectCfgId cfgIdPath(uint16_t size)
104 {
108 false,
109 size,
111 }
112
113 constexpr static SObjectCfg::ObjectCfgId cfgIdPerm()
114 {
118 false,
119 1,
121 }
122
123private:
124 char path[PATH_MAX] = {};
125 int fd;
126 size_t fsize;
127 uint8_t perm;
128 bool writeOnceLocked;
129 bool devNode;
130
131 int configureDesc(const CDescObject &desc);
132 int truncateFile();
133};
134} // Namespace dawn
Descriptor wrapper for individual object configuration.
Template helper for creating ObjectIDs for I/O types without timestamp support.
Definition common.hxx:329
static SObjectId::ObjectId create(uint16_t inst)
Create ObjectID with fixed data type and no timestamp.
Definition common.hxx:338
Base class for all I/O objects.
Definition common.hxx:27
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:451
@ IO_CLASS_FILE
File system I/O.
Definition common.hxx:109
File system I/O access.
Definition fileio.hxx:28
bool isSeekable() const
Check if IO supports partial (seekable) access.
Definition fileio.hxx:91
bool isBatch() const
Check if IO supports batch operations.
Definition fileio.hxx:86
int setDataImpl(IODataCmn &data)
Set data implementation (override in derived classes).
Definition fileio.cxx:270
@ IO_FILE_PERM_RW
Read-write.
Definition fileio.hxx:34
@ IO_FILE_PERM_WRITE
Write-only.
Definition fileio.hxx:33
@ IO_FILE_PERM_WRITE_ONCE
Write-once (per session on device nodes)
Definition fileio.hxx:35
@ IO_FILE_PERM_READ
Read-only.
Definition fileio.hxx:32
bool isNotify() const
Check if IO supports notifications.
Definition fileio.hxx:81
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
Definition fileio.cxx:240
size_t getDataDim() const
Get data vector dimension.
Definition fileio.cxx:405
int getDataAtImpl(IODataCmn &data, size_t len, size_t offset)
Get data at byte offset (override in seekable IOs).
Definition fileio.cxx:315
int deinit()
De-initialize object.
Definition fileio.cxx:229
@ IO_FILE_CFG_PATH
File path (null-terminated string, DTYPE_CHAR).
Definition fileio.hxx:41
@ IO_FILE_CFG_PERM
Permission mode (EIOFilePerm, DTYPE_UINT8).
Definition fileio.hxx:42
size_t getDataSize() const
Get data size in bytes.
Definition fileio.cxx:400
bool isWrite() const
Check if IO supports write operations.
Definition fileio.cxx:417
bool isRead() const
Check if IO supports read operations.
Definition fileio.cxx:412
int setDataAtImpl(IODataCmn &data, size_t offset)
Set data at byte offset (override in seekable IOs).
Definition fileio.cxx:345
int configure()
Configure object from descriptor data.
Definition fileio.cxx:118
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
@ OBJTYPE_IO
Input/Output object type.
Definition objectid.hxx:184
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
Definition objectid.hxx:80
@ 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