VuMessage

Subclasses: VuErrorMessage, VuRequestMessage, VuEvent, FalconEvent


friend class VuTargetEntity;
friend class VuMessageQueue;
#ifdef USE_SH_POOLS
public:
                // Overload new/delete to use a SmartHeap pool
                void *operator new(size_t size) { return MemAllocPtr(gVuMsgMemPool,size,FALSE); };
                void operator delete(void *mem) { if (mem) MemFreePtr(mem); };
#endif
public:
  virtual ~VuMessage();

  VU_MSG_TYPE Type() { return type_; }
  VU_ID Sender() { return sender_; }
  VU_ID Destination() { return tgtid_; }
  VU_BOOL IsLocal() { return (VU_BOOL)(sender_.creator_==vuLocalSession.creator_ ?
                                        TRUE : FALSE); }
  VU_ID EntityId() { return entityId_; }
  VU_BYTE Flags() { return flags_; }
  VuEntity *Entity() { return ent_; }
  VU_TIME PostTime() { return postTime_; }
  VuTargetEntity *Target() { return target_; }

  void SetPostTime(VU_TIME posttime) { postTime_ = posttime; }
  virtual int Size();
  int Read(VU_BYTE **buf, int length);
  int Write(VU_BYTE **buf);
  VU_ERRCODE Dispatch(VU_BOOL autod);
  int Send();

  void RequestLoopback() { flags_ |= VU_LOOPBACK_MSG_FLAG; }
  void RequestReliableTransmit() { flags_ |= VU_RELIABLE_MSG_FLAG; }
  void RequestOutOfBandTransmit() { flags_ |= VU_OUT_OF_BAND_MSG_FLAG; }
  void RequestLowPriorityTransmit() { flags_ &= 0xf0; }

// app needs to Ref & UnRef messages they keep around
//      most often this need not be done
  int Ref();
  int UnRef();

  // the following determines just prior to sending message whether or not
  // it goes out on the wire (default is TRUE, of course)
  virtual VU_BOOL DoSend();

protected:
  VuMessage(VU_MSG_TYPE type, VU_ID entityId, VuTargetEntity *target,
                VU_BOOL loopback);
  VuMessage(VU_MSG_TYPE type, VU_ID sender, VU_ID target);
  virtual VU_ERRCODE Activate(VuEntity *ent);
  virtual VU_ERRCODE Process(VU_BOOL autod) = 0;
  virtual int Encode(VU_BYTE **buf);
  virtual int Decode(VU_BYTE **buf, int length);
  VuEntity *SetEntity(VuEntity *ent);

private:
  int LocalSize();

private:
  VU_BYTE refcnt_;              // vu references

protected:
  VU_MSG_TYPE type_;
  VU_BYTE flags_;               // misc flags
  VU_ID sender_;
  VU_ID tgtid_;
  VU_ID entityId_;
  // scratch variables (not networked)
  VuTargetEntity *target_;
  VU_TIME postTime_;
private:
  VuEntity *ent_;