Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Platform/Aperios1.3.2/ProcessFramework.cpp

Go to the documentation of this file.
00001 /**
00002  * @file Platform/Aperios1.3.2/ProcessFramework.cpp
00003  * This file implements classes related to processes on the Aperios Platform.
00004  */
00005 #include "ProcessFramework.h"
00006 #include "IPEndpoint.h"
00007 
00008 #ifdef __GNUC__
00009 #include <apsys.h>
00010 /**
00011  * This is a big hack. For gcc, we need entry points for all callback functions,
00012  * and it is not possible to generate them automatically. Therefore, we define
00013  * a pool of 100 entry points here. The array "entry" contains the addresses of
00014  * the entry points, "link" contains the functions that will actually be called.
00015  */
00016 static void (*link[ENTRY_TABLE_MAX])(void*);
00017 
00018 /**
00019  * Create 100 entry points.
00020  */
00021 #define LINK(id) \
00022   extern "C" void link##id(void* msg) \
00023   { \
00024     link[id](msg); \
00025   } \
00026   GEN_ENTRY(link##id##Entry,link##id)
00027 
00028 #define LROW(n) \
00029   LINK(n##0); LINK(n##1); LINK(n##2); LINK(n##3); LINK(n##4); LINK(n##5); LINK(n##6); LINK(n##7); LINK(n##8); LINK(n##9)
00030 
00031 LROW(); LROW(1); LROW(2); LROW(3); LROW(4); LROW(5); LROW(6); LROW(7); LROW(8); LROW(9);
00032 
00033 /**
00034  * Create and initialize "entry".
00035  */
00036 #define ENTRY(id) link##id##Entry
00037 
00038 #define EROW(n) \
00039   ENTRY(n##0), ENTRY(n##1), ENTRY(n##2), ENTRY(n##3), ENTRY(n##4), \
00040   ENTRY(n##5), ENTRY(n##6), ENTRY(n##7), ENTRY(n##8), ENTRY(n##9)
00041 
00042 static void (*entry[ENTRY_TABLE_MAX])() =
00043 {
00044   EROW(), EROW(1), EROW(2), EROW(3), EROW(4), EROW(5), EROW(6), EROW(7), EROW(8), EROW(9)
00045 };
00046 
00047 GEN_ENTRY(PrologueEntry,Prologue);
00048 
00049 #endif // __GNUC__
00050 
00051 int ProcessBase::blockMask = 0,
00052     ProcessBase::eventMask = 0;
00053 ProcessBase* ProcessBase::theInstance = 0;
00054 
00055 ObjectEntry ObjectEntryTable[ENTRY_TABLE_MAX + 1];
00056 
00057 void ProcessBase::aperiosInit(OReasonMessage* reasonMsg)
00058 {
00059   theInstance->Init(OSystemEvent(reasonMsg->reason,reasonMsg->param,reasonMsg->paramSize));
00060   Return();
00061 }
00062 
00063 void ProcessBase::aperiosStart(OReasonMessage* reasonMsg)
00064 {
00065   theInstance->Start(OSystemEvent(reasonMsg->reason,reasonMsg->param,reasonMsg->paramSize));
00066   Return();
00067 }
00068 
00069 void ProcessBase::aperiosStop(OReasonMessage* reasonMsg)
00070 {
00071   theInstance->Stop(OSystemEvent(reasonMsg->reason,reasonMsg->param,reasonMsg->paramSize));
00072   Return();
00073 }
00074 
00075 void ProcessBase::aperiosDestroy(OReasonMessage* reasonMsg)
00076 {
00077   theInstance->Destroy(OSystemEvent(reasonMsg->reason,reasonMsg->param,reasonMsg->paramSize)); 
00078   Return();
00079 }
00080 
00081 void ProcessBase::awakeOnTimer(OReasonMessage* reasonMsg)
00082 {
00083   setEventId(31);
00084   Exit();
00085 }
00086 
00087     
00088 void ProcessBase::antListenCont(antEnvMsg* msg)
00089 {
00090   // When the message was send to the ANT-lib its continuation
00091   // field was set to the address of the Endpoint. So this calls
00092   // the listenCont funtion of the right IPEndpoint
00093   // cout << "ProcessBase::antListenCont " << msg << "\n";
00094   (static_cast<IPEndpoint*>(msg->continuation))->listenCont(msg);
00095   // cout << "ProcessBase::antListenCont done \n";
00096   Return();
00097 }
00098 
00099 void ProcessBase::antConnectCont(antEnvMsg* msg)
00100 {
00101   //cout << "ProcessBase::antConnectCont " << msg << "\n";
00102   (static_cast<IPEndpoint*>(msg->continuation))->connectCont(msg);
00103   //cout << "ProcessBase::antConnectCont done \n";
00104   Return();
00105 }
00106 
00107 void ProcessBase::antReceiveCont(antEnvMsg* msg)
00108 {
00109   //cout << "ProcessBase::antReceiveCont " << msg << "\n";
00110   (static_cast<IPEndpoint*>(msg->continuation))->receiveCont(msg);
00111   //cout << "ProcessBase::antReceiveCont done \n ";
00112   Return();
00113 }  
00114 
00115 void ProcessBase::antSendCont(antEnvMsg* msg)
00116 {
00117   //cout << "ProcessBase::antSendCont " << msg << "\n";
00118   (static_cast<IPEndpoint*>(msg->continuation))->sendCont(msg);
00119   //cout << "ProcessBase::antSendCont done \n";
00120   Return();
00121 }
00122 
00123 void ProcessBase::antCloseCont(antEnvMsg* msg)
00124 {
00125   //cout << "ProcessBase::antCloseCont " << msg << "\n";
00126   (static_cast<IPEndpoint*>(msg->continuation))->closeCont(msg);
00127   //cout << "ProcessBase::antCloseCont done \n";
00128   Return();
00129 }
00130 
00131 void ProcessBase::getAntInformation(int*& listenContSelector, int*& sendContSelector,
00132                  int*& receiveContSelector, int*& closeContSelector, 
00133                  int*& connectContSelector)
00134 {
00135     listenContSelector = &antListenContSelector;
00136     sendContSelector = &antSendContSelector;
00137     receiveContSelector = &antReceiveContSelector;
00138     closeContSelector = &antCloseContSelector;
00139     connectContSelector = &antConnectContSelector;   
00140 }
00141 
00142 void ProcessBase::init()
00143 {
00144   unsigned int id = 0;
00145   ObjectEntryTable[id].selector = id;
00146   ObjectEntryTable[id++].entry = (Entry) aperiosInit;
00147   ObjectEntryTable[id].selector = id;
00148   ObjectEntryTable[id++].entry = (Entry) aperiosStart;
00149   ObjectEntryTable[id].selector = id;
00150   ObjectEntryTable[id++].entry = (Entry) aperiosStop;
00151   ObjectEntryTable[id].selector = id;
00152   ObjectEntryTable[id++].entry = (Entry) aperiosDestroy;
00153   ObjectEntryTable[id].selector = id;
00154   ObjectEntryTable[id++].entry = (Entry) awakeOnTimer;
00155 
00156   for(ReceiverList* p = getProcess()->getFirstReceiver(); p; p = p->getNext())
00157     id = p->fillEntryTable(ObjectEntryTable,id);
00158   for(SenderList* q = getProcess()->getFirstSender(); q; q = q->getNext())
00159     id = q->fillEntryTable(ObjectEntryTable,id);
00160   ASSERT(id <= ENTRY_TABLE_MAX);
00161 
00162   // Entrys for IP-networking
00163 
00164   ObjectEntryTable[id].selector = id;
00165   antListenContSelector = id;
00166   ObjectEntryTable[id++].entry = (Entry) antListenCont;
00167   
00168   ObjectEntryTable[id].selector = id;
00169   antReceiveContSelector = id;
00170   ObjectEntryTable[id++].entry = (Entry) antReceiveCont;
00171 
00172   ObjectEntryTable[id].selector = id;
00173   antSendContSelector = id;
00174   ObjectEntryTable[id++].entry = (Entry) antSendCont;
00175 
00176   ObjectEntryTable[id].selector = id;
00177   antCloseContSelector = id;
00178   ObjectEntryTable[id++].entry = (Entry) antCloseCont;
00179 
00180   ObjectEntryTable[id].selector = id;
00181   antConnectContSelector = id;
00182   ObjectEntryTable[id++].entry = (Entry) antConnectCont;
00183 
00184   ASSERT(id <= ENTRY_TABLE_MAX);
00185  
00186 #ifdef __GNUC__
00187   // add entry points to callback functions
00188   for(unsigned int i = 0; i < id; ++i)
00189   {
00190     link[i] = (void (*)(void*)) ObjectEntryTable[i].entry;
00191     ObjectEntryTable[i].entry = (Entry) entry[i];
00192   }
00193 #endif // __GNUC__
00194 
00195   ObjectEntryTable[id].selector = UNDEF;
00196   ObjectEntryTable[id].entry = ENTRY_UNDEF;
00197 }
00198 
00199 void ProcessBase::nextFrame()
00200 {
00201   if(theInstance->isRunning())
00202     theInstance->processNextFrame();
00203 }
00204 
00205 void ProcessBase::setBlockingId(int id,bool block)
00206 {
00207   if(block)
00208     blockMask |= 1 << id;
00209   else
00210     blockMask &= ~(1 << id);
00211 }
00212 
00213 void ProcessBase::setEventId(int id)
00214 {
00215   eventMask |= 1 << id;
00216   if(blockMask && (eventMask & blockMask) == blockMask)
00217   {
00218     blockMask = 0;
00219     nextFrame();
00220   }
00221 }
00222 
00223 /*
00224  * Change log :
00225  * 
00226  * $Log: ProcessFramework.cpp,v $
00227  * Revision 1.1.1.1  2004/05/22 17:23:27  cvsadm
00228  * created new repository GT2004_WM
00229  *
00230  * Revision 1.2  2003/12/02 20:52:41  wachter
00231  * Added IP-networking to aperios process-framework.
00232  *
00233  * Revision 1.1  2003/10/07 10:06:59  cvsadm
00234  * Created GT2004 (M.J.)
00235  *
00236  * Revision 1.1.1.1  2003/07/02 09:40:24  cvsadm
00237  * created new repository for the competitions in Padova from the 
00238  * tamara CVS (Tuesday 2:00 pm)
00239  *
00240  * removed unused solutions
00241  *
00242  * Revision 1.4  2003/05/05 14:54:55  dueffert
00243  * comment corrected
00244  *
00245  * Revision 1.3  2003/03/06 11:52:37  dueffert
00246  * signed comparison warning removed
00247  *
00248  * Revision 1.2  2002/12/02 11:00:13  dueffert
00249  * doxygen docu corrected
00250  *
00251  * Revision 1.1  2002/09/10 15:40:04  cvsadm
00252  * Created new project GT2003 (M.L.)
00253  * - Cleaned up the /Src/DataTypes directory
00254  * - Removed challenge related source code
00255  * - Removed processing of incoming audio data
00256  * - Renamed AcousticMessage to SoundRequest
00257  *
00258  * Revision 1.3  2002/07/06 20:08:09  roefer
00259  * Advances towards gcc
00260  *
00261  * Revision 1.2  2002/07/06 15:28:28  roefer
00262  * Prologue function removed
00263  *
00264  * Revision 1.1.1.1  2002/05/10 12:40:18  cvsadm
00265  * Moved GT2002 Project from ute to tamara.
00266  *
00267  * Revision 1.8  2002/04/21 21:03:07  roefer
00268  * Again, events block with &-logic
00269  *
00270  * Revision 1.7  2002/04/20 15:52:20  roefer
00271  * Project simpified, WATCH and WATCH_PART added
00272  *
00273  * Revision 1.6  2001/12/15 20:32:08  roefer
00274  * Senders and receivers are now part of the processes
00275  *
00276  * Revision 1.5  2001/12/12 13:25:02  roefer
00277  * Blocking sender fixed
00278  *
00279  * Revision 1.4  2001/12/10 17:47:08  risler
00280  * change log added
00281  *
00282  */

Generated on Thu Sep 23 19:57:34 2004 for GT2004 by doxygen 1.3.6