Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 1 | /* 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 Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 23 | #ifndef OSMO_WQUEUE_H |
| 24 | #define OSMO_WQUEUE_H |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 25 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 26 | /*! \file write_queue.h |
| 27 | * \brief Osmocom write queues |
| 28 | */ |
| 29 | |
Pablo Neira Ayuso | dc35dbe | 2011-03-28 19:24:20 +0200 | [diff] [blame] | 30 | #include <osmocom/core/select.h> |
| 31 | #include <osmocom/core/msgb.h> |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 32 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 33 | /*! write queue instance */ |
Pablo Neira Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 34 | struct osmo_wqueue { |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 35 | /*! \brief osmocom file descriptor */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 36 | struct osmo_fd bfd; |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 37 | /*! \brief maximum length of write queue */ |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 38 | unsigned int max_length; |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 39 | /*! \brief current length of write queue */ |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 40 | unsigned int current_length; |
| 41 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 42 | /*! \brief actual linked list implementing the queue */ |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 43 | struct llist_head msg_queue; |
| 44 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 45 | /*! \brief call-back in case qeueue is readable */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 46 | int (*read_cb)(struct osmo_fd *fd); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 47 | /*! \brief call-back in case qeueue is writable */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 48 | int (*write_cb)(struct osmo_fd *fd, struct msgb *msg); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 49 | /*! \brief call-back in case qeueue has exceptions */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 50 | int (*except_cb)(struct osmo_fd *fd); |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 53 | /*! \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 Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 57 | void osmo_wqueue_init(struct osmo_wqueue *queue, int max_length); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 58 | |
| 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 Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 64 | void osmo_wqueue_clear(struct osmo_wqueue *queue); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 65 | |
| 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 Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 70 | int osmo_wqueue_enqueue(struct osmo_wqueue *queue, struct msgb *data); |
Harald Welte | bd598e3 | 2011-08-16 23:26:52 +0200 | [diff] [blame^] | 71 | |
| 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 Ayuso | 9111d93 | 2011-05-07 12:42:51 +0200 | [diff] [blame] | 79 | int osmo_wqueue_bfd_cb(struct osmo_fd *fd, unsigned int what); |
Holger Hans Peter Freyther | 8df932a | 2010-02-26 20:30:32 +0100 | [diff] [blame] | 80 | |
| 81 | #endif |