Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_iostream.h @ a7e54ea4

History | View | Annotate | Download (5.725 KB)

1
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  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
/**
20
 * @file    aos_iostream.h
21
 * @brief   Stream and channel macros and structures.
22
 *
23
 * @addtogroup aos_stream
24
 * @{
25
 */
26

    
27
#ifndef AMIROOS_IOSTREAM_H
28
#define AMIROOS_IOSTREAM_H
29

    
30
#include <amiroos.h>
31

    
32
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35

    
36
/**
37
 * @brief   Channel flag to indicate whether the channel is attached to a stream.
38
 */
39
#define AOS_IOCHANNEL_ATTACHED                  ((aos_iochannelflag_t)(1 << 0))
40

    
41
/**
42
 * @brief   Channel flag to indicate whether the channel is set as input.
43
 */
44
#define AOS_IOCHANNEL_INPUT_ENABLE              ((aos_iochannelflag_t)(1 << 1))
45

    
46
/**
47
 * @brief   Channel flag to indicate whether the channel is set as output.
48
 */
49
#define AOS_IOCHANNEL_OUTPUT_ENABLE             ((aos_iochannelflag_t)(1 << 2))
50

    
51
/******************************************************************************/
52
/* SETTINGS                                                                   */
53
/******************************************************************************/
54

    
55
/******************************************************************************/
56
/* CHECKS                                                                     */
57
/******************************************************************************/
58

    
59
/******************************************************************************/
60
/* DATA STRUCTURES AND TYPES                                                  */
61
/******************************************************************************/
62

    
63
typedef uint8_t aos_iochannelflag_t;
64

    
65
/**
66
 * @brief   AosIOChannel specific methods.
67
 */
68
#define _aos_iochannel_methods                                              \
69
  _base_asynchronous_channel_methods
70

    
71
/**
72
 * @brief   AosIOChannel specific data.
73
 */
74
#define _aos_iochannel_data                                                 \
75
  /* pointer to a BaseAsynchronousChannel object */                         \
76
  BaseAsynchronousChannel* asyncchannel;                                    \
77
  /* pointer to the next channel in a AosIOStream */                        \
78
  struct aos_iochannel* next;                                               \
79
  /* flags related to the channel */                                        \
80
  aos_iochannelflag_t flags;
81

    
82
/**
83
 * @extends BaseAsynchronousChannelVMT
84
 *
85
 * @brief   AosIOChannel virtual methods table.
86
 */
87
struct AosIOChannelVMT {
88
  _aos_iochannel_methods
89
};
90

    
91
/**
92
 * @extends BaseAsynchronousChannel
93
 *
94
 * @brief   I/O Channel class.
95
 * @details This class implements an asynchronous I/O channel.
96
 */
97
typedef struct aos_iochannel {
98
  /** @brief Virtual Methods Table. */
99
  const struct AosIOChannelVMT* vmt;
100
  _aos_iochannel_data
101
} AosIOChannel;
102

    
103
/**
104
 * @brief   AosIOStream methods.
105
 */
106
#define _aos_iostream_methods                                               \
107
  _base_sequential_stream_methods
108

    
109
/**
110
 * @brief   AosIOStream data.
111
 */
112
#define _aos_iostream_data                                                  \
113
  /* Pointer to the first channel in a list. */                             \
114
  AosIOChannel* channel;
115

    
116
/**
117
 * @extends BaseSequentialStream
118
 *
119
 * @brief   AosIOStream virtual methods table.
120
 */
121
struct AosIOStreamVMT {
122
  _aos_iostream_methods
123
};
124

    
125
/**
126
 * @extends BaseSequentialStream
127
 *
128
 * @brief   I/O Stream class.
129
 * @details This class implements an base sequential stream.
130
 * @todo    So far only output but no input is supported.
131
 */
132
typedef struct aos_ostream {
133
  const struct AosIOStreamVMT* vmt;
134
  _aos_iostream_data
135
} AosIOStream;
136

    
137
/******************************************************************************/
138
/* MACROS                                                                     */
139
/******************************************************************************/
140

    
141
/******************************************************************************/
142
/* EXTERN DECLARATIONS                                                        */
143
/******************************************************************************/
144

    
145
#if defined(__cplusplus)
146
extern "C" {
147
#endif /* defined(__cplusplus) */
148
  void aosIOStreamInit(AosIOStream* stream);
149
  void aosIOChannelInit(AosIOChannel* channel, BaseAsynchronousChannel* asyncchannel);
150
  void aosIOStreamAddChannel(AosIOStream* stream, AosIOChannel* channel);
151
  aos_status_t aosIOStreamRemoveChannel(AosIOStream* stream, AosIOChannel* channel);
152
  void aosIOChannelInputEnable(AosIOChannel* channel);
153
  void aosIOChannelInputDisable(AosIOChannel* channel);
154
  void aosIOChannelOutputEnable(AosIOChannel* channel);
155
  void aosIOChannelOutputDisable(AosIOChannel* channel);
156
#if defined(__cplusplus)
157
}
158
#endif /* defined(__cplusplus) */
159

    
160
/******************************************************************************/
161
/* INLINE FUNCTIONS                                                           */
162
/******************************************************************************/
163

    
164
#endif /* AMIROOS_IOSTREAM_H */
165

    
166
/** @} */