/*
 *    SCCS ID: %Z%%M% %I% %E% SST 
 *
 *    Copyright (c) 1992-1993 Mark Soloway.  All rights reserved.
 *    See SST_LEGAL_NOTICE file for terms of the license.
 */

#include "TTConstants.h"
#include "TTMessage.h"
#include "TTObjectSpec.h"
#include "TTPattern.h"

#include <stdio.h>
#include <string.h>

TTMessage::TTMessage (Tt_status &status) 
{
  setTTMessageDefaults ();
 
  ttMessage = tt_message_create ();
  status = tt_message_user_set (ttMessage, TT_OBJECT_KEY, this);

  checkNewMessage (status);
}

TTMessage::TTMessage (const char *op,
                      Tt_class    tt_class,
		      Tt_scope    scope,
		      Tt_address  address,
		      Tt_status  &status)
{
  setTTMessageDefaults ();

  ttMessage = tt_message_create ();
  (void)tt_message_op_set (ttMessage, op);
  (void)tt_message_class_set (ttMessage, tt_class);
  (void)tt_message_scope_set (ttMessage, scope);
  (void)tt_message_address_set (ttMessage, address);
  status = tt_message_user_set (ttMessage, TT_OBJECT_KEY, this);

  checkNewMessage (status);
}

TTMessage::TTMessage (const char *op,
		      Tt_class    tt_class,
		      Tt_scope    scope,
		      Tt_status  &status)
{
  setTTMessageDefaults ();
 
  ttMessage = tt_message_create ();
  (void)tt_message_op_set (ttMessage, op);
  (void)tt_message_class_set (ttMessage, tt_class);
  (void)tt_message_address_set (ttMessage, TT_PROCEDURE);
  (void)tt_message_scope_set (ttMessage, scope);
  status = tt_message_user_set (ttMessage, TT_OBJECT_KEY, this);
 
  checkNewMessage (status);
}
 
TTMessage::TTMessage (const char *objid,   
		      const char *op,
                      Tt_class    tt_class,
                      Tt_scope    scope,
                      Tt_status  &status)
{
  setTTMessageDefaults ();

  ttMessage = tt_message_create ();
  (void)tt_message_object_set (ttMessage, objid);
  (void)tt_message_op_set (ttMessage, op);
  (void)tt_message_class_set (ttMessage, tt_class);
  (void)tt_message_address_set (ttMessage, TT_OBJECT);
  (void)tt_message_scope_set (ttMessage, scope);
  status = tt_message_user_set (ttMessage, TT_OBJECT_KEY, this);

  checkNewMessage (status);
}

TTMessage::TTMessage (const TTObjectSpec &spec,
                      const char         *op,
                      Tt_class            tt_class,
                      Tt_scope            scope,
                      Tt_status          &status)
{
  setTTMessageDefaults ();
 
  ttMessage = tt_message_create ();
  (void)tt_message_object_set (ttMessage, spec.getID (status));
  (void)tt_message_op_set (ttMessage, op);
  (void)tt_message_class_set (ttMessage, tt_class);
  (void)tt_message_address_set (ttMessage, TT_OBJECT);
  (void)tt_message_scope_set (ttMessage, scope);
  status = tt_message_user_set (ttMessage, TT_OBJECT_KEY, this);
 
  checkNewMessage (status);
}

TTMessage::TTMessage (const TTMessage &message)
{
  copy (message);
}

TTMessage &TTMessage::operator= (const TTMessage &message)
{
  if (this != &message) {
    destroy ();
    copy (message);
  }

  return *this;
}

void TTMessage::setTTMessageDefaults ()
{
  sentFlag = TT_FALSE;
  ttMessage = (Tt_message)NULL;
}

TTMessage::~TTMessage ()
{
  destroy ();
}

TTMessage *TTMessage::createSuperClassMessage (Tt_status &status) const
{
  Tt_message tt_message = tt_message_create_super (ttMessage);
  status = tt_ptr_error (tt_message);

  TTMessage *new_message = (TTMessage *)NULL;
  if (status != TT_OK) {
    if (tt_message) {
      (void)tt_message_destroy (tt_message);
    }
  }
  else if (tt_message) {
    new_message = new TTMessage (tt_message);
  }

  return new_message;
}

