/*
   b_ptr_tm.cpp   Generated by the Ballista(tm) Project data object compiler
   Copyright (C) 1998-2001  Carnegie Mellon University

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

   File generated Wednesday, May 23 at 02:50 AM EDT

TITLE
   b_ptr_tm.cpp
*/

//--------------------------------------------------------------------

#include <errno.h>
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <stream.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "b_ptr_tm.h"

//--------------------------------------------------------------------


 static struct tm tm_struct;
//--------------------------------------------------------------------

CLASSNAME::CLASSNAME()
{
  //DIAL DECLARATIONS HERE

  //generated

   strcpy(_b_ptr_tmTYPENAME,CLASS_STRING);
strcpy(_b_ptr_tmLOCALTIME_R_NOW,"b_ptr_tm_LOCALTIME_R_NOW");
strcpy(_b_ptr_tmGMTIME_R_NOW,"b_ptr_tm_GMTIME_R_NOW");
strcpy(_b_ptr_tmALL_ZERO,"b_ptr_tm_ALL_ZERO");
strcpy(_b_ptr_tmALL_TOP_RANGE,"b_ptr_tm_ALL_TOP_RANGE");
strcpy(_b_ptr_tmALL_OVERFLOW,"b_ptr_tm_ALL_OVERFLOW");
strcpy(_b_ptr_tmALL_MAX,"b_ptr_tm_ALL_MAX");
strcpy(_b_ptr_tmALL_MIN,"b_ptr_tm_ALL_MIN");
}

//--------------------------------------------------------------------
b_param *b_ptr_tm::b_ptr_tmLOCALTIME_R_NOW()
{
   return &_b_ptr_tmLOCALTIME_R_NOW;
}

b_param *b_ptr_tm::b_ptr_tmGMTIME_R_NOW()
{
   return &_b_ptr_tmGMTIME_R_NOW;
}

b_param *b_ptr_tm::b_ptr_tmALL_ZERO()
{
   return &_b_ptr_tmALL_ZERO;
}

b_param *b_ptr_tm::b_ptr_tmALL_TOP_RANGE()
{
   return &_b_ptr_tmALL_TOP_RANGE;
}

b_param *b_ptr_tm::b_ptr_tmALL_OVERFLOW()
{
   return &_b_ptr_tmALL_OVERFLOW;
}

b_param *b_ptr_tm::b_ptr_tmALL_MAX()
{
   return &_b_ptr_tmALL_MAX;
}

b_param *b_ptr_tm::b_ptr_tmALL_MIN()
{
   return &_b_ptr_tmALL_MIN;
}

//--------------------------------------------------------------------
//---------------------------------------------------------------------------
//type name return method

