00001
00002
00003 #include <iostream>
00004
00005 using std::cerr ;
00006 using std::cout ;
00007 using std::endl ;
00008
00009 #include "resplistT.h"
00010 #include "BESResponseHandlerList.h"
00011 #include "TestResponseHandler.h"
00012
00013 int resplistT::
00014 run(void) {
00015 cout << endl << "*****************************************" << endl;
00016 cout << "Entered resplistT::run" << endl;
00017 int retVal = 0;
00018
00019 cout << endl << "*****************************************" << endl;
00020 cout << "add the 5 response handlers" << endl ;
00021 BESResponseHandlerList *rhl = BESResponseHandlerList::TheList() ;
00022 char num[10] ;
00023 for( int i = 0; i < 5; i++ )
00024 {
00025 sprintf( num, "resp%d", i ) ;
00026 if( rhl->add_handler( num, TestResponseHandler::TestResponseBuilder ) == true )
00027 {
00028 cout << "successfully added " << num << endl ;
00029 }
00030 else
00031 {
00032 cerr << "failed to add " << num << endl ;
00033 return 1 ;
00034 }
00035 }
00036
00037 cout << endl << "*****************************************" << endl;
00038 cout << "try to add resp3 again" << endl ;
00039 if( rhl->add_handler( "resp3", TestResponseHandler::TestResponseBuilder ) == true )
00040 {
00041 cerr << "successfully added resp3 again" << endl ;
00042 return 1 ;
00043 }
00044 else
00045 {
00046 cout << "failed to add resp3 again, good" << endl ;
00047 }
00048
00049 cout << endl << "*****************************************" << endl;
00050 cout << "finding the handlers" << endl ;
00051 for( int i = 4; i >= 0; i-- )
00052 {
00053 sprintf( num, "resp%d", i ) ;
00054 BESResponseHandler *rh = rhl->find_handler( num ) ;
00055 if( rh )
00056 {
00057 if( rh->get_name() == num )
00058 {
00059 cout << "found " << num << endl ;
00060 delete rh ;
00061 }
00062 else
00063 {
00064 cerr << "looking for " << num
00065 << ", found " << rh->get_name() << endl ;
00066 delete rh ;
00067 return 1 ;
00068 }
00069 }
00070 else
00071 {
00072 cerr << "coundn't find " << num << endl ;
00073 return 1 ;
00074 }
00075 }
00076
00077 cout << endl << "*****************************************" << endl;
00078 cout << "removing resp2" << endl ;
00079 if( rhl->remove_handler( "resp2" ) == true )
00080 {
00081 BESResponseHandler *rh = rhl->find_handler( "resp2" ) ;
00082 if( rh )
00083 {
00084 if( rh->get_name() == "resp2" )
00085 {
00086 cerr << "remove successful, but found resp2" << endl ;
00087 delete rh ;
00088 return 1 ;
00089 }
00090 else
00091 {
00092 cerr << "remove successful, but found not resp2 but "
00093 << rh->get_name() << endl ;
00094 delete rh ;
00095 return 1 ;
00096 }
00097 }
00098 else
00099 {
00100 cout << "successfully removed resp2" << endl ;
00101 }
00102 }
00103 else
00104 {
00105 cerr << "failed to remove resp2" << endl ;
00106 return 1 ;
00107 }
00108
00109 if( rhl->add_handler( "resp2", TestResponseHandler::TestResponseBuilder ) == true )
00110 {
00111 cout << "successfully added resp2 back" << endl ;
00112 }
00113 else
00114 {
00115 cerr << "failed to add resp2 back" << endl ;
00116 return 1 ;
00117 }
00118
00119 BESResponseHandler *rh = rhl->find_handler( "resp2" ) ;
00120 if( rh )
00121 {
00122 if( rh->get_name() == "resp2" )
00123 {
00124 cout << "found resp2" << endl ;
00125 delete rh ;
00126 }
00127 else
00128 {
00129 cerr << "looking for resp2, found " << rh->get_name() << endl ;
00130 delete rh ;
00131 return 1 ;
00132 }
00133 }
00134 else
00135 {
00136 cerr << "coundn't find resp2" << endl ;
00137 return 1 ;
00138 }
00139
00140 cout << endl << "*****************************************" << endl;
00141 cout << "Returning from resplistT::run" << endl;
00142
00143 return retVal;
00144 }
00145
00146 int
00147 main(int argC, char **argV) {
00148 Application *app = new resplistT();
00149 return app->main(argC, argV);
00150 }
00151