Tt_status TTMessage::refresh ()
{
  sentFlag = TT_FALSE;

  TTMessage new_message = *this;
  decreaseReferenceCount ();

  ttMessage = new_message.getMessage ();
  Tt_status status = tt_ptr_error (ttMessage);
  checkNewMessage (status);

  new_message.setMessage (NULL);
  return status;
}

Tt_status TTMessage::setAddress (Tt_address address)
{
  return tt_message_address_set (ttMessage, address);
}

Tt_status TTMessage::setClass (Tt_class tt_class)
{
  return tt_message_class_set (ttMessage, tt_class);
}

Tt_status TTMessage::setDisposition (Tt_disposition disposition)
{
  return tt_message_disposition_set (ttMessage, disposition);
}

Tt_status TTMessage::setFile (const char *file)
{
  return tt_message_file_set (ttMessage, file);
}

Tt_status TTMessage::setHandler (const char *procid)
{
  return tt_message_handler_set (ttMessage, procid);
}

Tt_status TTMessage::setHandlerPType (const char *ptype)
{
  return tt_message_handler_ptype_set (ttMessage, ptype);
}

Tt_status TTMessage::setObject (const char *objid)
{
  return tt_message_object_set (ttMessage, objid);
}

Tt_status TTMessage::setObjectSpec (const TTObjectSpec &spec)
{
  Tt_status status;
  return tt_message_object_set (ttMessage, spec.getID (status));
}

Tt_status TTMessage::setOp (const char *op)
{
  return tt_message_op_set (ttMessage, op);
}

Tt_status TTMessage::setOType (const char *otype)
{
  return tt_message_otype_set (ttMessage, otype);
}

Tt_status TTMessage::setScope (Tt_scope scope)
{
  return tt_message_scope_set (ttMessage, scope);
}

Tt_status TTMessage::setSenderPType (const char *ptype)
{
  return tt_message_sender_ptype_set (ttMessage, ptype);
}

Tt_status TTMessage::setSession (const char *session)
{
  return tt_message_session_set (ttMessage, session);
}

Tt_status TTMessage::setStatus (int status)
{
  return tt_message_status_set (ttMessage, status);
}

Tt_status TTMessage::setStatusString (const char *status_string)
{
  return tt_message_status_string_set (ttMessage, status_string);
}

Tt_address TTMessage::getAddress (Tt_status &status) const
{
  Tt_address address = tt_message_address (ttMessage);
  status = tt_int_error (address);
  return address;
}

Tt_class TTMessage::getClass (Tt_status &status) const
{
  Tt_class tt_class = tt_message_class (ttMessage);
  status = tt_int_error (tt_class);
  return tt_class;
}

Tt_disposition TTMessage::getDisposition (Tt_status &status) const
{
  Tt_disposition disposition = tt_message_disposition (ttMessage);
  status = tt_int_error (disposition);
  return disposition;
}

char *TTMessage::getFile (Tt_status &status) const
{
  char *file = tt_message_file (ttMessage);
  status = tt_ptr_error (file);
  return file;
}

gid_t TTMessage::getGID (Tt_status &status) const
{
  gid_t gid = tt_message_gid (ttMessage);
  status = tt_int_error ((int)gid);
  return gid;
}

char *TTMessage::getHandler (Tt_status &status) const
{
  char *handler = tt_message_handler (ttMessage);
  status = tt_ptr_error (handler);
  return handler;
}

char *TTMessage::getHandlerPType (Tt_status &status) const
{
  char *ptype = tt_message_handler_ptype (ttMessage);
  status = tt_ptr_error (ptype);
  return ptype;
}

char *TTMessage::getObject (Tt_status &status) const
{
  char *objid = tt_message_object (ttMessage);
  status = tt_ptr_error (objid);
  return objid;
}

TTObjectSpec *TTMessage::getObjectSpec (Tt_status &status) const
{
  char *objid = tt_message_object (ttMessage);
  status = tt_ptr_error (objid);

  TTObjectSpec *spec = (TTObjectSpec *)NULL;

  if (status == TT_OK)
    spec = new TTObjectSpec (objid, status);

  return spec;
}

char *TTMessage::getOp (Tt_status &status) const
{
  char *op = tt_message_op (ttMessage);
  status = tt_ptr_error (op);
  return op;
}

int TTMessage::getOpNum (Tt_status &status) const
{
  int opnum = tt_message_opnum (ttMessage);
  status = tt_int_error (opnum);
  return opnum;
}

char *TTMessage::getOType (Tt_status &status) const
{
  char *otype = tt_message_otype (ttMessage);
  status = tt_ptr_error (otype);
  return otype;
}

