//
// CRAM: CREATE Real-time Applications Manager
// See the copyright and acknowledgment of authors in the file COPYRIGHT
//
//// Server.h -- the CRAM service interface class ////
//
// This is the base class for CRAM-managed services. Each program that wants to be used with CRAM 
// will have a simple "wrapper" class that derives from Server. In this class, the start method 
// will start the actual application (see the ClockService example).
//

#ifndef __SERVER_INCLUDE__
#define __SERVER_INCLUDE__

#include "Program.h"

namespace cram {

// The CRAM Service class

class Server : public Program {
						// No additional state extending Program
						
public:					// Service operations (all virtual; override them in your application)
	virtual void initialize(void);				// may be ignored

	virtual void start(void) = 0;				// subclasses normally implement at least these two methods
	virtual void stop(void);	
	
	virtual void suspend(void) {};				// may be ignored
	virtual void resume(void) {};				// may be ignored
	
						// My command switch method (calls the above methods)
	virtual int handle_packet(in_addr_t sender, CRAMPacketHeader * pkt);
	
						// The constructor
	Server(char * name, unsigned short lport, unsigned short eport);
};


// The CRAM Service wrapper class (held in a list in the node manager)

class ServiceRecord : public Server {

public:					// data used by the node manager
	bool mHeartrate;				// its heartrate, or 0
	time_t mLastbeat;				// the time of the last heartbeat
	time_t mNextbeat;				// the time of the expected next heartbeat
	
	void start(void) {};			// provide degenerate implementations of these two methods
	void stop(void) {};	
	
	ServiceRecord(char * name, unsigned short lport, unsigned short eport, int pid);

};

}

#endif

