#!/bin/csh
# This script automatically generates most of the code for a subclass
# of SharedData (which uses shared memory as the underlying IPC mechanism)
# 
# NOTE: This script does not run under QNX, which doesn't have csh 
#
if ($#argv != 1) then
  echo usage: $0 classname
  exit 1
endif


set classname = $argv[1]

cat > ${classname}.h << EndHeader

#ifndef _${classname}_H
#define _${classname}_H

#include "SharedData.h"

#define ${classname}Name "${classname}_ShmemName"

/*
CLASS 
$classname

DESCRIPTION
!!!FILL IN CLASS DESCRIPTION HERE!!!

AUTHOR
!!!FILL IN AUTHOR HERE!!!
*/
class $classname : public SharedData {

public:

  struct Data {

    // Indicates that device is initialized and ready
    Boolean deviceReady;

    // DEFINE STRUCTURE ELEMENTS HERE
  };

  $classname(Access access = NoAccess, Boolean init = False);

  ~$classname();


  ////////////////////////////////////////////////////////////////////
  // Read from shared memory to this object's Data::data element
  void read();

  ////////////////////////////////////////////////////////////////////
  // Write from this object's Data::data element to shared memory
  void write();

  Data data;

};

#endif
EndHeader


cat > ${classname}.cc << Endcc

#include "${classname}.h"
#include "Syslog.h"

${classname}::${classname}(Access access, Boolean init)
  : SharedData(${classname}Name, 
               sizeof(${classname}::Data),
               access, init)
{
}


${classname}::~${classname}()
{
}


void ${classname}::read()
{
  SharedData::read((void *)&data);
}

void ${classname}::write()
{
  SharedData::write((void *)&data);
}



Endcc

echo Generated files ${classname}.h and ${classname}.cc
echo NOTE: You must define ${classname}::Data structure in ${classname}.h

exit 0


