// =====================================================================
//  $Id: TSoftwareClockModule.hh,v 1.2 2003/06/27 10:00:18 goiwai Exp $
//  $Name: CLDAQ-1-06-02 $
// =====================================================================
#ifndef __TSOFTWARECLOCKMODULE_HH
#define __TSOFTWARECLOCKMODULE_HH

#include "Tglobals.h"
#include "TSoftwareModule.hh"
#include "TSystemClock.hh"

class TDataElement;
class TSystemClock;

class TSoftwareClockModule
  : public TSoftwareModule
{
  public:
    enum { 
      tStringTime,
      tIntegerTime,
      tElapsedTimeOfLastInitialize,
      tElapsedTimeOfLastUpdate,
      tYear,
      tMonth,
      tDay,
      tHour,
      tMinute,
      tSecond,
      tNumberOfChannels
    };

  private:
    TSystemClock theSystemClock;

  public:
    TSoftwareClockModule( Tint nchannel = tNumberOfChannels );
    TSoftwareClockModule( const TSoftwareClockModule& right );
    ~TSoftwareClockModule();

  public:
    const TSoftwareClockModule& operator=( const TSoftwareClockModule& right );
    Tbool operator==( const TSoftwareClockModule& right ) const;
    Tbool operator!=( const TSoftwareClockModule& right ) const;

  public:
    Tint Clear();
    Tint Update();
    Tint Initialize();
    Tvoid FillData( TDataElement& element, Tint channel );

  public:
    const TSystemClock& GetSystemClock() const;
    TSystemClock& GetSystemClock();
    Tvoid SetSystemClock( const TSystemClock& clock );

  public:
    Tstring GetStringTime();
    Tint GetIntegerTime();
    Tstring WhatTimeIsItNow();
    Tstring WhatTimeIsIt( Tint second = -1 );
    Tint GetElapsedTimeOfLastInitialize( const Tstring& unit = Tsec );
    Tint GetElapsedTimeOfLastUpdate( const Tstring& unit = Tsec );
    Tint GetYear();
    Tint GetMonth();
    Tint GetDay();
    Tint GetHour();
    Tint GetMinute();
    Tint GetSecond();

};

inline const TSystemClock& TSoftwareClockModule::GetSystemClock() const
{
  return( theSystemClock );
}

inline TSystemClock& TSoftwareClockModule::GetSystemClock()
{
  return( theSystemClock );
}

inline Tvoid TSoftwareClockModule::SetSystemClock( const TSystemClock& clock )
{
  theSystemClock = clock;
  return;
}

inline Tstring TSoftwareClockModule::GetStringTime()
{
  return( theSystemClock.WhatTimeIsItNow() );
}

inline Tint TSoftwareClockModule::GetIntegerTime()
{
  theSystemClock.Update();
  return( theSystemClock.GetTime() );
}

inline Tstring TSoftwareClockModule::WhatTimeIsItNow()
{
  return( theSystemClock.WhatTimeIsItNow() );
}

inline Tstring TSoftwareClockModule::WhatTimeIsIt( Tint second )
{
  return( theSystemClock.WhatTimeIsIt( second ) );
}

inline Tint TSoftwareClockModule::GetYear()
{
  return( theSystemClock.GetYear() );
}

inline Tint TSoftwareClockModule::GetMonth()
{
  return( theSystemClock.GetMonth() );
}

inline Tint TSoftwareClockModule::GetDay()
{
  return( theSystemClock.GetDay() );
}

inline Tint TSoftwareClockModule::GetHour()
{
  return( theSystemClock.GetHour() );
}

inline Tint TSoftwareClockModule::GetMinute()
{
  return( theSystemClock.GetMinute() );
}

inline Tint TSoftwareClockModule::GetSecond()
{
  return( theSystemClock.GetSecond() );
}

inline Tint TSoftwareClockModule::GetElapsedTimeOfLastInitialize( const Tstring& unit )
{
  return( theSystemClock.GetElapsedTime( unit ) );
}

inline Tint TSoftwareClockModule::GetElapsedTimeOfLastUpdate( const Tstring& unit )
{
  return( theSystemClock.GetElapsedTimeOfLastUpdate( unit ) );
}

#endif
