comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/queue.h @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
comparison
equal deleted inserted replaced
4:26cd8f1ef0b1 5:f762bf195c4b
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * queue.h - simple in process message queuing
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2004 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2, as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: queue.h,v 1.4 2006/10/24 13:45:28 steveu Exp $
26 */
27
28 /*! \file */
29
30 /*! \page queue_page Queuing
31 \section queue_page_sec_1 What does it do?
32 ???.
33
34 \section queue_page_sec_2 How does it work?
35 ???.
36 */
37
38 #if !defined(_QUEUE_H_)
39 #define _QUEUE_H_
40
41 #define QUEUE_READ_ATOMIC 0x0001
42 #define QUEUE_WRITE_ATOMIC 0x0002
43
44 typedef struct
45 {
46 int len;
47 int iptr;
48 int optr;
49 int flags;
50 uint8_t *data;
51 } queue_t;
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 /*! Check if a queue is empty.
58 \brief Check if a queue is empty.
59 \param p The queue context.
60 \return TRUE if empty, else FALSE. */
61 int queue_empty(queue_t *p);
62
63 /*! Check the available free space in a queue's buffer.
64 \brief Check available free space.
65 \param p The queue context.
66 \return The number of bytes of free space. */
67 int queue_free_space(queue_t *p);
68
69 /*! Check the contents of a queue.
70 \brief Check the contents of a queue.
71 \param p The queue context.
72 \return The number of bytes in the queue. */
73 int queue_contents(queue_t *p);
74
75 /*! Flush the contents of a queue.
76 \brief Flush the contents of a queue.
77 \param p The queue context. */
78 void queue_flush(queue_t *p);
79
80 /*! Copy bytes from a queue. This is similar to queue_read, but
81 the data remains in the queue.
82 \brief Copy bytes from a queue.
83 \param p The queue context.
84 \param buf The buffer into which the bytes will be read.
85 \param len The length of the buffer.
86 \return the number of bytes returned. */
87 int queue_view(queue_t *p, uint8_t *buf, int len);
88
89 /*! Read bytes from a queue.
90 \brief Read bytes from a queue.
91 \param p The queue context.
92 \param buf The buffer into which the bytes will be read.
93 \param len The length of the buffer.
94 \return the number of bytes returned. */
95 int queue_read(queue_t *p, uint8_t *buf, int len);
96
97 /*! Write bytes to a queue.
98 \brief Write bytes to a queue.
99 \param p The queue context.
100 \param buf The buffer containing the bytes to be written.
101 \param len The length of the buffer.
102 \return the number of bytes actually written. */
103 int queue_write(queue_t *p, const uint8_t *buf, int len);
104
105 /*! Test the length of the message at the head of a queue.
106 \brief Test message length.
107 \param p The queue context.
108 \return The length of the next message, in byte. If there are
109 no messages in the queue, -1 is returned. */
110 int queue_test_msg(queue_t *p);
111
112 /*! Read a message from a queue. If the message is longer than the buffer
113 provided, only the first len bytes of the message will be returned. The
114 remainder of the message will be discarded.
115 \brief Read a message from a queue.
116 \param p The queue context.
117 \param buf The buffer into which the message will be read.
118 \param len The length of the buffer.
119 \return The number of bytes returned. If there are
120 no messages in the queue, -1 is returned. */
121 int queue_read_msg(queue_t *p, uint8_t *buf, int len);
122
123 /*! Write a message to a queue.
124 \brief Write a message to a queue.
125 \param p The queue context.
126 \param buf The buffer from which the message will be written.
127 \param len The length of the message.
128 \return The number of bytes actually written. */
129 int queue_write_msg(queue_t *p, const uint8_t *buf, int len);
130
131 /*! Create a queue.
132 \brief Create a queue.
133 \param p The queue context.
134 \param len The length of the queue's buffer.
135 \param flags Flags controlling the operation of the queue.
136 Valid flags are QUEUE_READ_ATOMIC and QUEUE_WRITE_ATOMIC.
137 \return 0 if created OK, else -1. */
138 int queue_create(queue_t *p, int len, int flags);
139
140 /*! Delete a queue.
141 \brief Delete a queue.
142 \param p The queue context.
143 \return 0 if deleted OK, else -1. */
144 int queue_delete(queue_t *p);
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif
151 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.