fortytwoServerMamesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Theimer, July 7, 1992 12:55 pm PDT
Willie-s, May 19, 1992 5:09 pm PDT
DIRECTORY
fortytwo,
fourtwo,
fortyone,
Commander,
IO,
Rope,
SunRPC,
SunRPCBinding;
fortytwoServerMain: CEDAR PROGRAM
IMPORTS Commander, IO, Rope, fortytwo, SunRPCBinding
= BEGIN
OPEN fortytwo, fourtwo;
ROPE: TYPE = Rope.ROPE;
out: IO.STREAM;
GETANSWER: getanswerProc =
BEGIN
aQ: ROPE ¬ IO.PutFR1["%g", IO.text[anotherQuestion]];
IO.PutRope[out, "GETANSWER\n"];
IO.PutF1[out, "theQuestion: %g\n", IO.rope[theQuestion]];
IO.PutF1[out, "aRandomNumber: %g\n", IO.int[aRandomNumber]];
IO.PutF[out, "anotherQuestion: (%g) %g\n", IO.int[Rope.Length[aQ]], IO.rope[aQ]];
res.theAnswer ¬ 42;
res.aDifferentAnswer ¬ "43";
res.anotherAnswer ¬ "444\000";
res.anotherDifferentAnswer ¬ NEW [INT32];
res.anotherDifferentAnswer­ ¬ 44;
END;
GETTRUEANSWER: gettrueanswerProc =
BEGIN
r: REF cosmic TheANSWERObject;
IO.PutRope[out, "GETTRUEANSWER\n"];
IO.PutF1[out, "questionType: %g\n", IO.int[ORD[questionType]]];
IO.PutF[out, "randomNumbers: (%g) {%g}\n", IO.int[randomNumbers.size], IO.int[randomNumbers­[0]]];
res.tellingTheTruth ¬ TRUE;
res.theTruth[0] ¬ 13;
res.theTruth[1] ¬ 42;
res.theTruth[2] ¬ 137;
r ¬ NEW[cosmic TheANSWERObject];
r.c ¬ 1024;
res.theTRUTH ¬ r;
END;
GETBOGUSANSWER: getbogusanswerProc =
BEGIN
IO.PutRope[out, "GETBOGUSANSWER\n"];
res ¬ 10;
END;
DONTANSWER: dontanswerProc =
BEGIN
IO.PutRope[out, "DONTANSWER\n"];
IO.PutF1[out, "in: %g\n", IO.int[in]];
END;
GETTHEANSWER: gettheanswerProc =
BEGIN
r: REF silly TheANSWERObject;
IO.PutRope[out, "GETTHEANSWER\n"];
IO.PutF1[out, "questionType: %g\n", IO.int[ORD[questionType]]];
IO.PutF[out, "randomNumbers: (%g) {%g, %g}\n", IO.int[randomNumbers.size], IO.int[randomNumbers­[0]], IO.int[randomNumbers­[0]]];
res.tellingTheTruth ¬ FALSE;
res.theTruth[0] ¬ -1;
res.theTruth[1] ¬ -2;
res.theTruth[2] ¬ -42;
r ¬ NEW[silly TheANSWERObject];
r.d ¬ NEW [answerRec];
r.d.theAnswer ¬ 137;
r.d.aDifferentAnswer ¬ "1/137";
r.d.anotherAnswer ¬ "666\000";
r.d.anotherDifferentAnswer ¬ NEW [INT32];
r.d.anotherDifferentAnswer­ ¬ 99;
res.theTRUTH ¬ r;
END;
DOTEST: dotestProc =
BEGIN
IO.PutRope[out, "DOTEST\n"];
IO.PutF1[out, "a: %g\n", IO.real[a]];
IO.PutF1[out, "c: %g\n", IO.char[VAL[c]]];
IO.PutF1[out, "d: %g\n", IO.int[d]];
IO.PutF1[out, "e: %g\n", IO.int[e]];
IO.PutF1[out, "f: %g\n", IO.int[f]];
IO.PutF1[out, "g: %g\n", IO.int[g]];
IO.PutF1[out, "h: %g\n", IO.int[h]];
IO.PutF1[out, "i: %g\n", IO.int[i]];
IO.PutF1[out, "j: %g\n", IO.int[j]];
IO.PutFL[out, "k: (%g) {(%g, %g), (%g, %g)}\n",
    LIST[IO.int[k.size],
    IO.int[k­[0].x], IO.int[k­[0].y],
    IO.int[k­[1].x], IO.int[k­[1].y]] ];
IO.PutF[out, "l: {%g%g%g}\n", IO.char[VAL[l[0]]], IO.char[VAL[l[1]]], IO.char[VAL[l[2]]]];
IO.PutF[out, "m: (%g) {%g, %g}\n",
    IO.int[m.size],
    IO.int[m­[0]],
    IO.int[m­[1]]];
res.a := 6.2832;
res.b := 8.53539;
res.c := ORD['d];
res.d := 14;
res.e := 43;
res.f := 138;
res.g := 130;
res.h := 15;
res.i := 44;
res.j := 139;
res.k := NEW[fortytwo.SeqType2Object[2]];
res.k­[0].x := -2;
res.k­[0].y := -2;
res.k­[1].x := 2;
res.k­[1].y := 2;
res.l[0] ¬ ORD['d];
res.l[1] ¬ ORD['o];
res.l[2] ¬ ORD['g];
res.m := NEW[fortytwo.SeqType3Object[2]];
res.m­[0] := 83;
res.m­[1] := 84;
END;
fortytwoServer: Commander.CommandProc =
BEGIN
p1: SunRPC.Server ¬ fortytwo.MakeFORTYTWOPROG1Server [NIL, GETANSWER, GETTRUEANSWER, GETBOGUSANSWER, DONTANSWER];
p2: SunRPC.Server ¬ fortytwo.MakeFORTYTWOPROG2Server[NIL, GETTHEANSWER];
p3: SunRPC.Server ¬ fortytwo.MakeTESTTYPESPROG3Server[NIL, DOTEST];
out ¬ cmd.out;
IO.PutRope[out, "Hello from the fortytwo server.\n"];
[] ← SunRPCBinding.Export[p1, NIL, $UDP];
[] ← SunRPCBinding.Export[p2, NIL, $UDP];
[] ← SunRPCBinding.Export[p3, NIL, $UDP];
END;
usage: ROPE = "
  \tfortytwo RPC server.";
Commander.Register["fortytwoServer", fortytwoServer, usage];
END.