root/juggler/tags/1.0.5/Kernel/vjQueuedConfigChunkHandler.h
| Revision 2828, 4.4 kB (checked in by patrickh, 8 years ago) | |
|---|---|
| |
| 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 | #ifndef _VJ_QUEUED_CONFIG_CHUNK_HANDLER_H_ |
| 34 | #define _VJ_QUEUED_CONFIG_CHUNK_HANDLER_H_ |
| 35 | |
| 36 | |
| 37 | #include <vjConfig.h> |
| 38 | #include <Kernel/vjDebug.h> |
| 39 | #include <Config/vjConfigChunk.h> |
| 40 | class vjConfigChunkDB; |
| 41 | #include <Sync/vjGuardedQueue.h> |
| 42 | #include <Kernel/vjConfigChunkHandler.h> |
| 43 | |
| 44 | //: Class that holds configuration queues for the system objects |
| 45 | class vjQueuedConfigChunkHandler : public vjConfigChunkHandler |
| 46 | { |
| 47 | public: |
| 48 | // --- Chunk Databases --- // |
| 49 | //: Add a database of config chunks |
| 50 | // Just loops through the chunks and calls configAdd for each one |
| 51 | virtual bool configAddDB(vjConfigChunkDB* chunkDB); |
| 52 | |
| 53 | //: Remove all config chunks in the given chunk db |
| 54 | virtual bool configRemoveDB(vjConfigChunkDB* chunkDB); |
| 55 | |
| 56 | // ---- Inidividual chunks --- // |
| 57 | //: Add a config chunk |
| 58 | // Puts chunk into the add queue |
| 59 | virtual bool configAdd(vjConfigChunk* chunk) |
| 60 | { |
| 61 | vjDEBUG(vjDBG_ALL,1) << "vjQueuedConfigChunkHandler::configAdd: Adding chunk to add queue\n" << vjDEBUG_FLUSH; |
| 62 | vjDEBUG(vjDBG_ALL,4) << chunk << ":\n" << *chunk << endl << vjDEBUG_FLUSH; |
| 63 | mConfigAddQueue.push(chunk); |
| 64 | vjASSERT(chunk != NULL); |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | //: Remove a config chunk |
| 69 | // Puts chunk into the add queue |
| 70 | virtual bool configRemove(vjConfigChunk* chunk) |
| 71 | { |
| 72 | vjDEBUG(vjDBG_ALL,1) << "vjQueuedConfigChunkHandler::configRemove: Adding chunk to remove queue\n" << vjDEBUG_FLUSH; |
| 73 | vjDEBUG(vjDBG_ALL,4) << chunk << ":\n" << *chunk << endl << vjDEBUG_FLUSH; |
| 74 | mConfigRemoveQueue.push(chunk); |
| 75 | vjASSERT(chunk != NULL); |
| 76 | return true; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | //: Check the queues and process any chunks found therein |
| 81 | //! NOTE: This should most likely only be called from the control thread of the object |
| 82 | void checkConfigQueues() |
| 83 | { |
| 84 | // ---- RECONFIGURATION --- // |
| 85 | if(!mConfigAddQueue.empty()) |
| 86 | processConfigAddQueue(); |
| 87 | |
| 88 | if(!mConfigRemoveQueue.empty()) |
| 89 | processConfigRemoveQueue(); |
| 90 | |
| 91 | // --- Ouput info --- // |
| 92 | outputQueueStats(); |
| 93 | } |
| 94 | |
| 95 | void outputQueueStats() |
| 96 | { |
| 97 | int add_size = mConfigAddQueue.size(); |
| 98 | int remove_size = mConfigRemoveQueue.size(); |
| 99 | if((add_size != 0) && (remove_size != 0)) |
| 100 | { |
| 101 | vjDEBUG(vjDBG_ALL,0) << "addQueue: size: " << add_size << endl << vjDEBUG_FLUSH; |
| 102 | vjDEBUG(vjDBG_ALL,0) << "removeQueue: size: " << remove_size << endl << vjDEBUG_FLUSH; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | protected: |
| 107 | //: Takes any chunks in add queue and adds them to running system |
| 108 | void processConfigAddQueue(); |
| 109 | |
| 110 | //: Takes any chunks in remove queue and reconfigures system by removing them |
| 111 | void processConfigRemoveQueue(); |
| 112 | |
| 113 | |
| 114 | //: Take care of adding a single chunk |
| 115 | //! RETVAL: true - Chunk has been added |
| 116 | virtual bool processChunkAdd(vjConfigChunk* chunk) = 0; |
| 117 | |
| 118 | //: Take care of removing a single chunk |
| 119 | //! RETVAL: true - Chunk has been added |
| 120 | virtual bool processChunkRemove(vjConfigChunk* chunk) = 0; |
| 121 | |
| 122 | protected: |
| 123 | vjGuardedQueue<vjConfigChunk*> mConfigAddQueue; //: A queue of chunDB's to reconfig from |
| 124 | vjGuardedQueue<vjConfigChunk*> mConfigRemoveQueue; //: A queue of chunkDB's to remove |
| 125 | }; |
| 126 | |
| 127 | #endif |
| 128 |
Note: See TracBrowser for help on using the browser.
