Update package version to 9.0.13
[platform/core/uifw/isf.git] / ism / src / scim_debug.cpp
1 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
2
3 /*
4  * Smart Common Input Method
5  *
6  * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
7  *
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this program; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  * Boston, MA  02111-1307  USA
23  *
24  * $Id: scim_debug.cpp,v 1.10 2005/08/05 01:54:24 suzhe Exp $
25  *
26  */
27
28 #define Uses_SCIM_DEBUG
29 #include "scim_private.h"
30 #include "scim.h"
31 #include <cstdio>
32
33 namespace scim {
34
35 struct _DebugMaskName
36 {
37     uint32      mask;
38     const char *name;
39 };
40
41 static _DebugMaskName _debug_mask_names [] =
42 {
43     {SCIM_DEBUG_AllMask,        "all"},
44     {SCIM_DEBUG_MainMask,       "main"},
45     {SCIM_DEBUG_ConfigMask,     "config"},
46     {SCIM_DEBUG_IMEngineMask,   "imengine"},
47     {SCIM_DEBUG_BackEndMask,    "backend"},
48     {SCIM_DEBUG_FrontEndMask,   "frontend"},
49     {SCIM_DEBUG_ModuleMask,     "module"},
50     {SCIM_DEBUG_UtilityMask,    "utility"},
51     {SCIM_DEBUG_IConvMask,      "iconv"},
52     {SCIM_DEBUG_LookupTableMask,"lookuptable"},
53     {SCIM_DEBUG_SocketMask,     "socket"},
54     {0, 0}
55 };
56
57 uint32         DebugOutput::current_verbose = 0;
58 uint32         DebugOutput::current_mask = 0;
59 uint32         DebugOutput::verbose_level = 0;
60 uint32         DebugOutput::output_mask = ~0;
61 std::ostream * DebugOutput::output_stream = &std::cerr;
62
63 static std::ofstream __debug_output_file;
64
65 #if ENABLE_DEBUG
66 DebugOutput::DebugOutput (uint32 mask, uint32 verbose)
67 {
68     current_mask    = mask;
69     current_verbose = verbose;
70 }
71 #else
72 DebugOutput::DebugOutput (uint32 mask, uint32 verbose)
73 {
74 }
75 #endif
76
77 void
78 DebugOutput::set_verbose_level (uint32 verbose)
79 {
80     verbose_level =
81         (verbose > SCIM_DEBUG_MAX_VERBOSE) ? SCIM_DEBUG_MAX_VERBOSE : verbose;
82 }
83
84 void
85 DebugOutput::enable_debug (uint32 debug)
86 {
87     output_mask |= debug;
88 }
89
90 void
91 DebugOutput::enable_debug_by_name (const String &debug)
92 {
93     _DebugMaskName *p = _debug_mask_names;
94     while (p->mask && p->name) {
95         if (String (p->name) == debug) {
96             output_mask |= p->mask;
97             return;
98         }
99         ++ p;
100     }
101 }
102
103 void
104 DebugOutput::disable_debug (uint32 debug)
105 {
106     output_mask &= (~debug);
107 }
108
109 void
110 DebugOutput::disable_debug_by_name (const String &debug)
111 {
112     _DebugMaskName *p = _debug_mask_names;
113     while (p->mask && p->name) {
114         if (String (p->name) == debug) {
115             output_mask &= (~(p->mask));
116             return;
117         }
118         ++ p;
119     }
120 }
121
122 void
123 DebugOutput::set_output (const String &file)
124 {
125     DebugOutput::output_stream = &std::cerr;
126
127     if (file.length ()) {
128         if (file == String ("stderr") || file == String ("cerr"))
129             DebugOutput::output_stream = &std::cerr;
130         else if (file == String ("stdout") || file == String ("cout"))
131             DebugOutput::output_stream = &std::cout;
132         else if (file == String ("none") || file == String ("off"))
133             DebugOutput::output_stream = 0;
134         else {
135             __debug_output_file.open (file.c_str ());
136             if (__debug_output_file.is_open ())
137                 DebugOutput::output_stream = &__debug_output_file;
138         }
139     }
140 }
141
142 String
143 DebugOutput::serial_number ()
144 {
145     static unsigned int serial = 0;
146     char buf [64] = {0};
147     snprintf (buf, 63, "<%08u>:", serial ++);
148     return String (buf);
149 }
150
151 } // namespace scim
152
153 /*
154 vi:ts=4:nowrap:ai:expandtab
155 */