blob: 373b64fff951865965b8e73f7296f4668002f154 [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 */
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020023#ifndef OSMO_WQUEUE_H
24#define OSMO_WQUEUE_H
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010025
Harald Weltebd598e32011-08-16 23:26:52 +020026/*! \file write_queue.h
27 * \brief Osmocom write queues
28 */
29
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 {
Harald Weltebd598e32011-08-16 23:26:52 +020035 /*! \brief osmocom file descriptor */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020036 struct osmo_fd bfd;
Harald Weltebd598e32011-08-16 23:26:52 +020037 /*! \brief maximum length of write queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010038 unsigned int max_length;
Harald Weltebd598e32011-08-16 23:26:52 +020039 /*! \brief current length of write queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010040 unsigned int current_length;
41
Harald Weltebd598e32011-08-16 23:26:52 +020042 /*! \brief actual linked list implementing the queue */
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010043 struct llist_head msg_queue;
44
Harald Weltebd598e32011-08-16 23:26:52 +020045 /*! \brief call-back in case qeueue is readable */
Pablo Neira Ayusof7f89d02011-05-07 12:42:40 +020046 int (*read_cb)(struct osmo_fd *fd);
Harald Weltebd598e32011-08-16 23:26:52 +020047 /*! \brief 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);
Harald Weltebd598e32011-08-16 23:26:52 +020049 /*! \brief 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
Harald Weltebd598e32011-08-16 23:26:52 +020053/*! \brief Initialize a \ref osmo_wqueue structure
54 * \param[in] queue Write queue to operate on
55 * \param[in] max_length Maximum length of write queue
56 */
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020057void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length);
Harald Weltebd598e32011-08-16 23:26:52 +020058
59/*! \brief Clear a \ref osmo_wqueue
60 * \param[in] queue Write queue to be cleared
61 *
62 * This function will clear (remove/release) all messages in it.
63 */
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020064void osmo_wqueue_clear(struct osmo_wqueue *queue);
Harald Weltebd598e32011-08-16 23:26:52 +020065
66/*! \brief Enqueue a new \ref msgb into a write queue
67 * \param[in] queue Write queue to be used
68 * \param[in] data to-be-enqueued message buffer
69 */
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020070int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data);
Harald Weltebd598e32011-08-16 23:26:52 +020071
72/*! \brief Select loop function for write queue handling
73 * \param[in] fd osmocom file descriptor
74 * \param[in] what bit-mask of events that have happened
75 *
76 * This function is provided so that it can be registered with the
77 * select loop abstraction code (\ref osmo_fd::cb).
78 */
Pablo Neira Ayuso9111d932011-05-07 12:42:51 +020079int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what);
Holger Hans Peter Freyther8df932a2010-02-26 20:30:32 +010080
81#endif