/* LICENSE:
  =========================================================================
    CMPack'04 Source Code Release for OPEN-R SDK 1.1.5-r2 for ERS7
    Copyright (C) 2004 Multirobot Lab [Project Head: Manuela Veloso]
    School of Computer Science, Carnegie Mellon University
    All rights reserved.
  ========================================================================= */

#ifndef INCLUDED_LogReader_h
#define INCLUDED_LogReader_h

#include <stdio.h>
#include <deque>
#include "../../../agent/headers/DogTypes.h"

using std::deque;

class RobotDataPacket;

/*------------------------------------------------------------------
CLASS
  LogReader

DESCRIPTION
  Reads log files created about the robot.
------------------------------------------------------------------*/
class LogReader {
public:
  LogReader();
  ~LogReader();

  void setSource(FILE *log_file, uint data_length=0);

  void seekToStart();

  // Closes the file descriptor
  void closeSource();

  //. ----------------------------------------------------------------
  // Set packet to the data from the next packet.
  // INPUT
  //   data_length - the space available for data in packet->data
  //   idx - an index into the cached queue, or -1 if we read from thefile
  //   initialize_packet_data - does this function initialize packet->data?
  // OUTPUT
  //   packet - the place to store the packet information
  // RETURNS
  //   success - true if the packet was successfully read
  // -----------------------------------------------------------------
  bool readNextPacket(RobotDataPacket *packet,
		      uint data_length,
		      int idx=-1,
		      bool initialize_packet_data=false);

  unsigned int size() { return packet_q.size(); }

private:
  FILE *logFile;
  deque<RobotDataPacket*> packet_q;
};

#endif
