-- fortytwoServerImpl.mesa
-- Please do not edit this file.
-- It was generated using CedarRPCGen.

DIRECTORY
  SunRPC,
  SunRPCAuth,
  Rope,
  fortyone,
  fourtwo,
  fourtwoGetPut,
  fortytwoGetPut,
  fortytwo;

fortytwoServerImpl: CEDAR PROGRAM
  IMPORTS Rope, SunRPC, fourtwoGetPut, fortytwoGetPut
  EXPORTS fortytwo =
BEGIN
ROPE: TYPE = Rope.ROPE;

Handle: TYPE = SunRPC.Handle;
Conversation: TYPE = SunRPCAuth.Conversation;

defaultReplyTTL: CARDINAL ← 10;

MakeFORTYTWOPROG1Server: PUBLIC PROC[
  data: REF,
  getanswer: fortytwo.getanswerProc,
  gettrueanswer: fortytwo.gettrueanswerProc,
  getbogusanswer: fortytwo.getbogusanswerProc,
  dontanswer: fortytwo.dontanswerProc
  ] RETURNS [SunRPC.Server] ~ {

  pseudoClient: fortytwo.FORTYTWOPROG1 ~
	NEW[fortytwo.FORTYTWOPROG1Object ← [
		rpcHandle ~ NIL, rpcConversation ~ NIL, data ~ data,
		getanswer ~ getanswer,
		gettrueanswer ~ gettrueanswer,
		getbogusanswer ~ getbogusanswer,
		dontanswer ~ dontanswer
	]];

unbound: SunRPC.Server ~ NEW[SunRPC.ServerObject ← [
	pgm ~ fortytwo.FORTYTWOPROG,
	version ~ fortytwo.FORTYTWOVERS1,
	clientData ~ pseudoClient,
	serverProc ~ FORTYTWOPROG1Handler
	]];

RETURN [unbound];
  };