b_param *CLASSNAME::typeName()
{
  return &_b_ptr_tmTYPENAME;
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
int CLASSNAME::distanceFromBase()
{
  return CLASSPARENT::distanceFromBase() +1;
}


//---------------------------------------------------------------------------
void CLASSNAME::typeList(b_param list[], int num)
{
  strcpy(list[num],(char *) typeName());
  CLASSPARENT::typeList(list,num+1);
}
//--------------------------------------------------------------------
  void *CLASSNAME::access(b_param data[])
{
  if (strcmp(data[0],(char *)typeName())!=0)
    return CLASSPARENT::access(data);

  //ACCESS CODE
b_ptr_tm_localtime_r_now = 0;
b_ptr_tm_gmtime_r_now = 0;
b_ptr_tm_all_zero = 0;
b_ptr_tm_all_top_range = 0;
b_ptr_tm_all_overflow = 0;
b_ptr_tm_all_max = 0;
b_ptr_tm_all_min = 0;
   int dataPTR =0;


   dataPTR++;
if (strcmp(data[dataPTR],_b_ptr_tmLOCALTIME_R_NOW)==0)
      b_ptr_tm_localtime_r_now = 1;
   else if (strcmp(data[dataPTR],_b_ptr_tmGMTIME_R_NOW)==0)
      b_ptr_tm_gmtime_r_now = 1;
   else if (strcmp(data[dataPTR],_b_ptr_tmALL_ZERO)==0)
      b_ptr_tm_all_zero = 1;
   else if (strcmp(data[dataPTR],_b_ptr_tmALL_TOP_RANGE)==0)
      b_ptr_tm_all_top_range = 1;
   else if (strcmp(data[dataPTR],_b_ptr_tmALL_OVERFLOW)==0)
      b_ptr_tm_all_overflow = 1;
   else if (strcmp(data[dataPTR],_b_ptr_tmALL_MAX)==0)
      b_ptr_tm_all_max = 1;
   else if (strcmp(data[dataPTR],_b_ptr_tmALL_MIN)==0)
      b_ptr_tm_all_min = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"TM_STRUCT_PTR"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }
 
 time_t time_since_epoch = time(NULL);

 FILE* logFile = NULL;
 if ((logFile = fopen ("/tmp/templateLog.txt","a+")) == NULL)
 {
 exit(99);
 }

if (b_ptr_tm_localtime_r_now==1)
{

 if((localtime_r(&time_since_epoch,&tm_struct))==NULL)
 {
 fprintf(logFile, "LOCALTIME_R_NOW: localtime_r failed in b_ptr_tm. Function not tested\n");
 fclose(logFile);
 exit(99);
 }
 
}

if (b_ptr_tm_gmtime_r_now==1)
{

 if((gmtime_r(&time_since_epoch,&tm_struct))==NULL)
 {
 fprintf(logFile, "GMTIME_R_NOW: gmtime_r failed in b_ptr_tm. Function not tested\n");
 fclose(logFile);
 exit(99);
 }
 
}

if (b_ptr_tm_all_zero==1)
{
 
 tm_struct.tm_sec = 0; /* seconds after the minute [0-60] */
 tm_struct.tm_min = 0; /* minutes after the hour [0-59] */
 tm_struct.tm_hour = 0; /* hours since midnight [0-23] */
 tm_struct.tm_mday = 0; /* day of the month [1-31] */
 tm_struct.tm_mon = 0; /* months since January [0-11] */
 tm_struct.tm_year = 0; /* years since 1900 */
 tm_struct.tm_wday = 0; /* days since Sunday [0-6] */
 tm_struct.tm_yday = 0; /* days since January 1 [0-365] */
 tm_struct.tm_isdst = 0; /* Daylight Savings Time flag */
 
}

if (b_ptr_tm_all_top_range==1)
{

 tm_struct.tm_sec = 60; /* seconds after the minute [0-60] */
 tm_struct.tm_min = 59; /* minutes after the hour [0-59] */
 tm_struct.tm_hour = 23; /* hours since midnight [0-23] */
 tm_struct.tm_mday = 31; /* day of the month [1-31] */
 tm_struct.tm_mon = 11; /* months since January [0-11] */
 tm_struct.tm_year = 9999; /* years since 1900 */
 tm_struct.tm_wday = 6; /* days since Sunday [0-6] */
 tm_struct.tm_yday = 365; /* days since January 1 [0-365] */
 tm_struct.tm_isdst = 1; /* Daylight Savings Time flag */
 
}

if (b_ptr_tm_all_overflow==1)
{

 tm_struct.tm_sec = 61; /* seconds after the minute [0-60] */
 tm_struct.tm_min = 60; /* minutes after the hour [0-59] */
 tm_struct.tm_hour = 24; /* hours since midnight [0-23] */
 tm_struct.tm_mday = 32; /* day of the month [1-31] */
 tm_struct.tm_mon = 12; /* months since January [0-11] */
 tm_struct.tm_year = 0; /* years since 1900 */
 tm_struct.tm_wday = 7; /* days since Sunday [0-6] */
 tm_struct.tm_yday = 366; /* days since January 1 [0-365] */
 tm_struct.tm_isdst = -1; /* Daylight Savings Time flag */
 
}

if (b_ptr_tm_all_max==1)
{

 tm_struct.tm_sec = MAXINT; /* seconds after the minute [0-60] */ 
 tm_struct.tm_min = MAXINT; /* minutes after the hour [0-59] */
 tm_struct.tm_hour = MAXINT; /* hours since midnight [0-23] */
 tm_struct.tm_mday = MAXINT; /* day of the month [1-31] */
 tm_struct.tm_mon = MAXINT; /* months since January [0-11] */
 tm_struct.tm_year = MAXINT; /* years since 1900 */
 tm_struct.tm_wday = MAXINT; /* days since Sunday [0-6] */
 tm_struct.tm_yday = MAXINT; /* days since January 1 [0-365] */
 tm_struct.tm_isdst = MAXINT; /* Daylight Savings Time flag */
 
}

if (b_ptr_tm_all_min==1)
{

 tm_struct.tm_sec = -MAXINT; /* seconds after the minute [0-60] */ 
 tm_struct.tm_min = -MAXINT; /* minutes after the hour [0-59] */
 tm_struct.tm_hour = -MAXINT; /* hours since midnight [0-23] */
 tm_struct.tm_mday = -MAXINT; /* day of the month [1-31] */
 tm_struct.tm_mon = -MAXINT; /* months since January [0-11] */
 tm_struct.tm_year = -MAXINT; /* years since 1900 */
 tm_struct.tm_wday = -MAXINT; /* days since Sunday [0-6] */
 tm_struct.tm_yday = -MAXINT; /* days since January 1 [0-365] */
 tm_struct.tm_isdst = -MAXINT; /* Daylight Savings Time flag */
 
}

 _theVariable=&tm_struct;
 fclose(logFile);
   return &_theVariable;
}

