//=-- AccessLog.h - access_log file manipulator ------------------------------=
//
//   This class encapsulates the notion of a single access_log file.  The 
//   source of the file is abstracted away through the FileStream plugin 
//   interface, and the format of the log is abstracted away through the 
//   AccessFormatPlugin interfaces.  This class simply coordinates access
//   between the two.
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-2000 Chris Lattner
//=---------------------------------------------------------------------------=

#ifndef ACCSSLOG_H
#define ACCSSLOG_H

#include "MSString.h"
#include "MSFilename.h"
#include <time.h>

class FileStreamPlugin;
class AccessFormatPlugin;

class AccessLog {
public:
  inline static AccessLog *Create(const String &PluginName, 
                                  const MSFilename &Filename, 
								  const String &Domain){
    int CE = 0;
    AccessLog *Result = new AccessLog(PluginName, Filename, Domain, CE);
    if (CE) {
      delete Result;
      Result = 0;
    }
    return Result;
  }

  AccessLog(const String &PluginName, const MSFilename &Filename, 
            const String &Domain, int &Error);
  ~AccessLog();

  // ReadAccess - Read one line from the access log and return a pointer to the
  // AccessFormatPlugin that it corresponds to.  If EOF is hit, a null pointer 
  // is returned...
  //
  AccessFormatPlugin *ReadAccess();

  // LoadState - Load current state from serialization record...
  void LoadState(Serialize &I);

  // SaveState - Save current state out to a serialization record...
  void SaveState(Serialize &O);

private:
  int NumAccesses;                  // Number of accesses read from file...
  FileStreamPlugin *File;           // The access_log file.
  AccessFormatPlugin *AccessFormat; // The String->Access converter...

  time_t LogChangedTime;            // Used for EOF handling, see Load/SaveState

  MSFilename Filename;              // Filename of accesslog, for error msgs

  // LastStreamPosition - Hold the file stream location from before the last
  // access that has been read.  The reason for this is that when we serialize
  // the access log, we want to forget that we have read one access... because
  // that access has not yet been dealt with...
  //
  unsigned long LastStreamPosition;
};

#endif
