/***************************************************************************
 *   Copyright (C) 2005 by Brian Lauber   *
 *   bml8@case.edu   *
 *                                                                         *
 *   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.             *
 ***************************************************************************/


#ifndef __SHARED_H__
#define __SHARED_H__

#include <sys/types.h>

/*******************************************
By default, shared memory is just a block
of bytes.  In order to structure the data
in variables, we need to "overlay" the
shared memory with a data structure.
See shmat() statement.
*******************************************/
struct SharedVars
{
  int CarsWaiting;    // Cars waiting to cross
  int CarsCrossing;   // Cars in the intersection
  int TrainsComing;   // Trains that are approaching the crossing
  int TrainsCrossing; // Trains in the intersection
  int Light;          // The state of the light
};


/*******************************************
This enum allows us to refer to semaphores
by names instead of index numbers
*******************************************/
enum eSEMAPHORES {CAR, TRAIN, CROSSING};


// This enumerates the possible states of the traffic light
enum eLIGHT      {GREEN = 0, YELLOW, RED};


/*******************************************
These functions allow for shared memory and
semaphore id's to be passed between processes.
They are really defined for convenience more
than necessity.
*******************************************/
int SetS_Group(key_t group);
int SetM_Group(key_t group);
int GetS_Group(void);
int GetM_Group(void);


// This function will print the overall status of all of the processes
void PrintStatus(const char *label, const struct SharedVars *s);

#endif

