libdap++ Updated for version 3.8.2
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2002,2003 OPeNDAP, Inc. 00008 // Author: James Gallagher <jgallagher@opendap.org> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 #ifndef alarm_handler_h 00027 #define alarm_handler_h 00028 00029 #include <cstdio> 00030 00031 #include <string> 00032 00033 #include "EventHandler.h" 00034 00035 namespace libdap 00036 { 00037 00045 class AlarmHandler : public EventHandler 00046 { 00047 private: 00048 //#if FILE_METHODS 00049 FILE *d_file; // Sink for the Error object. 00050 //#endif 00051 ostream &d_stream; 00052 string d_version; 00053 00054 // Ensure that d_stream gets initialized... 00055 AlarmHandler() : 00056 //#if FILE_METHODS 00057 d_file( 0 ), 00058 //#endif 00059 d_stream( cout ) 00060 {} 00061 00062 public: 00065 //#if FILE_METHODS 00066 AlarmHandler(FILE *s) : d_file(s), d_stream( cout ) 00067 {} 00068 //#endif 00069 AlarmHandler(ostream &out) : 00070 //#if FILE_METHODS 00071 d_file(0), 00072 //#endif 00073 d_stream( out ) 00074 {} 00075 00076 virtual ~AlarmHandler() 00077 { 00078 //#if FILE_METHODS 00079 if( d_file ) 00080 fclose( d_file ) ; 00081 //#endif 00082 } 00083 00096 virtual void handle_signal(int signum) 00097 { 00098 if (signum != SIGALRM) 00099 fprintf(stderr, "SIGALRM handler caught another signal!\n"); 00100 #if 0 00101 // Use this code, or a variant, once we have reliable error delivery. 00102 if( d_file ) 00103 fprintf(d_file, "\n\n\n\n"); 00104 else 00105 d_stream << "\n\n\n\n"; 00106 00107 Error e("The server has timed out. This happens when a request\n\ 00108 takes longer to process than the server's preset time-out value.\n\ 00109 Try making a request for a smaller amount of data. You can also contact\n\ 00110 the server's administrator and request that the time-out value be increased."); 00111 00112 if( d_file ) 00113 e.print(d_file); 00114 else 00115 e.print(d_stream); 00116 #endif 00117 exit(1); 00118 } 00119 00120 }; 00121 00122 } // namespace libdap 00123 00124 #endif