fdhwlib  2.0.25
/home/kopmann/git-mirror/fdhwlib/fdhwlib/Hw/IRhandler.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     IRhandler.h  -  description
00003 
00004     begin                : Thu Jun 29 2000
00005     copyright            : (C) 2000 by Andreas Kopmann
00006     email                : kopmann@hpe.fzk.de
00007  ***************************************************************************/
00008 
00009 
00010 #ifndef _INC_IR_HANDLER_38563E480220_INCLUDED
00011 #define _INC_IR_HANDLER_38563E480220_INCLUDED
00012 
00013 // IR dispatcher for the FD mirror electronic
00014 // hpe, june 2000 (ak)
00015 //
00016 // Goal: There is only one IR + one IR vector, therefore
00017 // we have to provide a master process, that reads the IR vector
00018 // and informs all the other interested processes
00019 //
00020 // History:
00021 // 20 june 2000 First version trying to emulate a real software
00022 //              IR with a couple of semaphores...
00023 
00024 #ifdef __linux__
00025 
00026 #include <cstdio>
00027 #include <cstdlib>
00028 #include <climits>
00029 #include <unistd.h>
00030 
00031 #include <akutil/semaphore.h>
00032 #include <akutil/sharedMemory.h>
00033 #include <akutil/procDuration.h>
00034 
00035 #include <Pbus/Pbus.h>
00036 
00037 //#  define INT_MAX     2147483647 // from limits.h
00038 
00039 
00040 #define IR_TEST_MODE  // use this switch to enable the test mode
00041 #define IR_SINGLE_CLIENT_ACK // use this switch to let the IRdispatcher
00042                          // wait for an acknoledge from the client
00043 
00044 #ifdef IR_TEST_MODE
00045 //#define IR_REQUESTS_MAX 8 // maxmal number of requests that
00046 //                       // that can be invoked (only for extented test mode)
00047 #endif // __linux__
00048 
00049 #define IR_NXPG_MAX 2   // at least two are necessary
00050 #define IR_ERROR_MAX 2  // buffer = IR_SEMA_MAX -2
00051 
00052 #define SEM_NXPG 0
00053 #define SEM_ERROR 1
00054 
00055 
00056 #define IR_HANDLER_MASTER 0
00057 #define IR_HANDLER_CLIENT 1
00058 #define IR_HANDLER_CLIENT_NXPG 2
00059 
00060 #ifndef IR_TEST_MODE
00061 
00062 typedef struct {
00063    int masterActive;        // 0 no master, 1 master started
00064    int page[IR_NXPG_MAX];  // corresp. pages for the IRs
00065 }  IRdata;
00066 
00067 #else
00068 
00069 typedef struct {
00070    int masterActive;        // 0 no master, 1 master started
00071    int page[IR_NXPG_MAX];  // corresp. pages for the IRs
00072    // simple test: do all the registered clients got the NxPg message?
00073    int nrNxPgClients; // number of registered clients
00074    int countNxPgRequests[IR_NXPG_MAX];  // number of requests
00075    //int reqMap[IR_NXPG_MAX,IR_REQUESTS_MAX] // detailed list for all procs
00076                                         // (extended test mode)
00077    // same for all errors ?!
00078 }  IRdata;
00079 #endif
00080 
00081 
00088 //##ModelId=3991397D0290
00089 class IRhandler : public Pbus {
00090 
00091 public:
00092 
00108         //##ModelId=3991397D0346
00109    void dispatcher();
00110 
00111         //##ModelId=3991397D0345
00112    int waitForNxPg();
00113 
00114    // this is only a template for others
00115         //##ModelId=3991397D0344
00116    void waitForError(); // in fact there are more than one sources...
00117 
00118 
00119         //##ModelId=3991397D033A
00120    void displayParameters();
00121         
00122 
00123         //##ModelId=3991397D0330
00124    IRhandler(int mode); // 0 master =dispatcher
00125                         // 1 client (set bits to indicate
00126                         // which IRs will be requested - only
00127                         // for testing. )
00128 
00129         //##ModelId=3991397D0326
00130    ~IRhandler();
00131 
00132 private:
00133 
00134         //##ModelId=3991397D031E
00135    sharedMemory shm;
00136         //##ModelId=3991397D0312
00137    IRdata *parameter;
00138         //##ModelId=3991397D02FE
00139    int mode;
00140 
00141         //##ModelId=3991397D02F6
00142    semaphore s_nxpg;
00143 #ifdef IR_SINGLE_CLIENT_ACK     
00144         //##ModelId=3991397D02EC
00145    semaphore s_nxpg_ack;
00146 #endif
00147         //##ModelId=3991397D02E2
00148    semaphore s_error;
00149 
00150    // indicates the next sema to wait for
00151         //##ModelId=3991397D02A4
00152    int w_nxpg;
00153         //##ModelId=3991397D029B
00154    int w_error;
00155 
00156 };
00157 
00158 #endif
00159 
00160 
00161 #endif