blob: 29ae0226942963b4f7313a2827825ae9916da12c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*************************************************************** -*- c++ -*-
* Copyright (c) 2003,2004 by Marcel Wiesweg *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef __STORAGE_H
#define __STORAGE_H
#include "rootdir.h"
#include "pageid.h"
#define TELETEXT_PAGESIZE 972
struct StorageHandle {
public:
StorageHandle() { handle=-1; }
StorageHandle(const StorageHandle &s) { handle=s.handle; }
StorageHandle(int h) { handle=h; }
StorageHandle &operator=(int h) { handle=h; return *this; }
StorageHandle &operator=(const StorageHandle &s) { handle=s.handle; return *this; }
operator bool() const { return handle!=-1; }
operator int() const { return handle; }
private:
int handle;
};
enum StorageSystem { StorageSystemLegacy, StorageSystemPacked };
class Storage : public RootDir {
public:
virtual ~Storage();
enum StorageSystem { StorageSystemLegacy, StorageSystemPacked };
//must be called before the first call to instance()
//must be called before operation starts. Set all options (RootDir, maxStorage) before.
virtual void cleanUp() = 0;
virtual void getFilename(char *buffer, int bufLength, PageID page);
virtual void prepareDirectory(tChannelID chan);
virtual StorageHandle openForWriting(PageID page) = 0;
virtual StorageHandle openForReading(PageID page, bool countAsAccess) = 0;
virtual ssize_t write(const void *ptr, size_t size, StorageHandle stream) = 0;
virtual ssize_t read(void *ptr, size_t size, StorageHandle stream) = 0;
virtual void close(StorageHandle stream) = 0;
protected:
Storage();
int cleanSubDir(const char *dir);
int doCleanUp();
virtual int actualFileSize(int netFileSize) { return netFileSize; }
void freeSpace();
bool exists(const char* file);
long byteCount;
cString currentDir;
private:
bool failedFreeSpace;
};
#endif
|