/****************************************************************************/
/* Copyright (c) 2015 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : FastTime.h                                                    */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 03/07/2015                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _FastTime_H
#define _FastTime_H

#if 0
#define FASTTIME

#include <time.h>
#include <stdlib.h>
#include "ourTypes.h"
#include "Syslog.h"
#include "SharedData.h"
#include "TimeIF.h"

/*
CLASS 
FastTime

DESCRIPTION
Artificial time for use in simulation 

AUTHOR
Henthorn
*/
#define FAST_TIME_DEFAULT  False

typedef enum{
    UNITIALIZED=-1,
    DISABLED=0,
    ENABLED=1
}tri_state_t;

class Simulator;
class Supervisor;

class FastTime {
  friend Simulator;
  friend Supervisor;

public:

   static FastTime* instance();
   void getFastTime(struct  timespec *ts);
   void getFastTime(TimeIF::TimeSpec *ts);
   Boolean fastTimeOn();
    // constructor (private, b/c singleton)
    FastTime();
    // virtual destructor
    virtual ~FastTime();
    
private:
    // local enable state
    static tri_state_t _fastTimeState;
    // reference to singleton instance (created by instance())
    static FastTime* _instance;

   // Initialize the simulation time. Default to current system time.
   void initialize(TimeIF::TimeSpec *ts = NULL);
   void incrFastTime(int milliseconds);

class MyTime : public SharedData {

  public:
    struct Data {
      TimeIF::TimeSpec ts;
      tri_state_t fastTimeState;
    };

    virtual void MyTime::read()
    {
      SharedData::read((void *)&data);
    }

    virtual void MyTime::write()
    {
      SharedData::write((void *)&data);
    }
    
    // This ensures that only the Time class can instatiate and access
    // the simulation time.
    //
    MyTime()
      : SharedData("FastTime", sizeof(MyTime::Data), SharedData::ReadWrite)
    {
      data.fastTimeState = UNITIALIZED;
    }
    
    // virtual destructor so that
    // SharedData destructor is called
    virtual ~MyTime(){
        Boolean debug = False;
        dprintf("**** MyTime destructor ****\n");
    }

    Data data;
  };

  MyTime  _time;

};

#endif

#endif
