FSDummyImpl.mesa
Copyright Ó 1985, 1986, 1987 by Xerox Corporation. All rights reserved.
Bob Hagmann October 17, 1988 1:59:56 pm PDT
Schroeder, December 14, 1983 11:43 am
Levin, August 9, 1983 11:29 am
Russ Atkinson (RRA) May 13, 1985 8:48:39 pm PDT
DIRECTORY
BasicTime USING [GMT],
FS USING [ErrorDesc, FileType, Lock, OpenFile, tUnspecified],
FSBackdoor USING [],
FSOpenFile USING [ProcFile, ProcFileObj],
Rope USING [Concat, ROPE],
YggFile USING [bytesPerPage];
FSDummyImpl: CEDAR PROGRAM
IMPORTS Rope
EXPORTS FS, FSBackdoor
= {
Types
ProcFile: TYPE = FSOpenFile.ProcFile;
ProcFileObj: TYPE = FSOpenFile.ProcFileObj;
Exported to FS
Error: PUBLIC ERROR [error: FS.ErrorDesc] = CODE;
BytesForPages: PUBLIC PROC[pages: INT] RETURNS [bytes: INT] = {
RETURN [YggFile.bytesPerPage*pages]
};
GetClass: PUBLIC PROC [file: FS.OpenFile] RETURNS [a: ATOM] = {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.GetClass = NIL
THEN NotImplemented[]
ELSE a ← p.fileProcs.GetClass[p.clientFile];
ENDCASE => InvalidOpenFile[];
};
SameFile: PUBLIC PROC [file1, file2: FS.OpenFile] RETURNS [same: BOOL] = {
WITH file1 SELECT FROM
p1: ProcFile =>
WITH file2 SELECT FROM
p2: ProcFile =>
IF p1.fileProcs = p2.fileProcs
THEN {
IF p1.fileProcs.SameFile = NIL
THEN NotImplemented[]
ELSE RETURN [p1.fileProcs.SameFile[p1.clientFile, p2.clientFile]];
}
ELSE RETURN [FALSE];
ENDCASE;
ENDCASE;
InvalidOpenFile[];
};
GetName: PUBLIC PROC [file: FS.OpenFile] RETURNS [fullFName, attachedTo: Rope.ROPE] = {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.GetName = NIL
THEN NotImplemented[]
ELSE [fullFName, attachedTo] ← p.fileProcs.GetName[p.clientFile];
ENDCASE => InvalidOpenFile[];
};
GetInfo: PUBLIC PROC [file: FS.OpenFile] RETURNS [keep: CARDINAL, pages, bytes: INT, created: BasicTime.GMT, lock: FS.Lock, fileType: FS.FileType ← FS.tUnspecified] = {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.GetInfo = NIL
THEN NotImplemented[]
ELSE [keep, pages, bytes, created, lock, fileType] ← p.fileProcs.GetInfo[p.clientFile];
ENDCASE => InvalidOpenFile[];
};
SetPageCount: PUBLIC PROC [file: FS.OpenFile, pages: INT] = {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.SetPageCount = NIL
THEN NotImplemented[]
ELSE p.fileProcs.SetPageCount[p.clientFile, pages];
ENDCASE => InvalidOpenFile[];
};
SetByteCountAndCreatedTime: PUBLIC PROC [file: FS.OpenFile, bytes: INT, created: BasicTime.GMT] = {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.SetByteCountAndCreatedTime = NIL
THEN NotImplemented[]
ELSE p.fileProcs.SetByteCountAndCreatedTime[p.clientFile, bytes, created];
ENDCASE => InvalidOpenFile[];
};
Read: PUBLIC PROC [file: FS.OpenFile, from, nPages: INT, to: LONG POINTER] = TRUSTED {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.Read = NIL
THEN NotImplemented[]
ELSE p.fileProcs.Read[p.clientFile, from, nPages, to];
ENDCASE => InvalidOpenFile[];
};
Write: PUBLIC PROC [file: FS.OpenFile, to: INT, nPages: INT, from: LONG POINTER] = {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.Write = NIL
THEN NotImplemented[]
ELSE p.fileProcs.Write[p.clientFile, to, nPages, from];
ENDCASE => InvalidOpenFile[];
};
Close: PUBLIC PROC [file: FS.OpenFile] = {
WITH file SELECT FROM
p: ProcFile =>
IF p.fileProcs.Close = NIL
THEN NotImplemented[]
ELSE p.fileProcs.Close[p.clientFile];
ENDCASE => InvalidOpenFile[];
};
Exported to FSBackdoor
FileProcs: PUBLIC TYPE = RECORD [
GetClass: PROC [REF] RETURNS [ATOM],
SameFile: PROC [REF, REF] RETURNS [BOOL],
GetName: PROC [REF] RETURNS [Rope.ROPE, Rope.ROPE],
GetInfo: PROC [REF] RETURNS [CARDINAL, INT, INT, BasicTime.GMT, FS.Lock, FS.FileType],
SetPageCount: PROC [REF, INT],
SetByteCountAndCreatedTime: PROC [REF, INT, BasicTime.GMT],
Read: UNSAFE PROC [REF, INT, INT, LONG POINTER],
Write: PROC [REF, INT, INT, LONG POINTER],
Close: PROC [REF]
];
CreateFileProcs: PUBLIC PROC [
GetClass
: PROC [REF] RETURNS [ATOM],
SameFile
: PROC [REF, REF] RETURNS [BOOL],
GetName
: PROC [REF] RETURNS [Rope.ROPE, Rope.ROPE],
GetInfo
: PROC [REF] RETURNS [CARDINAL, INT, INT, BasicTime.GMT, FS.Lock, FS.FileType],
SetPageCount
: PROC [REF, INT],
SetByteCountAndCreatedTime
: PROC [REF, INT, BasicTime.GMT],
Read
: UNSAFE PROC [REF, INT, INT, LONG POINTER],
Write
: PROC [REF, INT, INT, LONG POINTER],
Close
: PROC [REF]
] RETURNS [REF FileProcs] = {
RETURN [ NEW [ FileProcs ← [GetClass, SameFile, GetName, GetInfo, SetPageCount, SetByteCountAndCreatedTime, Read, Write, Close] ] ];
};
CreateProcsOpenFile: PUBLIC PROC [clientFile: REF, fileProcs: REF FileProcs] RETURNS [FS.OpenFile] = {
RETURN [ [ NEW [ ProcFileObj ← [fileProcs, clientFile] ] ] ];
};
GetClientFileAndProcs: PUBLIC PROC [file: FS.OpenFile] RETURNS [clientFile: REF, fileProcs: REF FileProcs] = {
clientFile ← fileProcs ← NIL;
WITH file SELECT FROM
p: ProcFile => {
clientFile ← p.clientFile;
fileProcs ← p.fileProcs;
};
ENDCASE;
};
Internal procedures
NotImplemented: PROC [] = {
ERROR Error [ [client, $notImplemented, "Operation not implemented for this file"] ];
};
InvalidOpenFile: PROC [closed: BOOLFALSE] = {
ERROR Error [ [client, $invalidOpenFile, Rope.Concat["File presented ", IF closed THEN "is closed." ELSE "is invalid"] ]];
};
Start code
}.