/*
 * This file was automatically generated with ILU (version 2.0beta1) tools
 * at Tue Sep 21 11:46:00 1999 by `nobody'
 * running "c:/iluwin/bin/c-stubber.exe" of Tue Sep 21 10:50:33 1999
 * on "C:/iluwin/examples/httest/iluhttp.isl" of Mon Sep 20 15:51:46 1999,
 * and "c:/iluwin/interfaces/ilu.isl" of Mon Sep 20 15:51:47 1999.
 *
 * ILU is Copyright 1991-1999 Xerox Corporation, All Rights Reserved.
 * ILU information:  ftp://ftp.parc.xerox.com/pub/ilu/ilu.html.
 */

#include <stdio.h>

#include "iluhttp.h"

static ILU_C_Class _iluhttp_Resource__DefaultClass = 0;

ILU_C_Class iluhttp_Resource__SetDefaultClass(ILU_C_Class c)
{
  ILU_C_Class oldclass = _iluhttp_Resource__DefaultClass;
  _iluhttp_Resource__DefaultClass = c;
  return oldclass;
}

static void _iluhttp_Resource_GET__truestub(ilu_Call _call, ilu_Error *_err)
{
  iluhttp_Resource _h = {0};
  ILU_C_ENVIRONMENT _status;
  int _state = 1; /* keeps track of state of args for resource mgmt purposes */
  iluhttp_Request request = {0};
  iluhttp_Response* _retvalue = {0};

  _status.returnCode = ILU_NIL;
  _status.ptr = ILU_NIL;
  ILU_CLER(*_err);
  _state = 2;
  _h = (iluhttp_Resource) _ILU_C_InputObject (_call, _iluhttp_Resource__ILUType, ilu_TRUE, _err);
  if (ILU_ERRNOK(*_err))
    goto errexit;
  (void) _iluhttp_Request__Input (_call, &request,  _err); if (ILU_ERRNOK(*_err)) goto marshalError;
  if (_ILU_C_FinishParameters (_call, _h, _err)) {
    _ILU_C_SetCallerContext(ilu_CallerPassportOfCall(_call));
    _retvalue = iluhttp_Resource_GET (_h, &request, &_status);
    _ILU_C_SetCallerContext(ILU_NIL);
    _state = 3;
    /* check for errors */
    if (_status.returnCode == ILU_NIL) {
      ilu_cardinal _size = 0;
      if (ilu_CallNeedsSizing(_call)) {
        _size = ilu_BeginSizingReply(_call, ilu_FALSE, _err);
        if (ILU_ERRNOK(*_err)) goto errexit;
        _size += _iluhttp_Response__SizeOf (_call, &*_retvalue,_err);
        if (ILU_ERRNOK(*_err)) goto errexit;
      };
      if (!_ILU_C_BeginReply (_call, ilu_FALSE, _size, _err)) goto errexit;
      _iluhttp_Response__Output(_call, _retvalue,_err); if (ILU_ERRNOK(*_err)) goto marshalError;
      if (! _ILU_C_FinishReply (_call, _err)) goto errexit;
    }
    else {
      (void) ILU_ERR_CONS1(bad_param, _err, minor, ilu_bpm_some_raise, 6);
    }
  }

marshalError:
errexit:
  _ILU_C_FinishServingCall(_call, _err);
  switch (_state) {
    case 3: /* after true call */
      if (_status.returnCode == ILU_NIL) {
        iluhttp_Response__Free (_retvalue);
        CORBA_free(_retvalue);
      };
    case 2: /* input args unmarshalled, but before call */
      iluhttp_Request__Free (&request);
      _ILU_C_Object_release(_h);
    case 1: /* before unmarshalling any arguments */
break;
    default:
      break;
  };
  return;
}

static void _iluhttp_Resource_HEAD__truestub(ilu_Call _call, ilu_Error *_err)
{
  iluhttp_Resource _h = {0};
  ILU_C_ENVIRONMENT _status;
  int _state = 1; /* keeps track of state of args for resource mgmt purposes */
  iluhttp_Request request = {0};
  iluhttp_Response* _retvalue = {0};

  _status.returnCode = ILU_NIL;
  _status.ptr = ILU_NIL;
  ILU_CLER(*_err);
  _state = 2;
  _h = (iluhttp_Resource) _ILU_C_InputObject (_call, _iluhttp_Resource__ILUType, ilu_TRUE, _err);
  if (ILU_ERRNOK(*_err))
    goto errexit;
  (void) _iluhttp_Request__Input (_call, &request,  _err); if (ILU_ERRNOK(*_err)) goto marshalError;
  if (_ILU_C_FinishParameters (_call, _h, _err)) {
    _ILU_C_SetCallerContext(ilu_CallerPassportOfCall(_call));
    _retvalue = iluhttp_Resource_HEAD (_h, &request, &_status);
    _ILU_C_SetCallerContext(ILU_NIL);
    _state = 3;
    /* check for errors */
    if (_status.returnCode == ILU_NIL) {
      ilu_cardinal _size = 0;
      if (ilu_CallNeedsSizing(_call)) {
        _size = ilu_BeginSizingReply(_call, ilu_FALSE, _err);
        if (ILU_ERRNOK(*_err)) goto errexit;
        _size += _iluhttp_Response__SizeOf (_call, &*_retvalue,_err);
        if (ILU_ERRNOK(*_err)) goto errexit;
      };
      if (!_ILU_C_BeginReply (_call, ilu_FALSE, _size, _err)) goto errexit;
      _iluhttp_Response__Output(_call, _retvalue,_err); if (ILU_ERRNOK(*_err)) goto marshalError;
      if (! _ILU_C_FinishReply (_call, _err)) goto errexit;
    }
    else {
      (void) ILU_ERR_CONS1(bad_param, _err, minor, ilu_bpm_some_raise, 6);
    }
  }

marshalError:
errexit:
  _ILU_C_FinishServingCall(_call, _err);
  switch (_state) {
    case 3: /* after true call */
      if (_status.returnCode == ILU_NIL) {
        iluhttp_Response__Free (_retvalue);
        CORBA_free(_retvalue);
      };
    case 2: /* input args unmarshalled, but before call */
      iluhttp_Request__Free (&request);
      _ILU_C_Object_release(_h);
    case 1: /* before unmarshalling any arguments */
break;
    default:
      break;
  };
  return;
}