FORTYTWOPROG1Handler: SunRPC.ServerProc -- [h: Handle, c: Conversation, proc: CARD, clientData: REFANY
		-- RETURNS [doReply: BOOLEAN, replyTimeToLive: CARDINAL] -- = {
  o: fortytwo.FORTYTWOPROG1 ← NARROW[clientData];
  doReply ← TRUE;
  replyTimeToLive ← defaultReplyTTL;
  SELECT proc FROM
    1 => getanswer1[h, c, o];
    2 => gettrueanswer1[h, c, o];
    3 => getbogusanswer1[h, c, o];
    4 => dontanswer1[h, c, o];
    ENDCASE => ERROR SunRPC.Error[$wrongProc];
  };

getanswer1: PROC[h: Handle, c: Conversation, o: fortytwo.FORTYTWOPROG1] = {
    theQuestion: ROPE;
    aRandomNumber: CARD16;
    anotherQuestion: REF TEXT;
    out: fourtwo.answerRec;
    theQuestion ← SunRPC.GetRope[h];
    aRandomNumber ← SunRPC.GetCard32[h];
    anotherQuestion ← SunRPC.GetRefText[h];
    out ← o.getanswer[o,
			theQuestion,
			aRandomNumber,
			anotherQuestion];
    SunRPC.StartReply[h];
    fourtwoGetPut.PutanswerRec[h, out];
};

gettrueanswer1: PROC[h: Handle, c: Conversation, o: fortytwo.FORTYTWOPROG1] = {
    questionType: fortytwo.QuestionType;
    randomNumbers: fortytwo.SeqType0;
    out: fortytwo.trueAnswerRec;
    questionType ← fortytwoGetPut.GetQuestionType[h];
    {
    len: INT ← SunRPC.GetInt32[h];
    randomNumbers ← NEW[fortytwo.SeqType0Object[len]];
    FOR i: INT IN [0..len) DO
      randomNumbers[i] ← SunRPC.GetInt32[h];
      ENDLOOP;
    };
    out ← o.gettrueanswer[o,
			questionType,
			randomNumbers];
    SunRPC.StartReply[h];
    fortytwoGetPut.PuttrueAnswerRec[h, out];
};

getbogusanswer1: PROC[h: Handle, c: Conversation, o: fortytwo.FORTYTWOPROG1] = {
    out: INT32;
    out ← o.getbogusanswer[o];
    SunRPC.StartReply[h];
    SunRPC.PutInt32[h, out];
};

dontanswer1: PROC[h: Handle, c: Conversation, o: fortytwo.FORTYTWOPROG1] = {
    in: INT32;
    in ← SunRPC.GetInt32[h];
    o.dontanswer[o, in];
    SunRPC.StartReply[h];
};


MakeFORTYTWOPROG2Server: PUBLIC PROC[
  data: REF,
  gettheanswer: fortytwo.gettheanswerProc
  ] RETURNS [SunRPC.Server] ~ {

  pseudoClient: fortytwo.FORTYTWOPROG2 ~
	NEW[fortytwo.FORTYTWOPROG2Object ← [
		rpcHandle ~ NIL, rpcConversation ~ NIL, data ~ data,
		gettheanswer ~ gettheanswer
	]];

unbound: SunRPC.Server ~ NEW[SunRPC.ServerObject ← [
	pgm ~ fortytwo.FORTYTWOPROG,
	version ~ fortytwo.FORTYTWOVERS2,
	clientData ~ pseudoClient,
	serverProc ~ FORTYTWOPROG2Handler
	]];

RETURN [unbound];
  };

FORTYTWOPROG2Handler: SunRPC.ServerProc -- [h: Handle, c: Conversation, proc: CARD, clientData: REFANY
		-- RETURNS [doReply: BOOLEAN, replyTimeToLive: CARDINAL] -- = {
  o: fortytwo.FORTYTWOPROG2 ← NARROW[clientData];
  doReply ← TRUE;
  replyTimeToLive ← defaultReplyTTL;
  SELECT proc FROM
    1 => gettheanswer2[h, c, o];
    ENDCASE => ERROR SunRPC.Error[$wrongProc];
  };

gettheanswer2: PROC[h: Handle, c: Conversation, o: fortytwo.FORTYTWOPROG2] = {
    questionType: fortytwo.QuestionType;
    randomNumbers: fortytwo.SeqType0;
    out: fortytwo.AnswerRec;
    questionType ← fortytwoGetPut.GetQuestionType[h];
    {
    len: INT ← SunRPC.GetInt32[h];
    randomNumbers ← NEW[fortytwo.SeqType0Object[len]];
    FOR i: INT IN [0..len) DO
      randomNumbers[i] ← SunRPC.GetInt32[h];
      ENDLOOP;
    };
    out ← o.gettheanswer[o,
			questionType,
			randomNumbers];
    SunRPC.StartReply[h];
    fortytwoGetPut.PutAnswerRec[h, out];
};


MakeTESTTYPESPROG3Server: PUBLIC PROC[
  data: REF,
  dotest: fortytwo.dotestProc
  ] RETURNS [SunRPC.Server] ~ {

  pseudoClient: fortytwo.TESTTYPESPROG3 ~
	NEW[fortytwo.TESTTYPESPROG3Object ← [
		rpcHandle ~ NIL, rpcConversation ~ NIL, data ~ data,
		dotest ~ dotest
	]];

unbound: SunRPC.Server ~ NEW[SunRPC.ServerObject ← [
	pgm ~ fortytwo.TESTTYPESPROG,
	version ~ fortytwo.TESTTYPES3,
	clientData ~ pseudoClient,
	serverProc ~ TESTTYPESPROG3Handler
	]];

RETURN [unbound];
  };

TESTTYPESPROG3Handler: SunRPC.ServerProc -- [h: Handle, c: Conversation, proc: CARD, clientData: REFANY
		-- RETURNS [doReply: BOOLEAN, replyTimeToLive: CARDINAL] -- = {
  o: fortytwo.TESTTYPESPROG3 ← NARROW[clientData];
  doReply ← TRUE;
  replyTimeToLive ← defaultReplyTTL;
  SELECT proc FROM
    13 => dotest3[h, c, o];
    ENDCASE => ERROR SunRPC.Error[$wrongProc];
  };

dotest3: PROC[h0: Handle, c0: Conversation, o: fortytwo.TESTTYPESPROG3] = {
    a: REAL;
    b: DREAL;
    c: BYTE;
    d: INT16;
    e: INT32;
    f: INT32;
    g: BYTE;
    h: CARD16;
    i: CARD32;
    j: CARD32;
    k: fortytwo.SeqType2;
    l: PACKED ARRAY [0..3) OF BYTE;
    m: fortytwo.SeqType3;
    out: fortytwo.randomTypes;
    a ← SunRPC.GetReal[h0];
    b ← SunRPC.GetDReal[h0];
    [] ← SunRPC.GetByte[h0];
    [] ← SunRPC.GetByte[h0];
    [] ← SunRPC.GetByte[h0];
    c ← SunRPC.GetByte[h0];
    d ← SunRPC.GetInt32[h0];
    e ← SunRPC.GetInt32[h0];
    f ← SunRPC.GetInt32[h0];
    [] ← SunRPC.GetByte[h0];
    [] ← SunRPC.GetByte[h0];
    [] ← SunRPC.GetByte[h0];
    g ← SunRPC.GetByte[h0];
    h ← SunRPC.GetCard32[h0];
    i ← SunRPC.GetCard32[h0];
    j ← SunRPC.GetCard32[h0];
    {
    len: INT ← SunRPC.GetInt32[h0];
    k ← NEW[fortytwo.SeqType2Object[len]];
    FOR i: INT IN [0..len) DO
      k[i] ← fortytwoGetPut.Gettuple[h0];
      ENDLOOP;
    };
    FOR i: INT IN [0..3) DO
      l[i] ← SunRPC.GetByte[h0];
      ENDLOOP;
    SunRPC.GetAlign[h0];
    {
    len: INT ← SunRPC.GetInt32[h0];
    m ← NEW[fortytwo.SeqType3Object[len]];
    FOR i: INT IN [0..len) DO
      [] ← SunRPC.GetByte[h0];
      [] ← SunRPC.GetByte[h0];
      [] ← SunRPC.GetByte[h0];
      m[i] ← SunRPC.GetByte[h0];
      ENDLOOP;
    };
    out ← o.dotest[o,
			a,
			b,
			c,
			d,
			e,
			f,
			g,
			h,
			i,
			j,
			k,
			l,
			m];
    SunRPC.StartReply[h0];
    fortytwoGetPut.PutrandomTypes[h0, out];
};


END.