midgard_error

midgard_error

Synopsis

#include <midgard/midgard.h>

#define             MIDGARD_GENERIC_ERROR
GQuark              midgard_error_generic               (void);
const gchar *       midgard_error_string                (GQuark domain,
                                                         gint errcode);
void                midgard_set_error                   (MidgardConnection *mgd,
                                                         GQuark domain,
                                                         gint errcode,
                                                         const gchar *msg,
                                                         ...);
void                midgard_error_default_log           (const gchar *domain,
                                                         GLogLevelFlags level,
                                                         const gchar *msg,
                                                         gpointer ptr);
gint                midgard_error_parse_loglevel        (const gchar *levelstring);
#define             MIDGARD_ERRNO_SET                   (str,
                                                         errcode)

Description

Details

MIDGARD_GENERIC_ERROR

#define MIDGARD_GENERIC_ERROR midgard_error_generic()


midgard_error_generic ()

GQuark              midgard_error_generic               (void);

GQuark for Midgard Error. It's used by Midgard Error implementation, and probably not needed to use by any application.

Returns :

MGD_GENERIC_ERROR GQuark

midgard_error_string ()

const gchar *       midgard_error_string                (GQuark domain,
                                                         gint errcode);

Get error message for the given error code.

domain :

GQuark which represents MidgardError domain.

errcode :

MidgardErrorGeneric enum value.

Returns :

error messages which is owned by midgard-core and should not be freed.

midgard_set_error ()

void                midgard_set_error                   (MidgardConnection *mgd,
                                                         GQuark domain,
                                                         gint errcode,
                                                         const gchar *msg,
                                                         ...);

This function sets internal error constant, and creates new error message. User defined message is appended to internal one. Any message created by application ( and its corresponding constant ) are destroyed and reset to MGD_ERR_OK when any API function is invoked. Second domain parameter is optional , and can be safely defined as NULL for MGD_GENERIC_ERROR domain.

Example 5. 


void set_wrong_property(MidgardConnection *mgd, gchar *prop)
{
	midgard_set_error(mgd, NULL, 
			MGD_ERR_INVALID_PROPERTY_VALUE,
			"My application doesn't accept %s property",
			prop);
}


mgd :

MidgardConnection instance

domain :

GQuark which represents MidgardError domain

errcode :

MidgardErrorGeneric enum value

msg :

a message which should be appended to string represented by errcode

... :

message argument list ( if required )

midgard_error_default_log ()

void                midgard_error_default_log           (const gchar *domain,
                                                         GLogLevelFlags level,
                                                         const gchar *msg,
                                                         gpointer ptr);

ptr pointer may be a pointer to MidgardConnection or MidgardTypeHolder structure. This function checks pointer type using MIDGARD_IS_CONNECTION convention macro. Next midgard_connection_get_loglevel is called to get loglevel. If MidgardConnection check fails , a typecast to MidgardTypeHolder is made. In this case, level member is used to get loglevel.

You are responsible to correctly set MidgardConnection or MidgardTypeHolder before passing ptr argument. The main approach is to follow configuration's loglevel even if MidgardConnection pointer is not yet available.

see midgard_connection_set_loglevel() to set log level.

domain :

domain for the given log message

level :

GLogLevelFlags

msg :

log message

ptr :

pointer to structure which holds loglevel

midgard_error_parse_loglevel ()

gint                midgard_error_parse_loglevel        (const gchar *levelstring);

This function returns level registered in GLib.

levelstring :

string which should be parsed

Returns :

GLogLevelFlags or -1 on failure

MIDGARD_ERRNO_SET()

#define             MIDGARD_ERRNO_SET(str, errcode)