Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/ps/src/dsc/co/mw/mwfwk/cmwfwSubscribtionManager.cc

Go to the documentation of this file.
00001 #include "cmwfwSubscribtionManager.h"
00002 #include "cmwfwList.h"
00003 
00004 
00005 
00006 #define FILE "source file:cmwfwSubscribtionManager.cc"
00007 #define ID "Contact Steen JENSEN, PS/CO"
00008 #define PROGRAM "Middleware server framework"
00009 #define T(a,b,c,d,e) TRACE(a,"%s(%s): %s %s %s %s\n",myname,FILE,b,c,d,e)
00010 #define E(a,b,c,d) ERROR("%s:%s(%s):ERROR: %s %s %s %s - %s\n",PROGRAM,myname,FILE,a,b,c,d,ID)
00011 //T(CMWFW_TRACE_,"","","","");
00012 //E("","","","");
00013 
00014 
00015 
00016 
00017 
00018 
00029 cmwfwSubscribtionManager::cmwfwSubscribtionManager(){
00030   char* myname = "cmwfwSubscribtionManager::cmwfwSubscribtionManager";
00031   T(CMWFW_TRACE_CALLS,"Entering","","","");
00032 
00033   iopoints = new subman_list_type(true);
00034   if(!iopoints)heaperr(33);
00035   attach_iop_func = 0;
00036   detach_iop_func = 0;
00037 
00038   T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00039 };
00040 
00041 
00042 
00043 
00054 cmwfwSubscribtionManager::~cmwfwSubscribtionManager(){
00055   char* myname = "cmwfwSubscribtionManager::~cmwfwSubscribtionManager";
00056   T(CMWFW_TRACE_CALLS,"Entering","","","");
00057 
00058   bool stat;
00059   int sz;
00060   cmwfwIOPoint* tmp_iop = 0;
00061 
00062   iopoints->Size(&sz,false);  //Do not use mutex - something is wrong since the
00063                                                           // subscribtionmanager is being brought down.
00064   if(sz > 0){
00065         iopoints->resetCurrent();
00066         stat = iopoints->getFirst(&tmp_iop,false);
00067         while(stat){
00068           delete tmp_iop;
00069           stat = iopoints->getNext(&tmp_iop,false);
00070         };
00071   };
00072     delete iopoints;
00073 
00074   T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00075 };
00076 
00077 
00078 
00089 bool cmwfwSubscribtionManager::find(const cmwfwIOPoint& iop,
00090                                                                     cmwfwIOPoint*& dst){
00091   char* myname = "cmwfwSubscribtionManager::find";
00092   T(CMWFW_TRACE_CALLS,"Entering","","","");
00093 
00094   bool stat               = false;
00095   cmwfwIOPoint* iop_tmp   = 0;
00096 
00097   if( (attach_iop_func) || (detach_iop_func) ){
00098         dst = 0;
00099         return true;
00100   };
00101 
00102 
00103   iopoints->lock();
00104   iopoints->resetCurrent(false);
00105   stat = iopoints->getFirst(&iop_tmp,false);
00106   while( (stat) && (!(*iop_tmp == iop)) )
00107     stat = iopoints->getNext(&iop_tmp,false);
00108 
00109   if(stat){
00110     dst = iop_tmp;
00111     iopoints->unlock();
00112     T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00113     return true;
00114   };
00115   dst = 0;
00116   iopoints->unlock();
00117 
00118   T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00119   return false;
00120 };
00121 
00122 
00123 
00124 
00125 
00136 bool cmwfwSubscribtionManager::attach(const cmwfwIOPoint& iop){
00137   char* myname = "cmwfwSubscribtionManager::attach";
00138   T(CMWFW_TRACE_CALLS,"Entering","","","");
00139 
00140   char*            cs         = iop.getCycleSelector();
00141   bool             stat       = false;
00142   cmwfwIOPoint*    res        = 0;
00143   cmwfwIOPoint*    iop_local  = 0;
00144 
00145   if(cs)T(CMWFW_TRACE_CLIENTS,"IOPoint ",iop.getDeviceName(),":",cs);
00146   else T(CMWFW_TRACE_CLIENTS,
00147                  "IOPoint ",iop.getDeviceName()," no cycleselector","");
00148 
00149   if( (attach_iop_func) ){
00150     T(CMWFW_TRACE_CALLS,"Returning user routine value - all ok","","","");
00151     return (*attach_iop_func)(this,iop);
00152   };
00153 
00154   if(!find(iop,res)){
00155         iop_local = new cmwfwIOPoint("","","","");
00156         if(!iop_local)heaperr(138);
00157         *iop_local = iop;
00158     stat = iopoints->insert(iop_local);
00159     T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00160     return (stat);
00161   };
00162   T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00163   return false;
00164 };
00165 
00166 
00176 bool cmwfwSubscribtionManager::detach(const cmwfwIOPoint& iop){
00177   char*              myname        = "cmwfwSubscribtionManager::detach";
00178   T(CMWFW_TRACE_CALLS,"Entering","","","");
00179 
00180   char*              cs            = iop.getCycleSelector();
00181   bool               stat          = false;
00182   cmwfwIOPoint*      res           = 0;
00183 
00184 
00185   if(cs)T(CMWFW_TRACE_CLIENTS,"IOPoint ",iop.getDeviceName(),":",cs);
00186   else T(CMWFW_TRACE_CLIENTS,
00187                  "IOPoint ",iop.getDeviceName()," no cycleselector","");
00188 
00189   if( (detach_iop_func) ){
00190     T(CMWFW_TRACE_CALLS,"Returning user routine value - all ok","","","");
00191     return (*detach_iop_func)(this,iop);
00192   };
00193 
00194   if(find(iop,res)){
00195     iopoints->remove(res);
00196         delete res;
00197     T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00198     return true;
00199   };
00200 
00201   T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00202   return false;
00203 };
00204 
00205 
00206 
00207 
00218 void cmwfwSubscribtionManager::passOnIOPoints(
00219                                                            bool(*att_func)(cmwfwSubscribtionManager*,
00220                                                                                            const cmwfwIOPoint& iop),
00221                                                            bool(*det_func)(cmwfwSubscribtionManager*,
00222                                                                                            const cmwfwIOPoint& iop)){
00223   char* myname = "cmwfwSubscribtionManager::passOnIOPoints";
00224   T(CMWFW_TRACE_CALLS,"Entering","","","");
00225 
00226   attach_iop_func = att_func;
00227   detach_iop_func = det_func;
00228 
00229   T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00230   };
00231 
00232 
00233 
00234 
00235 char* cmwfwSubscribtionManager::generateIOPString(const cmwfwIOPoint& iop){
00236   char* myname = "cmwfwSubscribtionManager::generateIOPString";
00237   T(CMWFW_TRACE_CALLS,"Entering","","","");
00238 
00239   char* cn = iop.getClassName();
00240   char* dn = iop.getDeviceName();
00241   char* pn = iop.getPropertyName();
00242   char* cs = iop.getCycleSelector();
00243   int cnl = strlen(cn);
00244   int dnl = strlen(dn);
00245   int pnl = strlen(pn);
00246   int csl = 0;
00247   if(cs)
00248         csl = strlen(cs);
00249 
00250   char* m = new char[cnl+dnl+pnl+csl+2+5];
00251   if(!m)heaperr(1928);
00252   m[0] = 0;
00253   strcat(m,cn);
00254   strcat(m,":");
00255   strcat(m,dn);
00256   strcat(m,":");
00257   strcat(m,pn);
00258   if(cs){
00259     strcat(m,":");
00260         strcat(m,cs);
00261   };
00262 
00263   T(CMWFW_TRACE_CALLS,"Returning - all ok","","","");
00264   return m;
00265 };
00266 
00267 
00268 
00269 void cmwfwSubscribtionManager::heaperr(int line){
00270   char* myname = "cmwfwSubscribtionManager";
00271   T(CMWFW_TRACE_CALLS,"Entering","","","");
00272 
00273   char l[30];
00274   itoa(line,l);
00275   E("Out of heap in line ",l,"","");
00276   T(CMWFW_TRACE_CALLS,"Exiting due to heap allocation error","","","");
00277   throw cmwfwInternalError(FILE,line,"Out of heap memory");
00278   exit(-1);
00279 };
00280 
00281 

Generated at Thu May 10 11:28:59 2001 for C.E.R.N.-PSControlsMiddlewareFramework by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001