static void _iluhttp_Resource_POST__truestub(ilu_Call _call, ilu_Error *_err)
{
  iluhttp_Resource _h = {0};
  ILU_C_ENVIRONMENT _status;
  int _state = 1; /* keeps track of state of args for resource mgmt purposes */
  iluhttp_Request request = {0};
  iluhttp_Response* _retvalue = {0};

  _status.returnCode = ILU_NIL;
  _status.ptr = ILU_NIL;
  ILU_CLER(*_err);
  _state = 2;
  _h = (iluhttp_Resource) _ILU_C_InputObject (_call, _iluhttp_Resource__ILUType, ilu_TRUE, _err);
  if (ILU_ERRNOK(*_err))
    goto errexit;
  (void) _iluhttp_Request__Input (_call, &request,  _err); if (ILU_ERRNOK(*_err)) goto marshalError;
  if (_ILU_C_FinishParameters (_call, _h, _err)) {
    _ILU_C_SetCallerContext(ilu_CallerPassportOfCall(_call));
    _retvalue = iluhttp_Resource_POST (_h, &request, &_status);
    _ILU_C_SetCallerContext(ILU_NIL);
    _state = 3;
    /* check for errors */
    if (_status.returnCode == ILU_NIL) {
      ilu_cardinal _size = 0;
      if (ilu_CallNeedsSizing(_call)) {
        _size = ilu_BeginSizingReply(_call, ilu_FALSE, _err);
        if (ILU_ERRNOK(*_err)) goto errexit;
        _size += _iluhttp_Response__SizeOf (_call, &*_retvalue,_err);
        if (ILU_ERRNOK(*_err)) goto errexit;
      };
      if (!_ILU_C_BeginReply (_call, ilu_FALSE, _size, _err)) goto errexit;
      _iluhttp_Response__Output(_call, _retvalue,_err); if (ILU_ERRNOK(*_err)) goto marshalError;
      if (! _ILU_C_FinishReply (_call, _err)) goto errexit;
    }
    else {
      (void) ILU_ERR_CONS1(bad_param, _err, minor, ilu_bpm_some_raise, 6);
    }
  }

marshalError:
errexit:
  _ILU_C_FinishServingCall(_call, _err);
  switch (_state) {
    case 3: /* after true call */
      if (_status.returnCode == ILU_NIL) {
        iluhttp_Response__Free (_retvalue);
        CORBA_free(_retvalue);
      };
    case 2: /* input args unmarshalled, but before call */
      iluhttp_Request__Free (&request);
      _ILU_C_Object_release(_h);
    case 1: /* before unmarshalling any arguments */
break;
    default:
      break;
  };
  return;
}

ILU_C_OBJECT iluhttp_Resource__CreateTrue  (ilu_string instance_handle, ILU_C_Server server, void * data)
{
  if (_iluhttp_Resource__DefaultClass == ILU_NIL) return ILU_NIL;
  return (ILU_C_CreateTrueObject (_iluhttp_Resource__DefaultClass, instance_handle, server, data, ilu_FALSE));
}

ILU_C_OBJECT iluhttp_Resource__OTCreateTrue  (ilu_string instance_handle, ILU_C_Server server, void * data)
{
  if (server == ILU_NIL || instance_handle == ILU_NIL || _iluhttp_Resource__DefaultClass == ILU_NIL) return ILU_NIL;
  return (ILU_C_CreateTrueObject (_iluhttp_Resource__DefaultClass, instance_handle, server, data, ilu_TRUE));
}

void iluhttp_Resource__SetDefaultClassFinalization  (ILU_C_FinalizationProc f)
{
  if (_iluhttp_Resource__DefaultClass != ILU_NIL)
    _iluhttp_Resource__DefaultClass->ilucc_finalize = f;
}

void iluhttp__InitializeServer(void)
{
  extern void _iluhttp__GeneralInitialization(void);
  static ilu_boolean initialized = ilu_FALSE;
  if (initialized) return;
  initialized = ilu_TRUE;

  _iluhttp__GeneralInitialization ();
  _iluhttp_Resource__DefaultClass = iluhttp_Resource__MakeClass(
    server_iluhttp_Resource_GET,
    server_iluhttp_Resource_HEAD,
    server_iluhttp_Resource_POST,
    0 /* no finalization */
    );

  ilu_SetMethodStubProc(&_iluhttp_Resource__ILUType->cl_methods[0], (ilu_StubProc) _iluhttp_Resource_GET__truestub, _ILU_C_LanguageIndex);;
  ilu_SetMethodStubProc(&_iluhttp_Resource__ILUType->cl_methods[1], (ilu_StubProc) _iluhttp_Resource_HEAD__truestub, _ILU_C_LanguageIndex);;
  ilu_SetMethodStubProc(&_iluhttp_Resource__ILUType->cl_methods[2], (ilu_StubProc) _iluhttp_Resource_POST__truestub, _ILU_C_LanguageIndex);;
}

