00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <assert.h>
00026 #include <eyedb/eyedb.h>
00027 #include "IteratorAtom.h"
00028 #include "IteratorBE.h"
00029 #include "OQLBE.h"
00030 #include "CollectionBE.h"
00031 #include "BEQueue.h"
00032
00033 namespace eyedb {
00034
00035 struct BELink {
00036 int id;
00037 Oid oid;
00038 void *data;
00039 void *info;
00040
00041 BELink(int, void *, void * = 0);
00042 BELink(const Oid&, void *, void * = 0);
00043 };
00044
00045 BELink::BELink(int i, void *d, void *xinfo)
00046 {
00047 id = i;
00048 data = d;
00049 info = xinfo;
00050 }
00051
00052 BELink::BELink(const Oid &o, void *d, void *xinfo)
00053 {
00054 oid = o;
00055 data = d;
00056 info = xinfo;
00057 }
00058
00059 BEQueue::BEQueue()
00060 {
00061 mxid = 100;
00062 iter_queue = new LinkedList();
00063 coll_queue = new LinkedList();
00064 oql_queue = new LinkedList();
00065 }
00066
00067
00068 IteratorBE *BEQueue::getIterator(int id)
00069 {
00070 LinkedListCursor c(iter_queue);
00071
00072 BELink *l;
00073 while (c.getNext((void* &)l))
00074 if (l->id == id)
00075 return (IteratorBE *)l->data;
00076
00077 return 0;
00078 }
00079
00080 int BEQueue::addIterator(IteratorBE *qbe)
00081 {
00082 BELink *l = new BELink(mxid, (void *)qbe);
00083 iter_queue->insertObject(l);
00084 return mxid++;
00085 }
00086
00087 void BEQueue::removeIterator(int id)
00088 {
00089 LinkedListCursor c(iter_queue);
00090
00091 BELink *l;
00092 while (c.getNext((void* &)l))
00093 if (l->id == id)
00094 {
00095 iter_queue->deleteObject(l);
00096 delete l;
00097 return;
00098 }
00099
00100 }
00101
00102 void BEQueue::removeIterator(IteratorBE *qbe)
00103 {
00104 LinkedListCursor c(iter_queue);
00105
00106 BELink *l;
00107 while (c.getNext((void* &)l))
00108 if (l->data == (void *)qbe)
00109 {
00110 iter_queue->deleteObject(l);
00111 delete l;
00112 return;
00113 }
00114 }
00115
00116
00117 CollectionBE *BEQueue::getCollection(const Oid *oid, void *info)
00118 {
00119 LinkedListCursor c(coll_queue);
00120
00121 BELink *l;
00122 while (c.getNext((void* &)l))
00123 if (l->oid.compare(*oid) && l->info == info)
00124 {
00125 if (((CollectionBE *)l->data)->isLocked())
00126 return (CollectionBE *)l->data;
00127 return 0;
00128 }
00129
00130 return 0;
00131 }
00132
00133 void BEQueue::addCollection(CollectionBE *collbe, void *info)
00134 {
00135 assert(collbe->isLocked());
00136 BELink *l = new BELink(collbe->getOid(), (void *)collbe, info);
00137
00138 coll_queue->insertObject(l);
00139 }
00140
00141 void BEQueue::removeCollection(CollectionBE *collbe, void *info)
00142 {
00143 LinkedListCursor c(coll_queue);
00144
00145 BELink *l;
00146 while (c.getNext((void* &)l))
00147 if (l->data == (void *)collbe && l->info == info)
00148 {
00149 coll_queue->deleteObject(l);
00150
00151 delete l;
00152 return;
00153 }
00154
00155
00156
00157 }
00158
00159
00160 OQLBE *BEQueue::getOQL(int id)
00161 {
00162 LinkedListCursor c(oql_queue);
00163
00164 BELink *l;
00165 while (c.getNext((void* &)l))
00166 if (l->id == id)
00167 return (OQLBE *)l->data;
00168
00169 return 0;
00170 }
00171
00172 int BEQueue::addOQL(OQLBE *qbe)
00173 {
00174 BELink *l = new BELink(mxid, (void *)qbe);
00175 oql_queue->insertObject(l);
00176 return mxid++;
00177 }
00178
00179 void BEQueue::removeOQL(int id)
00180 {
00181 LinkedListCursor c(oql_queue);
00182
00183 BELink *l;
00184 while (c.getNext((void* &)l))
00185 if (l->id == id)
00186 {
00187 oql_queue->deleteObject(l);
00188 delete l;
00189 return;
00190 }
00191 }
00192
00193 void BEQueue::removeOQL(OQLBE *qbe)
00194 {
00195 LinkedListCursor c(oql_queue);
00196
00197 BELink *l;
00198 while (c.getNext((void* &)l))
00199 if (l->data == (void *)qbe)
00200 {
00201 oql_queue->deleteObject(l);
00202 delete l;
00203 return;
00204 }
00205 }
00206
00207 static void
00208 purge(LinkedList *list)
00209 {
00210 LinkedListCursor c(list);
00211 BELink *l;
00212
00213 while (c.getNext((void* &)l))
00214 delete l;
00215
00216 delete list;
00217 }
00218
00219 BEQueue::~BEQueue()
00220 {
00221 purge(coll_queue);
00222 purge(iter_queue);
00223 purge(oql_queue);
00224 }
00225
00226 }