TTPattern *TTMessage::getPattern (Tt_status &status) const
{
  TTPattern *pattern = (TTPattern *)NULL;

  Tt_pattern tt_pattern = tt_message_pattern (ttMessage);
  status = tt_ptr_error (tt_pattern);

  if (status == TT_OK) {
    pattern = (TTPattern *)tt_pattern_user (tt_pattern, TT_OBJECT_KEY);
    if (tt_ptr_error (pattern) != TT_OK) {
      pattern = new TTPattern (tt_pattern);
    }
  }

  return pattern;
}

Tt_scope TTMessage::getScope (Tt_status &status) const
{
  Tt_scope scope = tt_message_scope (ttMessage);
  status = tt_int_error (scope);
  return scope;
}

char *TTMessage::getSender (Tt_status &status) const
{
  char *sender = tt_message_sender (ttMessage);
  status = tt_ptr_error (sender);
  return sender;
}

char *TTMessage::getSenderPType (Tt_status &status) const
{
  char *ptype = tt_message_sender_ptype (ttMessage);
  status = tt_ptr_error (ptype);
  return ptype;
}

#if (TT_VERSION >= 10100)
char *TTMessage::getSendID (Tt_status &status) const
{
  char *send_id = (char *)NULL;

  if (sentFlag) {
    send_id = tt_message_id (ttMessage);
    status = tt_ptr_error (send_id);
  }
  else {
    status = TT_OK;
  }

  return send_id;
}
#else
char *TTMessage::getSendID (Tt_status &status) const
{
  status = TT_ERR_UNIMP;
  return (char *)NULL;
}
#endif

char *TTMessage::getSession (Tt_status &status) const
{
  char *session = tt_message_session (ttMessage);
  status = tt_ptr_error (session);
  return session;
}

Tt_state TTMessage::getState (Tt_status &status) const
{
  Tt_state state = tt_message_state (ttMessage);
  status = tt_int_error (state);
  return state;
}

int TTMessage::getStatus (Tt_status &status) const
{
  int tt_status = tt_message_status (ttMessage);
  status = tt_int_error (status);
  return tt_status;
}

char *TTMessage::getStatusString (Tt_status &status) const
{
  char *status_string = tt_message_status_string (ttMessage);
  status = tt_ptr_error (status_string);
  return status_string;
}

uid_t TTMessage::getUID (Tt_status &status) const
{
  uid_t uid = tt_message_uid (ttMessage);
  status = tt_int_error ((int)uid);
  return uid;
}

Tt_status TTMessage::addArg (Tt_mode mode, const char *vtype, int value)
{
  return tt_message_iarg_add (ttMessage, mode, vtype, value);
}

Tt_status TTMessage::addArg (Tt_mode     mode,
			     const char *vtype,
			     const char *value)
{
  return tt_message_arg_add (ttMessage, mode, vtype, value);
}

Tt_status TTMessage::addArg (Tt_mode              mode,
			     const char          *vtype,
			     const unsigned char *value,
			     int                  length)
{
  return tt_message_barg_add (ttMessage, mode, vtype, value, length);
}

#if (TT_VERSION >= 10101)
Tt_status TTMessage::addArg (Tt_mode     mode,
			     const char *vtype,
			     xdrproc_t	 xdr_proc,
			     void	*value)
{
  return tt_message_xarg_add (ttMessage, mode, vtype, xdr_proc, value);
}
#else
Tt_status TTMessage::addArg (Tt_mode, const char *, xdrproc_t, void *)
{
  return TT_ERR_UNIMP;
}
#endif

Tt_status TTMessage::setArgValue (int index, int value)
{
  return tt_message_arg_ival_set (ttMessage, index, value);
}

Tt_status TTMessage::setArgValue (int index, const char *value)
{
  return tt_message_arg_val_set (ttMessage, index, value);
}

Tt_status TTMessage::setArgValue (int                  index,
				  const unsigned char *value,
				  int                  length)
{
  return tt_message_arg_bval_set (ttMessage, index, value, length);
}

#if (TT_VERSION >= 10101)
Tt_status TTMessage::setArgValue (int	     index,
                                  xdrproc_t  xdr_proc,
                                  void      *value)  
{
  return tt_message_arg_xval_set (ttMessage, int, xdr_proc, value);
}
#else 
Tt_status TTMessage::setArgValue (int, xdrproc_t, void *)
{
  return TT_ERR_UNIMP;
}
#endif 
 
