root/juggler/tags/1.0.5/Kernel/vjConfigChunkHandler.cpp

Revision 7539, 8.9 kB (checked in by anonymous, 7 years ago)

This commit was manufactured by cvs2svn to create tag
'RELENG_1_0_5_RELEASE'.

  • 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 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  * -----------------------------------------------------------------
26  * File:          $RCSfile$
27  * Date modified: $Date$
28  * Version:       $Revision$
29  * -----------------------------------------------------------------
30  *
31  *************** <auto-copyright.pl END do not edit this line> ***************/
32
33 #include <vjConfig.h>
34 #include <Kernel/vjConfigChunkHandler.h>
35 #include <Kernel/vjConfigManager.h>
36 #include <Config/vjConfigChunk.h>
37 #include <Kernel/vjDependencyManager.h>
38 #include <Kernel/vjDebug.h>
39 #include <typeinfo>
40
41 namespace {
42    enum PendItemResult
43    { SUCCESS, FAILED, NEED_DEPS };
44
45 void outputPendingItemState(int debugLevel, std::string chunkName, std::string chunkType, PendItemResult result);
46
47 }
48
49
50
51 int vjConfigChunkHandler::configProcessPending(bool lockIt)
52 {
53    vjConfigManager*     cfg_mgr = vjConfigManager::instance();
54    vjDependencyManager* dep_mgr = vjDependencyManager::instance();
55
56    bool     scan_for_lost_dependants(false);       // Do we need to scan for un-filled dependencies
57
58    // We need to track the number vefore and after to know if we changed anything
59    int num_pending_before = cfg_mgr->getNumPending();
60    int num_pending_after(0);
61
62    vjDEBUG_BEGIN(vjDBG_ALL,vjDBG_STATE_LVL) << typeid(*this).name() << "::configProcessPending: Entering: "
63                               << num_pending_before << " items pending.\n" << vjDEBUG_FLUSH;
64
65    if(lockIt)
66       cfg_mgr->lockPending();     // We need to lock the pending first
67    {
68       std::list<vjConfigManager::vjPendingChunk>::iterator current, end, remove_me;
69       current = cfg_mgr->getPendingBegin();
70       end = cfg_mgr->getPendingEnd();
71
72       // --- For each item in pending list --- //
73       while(current != end)
74       {
75          // Get information about the current chunk
76          vjConfigChunk* cur_chunk = (*current).mChunk;
77          vjASSERT(cur_chunk != NULL && "Trying to use an invalid chunk");
78          std::string chunk_name = cur_chunk->getProperty("name");
79          std::string chunk_type = cur_chunk->getType();
80
81          vjDEBUG_BEGIN(vjDBG_ALL,vjDBG_VERB_LVL) << "Item: name:" << chunk_name << " type:" << chunk_type << std::endl << vjDEBUG_FLUSH;
82
83          // If the current handler (this) knows about the chunk
84          if(this->configCanHandle(cur_chunk))
85          {
86             // ---- HANDLE THE CHUNK ---- //
87             switch ((*current).mType)
88             {
89             case vjConfigManager::vjPendingChunk::ADD:         // -- CONFIG ADD -- //
90                if(dep_mgr->depSatisfied(cur_chunk))            // Are all the dependencies satisfied
91                {
92                   bool added = this->configAdd(cur_chunk);
93                   if(added)                                 // SUCCESS adding
94                   {
95                      remove_me = current;
96                      current++;                          // Goto next item
97                      cfg_mgr->removePending(remove_me);  // Delete previous item
98                      cfg_mgr->addActive(cur_chunk);      // Add it to the current config
99
100                      outputPendingItemState(vjDBG_CONFIG_LVL,
101                                             cur_chunk->getProperty("name"),
102                                             ((std::string)cur_chunk->getType()).c_str(),
103                                             SUCCESS);
104                   }
105                   else  // FAILED adding
106                   {
107                      outputPendingItemState(vjDBG_CRITICAL_LVL,
108                                             cur_chunk->getProperty("name"),
109                                             ((std::string)cur_chunk->getType()).c_str(),
110                                             FAILED);
111                      current++;
112                   }
113                }
114                else     // Dependency failed
115                {
116
117                   outputPendingItemState(vjDBG_WARNING_LVL,
118                                             cur_chunk->getProperty("name"),
119                                             ((std::string)cur_chunk->getType()).c_str(),
120                                             NEED_DEPS);
121                   vjDEBUG_CONT(vjDBG_ALL,vjDBG_WARNING_LVL) << std::endl << vjDEBUG_FLUSH;
122                   dep_mgr->debugOutDependencies(cur_chunk,vjDBG_WARNING_LVL);
123                   current++;
124                }
125                break;
126
127             case vjConfigManager::vjPendingChunk::REMOVE:      // Config remove
128                {
129                   bool removed = this->configRemove(cur_chunk);
130                   if(removed)      // Was there success adding
131                   {
132                      remove_me = current;
133                      current++;                          // Goto next item
134                      cfg_mgr->removePending(remove_me);  // Delete previous item
135                      cfg_mgr->removeActive(cur_chunk->getProperty("name"));     // Add it to the current config
136                      scan_for_lost_dependants = true;    // We have to scan to see if somebody depended on that chunk
137                   }
138                   else // Failed to remove
139                   {
140                      current++;
141                   }
142                }
143                break;
144
145             default:
146                current++;  // Goto next entry
147                break;
148             }
149          }
150          // ---- CAN'T HANDLE THE CHUNK --- //
151          else           // if(can_handle)
152          {
153             vjDEBUG_NEXT(vjDBG_ALL,vjDBG_STATE_LVL) << "Pending item: " << cur_chunk->getProperty("name")
154                                                  << " type: " << ((std::string)cur_chunk->getType()).c_str()
155                                                  << " --> Not handled by this handler.\n" << vjDEBUG_FLUSH;
156             current++;
157          }
158          vjDEBUG_END(vjDBG_ALL,vjDBG_VERB_LVL) << "==== End item =====\n" << vjDEBUG_FLUSH;
159
160       }        // END: while(current != end)
161
162    }
163    if(lockIt)
164       cfg_mgr->unlockPending();   // Unlock it
165
166    num_pending_after = cfg_mgr->getNumPending();
167
168    vjDEBUG_END(vjDBG_ALL,vjDBG_STATE_LVL)
169                                         << "              Exiting: "
170                                         << num_pending_after << " items now pending ==> We processed "
171                                         << (num_pending_before-num_pending_after) << " items.\n" << vjDEBUG_FLUSH;
172
173    // Check for items that have lost their dependencies dues to a remove item being processed
174    if(scan_for_lost_dependants)
175    {
176       cfg_mgr->scanForLostDependencies();
177    }
178
179    return (num_pending_before-num_pending_after);
180 }
181
182 namespace {
183
184 void outputPendingItemState(int debugLevel, std::string chunkName, std::string chunkType, PendItemResult result)
185 {
186    const int item_width(25);
187    const int type_width(20);
188
189    const std::string name_prefix("Pending item: ");
190    const std::string type_prefix(" type: ");
191    vjDEBUG(vjDBG_ALL,debugLevel) << "Pending item: " << std::setiosflags(std::ios::right) << std::setfill(' ') << std::setw(item_width) << chunkName
192                                  <<    "     type: " << std::setiosflags(std::ios::right) << std::setfill(' ') << std::setw(type_width) << chunkType
193                                                      << std::resetiosflags(std::ios::right) << "  ";
194
195    /*
196    const int prefix_len = name_prefix.length() + type_prefix.length();
197    int item_and_type_len = chunkName.length() + chunkType.length() + prefix_len;
198    const int state_offset(60);
199
200    for(int c=0;c<(state_offset-item_and_type_len);c++)
201    {
202       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << " ";
203    }
204    */
205
206    switch(result)
207    {
208    case SUCCESS:
209       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrGREEN) << "OK" << clrRESET << " ]";
210       break;
211    case FAILED:
212       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrRED) << "FAILED" << clrRESET << " ]";
213       break;
214    case NEED_DEPS:
215       vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << "[ " << clrSetNORM(clrYELLOW) << "NEED DEPS" << clrRESET << " ]";
216       break;
217    }
218
219    vjDEBUG_CONTnl(vjDBG_ALL,debugLevel) << std::endl << vjDEBUG_FLUSH;
220 }
221
222 }
223
224
225
Note: See TracBrowser for help on using the browser.