/*
 * (c) 2005 Research Group Dr. Fuhrmann, University of Karlsruhe, Germany
 * All rights reserved.
 *
 * Author:
 *         Johannes Franz
 *
 * $Id: threads.h,v 1.11 2005/11/23 17:51:35 kutzner Exp $
 *
 */


#ifndef THREADS_H
#define THREADS_H


#include "datastructs.h"
#include <thread.h>

// delegate Timers to the apropriate threads
class cMainThread : public cThread {
		cSchedMsgQueue *queue;
		cCondWait w;
		// socket descriptor 
		int sd;
		std::list<cJob *> jobs;

	public:

		cMainThread() {}
		~cMainThread() {}
		void Action();
		void handle_message();
		void handle_timer(list<timer> t);
		void handle_rc(const cSchedMsgRC& m);
		void handle_suppress(const cSchedMsgSuppress& m);
		bool isInnerNode(const cSchedMsg& msg);
		bool isLeafNode(const cSchedMsg& msg);

};

// this thread will search the timers periodically

class cTimerSearch : public cThread {
	static const int interval =  600;
	int sd;
	class Job {
		int absTime;
		char * channel;
	};
	std::list<Job> * ListOfJobs;
public:
	cTimerSearch(int sd);
	void Action();

};




// this thread will receive messages
class cIgorRecv : public cThread {
	private:
		cSchedMsgQueue * queue;
		int socketd;
		int igor_recv(int sd, void **, int *, sa_igor *, sa_igor *);
		cCondWait *w;
	public:
		cIgorRecv(cSchedMsgQueue * q, int sd, cCondWait *cw) : queue(q), socketd(sd), w(cw) {}
		
		// the queue is used to store received msgs from igor socket sd
		void Action();

};

// this thread gets activated when a timer fires
class cFired : public cThread {
};

#endif // THREADS_H
