Imported Upstream version 3.3.2
[debian/amanda] / perl / Amanda / Debug.swg
1 /*
2  * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 %module "Amanda::Debug"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
24
25 %include "Amanda/Debug.pod"
26
27 %{
28 #include <glib.h>
29 #include "debug.h"
30 %}
31
32 /*
33  * Initialization
34  */
35
36 amglue_export_tag(init,
37     debug_init dbopen dbreopen dbrename dbclose
38     $error_exit_status
39 );
40
41 void    debug_init(void);
42 void    dbopen(char *subdir);
43 void    dbreopen(char *file, char *notation);
44 void    dbrename(char *config, char *subdir);
45 void    dbclose(void);
46
47 int error_exit_status;
48
49 /*
50  * Override die() and warn()
51  */
52 %perlcode %{
53 sub _my_die {
54     # $^S: (from perlvar)
55     #  undef -> parsing module/eval
56     #  1 -> executing an eval
57     #  0 -> otherwise
58     # we *only* want to call critical() in the "otherwise" case
59     if (!defined($^S) or $^S == 1) {
60         die(@_);
61     } else {
62         my ($msg) = @_;
63         chomp $msg;
64         suppress_error_traceback();
65         critical(@_);
66     }
67 };
68 $SIG{__DIE__} = \&_my_die;
69
70 sub _my_warn {
71     my ($msg) = @_;
72     chomp $msg;
73     warning(@_);
74 };
75 $SIG{__WARN__} = \&_my_warn;
76
77 # utility function for test scripts, which want to use the regular
78 # perl mechanisms
79 sub disable_die_override {
80     delete $SIG{__DIE__};
81     delete $SIG{__WARN__};
82 }
83 %}
84
85 /*
86  * Logging
87  */
88
89 %rename(error) error__; /* error() is a macro defined in debug.h .. just avoid that */
90 %inline %{
91 void error__(char *msg) { g_error("%s", msg); }
92 void critical(char *msg) { g_critical("%s", msg); }
93 void warning(char *msg) { g_warning("%s", msg); }
94 void message(char *msg) { g_message("%s", msg); }
95 void info(char *msg) { g_info("%s", msg); }
96 void debug(char *msg) { g_debug("%s", msg); }
97 %}
98
99 amglue_export_tag(logging,
100     error critical warning message info debug
101 );
102
103 void add_amanda_log_handler(amanda_log_handler_t *handler);
104 /* these functions are written as simple global variables, since they are just
105  * function pointers used in add_amanda_log_handler.  Note that the functions
106  * then appear as e.g., $amanda_log_null. */
107 %immutable;
108 amanda_log_handler_t *amanda_log_stderr, *amanda_log_syslog, *amanda_log_null;
109 %mutable;
110
111 amglue_export_tag(logging,
112     add_amanda_log_handler
113     $amanda_log_stderr $amanda_log_syslog $amanda_log_null
114 );
115
116 /* used to suppress the traceback when calling from perl */
117 void suppress_error_traceback(void);
118
119 /*
120  * Advanced
121  */
122
123 int     dbfd(void);
124 char *  dbfn(void);
125 void debug_dup_stderr_to_debug(void);