Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_iostream.h @ 47680f67

History | View | Annotate | Download (3.993 KB)

1
/*
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
/**
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 <hal.h>
31
#include <aos_types.h>
32
#include <stdarg.h>
33

    
34

    
35

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

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

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

    
51
/*
52
 * forward definitions
53
 */
54
typedef struct aos_iochannel AosIOChannel;
55
typedef struct aos_ostream AosIOStream;
56

    
57
/**
58
 * @brief   AosI=Channel specific methods.
59
 */
60
#define _aos_iochannel_methods                                              \
61
  _base_asynchronous_channel_methods
62

    
63
/**
64
 * @brief   AosIOChannel specific data.
65
 */
66
#define _aos_iochannel_data                                                 \
67
  /* pointer to a BaseAsynchronousChannel object */                         \
68
  BaseAsynchronousChannel* asyncchannel;                                    \
69
  /* pointer to the next channel in a AosIOStream */                        \
70
  AosIOChannel* next;                                                       \
71
  /* flags related to the channel */                                        \
72
  uint8_t flags;
73

    
74
/**
75
 * @extends BaseAsynchronousChannelVMT
76
 *
77
 * @brief   AosIOChannel virtual methods table.
78
 */
79
struct AosIOChannelVMT {
80
  _aos_iochannel_methods
81
};
82

    
83
/**
84
 * @extends BaseAsynchronousChannel
85
 *
86
 * @brief   I/O Channel class.
87
 * @details This class implements an asynchronous I/O channel.
88
 */
89
struct aos_iochannel {
90
  /** @brief Virtual Methods Table. */
91
  const struct AosIOChannelVMT* vmt;
92
  _aos_iochannel_data
93
};
94

    
95
/**
96
 * @brief   AosIOStream methods.
97
 */
98
#define _aos_iostream_methods                                               \
99
  _base_sequential_stream_methods
100

    
101
/**
102
 * @brief   AosIOStream data.
103
 */
104
#define _aos_iostream_data                                                  \
105
  /* Pointer to the first channel in a list. */                             \
106
  AosIOChannel* channel;
107

    
108
/**
109
 * @extends BaseSequentialStream
110
 *
111
 * @brief   AosIOStream virtual methods table.
112
 */
113
struct AosIOStreamVMT {
114
  _aos_iostream_methods
115
};
116

    
117
/**
118
 * @extends BaseSequentialStream
119
 *
120
 * @brief   I/O Stream class.
121
 * @details This class implements an base sequential stream.
122
 * @todo    So far only output but no input is supported.
123
 */
124
struct aos_ostream {
125
  const struct AosIOStreamVMT* vmt;
126
  _aos_iostream_data
127
};
128

    
129
#ifdef __cplusplus
130
extern "C" {
131
#endif
132
  void aosIOStreamInit(AosIOStream* stream);
133
  void aosIOChannelInit(AosIOChannel* channel, BaseAsynchronousChannel* asyncchannel);
134
  void aosIOStreamAddChannel(AosIOStream* stream, AosIOChannel* channel);
135
  aos_status_t aosIOStreamRemoveChannel(AosIOStream* stream, AosIOChannel* channel);
136
  void aosIOChannelInputEnable(AosIOChannel* channel);
137
  void aosIOChannelInputDisable(AosIOChannel* channel);
138
  void aosIOChannelOutputEnable(AosIOChannel* channel);
139
  void aosIOChannelOutputDisable(AosIOChannel* channel);
140
#ifdef __cplusplus
141
}
142
#endif
143

    
144
#endif /* _AMIROOS_IOSTREAM_H_ */
145

    
146
/** @} */