root/juggler/branches/1.0/Kernel/vjQueuedConfigChunkHandler.cpp

Revision 8789, 6.1 kB (checked in by patrickh, 7 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998, 1999, 2000, 2001, 2002
4  *   by Iowa State University
5  *
6  * Original Authors:
7  *   Allen Bierbaum, Christopher Just,
8  *   Patrick Hartling, Kevin Meinert,
9  *   Carolina Cruz-Neira, Albert Baker
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * -----------------------------------------------------------------
27  * File:          $RCSfile$
28  * Date modified: $Date$
29  * Version:       $Revision$
30  * -----------------------------------------------------------------
31  *
32  *************** <auto-copyright.pl END do not edit this line> ***************/
33
34 #include <vjConfig.h>
35 #include <Kernel/vjQueuedConfigChunkHandler.h>
36 #include <Kernel/vjKernel.h>
37
38 //: Add a database of config chunks
39 // Just loops through the chunks and calls configAdd for each one
40 bool vjQueuedConfigChunkHandler::configAddDB(vjConfigChunkDB* chunkDB)
41 {
42    // ---- DEPENDENCY SORT  ---- //
43    int dep_result = chunkDB->dependencySort(vjKernel::instance()->getChunkDB());
44
45    // If dependency sort fails, exit with error
46    if(dep_result == -1)
47    {
48       vjDEBUG(vjDBG_ERROR,0) << "vjQueuedConfiChunkHandler::processConfigAddQueue: ERROR: Dependency sort failed. Aborting add.\n" << vjDEBUG_FLUSH;
49       return false;
50    }
51
52    std::vector<vjConfigChunk*> sorted_chunks = chunkDB->getChunks();  // Get sorted list of chunks to add
53
54    //vjDEBUG_BEGIN(vjDBG_ALL,1) << "vjQueuedConfiChunkHandler: processConfigAddQueue: Processing chunks.\n" << vjDEBUG_FLUSH;
55    //std::vector<vjConfigChunk*> chunks = chunkDB->getChunks();
56
57    // For each element in chunk list
58    for (int i=0;i<sorted_chunks.size();i++)
59       configAdd(sorted_chunks[i]);
60
61    return true;
62 }
63
64 bool vjQueuedConfigChunkHandler::configRemoveDB(vjConfigChunkDB* chunkDB)
65 {
66    vjDEBUG_BEGIN(vjDBG_ALL,1) << "vjQueuedConfiChunkHandler: processConfigAddQueue: Processing chunks.\n" << vjDEBUG_FLUSH;
67
68    std::vector<vjConfigChunk*> chunks = chunkDB->getChunks();
69
70    // For each element in chunk list
71    for (int i=0;i<chunks.size();i++)
72       configRemove(chunks[i]);
73
74    return true;
75 }
76
77
78 void vjQueuedConfigChunkHandler::processConfigAddQueue()
79 {
80    vjDEBUG_BEGIN(vjDBG_ALL,1) << "vjQueuedConfiChunkHandler: processConfigAddQueue: Processing chunks.\n" << vjDEBUG_FLUSH;
81    //vjASSERT(vjThread::self() == mControlThread);      // ASSERT: We are being called from kernel thread
82
83    vjConfigChunk* chunk;     // Chunk db to add
84
85    while (!mConfigAddQueue.empty())
86    {
87       // -- GET CHUNK to work with -- //
88       chunk = mConfigAddQueue.front();
89       mConfigAddQueue.pop();
90       vjASSERT(chunk != NULL);
91
92       vjDEBUG(vjDBG_ALL,3) << "Processing chunk: " << chunk << endl << *chunk << vjDEBUG_FLUSH;
93
94       // --- ADD CHUNK -- //
95       bool added_chunk = false;        // Flag: true - chunk was added
96       added_chunk = processChunkAdd(chunk);      // PROCESS CHUNK
97
98       // --- ADD to ACTIVE CHUNKDB --- //
99       if (added_chunk)      // if added => add to config database
100       {
101          vjASSERT(chunk != NULL);
102          vjKernel::instance()->getChunkDB()->addChunk(chunk);    // Add to global DB
103          int num_chunks = vjKernel::instance()->getChunkDB()->getChunks().size();
104          vjDEBUG(vjDBG_ALL,1) << "vjQueuedConfiChunkHandler::processConfigAddQueue: Added chunk: " << chunk->getProperty("name") << ", Now have " << num_chunks << " chunks.\n" << vjDEBUG_FLUSH;
105       }
106       else                 // Else: Give unrecognized error
107       {
108          vjDEBUG(vjDBG_ALL,0) << "vjQueuedConfiChunkHandler::processConfigAddQueue: Unrecognized chunk.\n"
109          << "   type: " << chunk->getType() << endl << vjDEBUG_FLUSH;
110       }
111    }
112
113    // Tell the environment manager to refresh
114 //**//   environmentManager->sendRefresh();
115    vjDEBUG_END(vjDBG_ALL,1) << "vjQueuedConfiChunkHandler: configAdd: Done adding\n\n" << vjDEBUG_FLUSH;
116 }
117
118
119 void vjQueuedConfigChunkHandler::processConfigRemoveQueue()
120 {
121    //vjASSERT(vjThread::self() == mControlThread);      // ASSERT: We are being called from kernel thread
122    vjDEBUG_BEGIN(vjDBG_ALL,1) << "vjQueuedConfigChunkHandler: processConfigRemoveQueue: Removing chunk.\n" << vjDEBUG_FLUSH;
123
124    vjConfigChunk* chunk;
125
126    while(!mConfigRemoveQueue.empty())
127    {
128       chunk = mConfigRemoveQueue.front();
129       mConfigRemoveQueue.pop();
130       vjASSERT(chunk != NULL);
131
132       // Remove the chunk
133       bool removed_chunk = false;        // Flag: true - chunk was removed
134
135       // Find manager to handle them
136       removed_chunk = processChunkRemove(chunk);
137
138       // --- Check for removal from active config --- //
139       if(removed_chunk)      // if removed => remove from config database
140       {
141          vjASSERT(chunk != NULL);
142          vjKernel::instance()->getChunkDB()->removeNamed(chunk->getProperty("name"));
143          int num_chunks = vjKernel::instance()->getChunkDB()->getChunks().size();
144          vjDEBUG(vjDBG_ALL,3) << "vjQueuedConfigChunkHandler::processConfigRemoveQueue: Removed chunk: Now have " << num_chunks << " chunks.\n" << vjDEBUG_FLUSH;
145       }
146       else                 // Else: Give unrecognized error
147       {
148          vjDEBUG(vjDBG_ALL,0) << "vjQueuedConfigChunkHandler::processConfigRemoveQueue: Unrecognized chunk.\n"
149                     << "   type: " << chunk->getType() << endl << vjDEBUG_FLUSH;
150       }
151    }
152
153    vjDEBUG_END(vjDBG_ALL,1) << "vjQueuedConfigChunkHandler: processConfigRemoveQueue: Exiting.\n" << vjDEBUG_FLUSH;
154
155    // Tell the environment manager to refresh
156 //**//   environmentManager->sendRefresh();
157 }
Note: See TracBrowser for help on using the browser.