//=-- PlatformAbstraction.h - Definition of the Platform Abstraction Layer ---=
//
//  This file gives defines the interface to the system specific aspects of 
//  MagicStats.  The corresponding cpp files are seperated per platform.
//
//  This file also defines a macro based on which platform is currently 
//  available.  Currently supported are the UNIX and WINDOWS macros, though
//  more may be added later (and more divisions in the unix front)
//
//=---------------------------------------------------------------------------=
//  This file is copyright (c) 1997-1998 Chris Lattner
//=---------------------------------------------------------------------------=

#ifndef PLATFORMABSTRACTION_H
#define PLATFORMABSTRACTION_H

#include "Object.h"

// Figure out what platform we are running on.
#if defined(WIN32) || defined(_WIN32)         // It's Winderz!
  #define WINDOWS
#else                  // Lets just assume its Unix.
  #define UNIX
#endif


//=---------------------------------------------------------------------------=
//    Disable warnings in VC++...
//=---------------------------------------------------------------------------=
#ifdef WINDOWS  
// VC++ gives me this dumb warning... and I can't fix it in code, so disable
// it.  This warning says that if you ever do X, you'll get an error.  I never
// do X though, so I never get the error... even if I did, it would be an 
// error, so this warning is frivolous!
#pragma warning(disable : 4284)

// VC++ gives me annoying warnings related to templates and dllexporting.  I
// believe it's a bug in the compiler, so I'm disabling the warning...
#pragma warning(disable : 4251)

// VC++ give me REALLY annoying messages relating to the fact that some of the
// mangled names generated by the compiler are > 255 chars long and get 
// truncated.  What kind of company designs a compiler with a symbol table with 
// fixed sized entries!?!?!
// 
#pragma warning(disable : 4786)
#endif

class MSFilename;
template <class T> class LinkedList;
template <class P, class S> class DataPair;
class String;

class MSAPI PlatformAbstraction {
public :
  PlatformAbstraction();     // Initialize platform specific stuff...
  ~PlatformAbstraction();    // Shutdown platform specific stuff...

  // The suffix (or extension) of plugin files.  For unix, this is typically
  // .so and for Windows, typically .dll
  //
  static const char *PluginSuffix;

  // The official preferred directory seperator. Ex: '/' on unix and '\' on DOS
  //
  static const char  DirectorySeperator;

  // LoadPlugin - Loads a shared object into this address space, returns an 
  // error message on error, or a null pointer on success....
  //
  static const char *LoadPlugin(const MSFilename &Filename);

  enum FileType {
    RegularFile, Directory
  };

  // ScanDirectory - Stuffs all directory entries of type FT into the linked 
  // list.
  //
  static int ScanDirectory(const MSFilename &Directory, 
                           LinkedList<String> &Dest, FileType FT);

  // DecodeFilename - Decode filename from a possible tilde representation.
  //   For example, convert ~sabre to /home/sabre or ~/.MagicStats to
  //   /home/sabre/.MagicStats/ etc.
  //
  static void DecodeFilename(String &Filename);

  // ChDir - Set the current working directory in the local filesystem.  Return
  // TRUE if an error occurred.
  //
  static int ChDir(const MSFilename &Directory);

  // GetCWD - Get the current working directory in the local filesystem.  
  // Returns an in"Valid()" MSFilename object is an error occurs.
  //
  static MSFilename GetCWD(void);

  // GetUserName - Return the name of the user currently logged in.  Different
  // platforms have different restrictions on user name lengths, so don't depend
  // on the user name being <= 8 characters...
  //
  static String GetUserName(void);

  // Unix and windows don't agree on any one function to do case insensitive
  // string comparisons.  Because Unix is better than Windows, we name the 
  // function the unix name.  For systems without a version of this function,
  // we can always define it ourselves.
  //
  static int strcasecmp(const char *s1, const char *s2);

  // CreateHTMLSymlink - Creates a link between OutputFilename and LinkFilename.
  // on a unix platform, this would create an actual symlink between the two 
  // files, but on a machine without link support, this could create a meta 
  // refresh page to forward the user to their destination...
  //
  static void CreateHTMLSymlink(const MSFilename &OutputFilename, 
                                const MSFilename &LinkFilename);

  // GetServerConfigFilename() - Return the platform specific location for the
  // server configuration file.
  //
  static const char *GetServerConfigFilename(void);


  // GetSystemTime() - Return the time in seconds (with as much precision as 
  // possible) to the caller from an abitrary reference point (like when the 
  // machine was booted or 1970, whatever.  :)
  //
  static double GetSystemTime();


  // InstallInterruptHandler(int *x) - Install a signal handler to catch the
  // interrupt character (ie CTRL-C).  When pressed, set the specified int
  // to a true value...
  //
  static void InstallInterruptHandler(volatile int *Notifier);
};

#endif