//--------------------------------------------------------------------
  int CLASSNAME::commit(b_param tname)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::commit(tname);
  //COMMIT CODE HERE
//generated

   return 0;
}

//--------------------------------------------------------------------
  int CLASSNAME::cleanup(b_param tname)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::cleanup(tname);
      
  //CLEANUP CODE
//generated

   return 0;
}

//--------------------------------------------------------------------
int CLASSNAME::numDials(b_param tname)
{
  if (!strcmp(tname,(char *)typeName()))
    return NUMBER_OF_DIALS;
  else return CLASSPARENT::numDials(tname);
      
}


//---------------------------------------------------------------------------
int CLASSNAME::numItems(b_param tname,int dialNumber)
{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::numItems(tname,dialNumber);
  switch (dialNumber)
    {
      //NUMITEMS SWITCH CASES HERE
      //generated

   case 1:
      return 7;
      break;
//---------------------------------------------------------------------------
      //end generated

    default:
      cerr<<"Error, invalid dial number passed to "
          <<CLASS_STRING<<"::numItems\n"
          <<"Please check declaration files.  Dial number passed was "
          <<dialNumber<<endl;
      exit(1);
    }
  return 0;
}

//---------------------------------------------------------------------------
b_param *CLASSNAME::paramName(b_param tname,
                                   int dialNumber,
                                   int position)

{
  if (strcmp(tname,(char *)typeName())!=0)
    return CLASSPARENT::paramName(tname,dialNumber,position);
  
  switch (dialNumber)
    {
      //PARAMNAME SWITCH CASES HERE
      //generated

case 1:
 switch (position)
   {
      case 1:
         return b_ptr_tmLOCALTIME_R_NOW();
         break;
      case 2:
         return b_ptr_tmGMTIME_R_NOW();
         break;
      case 3:
         return b_ptr_tmALL_ZERO();
         break;
      case 4:
         return b_ptr_tmALL_TOP_RANGE();
         break;
      case 5:
         return b_ptr_tmALL_OVERFLOW();
         break;
      case 6:
         return b_ptr_tmALL_MAX();
         break;
      case 7:
         return b_ptr_tmALL_MIN();
         break;

      default:
          cerr<<"Error, invalid position number passed to "
              <<CLASS_STRING<<"::paramName\n"
              <<"Please check declaration files.  Dial number passed was"
              <<dialNumber<<" position "<<position<<".\n";
          exit(1);
   }
   break;
    default:
      cerr<<"Error, invalid dial number passed to "
          <<CLASS_STRING<<"::paramName\n"
          <<"Please check declaration files.  Dial number passed was "
          <<dialNumber<<endl;
      exit(1);

    }
  return NULL;
}

//---------------------------------------------------------------------------
