casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Diagnostic.h
Go to the documentation of this file.
1 //# Diagnostic.h: debugging diagnostic for dbus clents
2 //# Copyright (C) 2012
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_DBUS_DIAGNOSTIC_H_
29 #define CASA_DBUS_DIAGNOSTIC_H_
30 #include <string>
31 #include <stdarg.h>
32 
33 namespace casa {
34  namespace dbus {
35 
36  class Diagnostic {
37  public:
39  void argv( int argc_, const char *argv_[] ) {
40  kernel_t &k = lock_kernel( );
41  if ( k.do_log( ) ) k.argv(argc_,argv_);
42  release_kernel( );
43  }
44  void argv( int argc_, char *argv_[] ) {
45  kernel_t &k = lock_kernel( );
46  if ( k.do_log( ) ) k.argv(argc_,argv_);
47  release_kernel( );
48  }
49  Diagnostic( ) { }
50  virtual ~Diagnostic( ) { }
51 
52  void error(const char *fmt, ...) {
53  kernel_t &k = lock_kernel( );
54  if ( k.do_log( ) ) {
55  va_list argp;
56  va_start(argp, fmt);
57  verror(k, fmt, argp);
58  va_end(argp);
59  }
60  }
61 
62  void info(const char *fmt, ...) {
63  kernel_t &k = lock_kernel( );
64  if ( k.do_log( ) ) {
65  va_list argp;
66  va_start(argp, fmt);
67  vinfo(k, fmt, argp);
68  va_end(argp);
69  }
70  }
71 
72  private:
73 
74  struct kernel_t {
75  kernel_t( );
76  kernel_t( FILE *f );
77  bool do_log( ) const { return fptr != 0; }
78  ~kernel_t( ) { if ( fptr ) fclose(fptr); }
79  void argv( int argc_, const char *argv_[] );
80  void argv( int argc_, char *argv_[] );
81  FILE *fptr;
82  pid_t pid;
83  std::string name; /**** any non-argv messages should include 'name' ****/
84  };
85 
86  /* void verror(Diagnostic::kernel_t &, const char *fmt, va_list argp); */
87  /* void vinfo(Diagnostic::kernel_t &, const char *fmt, va_list argp); */
88  void verror(kernel_t &, const char *fmt, va_list argp);
89  void vinfo(kernel_t &, const char *fmt, va_list argp);
90 
92  void release_kernel( ) { }
93  void output_prologue( );
94  void output_epilogue( );
95  };
96 
97  extern Diagnostic diagnostic;
98 
99  static class init_diagnostic_object_t {
100  public:
103  private:
104  static unsigned long count;
106  }
107 }
108 
109 #endif
void verror(kernel_t &, const char *fmt, va_list argp)
void vinfo(kernel_t &, const char *fmt, va_list argp)
Diagnostic diagnostic
static class casa::dbus::init_diagnostic_object_t init_diagnostic_object_
void argv(int argc_, const char *argv_[])
void info(const char *fmt,...)
Definition: Diagnostic.h:62
void argv(int argc_, char *argv_[])
Definition: Diagnostic.h:44
void argv(int argc_, const char *argv_[])
Definition: Diagnostic.h:39
void error(const char *fmt,...)
Definition: Diagnostic.h:52
kernel_t & lock_kernel()