00001 /* 00002 FSF: Flow Scheduling Framework library 00003 00004 Version 1.0 Copyright (C) 2010 Alexandre R.J. Francois 00005 00006 Previous versions Copyright (C) 2001-2005 University of Southern California 00007 00008 Author: Alexandre R.J. Francois - alexandrefrancois@yahoo.com 00009 www.alexandrefrancois.org 00010 00011 Modular Flow Scheduling Middleware 00012 mfsm.sourceForge.net 00013 00014 This library is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU Lesser General Public 00016 License as published by the Free Software Foundation; either 00017 version 2.1 of the License, or (at your option) any later version. 00018 00019 This library is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00022 Lesser General Public License for more details. 00023 00024 You should have received a copy of the GNU Lesser General Public 00025 License along with this library; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00027 */ 00028 00029 #ifndef FSF_TYPE_CELL_BASE_H 00030 #define FSF_TYPE_CELL_BASE_H 00031 00032 #include "FsfCell.h" 00033 00034 namespace fsf { 00035 00038 class CTypeCellBase : public CCell { 00039 protected: 00040 public: 00042 00043 00044 CTypeCellBase() : CCell() {} 00046 00048 00049 00050 virtual void getTypeID(std::string &str) const { str.assign("FSF_TYPE_CELL_BASE"); } 00052 00053 00055 00056 00057 virtual void process(CPassiveHandle *pPassiveHandle, CActiveHandle *pActiveHandle, CActivePulse *pActivePulse) {} 00059 00060 00062 00063 00066 inline void startActiveThread(CActivePulse *pPulse=NULL); 00067 00068 // Calls Process if needed 00069 // Process incoming active pulse. 00070 // The semantics are slightly modified for the type cell 00071 // to handle Get and Set value operations. 00072 virtual void activeThread(CActivePulse *pPulse=NULL){ 00073 lockPassiveHandle(); 00074 if(getPassiveHandle()!=NULL){ 00075 // make a copy of passive handle 00076 CPassiveHandle *pPassiveHandle=new CPassiveHandle(*getPassiveHandle()); 00077 unlockPassiveHandle(); 00078 00079 // filter active pulse to get active node 00080 std::list<CActiveHandle*> listHandles; 00081 lockActiveFilter(); 00082 bool bMatch=getActiveFilter()->filter(listHandles,pPulse); 00083 unlockActiveFilter(); 00084 if(bMatch){ 00085 // no multiple matches allowed: only process first match 00086 // input found: SET value 00087 std::list<CActiveHandle*>::iterator it=listHandles.begin(); 00088 // make both nodes interact 00089 process(pPassiveHandle,*it,pPulse); 00090 // trigger update on passive loop 00091 getRepository()->notifyPulseUpdate(); 00092 // delete handles 00093 while(it!=listHandles.end()){ 00094 delete *it; 00095 ++it; 00096 } 00097 } 00098 else{ 00099 // no input found: GET value 00100 process(pPassiveHandle,NULL,pPulse); 00101 } 00102 delete pPassiveHandle; 00103 } 00104 else{ 00105 unlockPassiveHandle(); 00106 } 00107 00108 // Complete routing of active pulse 00109 lockDownstream(); 00110 if(!getListDownstream().empty()){ 00111 pPulse->incNbPaths(getListDownstream().size()-1); 00112 std::list<CCell*>::iterator it; 00113 for(it=getListDownstream().begin();it!=getListDownstream().end();++it){ 00114 (*it)->startActiveThread(pPulse); 00115 } 00116 unlockDownstream(); 00117 } 00118 else{ 00119 unlockDownstream(); 00120 // release the Pulse and delete if no longer needed 00121 if(pPulse->decNbPaths()==0) 00122 delete pPulse; 00123 } 00124 } 00125 00127 00128 }; 00129 00130 } // namespace fsf 00131 00132 #endif // FSF_TYPE_CELL_BASE_H 00133