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