source: psi/trunk/src/eventdb.h@ 9

Last change on this file since 9 was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 3.8 KB
Line 
1/*
2 * eventdb.h - asynchronous I/O event database
3 * Copyright (C) 2001, 2002 Justin Karneges
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#ifndef EVENTDB_H
22#define EVENTDB_H
23
24#include<qobject.h>
25#include<qtimer.h>
26#include<qfile.h>
27#include<qptrlist.h>
28#include"psievent.h"
29
30
31class EDBItem
32{
33public:
34 EDBItem(PsiEvent *, const QString &id, const QString &nextId, const QString &prevId);
35 ~EDBItem();
36
37 PsiEvent *event() const;
38 const QString & id() const;
39 const QString & nextId() const;
40 const QString & prevId() const;
41
42private:
43 QString v_id, v_prevId, v_nextId;
44 PsiEvent *e;
45};
46
47class EDBResult : public QPtrList<EDBItem>
48{
49public:
50 EDBResult() {}
51};
52
53class EDB;
54class EDBHandle : public QObject
55{
56 Q_OBJECT
57public:
58 enum { Read, Write };
59 EDBHandle(EDB *);
60 ~EDBHandle();
61
62 // operations
63 void getLatest(const Jid &, int len);
64 void getOldest(const Jid &, int len);
65 void get(const Jid &jid, const QString &id, int direction, int len);
66 void find(const QString &, const Jid &, const QString &id, int direction);
67 void append(const Jid &, PsiEvent *);
68
69 bool busy() const;
70 const EDBResult *result() const;
71 bool writeSuccess() const;
72 int lastRequestType() const;
73
74signals:
75 void finished();
76
77private:
78 class Private;
79 Private *d;
80
81 friend class EDB;
82 void edb_resultReady(EDBResult *);
83 void edb_writeFinished(bool);
84 int listeningFor() const;
85};
86
87class EDB : public QObject
88{
89 Q_OBJECT
90public:
91 enum { Forward, Backward };
92 EDB();
93 virtual ~EDB()=0;
94
95protected:
96 int genUniqueId() const;
97 virtual int getLatest(const Jid &, int len)=0;
98 virtual int getOldest(const Jid &, int len)=0;
99 virtual int get(const Jid &jid, const QString &id, int direction, int len)=0;
100 virtual int append(const Jid &, PsiEvent *)=0;
101 virtual int find(const QString &, const Jid &, const QString &id, int direction)=0;
102 void resultReady(int, EDBResult *);
103 void writeFinished(int, bool);
104
105private:
106 class Private;
107 Private *d;
108
109 friend class EDBHandle;
110 void reg(EDBHandle *);
111 void unreg(EDBHandle *);
112
113 int op_getLatest(const Jid &, int len);
114 int op_getOldest(const Jid &, int len);
115 int op_get(const Jid &, const QString &id, int direction, int len);
116 int op_find(const QString &, const Jid &, const QString &id, int direction);
117 int op_append(const Jid &, PsiEvent *);
118};
119
120class EDBFlatFile : public EDB
121{
122 Q_OBJECT
123public:
124 EDBFlatFile();
125 ~EDBFlatFile();
126
127 int getLatest(const Jid &, int len);
128 int getOldest(const Jid &, int len);
129 int get(const Jid &jid, const QString &id, int direction, int len);
130 int find(const QString &, const Jid &, const QString &id, int direction);
131 int append(const Jid &, PsiEvent *);
132
133 class File;
134
135private slots:
136 void performRequests();
137 void file_timeout();
138
139private:
140 class Private;
141 Private *d;
142
143 File *findFile(const Jid &) const;
144 File *ensureFile(const Jid &);
145};
146
147class EDBFlatFile::File : public QObject
148{
149 Q_OBJECT
150public:
151 File(const Jid &_j);
152 ~File();
153
154 int total() const;
155 void touch();
156 PsiEvent *get(int);
157 bool append(PsiEvent *);
158
159signals:
160 void timeout();
161
162private slots:
163 void timer_timeout();
164
165public:
166 Jid j;
167 QString fname;
168 QFile f;
169 bool valid;
170 QTimer *t;
171
172 class Private;
173 Private *d;
174
175private:
176 PsiEvent *lineToEvent(const QString &);
177 QString eventToLine(PsiEvent *);
178 void ensureIndex();
179};
180
181#endif
Note: See TracBrowser for help on using the repository browser.