1 //============================================================================== 2 // 3 // This file is part of GPSTk, the GPS Toolkit. 4 // 5 // The GPSTk is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published 7 // by the Free Software Foundation; either version 3.0 of the License, or 8 // any later version. 9 // 10 // The GPSTk is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public 16 // License along with GPSTk; if not, write to the Free Software Foundation, 17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 18 // 19 // This software was developed by Applied Research Laboratories at the 20 // University of Texas at Austin. 21 // Copyright 2004-2020, The Board of Regents of The University of Texas System 22 // 23 //============================================================================== 24 25 //============================================================================== 26 // 27 // This software was developed by Applied Research Laboratories at the 28 // University of Texas at Austin, under contract to an agency or agencies 29 // within the U.S. Department of Defense. The U.S. Government retains all 30 // rights to use, duplicate, distribute, disclose, or release this software. 31 // 32 // Pursuant to DoD Directive 523024 33 // 34 // DISTRIBUTION STATEMENT A: This software has been approved for public 35 // release, distribution is unlimited. 36 // 37 //============================================================================== 38 39 /** 40 * @file BasicFramework.cpp 41 * Basic framework for programs in the GPS toolkit 42 */ 43 44 45 #include "Exception.hpp" 46 #include "BasicFramework.hpp" 47 #include "StringUtils.hpp" 48 49 50 namespace gpstk 51 { 52 53 using namespace std; 54 55 BasicFramework(const string & applName,const string & applDesc)56 BasicFramework :: BasicFramework( const string& applName, 57 const string& applDesc ) 58 throw() 59 : debugLevel(0), 60 verboseLevel(0), 61 exitCode(0), 62 argv0(applName), 63 appDesc(applDesc), 64 debugOption('d', "debug", "Increase debug level"), 65 verboseOption('v', "verbose", "Increase verbosity"), 66 helpOption('h', "help", "Print help usage") 67 {} // End of constructor 'BasicFramework::BasicFramework()' 68 69 70 initialize(int argc,char * argv[],bool pretty)71 bool BasicFramework :: initialize( int argc, 72 char *argv[], 73 bool pretty ) 74 throw() 75 { 76 77 // Creating the parser here ensures that all the subclasses' 78 // option objects are constructed. 79 try 80 { 81 CommandOptionParser cop(appDesc); 82 83 cop.parseOptions(argc, argv); 84 85 if (cop.helpRequested()) 86 { 87 cop.printHelp(cerr, pretty); 88 return false; 89 } 90 91 if (cop.hasErrors()) 92 { 93 cop.dumpErrors(cerr); 94 cop.displayUsage(cerr, pretty); 95 exitCode = OPTION_ERROR; 96 return false; 97 } 98 99 debugLevel = debugOption.getCount(); 100 verboseLevel = verboseOption.getCount(); 101 } 102 catch (gpstk::Exception &exc) 103 { 104 cerr << exc << endl; 105 exitCode=OPTION_ERROR; 106 return false; 107 } 108 catch (std::exception &exc) 109 { 110 cerr << "BasicFramework::initialize caught " << exc.what() << endl; 111 exitCode=OPTION_ERROR; 112 return false; 113 } 114 catch (...) 115 { 116 cerr << "BasicFramework::initialize caught unknown exception" << endl; 117 exitCode=OPTION_ERROR; 118 return false; 119 } 120 121 return true; 122 123 } // End of method 'BasicFramework::initialize()' 124 125 run()126 bool BasicFramework :: run() 127 throw() 128 { 129 130 try 131 { 132 completeProcessing(); 133 } 134 catch (Exception& exc) 135 { 136 cerr << exc; 137 exitCode = EXCEPTION_ERROR; 138 return false; 139 } 140 catch (...) 141 { 142 cerr << "Caught unknown exception" << endl; 143 exitCode = EXCEPTION_ERROR; 144 return false; 145 } 146 147 shutDown(); 148 149 return true; 150 151 } // End of method 'BasicFramework::run()' 152 153 154 completeProcessing()155 void BasicFramework :: completeProcessing() 156 { 157 additionalSetup(); 158 159 spinUp(); 160 161 process(); 162 163 } // End of method 'BasicFramework::completeProcessing()' 164 165 166 } // End of namespace gpstk 167