~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to connect/ncbi_core_cxx.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  $Id: ncbi_core_cxx.cpp,v 6.6 2001/03/02 20:08:17 lavr Exp $
2
 
 * ===========================================================================
3
 
 *
4
 
 *                            PUBLIC DOMAIN NOTICE
5
 
 *               National Center for Biotechnology Information
6
 
 *
7
 
 *  This software/database is a "United States Government Work" under the
8
 
 *  terms of the United States Copyright Act.  It was written as part of
9
 
 *  the author's official duties as a United States Government employee and
10
 
 *  thus cannot be copyrighted.  This software/database is freely available
11
 
 *  to the public for use. The National Library of Medicine and the U.S.
12
 
 *  Government have not placed any restriction on its use or reproduction.
13
 
 *
14
 
 *  Although all reasonable efforts have been taken to ensure the accuracy
15
 
 *  and reliability of the software and data, the NLM and the U.S.
16
 
 *  Government do not and cannot warrant the performance or results that
17
 
 *  may be obtained by using this software or data. The NLM and the U.S.
18
 
 *  Government disclaim all warranties, express or implied, including
19
 
 *  warranties of performance, merchantability or fitness for any particular
20
 
 *  purpose.
21
 
 *
22
 
 *  Please cite the author in any work or product based on this material.
23
 
 *
24
 
 * ===========================================================================
25
 
 *
26
 
 * Author:  Anton Lavrentiev
27
 
 *
28
 
 * File description:
29
 
 *   C++->C conversion functions for basic corelib stuff:
30
 
 *     Registry
31
 
 *     Logging
32
 
 *     Locking
33
 
 *
34
 
 * ---------------------------------------------------------------------------
35
 
 * $Log: ncbi_core_cxx.cpp,v $
36
 
 * Revision 6.6  2001/03/02 20:08:17  lavr
37
 
 * Typos fixed
38
 
 *
39
 
 * Revision 6.5  2001/01/25 17:03:46  lavr
40
 
 * s_LOG_Handler: user_data commented out as unused
41
 
 *
42
 
 * Revision 6.4  2001/01/23 23:08:06  lavr
43
 
 * LOG_cxx2c introduced
44
 
 *
45
 
 * Revision 6.3  2001/01/12 05:48:50  vakatov
46
 
 * Use reinterpret_cast<> rather than static_cast<> to cast functions.
47
 
 * Added more paranoia to catch ALL possible exceptions in the s_*** functions.
48
 
 *
49
 
 * Revision 6.2  2001/01/11 23:51:47  lavr
50
 
 * static_cast instead of linkage specification 'extern "C" {}'.
51
 
 * Reason: MSVC++ doesn't allow C-linkage of the funs compiled in C++ file.
52
 
 *
53
 
 * Revision 6.1  2001/01/11 23:08:16  lavr
54
 
 * Initial revision
55
 
 *
56
 
 * ===========================================================================
57
 
 */
58
 
 
59
 
#include <connect/ncbi_core_cxx.hpp>
60
 
#include <corelib/ncbistr.hpp>
61
 
#include <string.h>
62
 
 
63
 
 
64
 
BEGIN_NCBI_SCOPE
65
 
 
66
 
 
67
 
static void s_REG_Get(void* user_data,
68
 
                      const char* section, const char* name,
69
 
                      char* value, size_t value_size)
70
 
{
71
 
    try {
72
 
        string result = static_cast<CNcbiRegistry*> (user_data)->
73
 
            Get(section, name);
74
 
 
75
 
        if ( !result.empty() ) {
76
 
            strncpy(value, result.c_str(), value_size - 1);
77
 
            value[value_size - 1] = '\0';
78
 
        }
79
 
    }
80
 
    STD_CATCH_ALL("s_REG_Get() failed");
81
 
}
82
 
 
83
 
 
84
 
static void s_REG_Set(void* user_data,
85
 
                      const char* section, const char* name,
86
 
                      const char* value, EREG_Storage storage)
87
 
{
88
 
    try {
89
 
        static_cast<CNcbiRegistry*> (user_data)->
90
 
            Set(section, name, value,
91
 
                (storage == eREG_Persistent ? CNcbiRegistry::ePersistent : 0) |
92
 
                CNcbiRegistry::eOverride | CNcbiRegistry::eTruncate);
93
 
    }
94
 
    STD_CATCH_ALL("s_REG_Set() failed");
95
 
}
96
 
 
97
 
 
98
 
static void s_REG_Cleanup(void* user_data)
99
 
{
100
 
    try {
101
 
        delete static_cast<CNcbiRegistry*> (user_data);
102
 
    }
103
 
    STD_CATCH_ALL("s_REG_Cleanup() failed");
104
 
}
105
 
 
106
 
 
107
 
extern REG REG_cxx2c(CNcbiRegistry* reg, bool pass_ownership)
108
 
{
109
 
    return REG_Create
110
 
        (static_cast<void*> (reg),
111
 
         reinterpret_cast<FREG_Get> (s_REG_Get),
112
 
         reinterpret_cast<FREG_Set> (s_REG_Set),
113
 
         pass_ownership ? reinterpret_cast<FREG_Cleanup> (s_REG_Cleanup) : 0,
114
 
         0);
115
 
}
116
 
 
117
 
 
118
 
static void s_LOG_Handler(void* /*user_data*/, SLOG_Handler* call_data)
119
 
{
120
 
    EDiagSev level;
121
 
    switch (call_data->level) {
122
 
    case eLOG_Trace:
123
 
        level = eDiag_Trace;
124
 
        break;
125
 
    case eLOG_Note:
126
 
        level = eDiag_Info;
127
 
        break;
128
 
    case eLOG_Warning:
129
 
        level = eDiag_Warning;
130
 
        break;
131
 
    case eLOG_Error:
132
 
        level = eDiag_Error;
133
 
        break;
134
 
    case eLOG_Critical:
135
 
        level = eDiag_Critical;
136
 
        break;
137
 
    case eLOG_Fatal:
138
 
        /*fallthru*/
139
 
    default:
140
 
        level = eDiag_Fatal;
141
 
        break;
142
 
    }
143
 
    CNcbiDiag diag(level, eDPF_Default);
144
 
    if (call_data->file)
145
 
        diag.SetFile(call_data->file);
146
 
    if (call_data->line)
147
 
        diag.SetLine(call_data->line);
148
 
    diag << call_data->message;
149
 
    if (call_data->raw_data && call_data->raw_size) {
150
 
        diag <<
151
 
            "\n#################### [BEGIN] Raw Data (" <<
152
 
            call_data->raw_size <<
153
 
            " byte" << (call_data->raw_size != 1 ? "s" : "") << ")\n" <<
154
 
            NStr::PrintableString
155
 
            (string(static_cast<const char*>(call_data->raw_data),
156
 
                    call_data->raw_size)) <<
157
 
            "\n#################### [END] Raw Data";
158
 
    }
159
 
}
160
 
 
161
 
 
162
 
extern LOG LOG_cxx2c(void)
163
 
{
164
 
    return LOG_Create(0,
165
 
                      reinterpret_cast<FLOG_Handler> (s_LOG_Handler),
166
 
                      0,
167
 
                      0);
168
 
}
169
 
 
170
 
 
171
 
END_NCBI_SCOPE