paulo@0: /* paulo@0: * $Id: tx_layer.h,v 1.5 2004/01/31 13:33:17 hipnod Exp $ paulo@0: * paulo@0: * Copyright (C) 2003 giFT project (gift.sourceforge.net) paulo@0: * paulo@0: * This program is free software; you can redistribute it and/or modify it paulo@0: * under the terms of the GNU General Public License as published by the paulo@0: * Free Software Foundation; either version 2, or (at your option) any paulo@0: * later version. paulo@0: * paulo@0: * This program is distributed in the hope that it will be useful, but paulo@0: * WITHOUT ANY WARRANTY; without even the implied warranty of paulo@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU paulo@0: * General Public License for more details. paulo@0: */ paulo@0: paulo@0: #ifndef GIFT_GT_TX_LAYER_H_ paulo@0: #define GIFT_GT_TX_LAYER_H_ paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: struct tx_layer_ops; paulo@0: struct tx_layer; paulo@0: paulo@0: struct io_buf; paulo@0: struct gt_tx_stack; paulo@0: paulo@0: /* paulo@0: * Return codes from the TX stack functions that lets the caller know paulo@0: * what processing occured. paulo@0: */ paulo@0: typedef enum tx_status paulo@0: { paulo@0: TX_OK, paulo@0: TX_FULL, /* lower layer became saturated */ paulo@0: TX_EMPTY, /* no waiting data */ paulo@0: TX_PARTIAL, /* buffer partially read */ paulo@0: TX_ERROR, /* general error */ paulo@0: } tx_status_t; paulo@0: paulo@0: struct tx_layer_ops paulo@0: { paulo@0: BOOL (*init) (struct tx_layer *tx); paulo@0: void (*destroy) (struct tx_layer *tx); paulo@0: paulo@0: /* paulo@0: * If the layer is capable of consuming data (for example paulo@0: * by sending it out on a connection), begin or stop flushing by obeying paulo@0: * the 'stop' argument. Only the bottommost layer in a stack paulo@0: * should implement this. paulo@0: */ paulo@0: void (*toggle) (struct tx_layer *tx, BOOL stop); paulo@0: paulo@0: /* upper layer has sent us a buffer */ paulo@0: tx_status_t (*queue) (struct tx_layer *tx, struct io_buf *io_buf); paulo@0: paulo@0: /* lower layer wants us to send a buffer */ paulo@0: tx_status_t (*ready) (struct tx_layer *tx); /* lower layer wants data */ paulo@0: paulo@0: /* enable/disable this layer completely */ paulo@0: void (*enable) (struct tx_layer *tx); paulo@0: void (*disable) (struct tx_layer *tx); paulo@0: }; paulo@0: paulo@0: struct tx_layer paulo@0: { paulo@0: void *udata; paulo@0: struct tx_layer_ops *ops; paulo@0: paulo@0: struct tx_layer *upper; paulo@0: struct tx_layer *lower; paulo@0: paulo@0: /* leftovers from previous queue operations */ paulo@0: struct io_buf *partial_buf; paulo@0: paulo@0: struct gt_tx_stack *stack; paulo@0: const char *name; paulo@0: }; paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: struct tx_layer *gt_tx_layer_new (struct gt_tx_stack *stack, paulo@0: const char *name, paulo@0: struct tx_layer_ops *ops); paulo@0: void gt_tx_layer_free (struct tx_layer *layer); paulo@0: paulo@0: void gt_tx_layer_enable (struct tx_layer *layer); paulo@0: void gt_tx_layer_disable (struct tx_layer *layer); paulo@0: paulo@0: tx_status_t gt_tx_layer_queue (struct tx_layer *layer, paulo@0: struct io_buf *buf); paulo@0: tx_status_t gt_tx_layer_ready (struct tx_layer *layer); paulo@0: paulo@0: /*****************************************************************************/ paulo@0: paulo@0: #endif /* GIFT_GT_TX_LAYER_H_ */