//=-- TestPlugin.cpp - -------------------------------------------------------=
//
//  PLUGIN DESCRIPTION:
//
//  PLUGIN AUTHOR:
//    Chris Lattner, Author of Magicstats  (sabre@nondot.org)
//
//  PLUGIN HOMEPAGE:
//     http://www.nondot.org/MagicStats/
//
//  PLUGIN VERSION / COMPATIBILITY:
//     TestPlugin v1.0 / MagicStats 2.0+
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-2000 Chris Lattner
//=---------------------------------------------------------------------------=

#include "PagePlugin.h"
#include "SerializeEx.h"
#include "VarTable.h"

class TestPlugin : public PluginTemplate<PagePlugin,TestPlugin> {
public:
  inline static unsigned int GetCurrentVersion() {
    return 100;                       // Version 1.00
  }

  inline static const char *GetPluginName() {
    return "TestPlugin";
  }

  TestPlugin(int &CE) { 
    CE = 0;
    Flags = FAutoFilter;
  }

  // The full name consists of all of the data settings that alter the data 
  // that is kept track of and stored.
  void GetFullName(VarTable &, String &fullName, int updateFreq) {
    fullName = String::IntToStr(updateFreq) + Name;
  }

  void ProcessAccess(AccessFormatPlugin &A) {
    URLs.AddToTail("<a href=\"" + A.GetURL() + "\">" + A.GetURL() + 
		   "</a> - " + A.GetHost());
  }
  
  void OutputHTML(ostream &O, VarTable &) {
    LinkedList<String>::Iterator I = URLs.GetIterator();

    O << "Pages visited - Host who visited... <ol>\n";
    for (; I; I++) {
      O << *I << "<br>\n";
    }
    O << "</ol>\n";
  }

  void ResetState() {
    URLs.ClearList();
  }
  
  void LoadState(Serialize &I) {
    unsigned int Version = 0;

    ResetState();
    I >> Version;
    
    // Check version number...
    switch (Version) {
    case 100:                  // Version 1.00
      I >> URLs;
      break;
      
    default:
      cout << "Serialized " << Name << " Page plugin is of a version that cannot "
           << "be deserialized\nwith this version of the plugin.  Reseting state.\n";
      break;
    }
    
  }
  
  void SaveState(Serialize &O) {
    O << GetCurrentVersion();  // Serialize the Version number
    O << URLs;
  }
private :
  LinkedList<String> URLs;
};

INIT_PLUGIN(TestPlugin);
