LoganBerrySunRPCServerStub.Mesa
Copyright Ó 1986, 1992 by Xerox Corporation. All rights reserved.
Adapted from LoganBerryP2205V1ServerImpl.mesa
Doug Terry, September 14, 1989 3:27:15 pm PDT
Brian Oki, May 29, 1990 4:31 pm PDT
Willie-s, April 23, 1992 3:14 pm PDT
DIRECTORY
Basics USING [Card16FromH],
Commander USING [CommandProc, Register],
SunPMap USING [ipProtocolUDP],
SunPMapLocal USING [SetLocal, UnsetLocal],
SunRPC,
SunRPCOnUDP,
LoganBerrySunRPC,
LoganBerrySunRPCServer;
LoganBerrySunRPCServerStub:
CEDAR
PROGRAM
IMPORTS Basics, Commander, SunPMapLocal, SunRPC, SunRPCOnUDP, LoganBerrySunRPCServer ~ {
OPEN LoganBerrySunRPC, LoganBerrySunRPCServer;
Types
Handle: TYPE ~ SunRPC.Handle;
CloseCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
[] ¬ Close[h, conv, db];
beginReturn[h];
};
DescribeCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
info: SchemaInfo;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
[info] ¬ Describe[h, conv, db];
beginReturn[h];
{
SunRPC.PutRope[h, info.dbName];
MProc12[h, info.logs];
MProc13[h, info.indices];
};
};
EndGenerateCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
cursor: CARD32;
{
conv ¬ SunRPC.GetCard32[h];
};
{
cursor ¬ SunRPC.GetCard32[h];
};
[] ¬ EndGenerate[h, conv, cursor];
beginReturn[h];
};
NextEntryCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
cursor: CARD32;
dir: CursorDirection;
entry: Entry;
{
conv ¬ SunRPC.GetCard32[h];
};
{
cursor ¬ SunRPC.GetCard32[h];
};
{
ord: CARDINAL ¬ SunRPC.GetCard32[h];
dir ¬ VAL[ord];
};
[entry] ¬ NextEntry[h, conv, cursor, dir];
beginReturn[h];
};
DeleteEntryCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
key: ROPE;
value: ROPE;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
{
key ¬ SunRPC.GetRope[h];
};
{
value ¬ SunRPC.GetRope[h];
};
[] ¬ DeleteEntry[h, conv, db, key, value];
beginReturn[h];
};
ReadEntryCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
key: ROPE;
value: ROPE;
entry: Entry;
others: BOOLEAN;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
{
key ¬ SunRPC.GetRope[h];
};
{
value ¬ SunRPC.GetRope[h];
};
[entry, others] ¬ ReadEntry[h, conv, db, key, value];
beginReturn[h];
};
OpenCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
dbName: ROPE;
db: CARD32;
{
conv ¬ SunRPC.GetCard32[h];
};
{
dbName ¬ SunRPC.GetRope[h];
};
[db] ¬ Open[h, conv, dbName];
beginReturn[h];
{
SunRPC.PutCard32[h, db];
};
};
WriteEntryCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
entry: Entry;
log: CARD32;
replace: BOOLEAN;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
{
log ¬ SunRPC.GetCard32[h];
};
{
replace ¬ GetBool[h];
};
[] ¬ WriteEntry[h, conv, db, entry, log, replace];
beginReturn[h];
};
GenerateEntriesCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
key: ROPE;
start: ROPE;
end: ROPE;
cursor: CARD32;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
{
key ¬ SunRPC.GetRope[h];
};
{
start ¬ SunRPC.GetRope[h];
};
{
end ¬ SunRPC.GetRope[h];
};
[cursor] ¬ GenerateEntries[h, conv, db, key, start, end];
beginReturn[h];
{
SunRPC.PutCard32[h, cursor];
};
};
BuildIndicesCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
[] ¬ BuildIndices[h, conv, db];
beginReturn[h];
};
CompactLogsCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
conv: CARD32;
db: CARD32;
{
conv ¬ SunRPC.GetCard32[h];
};
{
db ¬ SunRPC.GetCard32[h];
};
[] ¬ CompactLogs[h, conv, db];
beginReturn[h];
};
NullCaller:
PROC [h: Handle, beginReturn: SunRPCBeginReturnProc] ~ {
beginReturn[h];
};
SunRPCBeginReturnProc: TYPE ~ PROC [h: Handle];
Server: SunRPC.ServerProc ~ {
[h: Handle, c: Conversation, proc: CARD, clientData: REF] RETURNS [doReply: BOOL, replyTimeToLive: CARDINAL]
ENABLE {
LoganBerrySunRPCServer.Error => {
-- (1 )
SunRPC.StartReply[h];
SunRPC.PutRope[h, ec];
SunRPC.PutRope[h, explanation];
GOTO Finished;
};
};
beginReturn: SunRPCBeginReturnProc ~ {
SunRPC.StartReply[h];
SunRPC.PutRope[h, NIL]; -- no error
};
doReply ¬ TRUE;
replyTimeToLive ¬ 2;
SELECT proc
FROM
8 => CloseCaller[h, beginReturn];
1 => DescribeCaller[h, beginReturn];
5 => EndGenerateCaller[h, beginReturn];
4 => NextEntryCaller[h, beginReturn];
7 => DeleteEntryCaller[h, beginReturn];
2 => ReadEntryCaller[h, beginReturn];
11 => OpenCaller[h, beginReturn];
6 => WriteEntryCaller[h, beginReturn];
3 => GenerateEntriesCaller[h, beginReturn];
9 => BuildIndicesCaller[h, beginReturn];
10 => CompactLogsCaller[h, beginReturn];
0 => NullCaller[h, beginReturn];
ENDCASE => ERROR SunRPC.Error[$wrongProc];
EXITS
Finished => { NULL }
};
Unmarshal / Marshal Procs --
GetBool:
PROC [h: SunRPC.Handle]
RETURNS [
BOOL] ~
INLINE {
RETURN [SunRPC.GetCard32[h] # 0] };
PutBool:
PROC [h: SunRPC.Handle, bool:
BOOL] ~
INLINE {
SunRPC.PutCard32[h, IF bool THEN 1 ELSE 0] };
MProc14:
PROC [h: SunRPC.Handle, val: Entry] ~ {
SunRPC.PutCard32[h, val.length];
FOR i16:
CARDINAL
IN [0..val.length)
DO
SunRPC.PutRope[h, val.body[i16].type];
SunRPC.PutRope[h, val.body[i16].value];
ENDLOOP;
};
MProc13:
PROC [h: SunRPC.Handle, val: IndexList] ~ {
SunRPC.PutCard32[h, val.length];
FOR i17:
CARDINAL
IN [0..val.length)
DO
SunRPC.PutRope[h, val.body[i17].key];
SunRPC.PutRope[h, val.body[i17].file];
SunRPC.PutRope[h, val.body[i17].order];
ENDLOOP;
};
MProc12:
PROC [h: SunRPC.Handle, val: LogList] ~ {
SunRPC.PutCard32[h, val.length];
FOR i18:
CARDINAL
IN [0..val.length)
DO
SunRPC.PutCard32[h, val.body[i18].id];
SunRPC.PutRope[h, val.body[i18].file];
ENDLOOP;
};
UProc15:
PROC [h: SunRPC.Handle]
RETURNS [res: Entry] ~ {
{
length20: CARDINAL ~ SunRPC.GetCard32[h];
res ¬ NEW[EntryObject[length20]];
FOR i19:
CARDINAL
IN [0..length20)
DO
res.body[i19].type ¬ SunRPC.GetRope[h];
res.body[i19].value ¬ SunRPC.GetRope[h];
ENDLOOP;
};
};
LoganBerrySunServer: Commander.CommandProc ~ {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
sunPgm: CARD ¬ 390905; -- decimal program number
sunPgmVersion: CARD ¬ 1;
theServer: SunRPC.Server;
[] ¬ SunPMapLocal.UnsetLocal[program~sunPgm, version~sunPgmVersion]; -- in case server already running
theServer ¬ SunRPCOnUDP.CreateServer[pgm~sunPgm, serverProc~Server, version~sunPgmVersion];
[] ¬ SunPMapLocal.SetLocal[program~sunPgm, version~sunPgmVersion, protocol~SunPMap.ipProtocolUDP, port~Basics.Card16FromH[SunRPCOnUDP.GetServerPort[theServer]]];
};
Commander.Register[key: "LoganBerrySunServer", proc: LoganBerrySunServer, doc: "Install LoganBerry Sun server"];
}...