Tt_status TTMessage::getArgValue (int index, int &value) const
{
  return tt_message_arg_ival (ttMessage, index, &value);
}

Tt_status TTMessage::getArgValue (int index, char* &value) const
{
  value = tt_message_arg_val (ttMessage, index);
  return tt_ptr_error (value);
}

Tt_status TTMessage::getArgValue (int             index,
				  unsigned char* &value,
				  int            &length) const
{
  return tt_message_arg_bval (ttMessage, index, &value, &length);
}

#if (TT_VERSION >= 10101) 
Tt_status TTMessage::getArgValue (int        index,
                                  xdrproc_t  xdr_proc, 
                                  void      *value)   
{
  return tt_message_arg_xval (ttMessage, int, xdr_proc, value); 
} 
#else    
Tt_status TTMessage::getArgValue (int, xdrproc_t, void *)
{ 
  return TT_ERR_UNIMP; 
}
#endif   
  
int TTMessage::getArgsCount (Tt_status &status) const
{
  int count = tt_message_args_count (ttMessage);
  status = tt_int_error (count);
  return count;
}

Tt_mode TTMessage::getArgMode (int index, Tt_status &status) const
{
  Tt_mode mode = tt_message_arg_mode (ttMessage, index);
  status = tt_int_error (mode);
  return mode;
}

char *TTMessage::getArgType (int index, Tt_status &status) const
{
  char *type = tt_message_arg_type (ttMessage, index);
  status = tt_ptr_error (type);
  return type;
}

Tt_value_type TTMessage::getArgValueType (int index, Tt_status &status) const
{
  int            length;
  Tt_value_type  type;
  unsigned char *value;

  status = tt_message_arg_bval (ttMessage, index, &value, &length);

  if (status == TT_OK) {
    type = (value ? TT_BYTES_VALUE : TT_NULL_VALUE);
  }
  else {
    int int_value;
    status = tt_message_arg_ival (ttMessage, index, &int_value);
    type = ((status == TT_OK) ? TT_INT_VALUE : TT_NULL_VALUE);
  }

  return type;
}

#if (TT_VERSION >= 10100)
Tt_status TTMessage::addContext (const char *name, int value)
{
  return tt_message_icontext_set (ttMessage, name, value);
}
#else
Tt_status TTMessage::addContext (const char *, int)
{
  return TT_ERR_UNIMP;
}
#endif
 
#if (TT_VERSION >= 10100)
Tt_status TTMessage::addContext (const char *name,
                                 const char *value)
{
  return tt_message_context_set (ttMessage, name, value);
}
#else
Tt_status TTMessage::addContext (const char *, const char *)
{
  return TT_ERR_UNIMP;
}
#endif
 
#if (TT_VERSION >= 10100)
Tt_status TTMessage::addContext (const char          *name,
                                 const unsigned char *value,
                                 int                  length)
{
  return tt_message_bcontext_set (ttMessage, name, value, length);
}
#else
Tt_status TTMessage::addContext (const char *, const unsigned char *, int)
{
  return TT_ERR_UNIMP;
}
#endif
 
#if (TT_VERSION >= 10101)
Tt_status TTMessage::addContext (const char *name,
                                 xdrproc_t   xdr_proc,
                                 void       *value)
{
  return tt_message_xcontext_add (ttMessage, name, xdr_proc, value);
}
#else
Tt_status TTMessage::addContext (const char *, xdrproc_t, void *)
{
  return TT_ERR_UNIMP;
}
#endif
 
#if (TT_VERSION >= 10100)
Tt_status TTMessage::getContextValue (const char *name, int &value) const
{
  return tt_message_context_ival (ttMessage, name, &value);
}
#else
Tt_status TTMessage::getContextValue (const char *, int&) const
{
  return TT_ERR_UNIMP;
}
#endif

#if (TT_VERSION >= 10100)
Tt_status TTMessage::getContextValue (const char *name, char* &value) const
{
  value = tt_message_context_val (ttMessage, name);
  return tt_ptr_error (value);
}
#else
Tt_status TTMessage::getContextValue (const char *, char*&) const
{
  return TT_ERR_UNIMP;
}
#endif

