Main Page | Class List | File List | Class Members | File Members

Buffer.c File Reference

#include "Buffer.h"

Go to the source code of this file.

Functions

Buffermkbuffer (int n, size_t len)
int bsize (Buffer *b)
int bhead (Buffer *b)
int btail (Buffer *b)
void bwrite (Buffer *b, void *data)
int bread (Buffer *b, void *data)
int blevel (Buffer *b)
void * bpeek (Buffer *b, int n)
void closebuffer (Buffer *b)


Function Documentation

int bhead Buffer b  ) 
 

Definition at line 45 of file Buffer.c.

References Buffer::head.

00049 {
00050   return b->head;
00051 }

int blevel Buffer b  ) 
 

Definition at line 111 of file Buffer.c.

References Buffer::full, Buffer::head, Buffer::n, and Buffer::tail.

Referenced by al_buffer_level(), al_indication(), al_request(), al_requested_size(), al_send_byte(), al_send_request(), bpeek(), channel_read_indication(), find_rcpc(), and send_closing_flag().

00115 {
00116   if (b->head == b->tail) {
00117     if (b->full)
00118       return b->n;
00119     else
00120       return 0;
00121   }
00122   if (b->head > b->tail)
00123     return (b->head - b->tail);
00124   if (b->head < b->tail)
00125     return (b->n + b->head - b->tail);
00126 }

void* bpeek Buffer b,
int  n
 

Definition at line 129 of file Buffer.c.

References blevel(), Buffer::data, Buffer::len, Buffer::n, and Buffer::tail.

Referenced by al_requested_size(), find_rcpc(), and place_rcpc().

00134 {
00135   if (n<0)
00136     return NULL;
00137 
00138   if (blevel(b) < n+1)
00139     return NULL;
00140 
00141   return (b->data + ((b->tail + n) % b->n) * b->len);
00142 }

int bread Buffer b,
void *  data
 

Definition at line 87 of file Buffer.c.

References data, Buffer::data, Buffer::full, Buffer::head, Buffer::len, Buffer::n, and Buffer::tail.

Referenced by al_receive(), channel_read(), get_al_pdu(), MakeNewVideoPacket(), and send_closing_flag().

00091           :
00092  *   1 = ok
00093  *   0 = failed
00094  */
00095 {
00096   if ((b->head==b->tail) && !(b->full))
00097     return 0;
00098 
00099   memcpy(data, b->data + b->tail*b->len, b->len);
00100 
00101   b->tail++;
00102   if (b->tail==b->n)
00103     b->tail=0;
00104 
00105   b->full=0;
00106 
00107   return 1;
00108 }

int bsize Buffer b  ) 
 

Definition at line 36 of file Buffer.c.

References Buffer::n.

Referenced by al_send_byte(), and al_send_request().

00040 {
00041   return b->n;
00042 }

int btail Buffer b  ) 
 

Definition at line 54 of file Buffer.c.

References Buffer::tail.

00058 {
00059   return b->tail;
00060 }

void bwrite Buffer b,
void *  data
 

Definition at line 63 of file Buffer.c.

References Buffer::data, data, Buffer::full, Buffer::head, Buffer::len, Buffer::n, and Buffer::tail.

Referenced by al_arq_received(), al_arq_request(), al_send_byte(), al_send_request(), channel_write(), place_rcpc(), send_closing_flag(), and send_to_al().

00069 {
00070   int offset = b->head*b->len;
00071   memcpy(b->data+offset, data, b->len);
00072 
00073   if ((b->head == b->tail) && b->full) {
00074     b->tail++;
00075     if (b->tail==b->n)
00076       b->tail=0;
00077   }
00078   b->head++;
00079 
00080   if (b->head == b->n)
00081     b->head=0;
00082   if (b->head == b->tail)
00083     b->full=1;
00084 }

void closebuffer Buffer b  ) 
 

Definition at line 145 of file Buffer.c.

References Buffer::data.

Referenced by close_channel().

00149 {
00150   free(b->data);
00151   free(b);
00152 }

Buffer* mkbuffer int  n,
size_t  len
 

Definition at line 8 of file Buffer.c.

References Buffer::data, Buffer::full, Buffer::head, Buffer::len, Buffer::n, and Buffer::tail.

Referenced by new_al_receiving_entity(), new_al_sending_entity(), and new_channel().

00014 {
00015   Buffer *r;
00016 
00017   r = (Buffer *) malloc(sizeof(Buffer));
00018   if (r == NULL) 
00019     return NULL;
00020   
00021   r->data = (void *) malloc(n * len);
00022   if (r->data == NULL) {
00023     free(r);
00024     return NULL;
00025   }
00026   memset(r->data, 0, n * len);
00027   r->head=0;
00028   r->tail=0;
00029   r->full=0;
00030   r->n=n;
00031   r->len=len;
00032   return r;
00033 }


Generated on Sun Jul 16 16:27:45 2006 by  doxygen 1.3.9.1