er_errors.h

Go to the documentation of this file.
00001 #ifndef __er_errors_h__
00002 #define __er_errors_h__
00003 
00004 #include "guilog.h"
00005 #include "ld_log_db.h"
00006 
00007 #include "common/assertions.h"
00008 #include "common/error_list.h"
00009 #include "common/gxerror.h"
00010 #include "common/gxlowmem.h"
00011 #include "common/logging.h"
00012 #include "common/platform_error.h"
00013 
00014 #include <glib.h>
00015 
00016 #include <errno.h>
00017 
00018 #ifdef __cplusplus
00019 extern "C" {
00020 #endif
00021 
00022   // --------------------------------------------------
00023   // generic error reporting
00024   // --------------------------------------------------
00025 
00026 /*
00027  !concept {:name => "Flexible error reporting",
00028    :desc => "A powerful set of functions and macros for handling error reporting for different error (object) types."}
00029 */
00030 
00031   void er_fatal_quiet();
00032 
00033   void er_fatal();
00034 
00035   // The "msg" text should be fairly short.
00036   void er_fatal_msg(const char* msg);
00037 
00038   void er_show_error_msg(const char* text);
00039 
00040 #define er_fatal_general er_fatal_msg("Fatal error (CL2 exited)")
00041 #define er_fatal_oom er_fatal_msg("Out of memory (CL2 exited)")
00042 #define er_fatal_battery_low er_fatal_msg("Battery low (CL2 exited)")
00043 #define er_fatal_disk_low er_fatal_msg("Disk low (CL2 exited)")
00044 #define er_fatal_disk_not_ready er_fatal_msg("Disk not ready (CL2 exited)")
00045 
00046   // Error types. (In order of precedence.)
00047 #define er_NONE    (1<< 0)
00048 #define er_POSIX   (1<< 1)
00049 #define er_SYMBIAN (1<< 2)
00050 #define er_GERROR  (1<< 3)
00051 
00052   // Modifiers.
00053 #define er_FATAL   (1<< 8)
00054 #define er_FREE    (1<< 9)
00055 #define er_NODB    (1<<10)
00056 #define er_OOM     (1<<11)
00057 #define er_QUIET   (1<<12)
00058 
00059   // Do not use directly.
00060   void _er_log_any(int opt, void* errObj, 
00061        const char* func, const char* file, int line, 
00062        const char* user_fmt, ...);
00063   void _er_log_int(int opt, int errObj, 
00064        const char* func, const char* file, int line, 
00065        const char* user_fmt, ...);
00066   void _er_log_gerror(int opt, GError* errObj, 
00067           const char* func, const char* file, int line, 
00068           const char* user_fmt, ...);
00069 
00070 #define er_POSITION __func__, __FILE__, __LINE__
00071 
00072 #define er_log_int_(opt, err, fmt...) \
00073   _er_log_int(opt, err, __func__, __FILE__, __LINE__, fmt)
00074 
00075   // Type unsafe version.
00076 #define er_log_any_(opt, err, fmt...) \
00077   _er_log_any(opt, err, __func__, __FILE__, __LINE__, fmt)
00078 
00079   // Type safe versions.
00080 #define er_log_none(opt, fmt...) \
00081   er_log_any_((opt) | er_NONE, NULL, fmt) 
00082 #define er_log_posix(opt, val, fmt...) \
00083   er_log_int_((opt) | er_POSIX, val, fmt)
00084 #define er_log_errno(opt, fmt...) \
00085   er_log_int_((opt) | er_POSIX, errno, fmt)
00086 #define er_log_symbian(opt, val, fmt...) \
00087   er_log_int_((opt) | er_SYMBIAN, val, fmt)
00088 #define er_log_gerror(opt, val, fmt...) \
00089   _er_log_gerror((opt) | er_GERROR, val, __func__, __FILE__, __LINE__, fmt)
00090 
00091 #define er_log_oom er_log_none(er_OOM, "out of memory error")
00092 
00093 #define er_log_oom_on_false(x) \
00094   if (!(x)) { er_log_oom; }
00095 
00096   // --------------------------------------------------
00097   // status logging to database
00098   // --------------------------------------------------
00099   
00100   void er_log_status_string(const char* s);
00101 
00102   void er_log_status_fmt(const char* fmt, ...);
00103 
00104   // For compatibility with logt and logg macros.
00105 #define dblogt(s) er_log_status_string(s)
00106 #define dblogg(f...) er_log_status_fmt(f)
00107 
00108   // --------------------------------------------------
00109   // GLib extras
00110   // --------------------------------------------------
00111 
00112   // "error" must be non-NULL.
00113   // Caller must free the returned buffer.
00114   // Returns NULL on ENOMEM.
00115   gchar* gx_error_to_string(GError* error);
00116 
00117   // Frees the error.
00118   void gx_error_free(GError* error);
00119 
00120   // Does not free the error.
00121   void gx_txtlog_error(GError* error);
00122 
00123   void gx_txtlog_error_free(GError* error);
00124 
00125   void gx_txtlog_error_clear(GError** error);
00126 
00127   gboolean gx_dblog_error_check(LogDb* logDb, GError* errorToLog, GError** error);
00128 
00129   // Frees any "errorToLog" even if fails.
00130   gboolean gx_dblog_error_free_check(LogDb* logDb, GError* errorToLog, GError** error);
00131 
00132   // Clears any "errorToLog" even if fails.
00133   gboolean gx_dblog_error_clear_check(LogDb* logDb, GError** errorToLog, GError** error);
00134 
00135 #define gx_dblog_error(_db, _err) gx_dblog_error_check(_db, _err, NULL)
00136 #define gx_dblog_error_free(_db, _err) gx_dblog_error_free_check(_db, _err, NULL)
00137 #define gx_dblog_error_clear(_db, _err) gx_dblog_error_clear_check(_db, _err, NULL)
00138 
00139   // Best effort. Invokes EXIT_APPLICATION as the last thing.
00140   void gx_dblog_fatal_error_free(LogDb* logDb, GError* errorToLog);
00141 
00142   // Best effort. Invokes EXIT_APPLICATION as the last thing.
00143   void gx_dblog_fatal_error_clear(LogDb* logDb, GError** errorToLog);
00144 
00145   void gx_propagate_error(GError** dest, GError* src);
00146 
00147   // Invokes EXIT_APPLICATION as the last thing.
00148   void gx_txtlog_fatal_error_free(GError* errorToLog);
00149 
00150   // Invokes EXIT_APPLICATION as the last thing.
00151   void gx_txtlog_fatal_error_clear(GError** errorToLog);
00152 
00153   // --------------------------------------------------
00154   // POSIX extras
00155   // --------------------------------------------------
00156 
00157   void px_dblog_fatal_error(LogDb* logDb, int errCode);
00158 
00159   void px_dblog_fatal_errno(LogDb* logDb);
00160 
00161   void px_txtlog_fatal_error(int errCode);
00162 
00163   void px_txtlog_fatal_errno();
00164 
00165   // --------------------------------------------------
00166   // Symbian extras
00167   // --------------------------------------------------
00168 
00169 #if defined(__SYMBIAN32__)
00170   void ex_fatal_error(int errCode);
00171 
00172   void ex_txtlog_error(int errCode);
00173 
00174   gboolean ex_dblog_error(LogDb* logDb, int errCode, GError** error);
00175 
00176   gboolean ex_dblog_error_msg(LogDb* logDb, const char* msg, int errCode, GError** error);
00177 
00178   void ex_txtlog_fatal_error(int errCode);
00179 
00180   void ex_dblog_fatal_error(LogDb* logDb, int errCode);
00181 
00182   void ex_dblog_fatal_error_msg(LogDb* logDb, const char* msg, int errCode);
00183 
00184   // Displays the specified Symbian error code in a briefly displayed
00185   // global dialog.
00186   void ex_show_error(int errCode);
00187 
00188   void ex_show_nomem_error();
00189 
00190   void ex_show_error_msg(const char* text);
00191 
00192 #endif /* __SYMBIAN32__ */
00193 
00194 #ifdef __cplusplus
00195 } /* extern "C" */
00196 #endif
00197 
00198 #define new_not_found_error \
00199   gx_error_new(domain_cl2app, code_not_found, "not found")
00200 
00201 #define is_not_found_error(_errorptr) \
00202   gx_error_is(_errorptr, domain_cl2app, code_not_found)
00203 
00204 #endif /* __er_errors_h__ */
00205 
00206 /**
00207 
00208 er_errors.h
00209 
00210 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00211 and the authors. All rights reserved.
00212 
00213 Authors: Tero Hasu <tero.hasu@hut.fi>
00214 
00215 Permission is hereby granted, free of charge, to any person
00216 obtaining a copy of this software and associated documentation files
00217 (the "Software"), to deal in the Software without restriction,
00218 including without limitation the rights to use, copy, modify, merge,
00219 publish, distribute, sublicense, and/or sell copies of the Software,
00220 and to permit persons to whom the Software is furnished to do so,
00221 subject to the following conditions:
00222 
00223 The above copyright notice and this permission notice shall be
00224 included in all copies or substantial portions of the Software.
00225 
00226 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00227 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00228 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00229 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00230 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00231 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00232 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00233 SOFTWARE.
00234 
00235  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1