// file: $isip/class/asr/Machine/Machine.h
// version: $Id: Machine.h 8577 2002-08-14 00:04:41Z alphonso $
//

// make sure definitions are only made once
//
#ifndef ISIP_MACHINE
#define ISIP_MACHINE

#ifndef ISIP_VECTOR_DOUBLE
#include <VectorDouble.h>
#endif

#ifndef ISIP_STRING
#include <String.h>
#endif

#ifndef ISIP_DOUBLE
#include <Double.h>
#endif

#ifndef ISIP_LONG
#include <Long.h>
#endif

#ifndef ISIP_NAME_MAP
#include <NameMap.h>
#endif

// Machine: a class used to represent a machine and its attributes
//
class Machine {
  
  //--------------------------------------------------------------------------
  //
  // public constants
  //
  //--------------------------------------------------------------------------
public:
  
  // define the class name
  //
  static const String CLASS_NAME;

  //----------------------------------------
  //
  // other important constants
  //
  //----------------------------------------

  // define the algorithm choices
  //
  enum PROTOCOL { REMOTE_SHELL = 0, SECURE_SHELL,
		  DEF_PROTOCOL = REMOTE_SHELL };

  //----------------------------------------
  //
  // i/o related constants
  //
  //----------------------------------------

  static const String DEF_PARAM;
  static const String PARAM_PROTOCOL;
  static const String PARAM_NODE_NAME;
  static const String PARAM_ARCHITECTURE;
  static const String PARAM_NUM_PROCESSORS;
  static const String PARAM_PROCESSOR_SPEED;
  static const String PARAM_MAIN_MEMORY;
  static const String PARAM_SWAP_MEMORY;
  static const String PARAM_OS_NAME;
  static const String PARAM_OS_VERSION;  

  //----------------------------------------
  //
  // default values and arguments
  //
  //----------------------------------------
  
  // default values
  //
  static const long DEF_NUM_PROCESSORS = 1;
  static const double DEF_PROCESSOR_SPEED = 3.0e8;
  static const double DEF_MAIN_MEMORY = 0.0;
  static const double DEF_SWAP_MEMORY = 0.0;    

  // define the static NameMap objects
  //
  static const NameMap PROTOCOL_MAP;
  
  //---------------------------------------------------------------------------
  //
  // protected data
  //
  //---------------------------------------------------------------------------
  protected:

  // declare the preferred connection protocol for the machine (rsh/ssh)
  //
  PROTOCOL protocol_d;
  
  // declare the nodename of the machine (isip100.isip.msstate.edu)
  //
  String node_name_d;
  
  // declare the machine architecture (pentium/sparc)
  //
  String architecture_d;

  // declare the number of processors on the machine (single/dual)
  //
  Long num_processors_d;
  
  // declare the speed of the processor on the machine (8.0e08/1.0e09)
  //
  VectorDouble speed_d;
  
  // declare the amount of main memory on the machine (1.0e09/2.0e09)
  //
  Double main_memory_d;

  // declare the amount of swap space on the machine (1.0e06/2.0e06)
  //
  Double swap_memory_d;  

  // declare the operating system on the machine (solaris/linux)
  //
  String os_d;

  // declare the operating system version on the machine (v_7.0/v_8.0)
  //
  String os_version_d;
  
  // declare a static debug level for all class instantiations
  //
  static Integral::DEBUG debug_level_d;
  
  // a static memory manager
  //
  static MemoryManager mgr_d;
  
  //---------------------------------------------------------------------------
  //
  // required public methods
  //
  //---------------------------------------------------------------------------
public:
  
  // method: name
  //
  static const String& name() {
    return CLASS_NAME;
  }
  
  static boolean diagnose(Integral::DEBUG debug_level);
  
  // debug methods
  //
  boolean debug(const unichar* msg) const;

  // method: setDebug
  //
  static boolean setDebug(Integral::DEBUG arg) {
    debug_level_d = arg;
    return true;
  }
  
  // method: destructor
  //
  ~Machine() {
    clear();  
  }

  // method: default constructor
  //
  Machine();

  // method: copy constructor
  //
  Machine(const Machine& arg) {
    assign(arg);
  }

  // method: assign
  //
  boolean assign(const Machine& arg);
  
