#include <stdio.h>
#include <string.h>
#include "PrSocket.h"
#include "PrServerSocket.h"
#include "PrDataInput.h"
#include "PrDataOutput.h"

#define SERV_TCP_PORT 8189

#define RESET 0
#define RUN   1
#define STOP  2
#define OPEN  3
#define CLOSE 4
#define EXIT  5
#define SYNC  6
#define GOAL  7
#define FLOAT 8
#define GOTO  9

#define MAXLINE 80
#define NOJ 6

#define PR_TYPE_CHAR 0
#define PR_TYPE_ACTION 1
#define PR_TYPE_FLOAT 2

#define PR_ACTION_EXIT 0
#define PR_ACTION_JT_POS 1
#define PR_ACTION_SET_GOAL 2

int gState = STOP;

void MesgHandler( PrDataInput *in, PrDataOutput *out )
{
/*
    int i,n;
    float data[NOJ];
    char line[MAXLINE];
    int done = 0;
    
    while(!done)
      {
	  
	  n = in->ready();
	  if (n >= 0)
	    {
		switch(in->type())
		  {
		    case PR_TYPE_CHAR:
		      memset(line,NULL,MAXLINE);
		      n= in->readChar(line,n);
		      break;
		    case PR_TYPE_ACTION:
		      int action;
		      in->readInt(&action,1);
		      printf("action=%d\n",action);
		      switch(action)
			{
			  case PR_ACTION_EXIT:
			    printf("exit\n");
			    done = 1;
			    gState = EXIT;
			    break;
			  case PR_ACTION_JT_POS:
			    for(i=0;i<NOJ;i++)
			      data[i]+=0.01;

			    n=out->writeFloat(data,NOJ);
		      
			    if(out->flush(PR_TYPE_FLOAT)!=n)
			      perror("str_echo:run():writen error");
			    break;
			  case PR_ACTION_SET_GOAL:
			    in->readFloat(data,NOJ);
			    for(i=0;i<NOJ;i++)
			      printf("%f ",data[i]);
			    printf("\n");
			    break;
			}
		      break;
		  }
	    }
      }
*/
}

int main()
{
/*
  int count=0;

  PrServerSocket *s = new PrServerSocket(SERV_TCP_PORT);
  if (s->flag() != PR_SERVERSOCKET_OK)
    perror("server: can't create error");
  
  gState = STOP;
  while(gState != EXIT)
    {
      PrSocket *incoming = s->accept();
	  
      PrDataInput *in = NULL;
      PrDataOutput *out = NULL;

      if (incoming == NULL)
	perror("server: can't accept error");
      else
	{
	    in = new PrDataInput(incoming);
	    out = new PrDataOutput(incoming);
	}

      printf("serving: count = %d\n",count++);

      gState = OPEN;
      printf("open\n");

      MesgHandler(in,out);
	  
      delete in;
      delete out;
      incoming->close();
      delete incoming;

    }
  s->close();
  delete s;
*/
  return (1);
}