#if (TT_VERSION >= 10100)
Tt_status TTMessage::getContextValue (const char     *name,
                                      unsigned char* &value,
                                      int            &length) const
{
  return tt_message_context_bval (ttMessage, name, &value, &length);
}
#else
Tt_status TTMessage::getContextValue (const char *, unsigned char*&, int&) const
{
  return TT_ERR_UNIMP;
}
#endif

#if (TT_VERSION >= 10101) 
Tt_status TTMessage::getContextValue (const char *name,
                                      xdrproc_t   xdr_proc, 
                                      void       *value) 
{ 
  return tt_message_context_xval (ttMessage, name, xdr_proc, value);
} 
#else 
Tt_status TTMessage::getContextValue (const char *, xdrproc_t, void *) 
{ 
  return TT_ERR_UNIMP; 
} 
#endif 
  
#if (TT_VERSION >= 10100)
Tt_value_type TTMessage::getContextValueType (const char *name,
					      Tt_status  &status) const
{
  int            length;
  Tt_value_type  type;
  unsigned char *value;
 
  status = tt_message_context_bval (ttMessage, name, &value, &length);
 
  if (status == TT_OK) {
    type = (value ? TT_BYTES_VALUE : TT_NULL_VALUE);
  }
  else {
    int int_value;
    status = tt_message_context_ival (ttMessage, name, &int_value);
    type = ((status == TT_OK) ? TT_INT_VALUE : TT_NULL_VALUE);
  }
 
  return type;
}
#else
Tt_value_type TTMessage::getContextValueType (const char *,
					      Tt_status  &status) const
{
  status = TT_ERR_UNIMP;
  return TT_NULL_VALUE;
}
#endif
 
#if (TT_VERSION >= 10100)
int TTMessage::getContextsCount (Tt_status &status) const
{
  int count = tt_message_contexts_count (ttMessage);
  status = tt_int_error (count);
  return count;
}
#else
int TTMessage::getContextsCount (Tt_status &status) const
{
  status = TT_ERR_UNIMP;
  return 0;
}
#endif

#if (TT_VERSION >= 10100)
char *TTMessage::getContextName (int index, Tt_status &status) const
{
  char *name = tt_message_context_slotname (ttMessage, index);
  status = tt_ptr_error (name);
  return name;
}
#else
char *TTMessage::getContextName (int, Tt_status &status) const
{
  status = TT_ERR_UNIMP;
  return (char *)NULL;
}
#endif

Tt_status TTMessage::setCallback (TTMessageCallback callback)
{
  Tt_status status = TT_OK;

  if (!messageCallback)
    status = tt_message_callback_add (ttMessage,
				      &TTMessage::internalMessageCallback);

  messageCallback = callback;
  return status;
}

Tt_message TTMessage::getMessage () const
{
  return ttMessage;
}

void TTMessage::setMessage (Tt_message tt_message)
{
  if (ttMessage != tt_message) {
    decreaseReferenceCount ();
    ttMessage = tt_message;

    if (ttMessage) {
      Tt_status status = tt_message_user_set (ttMessage, TT_OBJECT_KEY, this);
      checkNewMessage (status);
    }
  }
}

void TTMessage::setSentFlag (TTBoolean flag)
{
  sentFlag = flag;
}

void TTMessage::copy (const TTMessage &message)
{
  setTTMessageDefaults ();

  ttMessage = tt_message_create ();
  Tt_status status = tt_ptr_error (ttMessage);

  if (status == TT_OK) {
    int mark = tt_mark ();

    (void)setAddress (message.getAddress (status)); 
    (void)setClass (message.getClass (status)); 
    (void)setDisposition (message.getDisposition (status)); 
#if (TT_VERSION >= 10100)
    (void)setFile (message.getFile (status)); 
#else
    char *file = message.getFile (status);
    if (file) (void)setFile (file);
#endif
    (void)setHandler (message.getHandler (status)); 
    (void)setHandlerPType (message.getHandlerPType (status));
    (void)setObject (message.getObject (status)); 
    (void)setOp (message.getOp (status)); 
    (void)setOType (message.getOType (status)); 
    (void)setScope (message.getScope (status)); 
    (void)setSenderPType (message.getSenderPType (status)); 
    (void)setStatus (message.getStatus (status)); 
    (void)setStatusString (message.getStatusString (status));
      
    int      num_args = message.getArgsCount (status);
    Tt_mode  mode;
    char    *type;
    
    unsigned char *bytes_value;
    int            bytes_length;
    int	           int_value;
    
    for (int index=0;
	 (index < num_args) && (status == TT_OK);
	 index++) {
      mode = message.getArgMode (index, status);
      type = message.getArgType (index, status);
      
      status = message.getArgValue (index,
				    bytes_value,
				    bytes_length);
      if (status == TT_OK) {
	status = addArg (mode, type, bytes_value, bytes_length);
      }
      else {
	status = message.getArgValue (index, int_value);
	if (status == TT_OK)
	  status = addArg (mode, type, int_value);
      }
    }

#if (TT_VERSION >= 10100)
    int   num_contexts = message.getContextsCount (status);
    char *name;

    for (index=0;
	 (index < num_contexts) && (status == TT_OK);
	 index++) {
      name = message.getContextName (index, status);

      if (status == TT_OK) {
        status = message.getContextValue (name,
					  bytes_value,
					  bytes_length);
        if (status == TT_OK) {
	  status = addContext (name, bytes_value, bytes_length);
        }
	else {
          status = message.getContextValue (name, int_value);
          if (status == TT_OK)
            status = addContext (name, int_value);
	} 
      }
    }
#endif

    tt_release (mark);
  }
  
  checkNewMessage (status);
}

