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

#include "Gauge.h"
#include "Slider.h"
#include "TTMessage.h"
#include "TTSession.h"

/*
 * Notify callback function for `slider'.
 */
void slider_notify (UIObject *object)
{
  static TTMessage *message;

  Tt_status  status;
  TTSession *session = (TTSession *)object->getObjectData ("TT_SESSION");

  int value = object->getValue (value);

  if (!message) {
    message = new TTMessage ("ExampleMessage", TT_NOTICE, TT_SESSION, status);
    status = message->addArg (TT_IN, "value", value);
  }
  else {
    status = message->setArgValue (0, value);
  }

  if (status == TT_OK)
    (void)session->sendAsynchronousMessage (*message);
}

void receive_tt_message (UIObject *object, int fd)
{
  Gauge *gauge = (Gauge *)object;

  int        mark = tt_mark ();
  Tt_status  status;
  TTSession *session = (TTSession *)gauge->getObjectData ("TT_SESSION");
  TTMessage *message = session->receiveAsynchronousMessage (status);

  if (message) {
    int value;

    status = message->getArgValue (0, value);    
    if (status == TT_OK)
      gauge->setValue (value);

    delete message;
  }

  tt_release (mark);
}
