PCMNode.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "../include/PCMNode.h"
00030
00031 #include "../include/PCMStringConverter.h"
00032
00033 namespace ParCompMark
00034 {
00035
00036
00037
00038
00039
00040 Node::Node()
00041
00042
00043
00044
00045
00046
00047
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
00057 Name(name
00058 ),
00059
00060 mParent(parent
00061 )
00062
00063
00064
00065
00066
00067
00068
00069 {
00070 Assert(parent, NULL_POINTER_ERROR, "Node::Node()");
00071
00072 mSearchPath = "./../lib";
00073
00074
00075 mProcesses = new Container < Process, Mutex >;
00076
00077
00078 mBuffers = new Container < Buffer, Mutex >;
00079
00080
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
00103
00104
00105 void Node::initialize()
00106 {
00107 Assert(!mInitialized, INVALID_OPERATION_ERROR, "Node::initialize()");
00108
00109
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 }