/***********************************************************************
tjs - 98.12.04

This example is to show the following:

- Attaching a seperately compiled and executing client to a server

- The invocation of member functions in a class on the server by using
  a global pointer on the client.

tjs - 98.12.15

Pulling out the local array stuff in order to concentrate on the class stuff

***********************************************************************/
#define coutline cout << __FILE__ << ": line " << __LINE__ << endl << flush;

#include <HPCxx_Profile.h>
#include <math.h>
#include <assert.h>
#include "Complex.C"
#include <iostream.h>
#include <hpcxx_rts.h>
#include "allHPCxxTemplates.h"
#include "ToyClass.h"
#include "ClientServerAttach.h"

int waitVal = 1;
int setWaitVal(int intVal)              // for releasing server
{
  waitVal = intVal;
  return(intVal);
}

int main(int argc, char* argv[])
{
  // initialize HPC++

  HPCxx_Group* group;
  hpcxx_init(argc, argv, group);

  cout << "server: HPC++ initialized" << endl << flush;

  serverAllowAttach("gpServer.url");

  cout << "server: done with attach set up " << endl << flush;

  // register the functions that will provide the GPs 
  // and the function to release the server

  hpcxx_id_t setWaitValID = hpcxx_register(setWaitVal,12);

  cout << "server: remote functions registered" << endl << flush;

  // create the class and its global pointer

  Toy *localToyObj = new ToyServer();

  cout << "server: ToyObj initialized." << endl << flush;

  cout << "server: initial arrays:" << endl << flush;

  localToyObj->printLocal();
  localToyObj->exchangeArr();

  cout << "server: arrays exchanged by server:" << endl << flush;
  localToyObj->printLocal();

  cout << "server at barrier" << endl << flush;

  // block on a variable in server space that can be reset by a
  // remote function call from the client.

  while(waitVal);
  return hpcxx_exit(group);
}

