XMMS2
src/include/xmms/xmms_error.h
Go to the documentation of this file.
00001 /*  XMMS2 - X Music Multiplexer System
00002  *  Copyright (C) 2003-2011 XMMS2 Team
00003  *
00004  *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  */
00016 
00017 
00018 
00019 
00020 #ifndef __XMMS_ERROR_H__
00021 #define __XMMS_ERROR_H__
00022 
00023 #include <glib.h>
00024 #include "xmmsc/xmmsc_errorcodes.h"
00025 
00026 #define XMMS_ERROR_MESSAGE_MAXLEN 255
00027 
00028 G_BEGIN_DECLS
00029 
00030 typedef struct xmms_error_St {
00031     xmms_error_code_t code;
00032     gchar message[XMMS_ERROR_MESSAGE_MAXLEN + 1];
00033 } xmms_error_t;
00034 
00035 static inline void
00036 xmms_error_set (xmms_error_t *err, xmms_error_code_t code, const gchar *message)
00037 {
00038     g_return_if_fail (err);
00039 
00040     err->code = code;
00041     if (message) {
00042         g_strlcpy (err->message, message, XMMS_ERROR_MESSAGE_MAXLEN);
00043     } else {
00044         err->message[0] = 0;
00045     }
00046 }
00047 
00048 static inline void
00049 xmms_error_reset (xmms_error_t *err)
00050 {
00051     g_return_if_fail (err);
00052 
00053     err->code = XMMS_ERROR_NONE;
00054     err->message[0] = 0;
00055 }
00056 
00057 #define xmms_error_iserror(e) ((e)->code != XMMS_ERROR_NONE)
00058 #define xmms_error_isok(e) ((e)->code == XMMS_ERROR_NONE)
00059 
00060 #define xmms_error_type_get(e) ((e)->code)
00061 
00062 const gchar *xmms_error_message_get (xmms_error_t *err);
00063 
00064 G_END_DECLS
00065 
00066 #endif