blob: 4e0fdf3dc99f87ce8a42c215e1db9c60a2c723c5 [file] [log] [blame]
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +01001/* Generic write queue implementation */
2/*
3 * (C) 2010 by Holger Hans Peter Freyther
4 * (C) 2010 by On-Waves
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
Sylvain Munaut12ba7782014-06-16 10:13:40 +020023#pragma once
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010024
Harald Welte2777ecd2011-08-17 14:23:42 +020025/*! \defgroup write_queue Osmocom msgb write queues
26 * @{
27 */
28
Harald Weltebd598e32011-08-16 23:26:52 +020029/*! \file write_queue.h
Harald Weltebd598e32011-08-16 23:26:52 +020030 */
31
Pablo Neira Ayusodc35dbe2011-03-28 19:24:20 +020032#include <osmocom/core/select.h>
33#include <osmocom/core/msgb.h>
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010034
Harald Weltebd598e32011-08-16 23:26:52 +020035/*! write queue instance */
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020036struct osmo_wqueue {
Harald Weltebd598e32011-08-16 23:26:52 +020037 /*! \brief osmocom file descriptor */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020038 struct osmo_fd bfd;
Harald Weltebd598e32011-08-16 23:26:52 +020039 /*! \brief maximum length of write queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010040 unsigned int max_length;
Harald Weltebd598e32011-08-16 23:26:52 +020041 /*! \brief current length of write queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010042 unsigned int current_length;
43
Harald Weltebd598e32011-08-16 23:26:52 +020044 /*! \brief actual linked list implementing the queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010045 struct llist_head msg_queue;
46
Harald Weltebd598e32011-08-16 23:26:52 +020047 /*! \brief call-back in case qeueue is readable */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020048 int (*read_cb)(struct osmo_fd *fd);
Harald Weltebd598e32011-08-16 23:26:52 +020049 /*! \brief call-back in case qeueue is writable */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020050 int (*write_cb)(struct osmo_fd *fd, struct msgb *msg);
Harald Weltebd598e32011-08-16 23:26:52 +020051 /*! \brief call-back in case qeueue has exceptions */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020052 int (*except_cb)(struct osmo_fd *fd);
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010053};
54
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020055void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length);
56void osmo_wqueue_clear(struct osmo_wqueue *queue);
57int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data);
58int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what);
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010059
Sylvain Munautdca7d2c2012-04-18 21:53:23 +020060/*! @} */