#include <pthread.h>
#include <unistd.h>
#include <malloc.h>
#include <string.h>
#include "VxStubs.h"


Void setSerialLinkState(microIOControl *microIOCtrl, serialComState linkState)
{
  return;
}

STATUS microCmdEnable( sio32Chan *sio32Channel )
{
  return OK;
}


switchStatus microDevPowerSwitchState(microIOControl *microIOCtrl)
{
  return SWITCH_ON;
}


STATUS sio32ChanDestroy(Nat16 channel, sio32Chan *sio32DataChan)
{
  return OK;
}


STATUS sio32ChanInit(Nat16 serialChannel, char *sio32DevName,
		     sio32Chan *sio32DataChan)
{
  return OK;
}


DM_Item initMicroDmItem( const char *dmPrefix, char *itemName,
			DM_Type itemType, DM_Num numElements )
{
  return (DM_Item )NULL;
}



STATUS writeBooleanDmItem(DM_Item dmItem, MBool status)
{
  return OK;
}

STATUS updateMicroIdentDm( sio32Chan *sio32DataChan, DM_Item microIdentDm )
{
  return OK;
}

STATUS updateSerialNoDm( sio32Chan *sio32DataChan, DM_Item serialNoDm )
{
  return OK;
}

STATUS writeMicroSerialNo( sio32Chan *sio32DataChan, DM_Item serialNoDm )
{
  return OK;
}

STATUS updateSoftwareRevDm( sio32Chan *sio32DataChan, DM_Item softwareRevDm )
{
  return OK;
}

STATUS updateMicroRamTestDm( sio32Chan *sio32DataChan, DM_Item microRamTestDm)
{
  return OK;
}

void taskSafe()
{
}


void taskUnsafe()
{
}


int taskSpawn(char *taskName, int priority, int options, int stackSize, 
	      FUNCPTR entry, int arg0, int arg1, int arg2, int arg3, int arg4,
	      int arg5, int arg6, int arg7, int arg8, int arg9)
{
  static int taskNo = 0;
  
  pthread_t task;
  
  pthread_create(&task, pthread_attr_default, 
		 (pthread_startroutine_t )entry, (void *)arg0);

  return ++taskNo;
}


#if 0
int taskSpawn(char *taskName, int priority, int options, int stackSize, 
	      FUNCPTR entry, int arg0, int arg1, int arg2, int arg3, int arg4,
	      int arg5, int arg6, int arg7, int arg8, int arg9)

{
  pid_t pid;
  char buf[100];
  char *argv[10];

  sprintf(buf, "%d", arg0);
  argv[0] = strdup(buf);

  sprintf(buf, "%d", arg1);
  argv[1] = strdup(buf);

  sprintf(buf, "%d", arg2);
  argv[2] = strdup(buf);

  sprintf(buf, "%d", arg3);
  argv[3] = strdup(buf);

  sprintf(buf, "%d", arg4);
  argv[4] = strdup(buf);

  sprintf(buf, "%d", arg5);
  argv[5] = strdup(buf);

  sprintf(buf, "%d", arg6);
  argv[6] = strdup(buf);

  sprintf(buf, "%d", arg7);
  argv[7] = strdup(buf);

  sprintf(buf, "%d", arg8);
  argv[8] = strdup(buf);

  sprintf(buf, "%d", arg9);
  argv[9] = strdup(buf);
  
  switch (pid = fork())
  {
    case -1:
    perror("taskSpawn()");
    return ERROR;
    break;
    
    case 0:
    // In child process
    fprintf(stderr, "Child process %d\n", getpid());
    
    execlp(taskName, taskName, argv[0], argv[1], argv[2], argv[3], argv[4],
	   argv[5], argv[6], argv[7], argv[8], argv[9], NULL);
    
    sprintf(buf, "execlp() of \"%s\"", taskName);
    perror(buf);
    exit(1);

  }

  for (int i = 0; i < 10; i++)
    free(argv[i]);
  
  return pid;
}

#endif
