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

Revision 8789, 8.9 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/vjConfigChunkHandler.h>
36 #include <Kernel/vjConfigManager.h>
37 #include <Config/vjConfigChunk.h>
38 #include <Kernel/vjDependencyManager.h>
39 #include <Kernel/vjDebug.h>
40 #include <typeinfo>
41
42 namespace {
43    enum PendItemResult
44    { SUCCESS, FAILED, NEED_DEPS };
45
46 void outputPendingItemState(int debugLevel, std::string chunkName, std::string chunkType, PendItemResult result);
47
48 }
49
50
51
52 int vjConfigChunkHandler::configProcessPending(bool lockIt)
53 {
54    vjConfigManager*     cfg_mgr = vjConfigManager::instance();
55    vjDependencyManager* dep_mgr = vjDependencyManager::instance();
56
57    bool     scan_for_lost_dependants(false);       // Do we need to scan for un-filled dependencies
58
59    // We need to track the number vefore and after to know if we changed anything
60    int num_pending_before = cfg_mgr->getNumPending();
61    int num_pending_after(0);
62
63    vjDEBUG_BEGIN(vjDBG_ALL,vjDBG_STATE_LVL) << typeid(*this).name() << "::configProcessPending: Entering: "
64                               << num_pending_before << " items pending.\n" << vjDEBUG_FLUSH;
65
66    if(lockIt)
67       cfg_mgr->lockPending();     // We need to lock the pending first
68    {
69       std::list<vjConfigManager::vjPendingChunk>::iterator current, end, remove_me;
70       current = cfg_mgr->getPendingBegin();
71       end = cfg_mgr->getPendingEnd();
72
73       // --- For each item in pending list --- //
74       while(current != end)
75       {
76          // Get information about the current chunk
77          vjConfigChunk* cur_chunk = (*current).mChunk;
78          vjASSERT(cur_chunk != NULL && "Trying to use an invalid chunk");
79          std::string chunk_name = cur_chunk->getProperty("name");
80          std::string chunk_type = cur_chunk->getType();
81
82          vjDEBUG_BEGIN(vjDBG_ALL,vjDBG_VERB_LVL) << "Item: name:" << chunk_name << " type:" << chunk_type << std::endl << vjDEBUG_FLUSH;
83
84          // If the current handler (this) knows about the chunk
85          if(this->configCanHandle(cur_chunk))
86          {
87             // ---- HANDLE THE CHUNK ---- //
88             switch ((*current).mType)
89             {
90             case vjConfigManager::vjPendingChunk::ADD:         // -- CONFIG ADD -- //
91                if(dep_mgr->depSatisfied(cur_chunk))            // Are all the dependencies satisfied
92                {
93                   bool added = this->configAdd(cur_chunk);
94                   if(added)                                 // SUCCESS adding
95                   {
96                      remove_me = current;
97                      current++;                          // Goto next item
98                      cfg_mgr->removePending(remove_me);  // Delete previous item
99                      cfg_mgr->addActive(cur_chunk);      // Add it to the current config
100
101                      outputPendingItemState(vjDBG_CONFIG_LVL,
102                                             cur_chunk->getProperty("name"),
103                                             ((std::string)cur_chunk->getType()).c_str(),
104                                             SUCCESS);
105                   }
106                   else  // FAILED adding
107                   {
108                      outputPendingItemState(vjDBG_CRITICAL_LVL,
109                                             cur_chunk->getProperty("name"),
110                                             ((std::string)cur_chunk->getType()).c_str(),
111                                             FAILED);
112                      current++;
113                   }
114                }
115                else     // Dependency failed
116                {
117
118                   outputPendingItemState(vjDBG_WARNING_LVL,
119                                             cur_chunk->getProperty("name"),
120                                             ((std::string)cur_chunk->getType()).c_str(),
121                                             NEED_DEPS);
122                   vjDEBUG_CONT(vjDBG_ALL,vjDBG_WARNING_LVL) << std::endl << vjDEBUG_FLUSH;
123                   dep_mgr->debugOutDependencies(cur_chunk,vjDBG_WARNING_LVL);
124                   current++;
125                }
126                break;
127
128             case vjConfigManager::vjPendingChunk::REMOVE:      // Config remove
129                {
130                   bool removed = this->configRemove(cur_chunk);
131                   if(removed)      // Was there success adding
132                   {
133                      remove_me = current;
134                      current++;                          // Goto next item
135                      cfg_mgr->removePending(remove_me);  // Delete previous item
136                      cfg_mgr->removeActive(cur_chunk->getProperty("name"));     // Add it to the current config
137                      scan_for_lost_dependants = true;    // We have to scan to see if somebody depended on that chunk
138                   }
139                   else // Failed to remove
140                   {
141                      current++;
142                   }
143                }
144                break;
145
146             default:
147                current++;  // Goto next entry
148                break;
149             }
150          }
151          // ---- CAN'T HANDLE THE CHUNK --- //
152          else           // if(can_handle)
153          {
154             vjDEBUG_NEXT(vjDBG_ALL,vjDBG_STATE_LVL) << "Pending item: " << cur_chunk->getProperty("name")
155                                                  << " type: " << ((std::string)cur_chunk->getType()).c_str()
156                                                  << " --> Not handled by this handler.\n" << vjDEBUG_FLUSH;
157             current++;
158          }
159          vjDEBUG_END(vjDBG_ALL,vjDBG_VERB_LVL) << "==== End item =====\n" << vjDEBUG_FLUSH;
160
161       }        // END: while(current != end)
162
163    }
164    if(lockIt)
165       cfg_mgr->unlockPending();   // Unlock it
166
167    num_pending_after = cfg_mgr->getNumPending();
168
169    vjDEBUG_END(vjDBG_ALL,vjDBG_STATE_LVL)
170                                         << "              Exiting: "
171                                         << num_pending_after << " items now pending ==> We processed "
172                                         << (num_pending_before-num_pending_after) << " items.\n" << vjDEBUG_FLUSH;
173
174    // Check for items that have lost their dependencies dues to a remove item being processed
175    if(scan_for_lost_dependants)
176    {
177       cfg_mgr->scanForLostDependencies();
178    }
179
180    return (num_pending_before-num_pending_after);
181 }
182
183 namespace {
184
185 void outputPendingItemState(int debugLevel, std::string chunkName, std::string chunkType, PendItemResult result)
186 {
187    const int item_width(25);
188    const int type_width(20);
189
190    const std::string name_prefix("Pending item: ");
191    const std::string type_prefix(" type: ");
192    vjDEBUG(vjDBG_ALL,debugLevel) << "Pending item: " << std::setiosflags(std::ios::right) << std::setfill(' ') << std::setw(item_width) << chunkName
193                                  <<    "     type: " << std::setiosflags(std::ios::right) << std::setfill(' ') << std::setw(type_width) << chunkType
194                                                      << std::resetiosflags(std::ios::right) << "  ";
195
196    /*
197    const int prefix_len = name_prefix.length() + type_prefix.length();
198    int item_and_type_len = chunkName.length() + chunkType.length() + prefix_len;
199    const int state_offset(60);
200
201    for(int c=0;c<(state_offset-item_and_type_len);c++)
202    {
203       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << " ";
204    }
205    */
206
207    switch(result)
208    {
209    case SUCCESS:
210       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]";
211       break;
212    case FAILED:
213       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrRED) << "FAILED" << clrRESET << " ]";
214       break;
215    case NEED_DEPS:
216       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrYELLOW) << "NEED DEPS" << clrRESET << " ]";
217       break;
218    }
219
220    vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << std::endl << vjDEBUG_FLUSH;
221 }
222
223 }
224
225
226
Note: See TracBrowser for help on using the browser.