/* 
*	file: nikonServerMessageQueue.h
*	author: Eric J Martin
*	
*	copyright: MBARI 2013
*
*	Defines two similar classes which employ queues of 
*	information for server interaction.
*
*/
#pragma once

#ifndef NIKONSERVERMESSAGEQUEUE_H_
#define	NIKONSERVERMESSAGEQUEUE_H_

#include <queue>
#include "..\common\nikonMessage.h"

/*
*	Class for strings to be enqueued by the server thread and responded 
*	to in the camera thread.
*/
class nikonServerMessageQueue
{
	typedef struct {
		char msgbuf[ulMaxNikonTotalPacketSize_c];
		unsigned long msglen;
		unsigned long srcID;
	} nikonPacket;


public:
	nikonServerMessageQueue(void);
	~nikonServerMessageQueue(void);
	bool newRecvMsg();
	bool newSendMsg();

	bool retrieveRecvPacket(char * destbuff, int &destlen, int &destID);
	bool enqueueRecvPacket(char * srcbuff, int srclen, int srcID);
	bool retrieveSendPacket(char * destbuff, int &destlen, int &destID);
	bool enqueueSendPacket(char * srcbuff, int srclen, int srcID);


private:

	std::queue<nikonPacket> recvQ;	// messages received by the server
	std::queue<nikonPacket> sendQ;	// messages to be sent by the server.
	unsigned long ulQueueMaxSize;

};

/*
*	Class for strings to be queue from the trigger thread and read in by
*	the camera thread. i.e. every trigger creates a filename and records
*	the time  for input when the image actually arrives from the camera.
*/
class stringQueue
{
	static const int iMaxQueueSize = 15;
	static const int iMaxBuffSize = 256;
	typedef struct {
		char buff[256];
		int msglen;
		char exifDTOrig[20];	// DateTimeOriginal metadata string
		char exifDTOrigSS[4];	// DateTimeOriginal Subseconds metadata string
	} sString;

public:
	stringQueue(void);
	~stringQueue(void);
	
	bool enqueueString(char * srcbuff, int srclen, char * srcExifDTOrig, char * srcExifDTOrigSS);
	bool retrieveString(char * destbuff, int  &destlen,char * destExifDTOrig, char * destExifDTOrigSS);

private:
	std::queue<sString> stringQ;

};

#endif //NIKONSERVERMESSAGEQUEUE_H_