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

DIRECTORY
  SunRPC,
  SunRPCAuth,
  Rope,
  TabPostOfficeGetPut,
  TabPostOffice;

TabPostOfficeServerImpl: CEDAR PROGRAM
  IMPORTS Rope, SunRPC, TabPostOfficeGetPut
  EXPORTS TabPostOffice =
BEGIN
ROPE: TYPE = Rope.ROPE;

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

defaultReplyTTL: CARDINAL ← 10;

MakeServer1Server: PUBLIC PROC[
  data: REF,
  tpostartsession: TabPostOffice.tpostartsessionProc,
  tpogetmsginfo: TabPostOffice.tpogetmsginfoProc,
  tpogetmsgtext: TabPostOffice.tpogetmsgtextProc,
  tpochecknewmail: TabPostOffice.tpochecknewmailProc,
  tpogetfolders: TabPostOffice.tpogetfoldersProc,
  tpomarkmsg: TabPostOffice.tpomarkmsgProc,
  tpoendsession: TabPostOffice.tpoendsessionProc
  ] RETURNS [SunRPC.Server] ~ {

  pseudoClient: TabPostOffice.Server1 ~
	NEW[TabPostOffice.Server1Object ← [
		rpcHandle ~ NIL, rpcConversation ~ NIL, data ~ data,
		tpostartsession ~ tpostartsession,
		tpogetmsginfo ~ tpogetmsginfo,
		tpogetmsgtext ~ tpogetmsgtext,
		tpochecknewmail ~ tpochecknewmail,
		tpogetfolders ~ tpogetfolders,
		tpomarkmsg ~ tpomarkmsg,
		tpoendsession ~ tpoendsession
	]];

unbound: SunRPC.Server ~ NEW[SunRPC.ServerObject ← [
	pgm ~ TabPostOffice.Server,
	version ~ TabPostOffice.Vers1,
	clientData ~ pseudoClient,
	serverProc ~ Server1Handler
	]];

RETURN [unbound];
  };

Server1Handler: SunRPC.ServerProc -- [h: Handle, c: Conversation, proc: CARD, clientData: REFANY
		-- RETURNS [doReply: BOOLEAN, replyTimeToLive: CARDINAL] -- = {
  o: TabPostOffice.Server1 ← NARROW[clientData];
  doReply ← TRUE;
  replyTimeToLive ← defaultReplyTTL;
  SELECT proc FROM
    1 => tpostartsession1[h, c, o];
    2 => tpogetmsginfo1[h, c, o];
    3 => tpogetmsgtext1[h, c, o];
    4 => tpochecknewmail1[h, c, o];
    5 => tpogetfolders1[h, c, o];
    6 => tpomarkmsg1[h, c, o];
    7 => tpoendsession1[h, c, o];
    ENDCASE => ERROR SunRPC.Error[$wrongProc];
  };

tpostartsession1: PROC[h: Handle, c: Conversation, o: TabPostOffice.Server1] = {
    numselects: INT32;
    plist: TabPostOffice.PropInfoArray;
    numorders: INT32;
    olist: TabPostOffice.PropertyArray;
    out: TabPostOffice.SessionResult;
    numselects ← SunRPC.GetInt32[h];
    plist ← TabPostOfficeGetPut.GetPropInfoArray[h];
    numorders ← SunRPC.GetInt32[h];
    olist ← TabPostOfficeGetPut.GetPropertyArray[h];
    out ← o.tpostartsession[o,
			numselects,
			plist,
			numorders,
			olist];
    SunRPC.StartReply[h];
    TabPostOfficeGetPut.PutSessionResult[h, out];
};

tpogetmsginfo1: PROC[h: Handle, c: Conversation, o: TabPostOffice.Server1] = {
    beginId: TabPostOffice.MsgID;
    endId: TabPostOffice.MsgID;
    out: TabPostOffice.MsgInfoResult;
    beginId ← TabPostOfficeGetPut.GetMsgID[h];
    endId ← TabPostOfficeGetPut.GetMsgID[h];
    out ← o.tpogetmsginfo[o,
			beginId,
			endId];
    SunRPC.StartReply[h];
    TabPostOfficeGetPut.PutMsgInfoResult[h, out];
};

tpogetmsgtext1: PROC[h: Handle, c: Conversation, o: TabPostOffice.Server1] = {
    msgId: TabPostOffice.MsgID;
    beginByte: INT32;
    numBytes: INT32;
    whence: TabPostOffice.Whences;
    out: TabPostOffice.MsgTextResult;
    msgId ← TabPostOfficeGetPut.GetMsgID[h];
    beginByte ← SunRPC.GetInt32[h];
    numBytes ← SunRPC.GetInt32[h];
    whence ← TabPostOfficeGetPut.GetWhences[h];
    out ← o.tpogetmsgtext[o,
			msgId,
			beginByte,
			numBytes,
			whence];
    SunRPC.StartReply[h];
    TabPostOfficeGetPut.PutMsgTextResult[h, out];
};

tpochecknewmail1: PROC[h: Handle, c: Conversation, o: TabPostOffice.Server1] = {
    out: TabPostOffice.NewMailResult;
    out ← o.tpochecknewmail[o];
    SunRPC.StartReply[h];
    TabPostOfficeGetPut.PutNewMailResult[h, out];
};

tpogetfolders1: PROC[h: Handle, c: Conversation, o: TabPostOffice.Server1] = {
    out: TabPostOffice.FoldersResult;
    out ← o.tpogetfolders[o];
    SunRPC.StartReply[h];
    TabPostOfficeGetPut.PutFoldersResult[h, out];
};

tpomarkmsg1: PROC[h: Handle, c: Conversation, o: TabPostOffice.Server1] = {
    msgId: TabPostOffice.MsgID;
    markID: ROPE;
    markMsg: ROPE;
    out: TabPostOffice.ErrorInfo;
    msgId ← TabPostOfficeGetPut.GetMsgID[h];
    markID ← SunRPC.GetRope[h];
    markMsg ← SunRPC.GetRope[h];
    out ← o.tpomarkmsg[o,
			msgId,
			markID,
			markMsg];
    SunRPC.StartReply[h];
    TabPostOfficeGetPut.PutErrorInfo[h, out];
};

tpoendsession1: PROC[h: Handle, c: Conversation, o: TabPostOffice.Server1] = {
    out: TabPostOffice.ErrorInfo;
    out ← o.tpoendsession[o];
    SunRPC.StartReply[h];
    TabPostOfficeGetPut.PutErrorInfo[h, out];
};


END.