//=========================================================================
// Summary  : */
// Filename : SharedObject.h
// Author   : */
// Project  : */
// Revision : 1
// Created  : 2000/08/19
// Modified : 2000/08/19
//=========================================================================
// Description :
//=========================================================================
#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;
    Boolean otherNode;
  };

  struct SubscriptionReply : Reply {
    Boolean confirmed;
  };


private:

  const char *_name;
};


#endif
