defT.cc

Go to the documentation of this file.
00001 // defT.C
00002 
00003 #include <iostream>
00004 #include <sstream>
00005 
00006 using std::cerr ;
00007 using std::cout ;
00008 using std::endl ;
00009 using std::stringstream ;
00010 
00011 #include "defT.h"
00012 #include "BESDefinitionStorageList.h"
00013 #include "BESDefinitionStorageVolatile.h"
00014 #include "BESDefine.h"
00015 #include "BESTextInfo.h"
00016 #include "BESException.h"
00017 
00018 int defT::
00019 run(void)
00020 {
00021     cout << endl << "*****************************************" << endl;
00022     cout << "Entered defT::run" << endl;
00023     int retVal = 0;
00024 
00025     BESDefinitionStorageList::TheList()->add_persistence( new BESDefinitionStorageVolatile( PERSISTENCE_VOLATILE ) ) ;
00026     BESDefinitionStorage *store = BESDefinitionStorageList::TheList()->find_persistence( PERSISTENCE_VOLATILE ) ;
00027 
00028     cout << endl << "*****************************************" << endl;
00029     cout << "add d1, d2, d3, d4, d5" << endl;
00030     for( unsigned int i = 1; i < 6; i++ )
00031     {
00032         stringstream name ; name << "d" << i ;
00033         stringstream agg ; agg << "d" << i << "agg" ;
00034         BESDefine *dd = new BESDefine ;
00035         dd->set_agg_cmd( agg.str() ) ;
00036         bool status = store->add_definition( name.str(), dd ) ;
00037         if( status == true )
00038         {
00039             cout << "successfully added " << name.str() << endl ;
00040         }
00041         else
00042         {
00043             cerr << "failed to add " << name.str() << endl ;
00044             return 1 ;
00045         }
00046     }
00047 
00048     cout << endl << "*****************************************" << endl;
00049     cout << "find d1, d2, d3, d4, d5" << endl;
00050     for( unsigned int i = 1; i < 6; i++ )
00051     {
00052         stringstream name ; name << "d" << i ;
00053         stringstream agg ; agg << "d" << i << "agg" ;
00054         BESDefine *dd = store->look_for( name.str() ) ;
00055         if( dd )
00056         {
00057             cout << "found " << name.str() << endl ;
00058             if( dd->get_agg_cmd() == agg.str() )
00059             {
00060                 cout << "    agg command correct" << endl ;
00061             }
00062             else
00063             {
00064                 cerr << "    agg command incorrect, = "
00065                      << dd->get_agg_cmd()
00066                      << ", should be " << agg.str() << endl ;
00067                 return 1 ;
00068             }
00069         }
00070         else
00071         {
00072             cerr << "didn't find " << name.str() << endl ;
00073             return 1 ;
00074         }
00075     }
00076 
00077     cout << endl << "*****************************************" << endl;
00078     cout << "show definitions" << endl;
00079     {
00080         BESTextInfo info ;
00081         store->show_definitions( info ) ;
00082         info.print( stdout ) ;
00083     }
00084 
00085     cout << endl << "*****************************************" << endl;
00086     cout << "delete d3" << endl;
00087     {
00088         bool ret = store->del_definition( "d3" ) ;
00089         if( ret == true )
00090         {
00091             cout << "successfully deleted d3" << endl ;
00092         }
00093         else
00094         {
00095             cerr << "unable to delete d3" << endl ;
00096             return 1 ;
00097         }
00098         BESDefine *dd = store->look_for( "d3" ) ;
00099         if( dd )
00100         {
00101             cerr << "    found d3, bad" << endl ;
00102             return 1 ;
00103         }
00104         else
00105         {
00106             cout << "    did not find d3" << endl ;
00107         }
00108     }
00109 
00110     cout << endl << "*****************************************" << endl;
00111     cout << "delete d1" << endl;
00112     {
00113         bool ret = store->del_definition( "d1" ) ;
00114         if( ret == true )
00115         {
00116             cout << "successfully deleted d1" << endl ;
00117         }
00118         else
00119         {
00120             cerr << "unable to delete d1" << endl ;
00121             return 1 ;
00122         }
00123         BESDefine *dd = store->look_for( "d1" ) ;
00124         if( dd )
00125         {
00126             cerr << "    found d1, bad" << endl ;
00127             return 1 ;
00128         }
00129         else
00130         {
00131             cout << "    did not find d1" << endl ;
00132         }
00133     }
00134 
00135     cout << endl << "*****************************************" << endl;
00136     cout << "delete d5" << endl;
00137     {
00138         bool ret = store->del_definition( "d5" ) ;
00139         if( ret == true )
00140         {
00141             cout << "successfully deleted d5" << endl ;
00142         }
00143         else
00144         {
00145             cerr << "unable to delete d5" << endl ;
00146             return 1 ;
00147         }
00148         BESDefine *dd = store->look_for( "d5" ) ;
00149         if( dd )
00150         {
00151             cerr << "    found d5, bad" << endl ;
00152             return 1 ;
00153         }
00154         else
00155         {
00156             cout << "    did not find d5" << endl ;
00157         }
00158     }
00159 
00160     cout << endl << "*****************************************" << endl;
00161     cout << "find d2 and d4" << endl;
00162     {
00163         BESDefine *dd = store->look_for( "d2" ) ;
00164         if( dd )
00165         {
00166             cout << "found " << "d2" << ", good" << endl ;
00167         }
00168         else
00169         {
00170             cerr << "didn't find " << "d2" << ", bad" << endl ;
00171             return 1 ;
00172         }
00173 
00174         dd = store->look_for( "d4" ) ;
00175         if( dd )
00176         {
00177             cout << "found " << "d4" << ", good" << endl ;
00178         }
00179         else
00180         {
00181             cerr << "didn't find " << "d4" << ", bad" << endl ;
00182             return 1 ;
00183         }
00184     }
00185 
00186     cout << endl << "*****************************************" << endl;
00187     cout << "delete all definitions" << endl;
00188     store->del_definitions() ;
00189 
00190     cout << endl << "*****************************************" << endl;
00191     cout << "find definitions d1, d2, d3, d4, d5" << endl;
00192     for( unsigned int i = 1; i < 6; i++ )
00193     {
00194         stringstream name ; name << "d" << i ;
00195         stringstream agg ; agg << "d" << i << "agg" ;
00196         BESDefine *dd = store->look_for( name.str() ) ;
00197         if( dd )
00198         {
00199             cerr << "found " << name.str() << ", bad" << endl ;
00200             return 1 ;
00201         }
00202         else
00203         {
00204             cout << "didn't find " << name.str() << ", good" << endl ;
00205         }
00206     }
00207 
00208     cout << endl << "*****************************************" << endl;
00209     cout << "Returning from defT::run" << endl;
00210 
00211     return retVal;
00212 }
00213 
00214 int
00215 main(int argC, char **argV) {
00216     Application *app = new defT();
00217     putenv( "BES_CONF=./defT.ini" ) ;
00218     return app->main(argC, argV);
00219 }
00220 

Generated on Wed Aug 29 03:24:05 2007 for OPeNDAP Back End Server (BES) by  doxygen 1.5.2