PCMNode.cpp

Go to the documentation of this file.
00001 
00002 //
00003 // This source file is a part of ParCompMark
00004 // Parallel Compositing Benchmark Framework
00005 //
00006 // for latest info see http://parcompmark.sourceforge.net
00007 
00008 //
00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team
00010 // 
00011 // This program is free software; you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2
00014 // of the License, or (at your option) any later version.
00015 // 
00016 // This program is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU General Public License
00022 // along with this program; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 
00025 //
00026 // Inner includes
00027 //
00028 
00029 #include "../include/PCMNode.h"
00030 
00031 #include "../include/PCMStringConverter.h"
00032 
00033 namespace ParCompMark
00034 {
00035 
00036   //
00037   // Constructors & destructor
00038   //
00039 
00040   Node::Node()
00041         // You have to initialize the following attributes:
00042         // - mParent
00043         // - mSearchPath
00044         // - mProcesses
00045         // - mOutputDocument
00046         // - mBuffers
00047         // - mInitialized
00048   {
00049         Except(INVALID_OPERATION_ERROR, "Node::Node()",
00050            "Default constructor for Squirrel compatibility. Calling this constructor always raises an exception.");
00051   }
00052 
00053  /*----------------------------------------------------------------------*/
00054 
00055   Node::Node(const std::string & name, Host * parent):
00056         // Parent initialize 
00057    Name(name                    /* Name of the node */
00058   ),
00059         // Initialize parent 
00060    mParent(parent               /* Parent host */
00061         )
00062         // You have to initialize the following attributes:
00063         // - mParent
00064         // - mSearchPath
00065         // - mProcesses
00066         // - mOutputDocument
00067         // - mBuffers
00068         // - mInitialized
00069   {
00070         Assert(parent, NULL_POINTER_ERROR, "Node::Node()");
00071 
00072         mSearchPath = "./../lib";
00073 
00074         // Create processes
00075         mProcesses = new Container < Process, Mutex >;
00076 
00077         // Create buffers
00078         mBuffers = new Container < Buffer, Mutex >;
00079 
00080         // Create output document
00081         mOutputDocument = new OutputNode("node", OutputNode::INFORMATION);
00082         mOutputDocument->setAttribute("name", mName);
00083 
00084         mInitialized = false;
00085 
00086         Logger::getInstance()->log(Logger::NOTICE, "Node `" + mName + "\' has been created.");
00087   }
00088 
00089  /*----------------------------------------------------------------------*/
00090 
00091   Node::~Node()
00092   {
00093         if(mInitialized)
00094          finalize();
00095 
00096         Logger::getInstance()->log(Logger::NOTICE, "Node `" + mName + "\' has been destroyed.");
00097   }
00098 
00099  /*----------------------------------------------------------------------*/
00100 
00101   //
00102   // Methods
00103   //
00104 
00105   void Node::initialize()
00106   {
00107         Assert(!mInitialized, INVALID_OPERATION_ERROR, "Node::initialize()");
00108 
00109         // Initialize buffers
00110         for(Container < Buffer, Mutex >::Iterator i = mBuffers->begin(); i != mBuffers->end(); i++)
00111          if(!i->second->getInitialized())
00112                 i->second->initialize();
00113 
00114         mInitialized = true;
00115 
00116         Logger::getInstance()->log(Logger::DEBUG, "Node `" + mName + "\' has been initialized.");
00117   }
00118 
00119  /*----------------------------------------------------------------------*/
00120 
00121   void Node::finalize()
00122   {
00123         Assert(mInitialized, INVALID_OPERATION_ERROR, "Node::finalize()");
00124 
00125         mProcesses.kill();
00126 
00127         mBuffers.kill();
00128 
00129         mInitialized = false;
00130 
00131         Logger::getInstance()->log(Logger::DEBUG, "Node `" + mName + "\' has been finalized.");
00132   }
00133 
00134  /*----------------------------------------------------------------------*/
00135 
00136   Process *Node::createProcess(const char *processName)
00137   {
00138 
00139         mProcesses.lock();
00140 
00141         Process::Pointer process(new Process(processName, this));
00142 
00143         mProcesses->add(processName, process);
00144         process->initThread(0, 0, true);
00145 
00146         mProcesses.unlock();
00147 
00148         return process.getPtr();
00149   }
00150 
00151  /*----------------------------------------------------------------------*/
00152 
00153   Buffer *Node::createBuffer(const char *name, const PCuint left, const PCuint top,
00154                            const PCuint width, const PCuint height, const PCuint depthFormat)
00155   {
00156         mBuffers.lock();
00157 
00158         Buffer::Pointer buffer(new Buffer(left, top, width, height, depthFormat, this));
00159 
00160         mBuffers->add(name, buffer);
00161 
00162         mBuffers.unlock();
00163 
00164         return buffer.getPtr();
00165   }
00166 
00167  /*----------------------------------------------------------------------*/
00168 
00169   Buffer::Pointer Node::getBuffer(const std::string name)
00170   {
00171         return mBuffers->get(name);
00172   }
00173 
00174  /*----------------------------------------------------------------------*/
00175 
00176   void Node::start()
00177   {
00178         for(Container < Process, Mutex >::Iterator i = mProcesses->begin(); i != mProcesses->end(); i++)
00179          i->second->start();
00180   }
00181 
00182  /*----------------------------------------------------------------------*/
00183 
00184   u32 Node::stop()
00185   {
00186 
00187         u32 result = 0;
00188         u32 u;
00189 
00190         for(Container < Process, Mutex >::Iterator i = mProcesses->begin(); i != mProcesses->end(); i++)
00191         {
00192          u = i->second->stop();
00193          if(u > result)
00194          {
00195                 result = u;
00196          }
00197         }
00198 
00199         return result;
00200   }
00201 
00202  /*----------------------------------------------------------------------*/
00203 
00204   void Node::collectData()
00205   {
00206         for(Container < Process, Mutex >::Iterator i = mProcesses->begin(); i != mProcesses->end(); i++)
00207          mOutputDocument->addChildNode(i->second->getOutputDocument());
00208   }
00209 
00210  /*----------------------------------------------------------------------*/
00211 
00212   void Node::setFrameID(const u32 & frameID)
00213   {
00214         for(Container < Process, Mutex >::Iterator i = mProcesses->begin(); i != mProcesses->end(); i++)
00215         {
00216          i->second->setFinito(frameID);
00217         }
00218 
00219         for(Container < Process, Mutex >::Iterator i = mProcesses->begin(); i != mProcesses->end(); i++)
00220         {
00221 
00222          if(i->second->getStopAble())
00223          {
00224 
00225                 i->second->go();
00226          }
00227         }
00228 
00229   }
00230 
00231  /*----------------------------------------------------------------------*/
00232 
00233 }