libdap++ Updated for version 3.8.2

AlarmHandler.h

Go to the documentation of this file.
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 #define FILE_METHODS 1
00036 
00037 namespace libdap
00038 {
00039 
00047 class AlarmHandler : public EventHandler
00048 {
00049 private:
00050 #if FILE_METHODS
00051     FILE *d_file;  // Sink for the Error object.
00052 #endif
00053     ostream &d_stream;
00054     string d_version;
00055 
00056     // Ensure that d_stream gets initialized...
00057     AlarmHandler() :
00058 #if FILE_METHODS
00059         d_file( 0 ),
00060 #endif
00061         d_stream( cout )
00062     {}
00063 
00064 public:
00067 #if FILE_METHODS
00068     AlarmHandler(FILE *s) : d_file(s), d_stream( cout )
00069     {}
00070 #endif
00071     AlarmHandler(ostream &out) :
00072 #if FILE_METHODS
00073         d_file(0),
00074 #endif
00075         d_stream( out )
00076     {}
00077 
00078     virtual ~AlarmHandler()
00079     {
00080 #if FILE_METHODS
00081         if( d_file )
00082             fclose( d_file ) ;
00083 #endif
00084     }
00085 
00098     virtual void handle_signal(int signum)
00099     {
00100         if (signum != SIGALRM)
00101             fprintf(stderr, "SIGALRM handler caught another signal!\n");
00102         exit(1);
00103     }
00104 
00105 };
00106 
00107 } // namespace libdap
00108 
00109 #endif