Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

net/prohandler.cpp

Go to the documentation of this file.
00001 
00017 #include <assert.h>
00018 #include <stdio.h>
00019 #include "prohandler.h"
00020 #include "mem/memory.cpp"
00021 
00022 #ifndef _NET_PROHAN_CPP_
00023 #define _NET_PROHAN_CPP_
00024 
00025 static const char phdid[] = "\100$ Free Agent: prohandler.cpp, v 0.1 2002/05/29 red0x Exp $";
00026 
00032 protocolHandler::protocolHandler()
00033 {
00034     //myPro = 0;
00035     packets = 0;
00036     top = bottom = NULL;
00037 }
00038 
00048 int protocolHandler::add(char *pkt)
00049 {
00050     {assert(pkt != NULL);}
00051     pronode_t *newNode;
00052     agent_new(&newNode);
00053     {assert(newNode != NULL);}
00054     newNode->payload = pkt;
00055     if (top == NULL)
00056         {
00057             top = newNode;
00058             bottom = top;
00059         }
00060         else //nope
00061         {
00062             //insert at end
00063             bottom->next = newNode;
00064             newNode->prev = bottom;
00065             bottom = newNode;
00066         }
00067         packets++;
00068     return packets;
00069 }
00070 
00075 bool protocolHandler::hasNext(void)
00076 {
00077     return (packets > 0);
00078 }
00079 
00088 char *protocolHandler::next(void)
00089 {
00090     if(!hasNext())
00091         return NULL;
00092     //top is not NULL
00093     {assert(top != NULL);}
00094     char *data;
00095     data = top->payload;
00096     top->payload = NULL;
00097     if(top == bottom)
00098     {
00099         //delete it
00100         agent_zaparr(top);
00101         top = bottom = NULL;
00102     }
00103     else
00104     {
00105         pronode_t *t = top;
00106         top->next->prev = NULL;
00107         top = top->next;
00108         t->prev = t->next = NULL;
00109         agent_zaparr(t);
00110     }
00111     packets--;
00112     return data;
00113 }
00114 
00115 #endif

Generated at Thu May 30 15:12:33 2002 for Freeagent by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001