amiro-os / os / core / inc / aos_iostream.h @ ba516b61
History | View | Annotate | Download (3.615 KB)
1 | ba516b61 | Thomas Schöpping | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2018 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | #ifndef _AMIROOS_IOSTREAM_H_
|
||
20 | #define _AMIROOS_IOSTREAM_H_
|
||
21 | |||
22 | #include <hal.h> |
||
23 | #include <aos_types.h> |
||
24 | #include <stdarg.h> |
||
25 | |||
26 | |||
27 | |||
28 | /**
|
||
29 | * @brief Channel flag to indicate whether the channel is attached to a stream.
|
||
30 | */
|
||
31 | #define AOS_IOCHANNEL_ATTACHED (1 << 0) |
||
32 | |||
33 | /**
|
||
34 | * @brief Channel flag to indicate whether the channel is set as output.
|
||
35 | */
|
||
36 | #define AOS_IOCHANNEL_OUTPUT_ENABLE (1 << 1) |
||
37 | |||
38 | /*
|
||
39 | * forward definitions
|
||
40 | */
|
||
41 | typedef struct aos_iochannel AosIOChannel; |
||
42 | typedef struct aos_ostream AosIOStream; |
||
43 | |||
44 | /**
|
||
45 | * @brief AosI=Channel specific methods.
|
||
46 | */
|
||
47 | #define _aos_iochannel_methods \
|
||
48 | _base_asynchronous_channel_methods |
||
49 | |||
50 | /**
|
||
51 | * @brief AosIOChannel specific data.
|
||
52 | */
|
||
53 | #define _aos_iochannel_data \
|
||
54 | /* pointer to a BaseAsynchronousChannel object */ \
|
||
55 | BaseAsynchronousChannel* asyncchannel; \ |
||
56 | /* pointer to the next channel in a AosIOStream */ \
|
||
57 | AosIOChannel* next; \ |
||
58 | /* flags related to the channel */ \
|
||
59 | uint8_t flags; |
||
60 | |||
61 | /**
|
||
62 | * @extends BaseAsynchronousChannelVMT
|
||
63 | *
|
||
64 | * @brief AosIOChannel virtual methods table.
|
||
65 | */
|
||
66 | struct AosIOChannelVMT {
|
||
67 | _aos_iochannel_methods |
||
68 | }; |
||
69 | |||
70 | /**
|
||
71 | * @extends BaseAsynchronousChannel
|
||
72 | *
|
||
73 | * @brief I/O Channel class.
|
||
74 | * @details This class implements an asynchronous I/O channel.
|
||
75 | */
|
||
76 | struct aos_iochannel {
|
||
77 | /** @brief Virtual Methods Table. */
|
||
78 | const struct AosIOChannelVMT* vmt; |
||
79 | _aos_iochannel_data |
||
80 | }; |
||
81 | |||
82 | /**
|
||
83 | * @brief AosIOStream methods.
|
||
84 | */
|
||
85 | #define _aos_iostream_methods \
|
||
86 | _base_sequential_stream_methods |
||
87 | |||
88 | /**
|
||
89 | * @brief AosIOStream data.
|
||
90 | */
|
||
91 | #define _aos_iostream_data \
|
||
92 | /* Pointer to the first channel in a list. */ \
|
||
93 | AosIOChannel* channel; |
||
94 | |||
95 | /**
|
||
96 | * @extends BaseSequentialStream
|
||
97 | *
|
||
98 | * @brief AosIOStream virtual methods table.
|
||
99 | */
|
||
100 | struct AosIOStreamVMT {
|
||
101 | _aos_iostream_methods |
||
102 | }; |
||
103 | |||
104 | /**
|
||
105 | * @extends BaseSequentialStream
|
||
106 | *
|
||
107 | * @brief I/O Stream class.
|
||
108 | * @details This class implements an base sequential stream.
|
||
109 | * @todo So far only output but no input is supported.
|
||
110 | */
|
||
111 | struct aos_ostream {
|
||
112 | const struct AosIOStreamVMT* vmt; |
||
113 | _aos_iostream_data |
||
114 | }; |
||
115 | |||
116 | #ifdef __cplusplus
|
||
117 | extern "C" { |
||
118 | #endif
|
||
119 | void aosIOStreamInit(AosIOStream* stream);
|
||
120 | void aosIOChannelInit(AosIOChannel* channel, BaseAsynchronousChannel* asyncchannel);
|
||
121 | void aosIOStreamAddChannel(AosIOStream* stream, AosIOChannel* channel);
|
||
122 | aos_status_t aosIOStreamRemoveChannel(AosIOStream* stream, AosIOChannel* channel); |
||
123 | void aosIOChannelOutputEnable(AosIOChannel* channel);
|
||
124 | void aosIOChannelOutputDisable(AosIOChannel* channel);
|
||
125 | #ifdef __cplusplus
|
||
126 | } |
||
127 | #endif
|
||
128 | |||
129 | #endif /* _AMIROOS_IOSTREAM_H_ */ |