void TTMessage::destroy ()
{
  decreaseReferenceCount ();
}

void TTMessage::checkNewMessage (Tt_status status)
{
  if (status != TT_OK) { 
    if (ttMessage) {
      (void)tt_message_destroy (ttMessage);
      ttMessage = (Tt_message)NULL;
    }
  } 
  else { 
    initializeOrIncreaseReferenceCount (); 
  } 
}

void TTMessage::initializeOrIncreaseReferenceCount ()
{
  if (!ttMessage) return;
 
  int reference_count = (int)tt_message_user (ttMessage, TT_REFERENCE_COUNT);
  if ((tt_ptr_error ((void *)reference_count) != TT_OK) || !reference_count)
    (void)tt_message_user_set (ttMessage, TT_REFERENCE_COUNT, (void *)1);
  else
    (void)tt_message_user_set (ttMessage,
                               TT_REFERENCE_COUNT,
                               (void *) (reference_count + 1));
}
 
void TTMessage::increaseReferenceCount ()
{
  if (!ttMessage) return;
 
  int reference_count = (int)tt_message_user (ttMessage, TT_REFERENCE_COUNT);
  if ((tt_ptr_error ((void *)reference_count) == TT_OK) && reference_count)
    (void)tt_message_user_set (ttMessage,
                               TT_REFERENCE_COUNT,
                               (void *) (reference_count + 1));
}
 
void TTMessage::decreaseReferenceCount ()
{
  if (!ttMessage) return;
 
  int reference_count = (int)tt_message_user (ttMessage, TT_REFERENCE_COUNT);
  if (tt_ptr_error ((void *)reference_count) == TT_OK) {
    if (reference_count > 1) {
      (void)tt_message_user_set (ttMessage,
                                 TT_REFERENCE_COUNT, 
                                 (void *) (reference_count - 1));
 
      if (this == tt_message_user (ttMessage, TT_OBJECT_KEY))
        (void)tt_message_user_set (ttMessage, TT_OBJECT_KEY, 0);
    } 
    else {
      (void)tt_message_destroy (ttMessage);
    }    
  } 
}   
 
Tt_status TTMessage::useDefaultMessageCallback (TTBoolean flag)
{
  Tt_status status;
 
  if (flag && !messageCallback && !useDefaultMessageCallbackFlag) 
    status = tt_message_callback_add (ttMessage,
                                      &TTMessage::internalMessageCallback);
 
  useDefaultMessageCallbackFlag = (status == TT_OK ? flag : TT_FALSE);
  return status; 
}

Tt_callback_action TTMessage::defaultMessageCallback ()
{
  return TT_CALLBACK_CONTINUE;
}

Tt_callback_action TTMessage::internalMessageCallback (Tt_message message,
						       Tt_pattern /* pattern */)
{
  TTMessage *message_object = (TTMessage *)tt_message_user (message,
							    TT_OBJECT_KEY);
  if (!message_object || (tt_ptr_error (message_object) != TT_OK))
    return TT_CALLBACK_CONTINUE;

  if (message_object->useDefaultMessageCallbackFlag)
    return message_object->defaultMessageCallback ();
  else if (message_object->messageCallback)
    return (*message_object->messageCallback) (message_object);

  return TT_CALLBACK_CONTINUE;
}
