libdap++  Updated for version 3.8.2
AlarmHandler.h
Go to the documentation of this file.
1 
2 // -*- mode: c++; c-basic-offset:4 -*-
3 
4 // This file is part of libdap, A C++ implementation of the OPeNDAP Data
5 // Access Protocol.
6 
7 // Copyright (c) 2002,2003 OPeNDAP, Inc.
8 // Author: James Gallagher <jgallagher@opendap.org>
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 //
24 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25 
26 #ifndef alarm_handler_h
27 #define alarm_handler_h
28 
29 #include <cstdio>
30 
31 #include <string>
32 
33 #include "EventHandler.h"
34 
35 #define FILE_METHODS 1
36 
37 namespace libdap
38 {
39 
47 class AlarmHandler : public EventHandler
48 {
49 private:
50 #if FILE_METHODS
51  FILE *d_file; // Sink for the Error object.
52 #endif
53  ostream &d_stream;
54  string d_version;
55 
56  // Ensure that d_stream gets initialized...
57  AlarmHandler() :
58 #if FILE_METHODS
59  d_file( 0 ),
60 #endif
61  d_stream( cout )
62  {}
63 
64 public:
65 #if FILE_METHODS
66  AlarmHandler(FILE *s) : d_file(s), d_stream( cout )
67  {}
68 #endif
69 
71  AlarmHandler(ostream &out) :
72 #if FILE_METHODS
73  d_file(0),
74 #endif
75  d_stream( out )
76  {}
77 
78  virtual ~AlarmHandler()
79  {
80 #if FILE_METHODS
81  if( d_file )
82  fclose( d_file ) ;
83 #endif
84  }
85 
98  virtual void handle_signal(int signum)
99  {
100  if (signum != SIGALRM)
101  fprintf(stderr, "SIGALRM handler caught another signal!\n");
102  exit(1);
103  }
104 
105 };
106 
107 } // namespace libdap
108 
109 #endif
virtual ~AlarmHandler()
Definition: AlarmHandler.h:78
AlarmHandler(ostream &out)
Definition: AlarmHandler.h:71
virtual void handle_signal(int signum)
Definition: AlarmHandler.h:98
#define FILE_METHODS
Definition: AlarmHandler.h:35