/****************************************************************************/
/* Copyright (c) 2000 MBARI                                                 */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Summary  :                                                               */
/* Filename : TaskInterface.h                                               */
/* Author   : Tom O'Reilly                                                  */
/* Project  :                                                               */
/* Version  : 1.0                                                           */
/* Created  : 02/07/2000                                                    */
/* Modified :                                                               */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/****************************************************************************/
#ifndef _TASKCLIENT_H
#define _TASKCLIENT_H

#include "SharedObjectClient.h"
#include "ExternalMessage.h"


/*
CLASS 
TaskInterface

DESCRIPTION
Each TaskServer class has a corresponding TaskInterface, which allows client
applications to access the TaskServer. The client application simply creates
an instance of TaskInterface subclass, and invokes its public methods
to access the TaskServer. Client can also use TaskInterface to "subscribe" 
to events defined by the TaskServer, and will be notified by the TaskServer
when the events occur.

AUTHOR
Tom O'Reilly
*/
class TaskInterface : public SharedObjectClient {

  friend class Supervisor;
  friend class ExternalComms;

public:

  TaskInterface(const char *name, const char *serverName,
		int serverConnectTimeout = 10);

  TaskInterface(const char *name);

  ~TaskInterface();


  ///////////////////////////////////////////////////////////////////
  // Subscribe to specified server event
  void subscribe(EventCode eventCode)
    throw (Error);


  ///////////////////////////////////////////////////////////////////
  // Wait for a subscribed-to event, and return its code 
  EventCode waitForEvent();

protected:

  ///////////////////////////////////////////////////////////////////
  // Graceful shutdown and termination of Task
  void shutdown();
  
  ////////////////////////////////////////////////////////////////////
  // Reset Task
  void reset();

  ////////////////////////////////////////////////////////////////////
  // Decode ExternalMethodMessage, send it to server, then re-encode it
  virtual void sendExternalMsg(ExternalMethodMessage *message);
};

#endif
