/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : ExternalCommsServer.cc                                        */
/* Author   :                                                               */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#include <process.h>
#include "ExternalCommsServer.h"


ExternalCommsServer::ExternalCommsServer()
  : ExternalCommsIF_SK()
{
  _channel = ExternalCommsIF::NoLink;
}


ExternalCommsServer::~ExternalCommsServer()
{
}


long ExternalCommsServer::setChannel(ExternalCommsIF::Channel channel)
{
  _channel = channel;
  return 0;
}


void ExternalCommsServer::channel(ExternalCommsIF::Channel *channel)
{
  *channel = _channel;
}


int ExternalCommsServer::spawnAuxTasks()
{
  char *program = "externalComms";
  char errorBuf[256];

  pid_t pid;
  Boolean error = False;

  switch ((pid = fork())) {
    
  case 0:
    // In child
    // Execute server program
    execlp(program, program, 0);

    sprintf(errorBuf, 
	    "Task::spawnServer() - execlp() of \"%s\" failed", program);

    perror(errorBuf);

    break;

  case -1:
    perror("Task::spawnServer() - fork() failed");
    error = True;
    break;
  }

  if (error)
    return -1;
  else
    return 0;
}


