#include <stdlib.h>
#include "TempControl_SK.h"

TempControl_SK::TempControl_SK()
  :  TaskServer(TempControlServerName)
{
  // Add callbacks for each method
  addCallback(TempControl::SetpointMsgCode,
             (CallbackPtr )TempControl_SK::setpointCallback);

  addCallback(TempControl::FooMsgCode,
             (CallbackPtr )TempControl_SK::fooCallback);

  addCallback(TempControl::ActualMsgCode,
             (CallbackPtr )TempControl_SK::actualCallback);

  addCallback(TempControl::Func2MsgCode,
             (CallbackPtr )TempControl_SK::func2Callback);

}


TempControl_SK::~TempControl_SK()
{
}

Boolean TempControl_SK::setpointCallback(Request *request, int nReqBytes,
                          Reply **reply, int *nReplyBytes)
{
  // Invoke method implementation
  _setpointMsg->returnVal = 
     setpoint();

  *reply = _setpointMsg;
  *nReplyBytes = sizeof(TempControl::SetpointMsg);
  return True;
}


Boolean TempControl_SK::fooCallback(Request *request, int nReqBytes,
                          Reply **reply, int *nReplyBytes)
{
  // Invoke method implementation
  _fooMsg->returnVal = 
     foo(_fooMsg->junk);

  *reply = _fooMsg;
  *nReplyBytes = sizeof(TempControl::FooMsg);
  return True;
}


Boolean TempControl_SK::actualCallback(Request *request, int nReqBytes,
                          Reply **reply, int *nReplyBytes)
{
  // Invoke method implementation
  _actualMsg->returnVal = 
     actual(_actualMsg->index, &_actualMsg->mdata, &_actualMsg->tdata);

  *reply = _actualMsg;
  *nReplyBytes = sizeof(TempControl::ActualMsg);
  return True;
}


Boolean TempControl_SK::func2Callback(Request *request, int nReqBytes,
                          Reply **reply, int *nReplyBytes)
{
  // Invoke method implementation
  func2(_func2Msg->value, &_func2Msg->flag);

  *reply = _func2Msg;
  *nReplyBytes = sizeof(TempControl::Func2Msg);
  return True;
}


size_t TempControl_SK::maxRequestBytes()
{
  size_t nBytes = 0;
  nBytes = max(nBytes, sizeof(TempControl::SetpointMsg));
  nBytes = max(nBytes, sizeof(TempControl::FooMsg));
  nBytes = max(nBytes, sizeof(TempControl::ActualMsg));
  nBytes = max(nBytes, sizeof(TempControl::Func2Msg));
  return nBytes;
}


void TempControl_SK::allocateBuffers()
{
  TaskServer::allocateBuffers();

  _setpointMsg = (TempControl::SetpointMsg *)_requestPtr;
  _fooMsg = (TempControl::FooMsg *)_requestPtr;
  _actualMsg = (TempControl::ActualMsg *)_requestPtr;
  _func2Msg = (TempControl::Func2Msg *)_requestPtr;
}


