<<>> <> <> <> <> <<>> <> <<>> DIRECTORY Atom USING [GetPName, MakeAtom], LoganBerry, LoganBerrySunRPC, LoganBerrySunRPCServer, Rope USING [Equal]; LoganBerrySunRPCToLoganBerry: CEDAR PROGRAM IMPORTS Atom, LoganBerry, Rope EXPORTS LoganBerrySunRPCServer ~ BEGIN OPEN LoganBerrySunRPC, LoganBerrySunRPCServer; <> Error: PUBLIC ERROR [ec: ErrorCode, explanation: ROPE ¬ NIL] = CODE; Null: PUBLIC NullType ~ { NULL; }; Open: PUBLIC OpenType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; db ¬ LoganBerry.Open[NIL, dbName]; }; ReadEntry: PUBLIC ReadEntryType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; lbentry: LoganBerry.Entry; [lbentry, others] ¬ LoganBerry.ReadEntry[NIL, db, Atom.MakeAtom[key], value]; entry ¬ EntryToSr[lbentry]; }; GenerateEntries: PUBLIC GenerateEntriesType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; cursor ¬ LoganBerry.GenerateEntries[NIL, db, Atom.MakeAtom[key], IF Rope.Equal[start, ""] THEN NIL ELSE start, IF Rope.Equal[end, ""] THEN NIL ELSE end]; }; NextEntry: PUBLIC NextEntryType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; lbentry: LoganBerry.Entry; lbentry ¬ LoganBerry.NextEntry[NIL, cursor, IF dir=increasing THEN increasing ELSE decreasing]; entry ¬ EntryToSr[lbentry]; }; EndGenerate: PUBLIC EndGenerateType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; LoganBerry.EndGenerate[NIL, cursor]; }; WriteEntry: PUBLIC WriteEntryType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; LoganBerry.WriteEntry[NIL, db, SrToEntry[entry], log, replace]; }; DeleteEntry: PUBLIC DeleteEntryType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; LoganBerry.DeleteEntry[NIL, db, Atom.MakeAtom[key], value]; }; Close: PUBLIC CloseType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; LoganBerry.Close[NIL, db]; }; BuildIndices: PUBLIC BuildIndicesType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; LoganBerry.BuildIndices[NIL, db]; }; CompactLogs: PUBLIC CompactLogsType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; LoganBerry.CompactLogs[NIL, db]; }; Describe: PUBLIC DescribeType ~ { ENABLE LoganBerry.Error => ERROR Error[Atom.GetPName[ec], explanation]; lbinfo: LoganBerry.SchemaInfo; lbinfo ¬ LoganBerry.Describe[NIL, db]; info ¬ SchemaInfoToSr[lbinfo]; }; <> SrToEntry: PROC [srEntry: LoganBerrySunRPC.Entry] RETURNS [entry: LoganBerry.Entry] ~ { entry ¬ NIL; FOR i: CARDINAL DECREASING IN [0..srEntry.length) DO attr: LoganBerry.Attribute ¬ [Atom.MakeAtom[srEntry[i].type], srEntry[i].value]; entry ¬ CONS[attr, entry]; ENDLOOP; }; EntryToSr: PROC [entry: LoganBerry.Entry] RETURNS [crEntry: LoganBerrySunRPC.Entry] ~ { count: CARDINAL ¬ 0; FOR e: LoganBerry.Entry ¬ entry, e.rest WHILE e # NIL DO count ¬ count + 1; ENDLOOP; crEntry ¬ NEW[LoganBerrySunRPC.EntryObject[count]]; count ¬ 0; FOR e: LoganBerry.Entry ¬ entry, e.rest WHILE e # NIL DO crEntry[count].type ¬ Atom.GetPName[e.first.type]; crEntry[count].value ¬ e.first.value; count ¬ count + 1; ENDLOOP; }; SrToSchemaInfo: PROC [crInfo: LoganBerrySunRPC.SchemaInfo] RETURNS [info: LoganBerry.SchemaInfo] ~ { SrToLogList: PROC [crLogs: LoganBerrySunRPC.LogList] RETURNS [logs: LIST OF LoganBerry.LogInfo] ~ { logs ¬ NIL; FOR i: CARDINAL DECREASING IN [0..crLogs.length) DO loginfo: LoganBerry.LogInfo ¬ NEW[LoganBerry.LogInfoRec ¬ [crLogs[i].id, crLogs[i].file]]; logs ¬ CONS[loginfo, logs]; ENDLOOP; }; SrToIndexList: PROC [crIndices: LoganBerrySunRPC.IndexList] RETURNS [indices: LIST OF LoganBerry.IndexInfo] ~ { indices ¬ NIL; FOR i: CARDINAL DECREASING IN [0..crIndices.length) DO indexinfo: LoganBerry.IndexInfo ¬ NEW[LoganBerry.IndexInfoRec ¬ [Atom.MakeAtom[crIndices[i].key], crIndices[i].file, Atom.MakeAtom[crIndices[i].order]]]; indices ¬ CONS[indexinfo, indices]; ENDLOOP; }; info ¬ NEW[LoganBerry.SchemaInfoRec ¬ [crInfo.dbName, SrToLogList[crInfo.logs], SrToIndexList[crInfo.indices]]]; }; SchemaInfoToSr: PROC [info: LoganBerry.SchemaInfo] RETURNS [crInfo: LoganBerrySunRPC.SchemaInfo] ~ { LogListToSr: PROC [logs: LIST OF LoganBerry.LogInfo] RETURNS [crLogs: LoganBerrySunRPC.LogList] ~ { count: CARDINAL ¬ 0; FOR i: LIST OF LoganBerry.LogInfo ¬ logs, i.rest WHILE i # NIL DO count ¬ count + 1; ENDLOOP; crLogs ¬ NEW[LoganBerrySunRPC.LogListObject[count]]; count ¬ 0; FOR i: LIST OF LoganBerry.LogInfo ¬ logs, i.rest WHILE i # NIL DO crLogs[count].id ¬ i.first.id; crLogs[count].file ¬ i.first.file; count ¬ count + 1; ENDLOOP; }; IndexListToSr: PROC [indices: LIST OF LoganBerry.IndexInfo] RETURNS [crIndices: LoganBerrySunRPC.IndexList] ~ { count: CARDINAL ¬ 0; FOR i: LIST OF LoganBerry.IndexInfo ¬ indices, i.rest WHILE i # NIL DO count ¬ count + 1; ENDLOOP; crIndices ¬ NEW[LoganBerrySunRPC.IndexListObject[count]]; count ¬ 0; FOR i: LIST OF LoganBerry.IndexInfo ¬ indices, i.rest WHILE i # NIL DO crIndices[count].key ¬ Atom.GetPName[i.first.key]; crIndices[count].file ¬ i.first.file; crIndices[count].order ¬ Atom.GetPName[i.first.order]; count ¬ count + 1; ENDLOOP; }; crInfo.dbName ¬ info.dbName; crInfo.logs ¬ LogListToSr[info.logs]; crInfo.indices ¬ IndexListToSr[info.indices]; }; END.