BEQueue.cc

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
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   /* QueryBE */
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     //printf("WARNING removeIterator(%d) -> not found\n", id);
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   /* CollectionBE */
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     //printf("BEQUEUE add %p %p `%d'\n", collbe, info, coll_queue->getCount());
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           //printf("removeCollection: %p\n", collbe);
00151           delete l;
00152           return;
00153         }
00154 
00155     //printf("removeCollection: %p not found\n", collbe);
00156     //  assert(0);
00157   }
00158 
00159   /* OQLBE */
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 }

Generated on Mon Dec 22 18:15:50 2008 for eyedb by  doxygen 1.5.3