/*
   b_ptr_sched_param.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 05:53 AM EDT

TITLE
   b_ptr_sched_param.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_sched_param.h"

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


 static struct sched_param sched_param_temp;
//--------------------------------------------------------------------

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

  //generated

   strcpy(_b_ptr_sched_paramTYPENAME,CLASS_STRING);
strcpy(_b_ptr_sched_paramCURRENT,"b_ptr_sched_param_CURRENT");
strcpy(_b_ptr_sched_paramZERO,"b_ptr_sched_param_ZERO");
strcpy(_b_ptr_sched_paramNEG_ONE,"b_ptr_sched_param_NEG_ONE");
strcpy(_b_ptr_sched_paramMIN,"b_ptr_sched_param_MIN");
strcpy(_b_ptr_sched_paramMAX,"b_ptr_sched_param_MAX");
strcpy(_b_ptr_sched_paramONE,"b_ptr_sched_param_ONE");
}

//--------------------------------------------------------------------
b_param *b_ptr_sched_param::b_ptr_sched_paramCURRENT()
{
   return &_b_ptr_sched_paramCURRENT;
}

b_param *b_ptr_sched_param::b_ptr_sched_paramZERO()
{
   return &_b_ptr_sched_paramZERO;
}

b_param *b_ptr_sched_param::b_ptr_sched_paramNEG_ONE()
{
   return &_b_ptr_sched_paramNEG_ONE;
}

b_param *b_ptr_sched_param::b_ptr_sched_paramMIN()
{
   return &_b_ptr_sched_paramMIN;
}

b_param *b_ptr_sched_param::b_ptr_sched_paramMAX()
{
   return &_b_ptr_sched_paramMAX;
}

b_param *b_ptr_sched_param::b_ptr_sched_paramONE()
{
   return &_b_ptr_sched_paramONE;
}

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

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

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
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_sched_param_current = 0;
b_ptr_sched_param_zero = 0;
b_ptr_sched_param_neg_one = 0;
b_ptr_sched_param_min = 0;
b_ptr_sched_param_max = 0;
b_ptr_sched_param_one = 0;
   int dataPTR =0;


   dataPTR++;
if (strcmp(data[dataPTR],_b_ptr_sched_paramCURRENT)==0)
      b_ptr_sched_param_current = 1;
   else if (strcmp(data[dataPTR],_b_ptr_sched_paramZERO)==0)
      b_ptr_sched_param_zero = 1;
   else if (strcmp(data[dataPTR],_b_ptr_sched_paramNEG_ONE)==0)
      b_ptr_sched_param_neg_one = 1;
   else if (strcmp(data[dataPTR],_b_ptr_sched_paramMIN)==0)
      b_ptr_sched_param_min = 1;
   else if (strcmp(data[dataPTR],_b_ptr_sched_paramMAX)==0)
      b_ptr_sched_param_max = 1;
   else if (strcmp(data[dataPTR],_b_ptr_sched_paramONE)==0)
      b_ptr_sched_param_one = 1;
  else
    {
      cerr<<"Error: Unknown setting for the "
          <<"PRIORITY"
          <<" dial of the data object "
          <<CLASS_STRING
          <<". "<<endl
          <<"The offending string is : "
          <<data[dataPTR]
          <<endl;
      exit(1);
    }

if (b_ptr_sched_param_current==1)
{

 if ((sched_getparam(getpid(), &sched_param_temp)) == -1)
 {
 FILE* logFile = NULL;
 
 if ((logFile = fopen ("/tmp/templateLog.txt","a+")) == NULL)
 {
 exit(99);
 }
 fprintf(logFile, "b_ptr_sched_param CURRENT - error getting sched_param - function not tested\n");
 fclose(logFile);
 exit(99);
 }
 
}

if (b_ptr_sched_param_zero==1)
{

 sched_param_temp.sched_priority = 0;
 
}

if (b_ptr_sched_param_neg_one==1)
{

 sched_param_temp.sched_priority = -1;
 
}

if (b_ptr_sched_param_min==1)
{

 sched_param_temp.sched_priority = -MAXINT;
 
}

if (b_ptr_sched_param_max==1)
{

 sched_param_temp.sched_priority = MAXINT;
 
}

if (b_ptr_sched_param_one==1)
{

 sched_param_temp.sched_priority = 1;
 
}

 _theVariable=&sched_param_temp;
   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 6;
      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_sched_paramCURRENT();
         break;
      case 2:
         return b_ptr_sched_paramZERO();
         break;
      case 3:
         return b_ptr_sched_paramNEG_ONE();
         break;
      case 4:
         return b_ptr_sched_paramMIN();
         break;
      case 5:
         return b_ptr_sched_paramMAX();
         break;
      case 6:
         return b_ptr_sched_paramONE();
         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;
}

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