Lookup.h

00001 
00002 #ifndef SCT_LOOKUP_H
00003 #define SCT_LOOKUP_H
00004 
00005 
00006 
00007 #include <string>
00008 #include "ipc/partition.h"
00009 #include "is/info.h"
00010 #include "Sct/SctNames.h"
00011 #include "Sct/MultiMessageDebugStream.h"
00012 
00013 namespace Sct {
00014 
00057   template < class TT >
00058   typename TT::_ptr_type Lookup(const std::string & name, const IPCPartition & p){
00059     const bool PRINT_DEBUG = true;
00060     
00061     typename TT::_ptr_type ob = TT::_nil();
00062     bool valid=false;
00063     int ntries=0;
00064     const int maxtries=10; // must be >= 2
00065     
00066     while (valid==false && ntries<maxtries){
00067 
00068       if (PRINT_DEBUG) {
00069         MultiMessageDebugStream m(true,false,false);
00070         m << "Starting attempt " << ntries;
00071         m.flush();
00072       };
00073       
00074       const bool NIL=CORBA::is_nil(ob);
00075       bool NXT=true;
00076       try {
00077         if (PRINT_DEBUG) {
00078           MultiMessageDebugStream m(true,false,false);
00079           m << "about to test existence";
00080           m.flush();
00081         };
00082         NXT=ob->_non_existent();
00083       } catch (const ipc::CacheExpired & e) {
00085     NXT=true; // Since it appears not to exist yet !   :(
00086       };
00087       
00088       if (PRINT_DEBUG) {
00089         MultiMessageDebugStream m(true,false,false);
00090         m << "thingkinsdf";
00091         m.flush();
00092       };
00093       
00094       if (NIL || NXT) {
00095     if (PRINT_DEBUG) {
00096       MultiMessageDebugStream m(true,false,false);
00097       m << "At attempt "<<ntries<<" it was found that NIL="<<NIL<<" and NXT="<<NXT<<" so trying to lookup again!";
00098       m.flush();
00099         };    
00100     try {
00101           ob = (p.template lookup<TT>( name ));
00102       if (PRINT_DEBUG) {
00103         MultiMessageDebugStream m(true,false,false);
00104         m << "No exception here, fortunately";
00105         m.flush();
00106       };
00107     } catch (const ipc::CacheExpired & e) {
00109       ob = TT::_nil(); // let's try again
00110       if (PRINT_DEBUG) {
00111         MultiMessageDebugStream m(true,false,false);
00112         m << "Good job we caught that!";
00113         m.flush();
00114       };
00115     };
00116       } else {
00117     if (PRINT_DEBUG) {
00118       MultiMessageDebugStream m(true,false,false);
00119       m << "At attempt "<<ntries<<" we think we have a good answer.";
00120       m.flush();
00121     };    
00122         valid=true;
00123       }
00124       ++ntries;
00125     }
00126     if (!valid) {
00127       if (PRINT_DEBUG) {
00128         Sct::MultiMessageDebugStream m(true,true,false);
00129         m << "Our lookup wrapper failed to look up ["<<name<<"] after "<<maxtries<<" attempts.";
00130         m.flush();
00131       };
00132       return TT::_nil();
00133     } else {
00134       if (PRINT_DEBUG) {
00135     MultiMessageDebugStream m(true,false,false);
00136     m << "Lookup returning something successfully";
00137     m.flush();  
00138       };
00139       return ob;
00140     }
00141   };
00142   
00143 };
00144 #endif

Generated on Mon Feb 6 14:01:22 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6