  // method: sofSize
  //
  long sofSize() const {
    return (PROTOCOL_MAP.elementSofSize() + node_name_d.sofSize() + architecture_d.sofSize() + num_processors_d.sofSize() + speed_d.sofSize() + main_memory_d.sofSize() + swap_memory_d.sofSize() + os_d.sofSize() + os_version_d.sofSize());
  }

  // method: read
  //
  boolean read(Sof& sof, long tag) {
    return read(sof, tag, name());
  }
  boolean read(Sof& sof, long tag, const String& name);
  
  // method: write
  //
  boolean write(Sof& sof, long tag) const {
    return write(sof, tag, name());
  }
  boolean write(Sof& sof, long tag, const String& name) const;
  

  boolean readData(Sof& sof, const String& pname = DEF_PARAM,
		   long size = SofParser::FULL_OBJECT, boolean param = true,
		   boolean nested = false);
  boolean writeData(Sof& sof, const String& pname =  DEF_PARAM) const;
  
  // method: eq
  //
  boolean eq(const Machine& arg) const;

  // method: new
  //
  static void* operator new(size_t arg) {
    return mgr_d.get();
  }

  // method: new[]
  //
  static void* operator new[](size_t arg) {
    return mgr_d.getBlock(arg);
  }

  // method: delete
  //
  static void operator delete(void* arg) {
    mgr_d.release(arg);
  }

  // method: delete[]
  //
  static void operator delete[](void* arg) {
    mgr_d.releaseBlock(arg);
  }

  // method: setGrowSize
  //
  static boolean setGrowSize(long arg) {
    return mgr_d.setGrow(arg);
  }

  // method: clear
  //
  boolean clear(Integral::CMODE cmode = Integral::DEF_CMODE);
  
  //---------------------------------------------------------------------------
  //
  // class-specific public methods
  //
  //---------------------------------------------------------------------------

  // method: getProtocol
  //
  PROTOCOL getProtocol() {
    return protocol_d;
  }
  
  // method: setProtocol
  //
  boolean setProtocol(PROTOCOL arg) {
    protocol_d = arg;
    return true;
  }
  
  // method: getNodeName
  //
  String& getNodeName() {
    return node_name_d;
  }
  
  // method: setNodeName
  //
  boolean setNodeName(String& arg) {
    return node_name_d.assign(arg);
  }
  
  // method: getArchitecture
  //
  String& getArchitecture() {
    return architecture_d;
  }
  
  // method: setArchitecture
  //  
  boolean setArchitecture(String& arg) {
    return architecture_d.assign(arg);
  }
  
  // method: getNumProcessors
  //
  long getNumProcessors() {
    return (long)num_processors_d;
  }
  
  // method: setNumProcessors
  //  
  boolean setNumProcessors(long arg) {
    return (num_processors_d = arg);
  }

  // method: getProcessorSpeed
  //
  VectorDouble& getProcessorSpeed() {
    return speed_d;
  }
  
  // method: setProcessorSpeed
  //
  boolean setProcessorSpeed(VectorDouble& arg) {
    return speed_d.assign(arg);
  }
  
  // method: getMainMemory
  //
  double getMainMemory() {
    return (double)main_memory_d;
  }
  
  // method: setMainMemory
  //  
  boolean setMainMemory(double arg) {
    return (main_memory_d = arg);
  }
  
  // method: getSwapMemory
  //
  double getSwapMemory() {
    return (double)swap_memory_d;
  }
  
  // method: setSwapMemory
  //  
  boolean setSwapMemory(double arg) {
    return (swap_memory_d = arg);
  }
  
  // method: getOS
  //
  String& getOS() {
    return os_d;
  }
  
  // method: setOS
  //  
  boolean setOS(String& arg) {
    return os_d.assign(arg);
  }
  
  // method: getOSVersion
  //
  String& getOSVersion() {
    return os_version_d;
  }
  
  // method: setOSVersion
  //  
  boolean setOSVersion(String& arg) {
    return os_version_d.assign(arg);
  }
  
  //---------------------------------------------------------------------------
  //
  // private methods
  //
  //---------------------------------------------------------------------------
  private:

};

//end of include file
//
#endif
