disposer.C

00001 /*
00002  * This file is part of the "Archon" framework.
00003  * (http://files3d.sourceforge.net)
00004  *
00005  * Copyright © 2002 by Kristian Spangsege and Brian Kristiansen.
00006  *
00007  * Permission to use, copy, modify, and distribute this software and
00008  * its documentation under the terms of the GNU General Public License is
00009  * hereby granted. No representations are made about the suitability of
00010  * this software for any purpose. It is provided "as is" without express
00011  * or implied warranty. See the GNU General Public License
00012  * (http://www.gnu.org/copyleft/gpl.html) for more details.
00013  *
00014  * The characters in this file are ISO8859-1 encoded.
00015  *
00016  * The documentation in this file is in "Doxygen" style
00017  * (http://www.doxygen.org).
00018  */
00019 
00020 #include <iostream>
00021 
00022 #include <archon/x3d/proxy/disposer.H>
00023 
00024 namespace Archon
00025 {
00026   namespace X3D
00027   {
00028     namespace Proxy
00029     {
00030       Disposer::Disposer(x3d::sai::Session_ptr ref):
00031         more(disposerMutex)
00032       {
00033         session = x3d::sai::Session::_duplicate(ref);
00034       }
00035 
00036       Disposer::~Disposer()
00037       {
00038       }
00039 
00040       void Disposer::addContext(unsigned long id, unsigned long transCount)
00041       {
00042         {
00043           Mutex::Lock l(disposerMutex);
00044           contexts.push_back(Entry(id, transCount));
00045         }
00046         more.notifyAll();
00047       }
00048 
00049 
00050       void Disposer::addNode(unsigned long id, unsigned long transCount)
00051       {
00052         {
00053           Mutex::Lock l(disposerMutex);
00054           nodes.push_back(Entry(id, transCount));
00055         }
00056         more.notifyAll();
00057       }
00058 
00059       void Disposer::main()
00060       {
00061         for(;;)
00062         {
00063           vector<Entry> c, n;
00064           {
00065             Mutex::Lock l(disposerMutex);
00066             while(!contexts.size() && !nodes.size()) more.wait();
00067             swap(contexts, c);
00068             swap(nodes, n);
00069           }
00070 
00071           x3d::sai::DisposeSeq cs(c.size());
00072           cs.length(c.size());
00073           for(unsigned i=0; i<c.size(); ++i)
00074           {
00075             Entry &e = c[i];
00076             x3d::sai::DisposeEntry &f = cs[i];
00077             f.id = e.id;
00078             f.transCount = e.transCount;
00079           }
00080         
00081           x3d::sai::DisposeSeq ns(n.size());
00082           ns.length(n.size());
00083           for(unsigned i=0; i<n.size(); ++i)
00084           {
00085             Entry &e = n[i];
00086             x3d::sai::DisposeEntry &f = ns[i];
00087             f.id = e.id;
00088             f.transCount = e.transCount;
00089           }
00090 
00091           session->disposeBatch(cs, ns);
00092         }
00093       }
00094     }
00095   }
00096 }

Generated on Sun Jul 30 22:55:46 2006 for Archon by  doxygen 1.4.4