libdap  Updated for version 3.17.0
AlarmHandler.h
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  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     FILE *d_file;  // Sink for the Error object.
00049     string d_version;
00050 
00051 public:
00052     // Ensure that d_stream gets initialized...
00053     AlarmHandler() : d_file( 0 )// , d_stream( cout )
00054     {}
00055 
00056     AlarmHandler(FILE *s) : d_file(s)//, d_stream( cout )
00057     {}
00058 
00062     AlarmHandler(ostream &) : d_file(0)//, d_stream( out )
00063     {}
00064 
00065     virtual ~AlarmHandler()
00066     {
00067         if( d_file )
00068             fclose( d_file ) ;
00069     }
00070 
00082     virtual void handle_signal(int signum)
00083     {
00084         if (signum != SIGALRM)
00085             throw Error("SIGALRM handler caught another signal!");
00086 
00087         throw Error("Timeout");
00088     }
00089 
00090 };
00091 
00092 } // namespace libdap
00093 
00094 #endif