/*****************************************************************************
* 	Project 	: Network Based Message Queue System		    **
*	Course		: CIS 650 - Software Engineering		    **
*	Location 	: /research/paraducks3/courses/cis650/proj/rt	    **
*	File		: rtwl.h					    **
*	Description 	: Waiting List class declaration.		    **
*****************************************************************************/

#ifndef RTWL_H
#define RTWL_H

class WaitItem {
public:
  int type;              /* type of the message a process is waiting for */
  int sockFd;         /* the socket descriptor the process communicates thru*/
  WaitItem(int ty,int sockId); /* constructor */
  WaitItem(int ty); /* constructor */
};

class WaitListItem      /* an item of the waitlist */
{
public: 
  WaitItem*    waitItemPtr; /*pointer to wait Item*/
  WaitListItem* next;      /* pointer to next element  on list */
  WaitListItem(int ty, int sfd); /* constructor */
  WaitListItem(int ty);         /* constructor*/
  
  WaitListItem();      /* constructor to create a dummy item */
 
};

class WaitList
{                  /* list of waiting processes */
private:
  WaitListItem* first;   /* pointer to the head of the list */
  WaitListItem* last;    /* pointer to the tail */
  WaitListItem* counter; /* counter for iteration */
  int countItem;
public:
  WaitList();
  
  void add_item(int key,int sockId); /* add a waiting process to list */
  WaitItem* delete_item(int key);         /* delete a process with type = key */
  int is_empty();                    /* is the list empty */
  WaitItem* next();                        /* return the next key */
  void check_and_delete(int sockId); /* check if the socket is on the queue
		and if it is then delete it */
  int get_count_of_waiting_processes() ;
  void reset();                      /* reset the counter to the head*/
};                                          /* of the list */

#endif /* RTWL_H */

