9
[brdnet.git] / Store1.pas
blob2bcad5a29ff516efd45334efd1498f46fdc34472
1 UNIT Store1;
2 {Take tracks of files in store}
3 {just simple, no cleaning, etc}
4 INTERFACE
5 uses SysUtils;
7 type
8 tfid=array [0..19] of byte;
9 tStoreObjectInfo=object
10 final:boolean; {hash matched}
11 rc:Word; {0=no error 1=not found, other}
12 length:LongWord; {the whole file}
13 seglen:longword; {from cur to end of segment}
15 procedure Open(const fid:tfid);
16 procedure Close;
17 procedure SegSeek(ofs:LongWord);
18 procedure ReadAhead(cnt:Word; into:pointer);
19 procedure WaitRead; {wait for read to finish, rc}
20 private
21 dh:tHandle; {handle to the data file}
22 filename:string[80];
23 procedure mkfilen(var d:string; flag:char; const fid:tfid);
24 end;
26 IMPLEMENTATION
27 const prefix='object';
29 procedure tStoreObjectInfo.mkfilen(var d:string; flag:char; const fid:tfid);
30 function hc(b:byte):char;
31 begin
32 if b<10 then hc:=char(ord('0')+b)
33 else hc:=char(ord('A')-10+b);
34 end;
35 var b,i:byte;
36 begin
37 d:=prefix+flag+DirectorySeparator;
38 b:=system.length(d);
39 SetLength(d,b+40);
40 for i:=0 to 19 do begin
41 filename[b+(i*2)]:=hc(fid[i] shr 4);
42 filename[b+(i*2)+1]:=hc(fid[i] and $F);
43 end;
44 end;
45 procedure tStoreObjectInfo.Open(const fid:tfid);
46 begin
47 mkfilen(filename,'f',fid);
48 dh:=FileOpen(filename,fmOpenRead);
49 if dh<>-1 then begin
50 rc:=0;
51 final:=true;
52 length:=1000;
53 end else begin
54 Writeln('Store1: open failed for file ',filename,', ioresult=',IOResult);
55 rc:=2;
56 end;
57 end;
58 procedure tStoreObjectInfo.ReadAhead(cnt:Word; into:pointer);
59 var red:LongWord;
60 begin
61 //todo, do real async read
62 red:=FileRead(dh,into^,cnt);
63 if red=cnt then rc:=0 else begin
64 //todo
65 writeln('Store1: read ',red,' out of ',cnt,' requested bytes');
66 rc:=2;
67 end;
68 end;
69 procedure tStoreObjectInfo.WaitRead; {wait for read to finish, rc}
70 begin
71 //todo
72 end;
73 procedure tStoreObjectInfo.Close;
74 begin
75 FileClose(dh);
76 end;
77 procedure tStoreObjectInfo.SegSeek(ofs:longword);
78 begin
79 if ofs=0 then begin
80 rc:=0;
81 seglen:=length;
82 end else rc:=7;
83 end;
85 END.