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

#include <string.h>
#include <sys/proxy.h>
#include "ourTypes.h"
#include "Exception.h"

typedef int EventCode;

/*
CLASS 
SharedObject

DESCRIPTION
SharedObject is the base class for objects which provide an 
object-oriented interface to QNX message-based IPC.

AUTHOR
Tom O'Reilly
*/

class SharedObject {

  friend class ExternalMethodMessage;

public:

  class Error : public Exception {

  public:

    Error(char *errorMsg) : Exception(errorMsg) {
    }
  };

  enum GeneralRequestCodes {
    SubscribeCode = 1000, NotifyCode, EventMarkerCode
  };

  ///////////////////////////////////////////////////////////////////
  // Constructor
  // [input] name: Name of object instance
  SharedObject(const char *name);
  virtual ~SharedObject();

  ///////////////////////////////////////////////////////////////////
  // Object name
  const char *name() {
    return _name;
  }


protected:

  typedef int RequestCode;

  ///////////////////////////////////////////////////////////////////
  // Base class for request structures passed to server
  struct Request {
    RequestCode code;
  };

  ///////////////////////////////////////////////////////////////////
  // Base class for reply structures passed back to clients
  struct Reply {
  };


  struct Subscription : Request {

    Subscription() {
      code = SubscribeCode;
    }

    // Which event is being subscribed to
    int eventCode;   

    // Proxy to be triggered by server
    pid_t subscriberPid;
  };

  struct SubscriptionReply : Reply {
    Boolean confirmed;
  };


private:

  const char *_name;
};


#endif
