
#define PROTOCOL_INITIAL 10
#define PROTOCOL_EXTEND  10

#include "time.h"

class ProtocolRoot {
	HANDLE hSem;
	ProtocolRoot **ppColl;
	unsigned int count, alloc;

protected:
	void CollAdd (ProtocolRoot *);
	unsigned int CollGetCount () const;
	ProtocolRoot *CollGet (unsigned int nr) const;
	ProtocolRoot *pParentObject;
	time_t start_time;
	time_t end_time;

	ProtocolRoot (int hasSemaphore);
	virtual ~ProtocolRoot ();

	void SetParent (ProtocolRoot *);
public:
	void EnterCS ();
	void LeaveCS ();
} ;

#define PROTOCOL_CALL_SIZE				20
#define PROTOCOL_CALL_PARAMETERS	    40
#define PROTOCOL_CALL_RESULT		    40

class ProtocolCall : public ProtocolRoot {
	char sCall[PROTOCOL_CALL_SIZE];
	char sParameters[PROTOCOL_CALL_PARAMETERS];
	char sResult[PROTOCOL_CALL_RESULT];
public:
	ProtocolCall (const char *call, const char *parameters);
	virtual ~ProtocolCall ();
	void SetResult (const char *result);
	unsigned int GetLine (unsigned int object_id, unsigned int id, char *buffer, unsigned int buflen) const;
} ;

class ProtocolObject : public ProtocolRoot {
	int opened;
public:
	ProtocolObject ();
	virtual ~ProtocolObject ();
	void SaveClose ();
	void SaveAddCall (ProtocolCall *);
	unsigned int GetLine (unsigned int id, char *buffer, unsigned int buflen) const;
	inline unsigned int GetCallCount () const { return CollGetCount (); }
	inline ProtocolCall *GetCall (unsigned int i) const { return (ProtocolCall *) CollGet (i); }
} ;


class Protocol : public ProtocolRoot {
public:
	Protocol ();
	virtual ~Protocol ();
	void SaveAddObject (ProtocolObject *);
	inline unsigned int GetObjectCount () const { return CollGetCount (); }
	inline ProtocolObject *GetObject (unsigned int i) const { return (ProtocolObject *) CollGet(i); }
} ;

Protocol *GetStaticProtocolObject ();


