OPeNDAP Hyrax Back End Server (BES) Updated for version 3.8.3
BESBaseApp.cc
Go to the documentation of this file.
00001 // BESBaseApp.C
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 //
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025 
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include <iostream>
00034 
00035 using std::cerr ;
00036 using std::endl ;
00037 
00038 #include "BESBaseApp.h"
00039 #include "BESGlobalIQ.h"
00040 #include "BESInternalError.h"
00041 
00042 BESApp *BESApp::_theApplication = 0;
00043 
00049 BESBaseApp::BESBaseApp(void)
00050 {
00051     BESApp::_theApplication = this;
00052 }
00053 
00059 BESBaseApp::~BESBaseApp(void)
00060 {
00061     BESApp::_theApplication = 0;
00062 }
00063 
00074 int
00075 BESBaseApp::main(int argC, char **argV)
00076 {
00077     _appName = argV[0] ;
00078     int retVal = initialize( argC, argV ) ;
00079     if( retVal == 0 )
00080     {
00081         retVal = run() ;
00082         retVal = terminate( retVal ) ;
00083     }
00084     return retVal ;
00085 }
00086 
00098 int
00099 BESBaseApp::initialize(int argC, char **argV)
00100 {
00101     int retVal = 0;
00102 
00103     // initialize application information
00104     try
00105     {
00106         if( !_isInitialized )
00107             BESGlobalIQ::BESGlobalInit( argC, argV ) ;
00108         _isInitialized = true ;
00109     }
00110     catch( BESError &e )
00111     {
00112         string newerr = "Error initializing application: " ;
00113         newerr += e.get_message() ;
00114         cerr << newerr << endl ;
00115         retVal = 1 ;
00116     }
00117     catch( ... )
00118     {
00119         string newerr = "Error initializing application: " ;
00120         newerr += "caught unknown exception" ;
00121         cerr << newerr << endl ;
00122         retVal = 1 ;
00123     }
00124 
00125     return retVal ;
00126 }
00127 
00136 int
00137 BESBaseApp::run(void)
00138 {
00139     throw BESInternalError( "BESBaseApp::run - run method not implemented",
00140                             __FILE__, __LINE__ ) ;
00141     return 0;
00142 }
00143 
00153 int
00154 BESBaseApp::terminate( int sig )
00155 {
00156     BESGlobalIQ::BESGlobalQuit() ;
00157     _isInitialized = false ;
00158     return sig ;
00159 }
00160 
00168 void
00169 BESBaseApp::dump( ostream &strm ) const
00170 {
00171     strm << BESIndent::LMarg << "BESBaseApp::dump - (" << (void *)this << ")" << endl ;
00172     BESIndent::Indent() ;
00173     strm << BESIndent::LMarg << "appName: " << appName() << endl ;
00174     strm << BESIndent::LMarg << "is initialized: " << _isInitialized << endl ;
00175     BESIndent::UnIndent() ;
00176 }
00177