midgard_error

midgard_error

Synopsis

#include <midgard/midgard.h>

#define             MIDGARD_GENERIC_ERROR
enum                MidgardGenericError;
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()


enum MidgardGenericError

typedef enum {
	MIDGARD_GENERIC_ERROR_OK = -0, /**< MD_ERR_OK  <br /> */ 
	MIDGARD_GENERIC_ERROR_ERROR = -1, /**<  <br />*/ 
	MIDGARD_GENERIC_ERROR_ACCESS_DENIED = -2, /**< Access denied *  <br /> */
	MIDGARD_GENERIC_ERROR_NO_METADATA = -3,
	MIDGARD_GENERIC_ERROR_NOT_OBJECT = -4, /**< Not Midgard Object   <br /> */
	MIDGARD_GENERIC_ERROR_NOT_EXISTS = -5, /**< Object does not exist   <br /> */
	MIDGARD_GENERIC_ERROR_INVALID_NAME = -6 , /**<   <br /> */
	MIDGARD_GENERIC_ERROR_DUPLICATE = -7 , /**< Object already exist   <br /> */
	MIDGARD_GENERIC_ERROR_HAS_DEPENDANTS = -8 , /**< Object has dependants   <br /> */
	MIDGARD_GENERIC_ERROR_RANGE = -9, /**<   <br /> */
	MIDGARD_GENERIC_ERROR_NOT_CONNECTED = -10, /**< Not connected to the Midgard database   <br /> */
	MIDGARD_GENERIC_ERROR_SG_NOTFOUND = -11, /**< Sitegroup not found   <br /> */
	MIDGARD_GENERIC_ERROR_INVALID_OBJECT = -12, /**< Object not registered as Midgard Object   <br /> */ 
	MIDGARD_GENERIC_ERROR_QUOTA = -13, /**< Quota limit reached   <br /> */
	MIDGARD_GENERIC_ERROR_INTERNAL = -14, /**< Critical internal error   <br /> */
	MIDGARD_GENERIC_ERROR_OBJECT_NAME_EXISTS = -15, /**< Object with such name exists in tree   <br /> */
	MIDGARD_GENERIC_ERROR_OBJECT_NO_STORAGE = -16, /**< Storage table not defined for object   <br /> */
	MIDGARD_GENERIC_ERROR_OBJECT_NO_PARENT= -17, /**< Parent object in tree not defined   <br /> */
	MIDGARD_GENERIC_ERROR_INVALID_PROPERTY_VALUE = -18, /**< Invalid property value   <br /> */
	MIDGARD_GENERIC_ERROR_INVALID_PROPERTY = -19, /**<Invalid property <br />*/
	MIDGARD_GENERIC_ERROR_USER_DATA = -20, /**< Empty error message reserved for application's developers   <br /> */
	MIDGARD_GENERIC_ERROR_OBJECT_DELETED = -21, /**< Object deleted   <br /> */
	MIDGARD_GENERIC_ERROR_OBJECT_PURGED = -22, /**< Object purged   <br /> */
	MIDGARD_GENERIC_ERROR_OBJECT_EXPORTED = -23, /**< Object already exported   <br /> */
	MIDGARD_GENERIC_ERROR_OBJECT_IMPORTED = -24, /**< Object already imported   <br /> */
	MIDGARD_GENERIC_ERROR_MISSED_DEPENDENCE = -25, /**< Missed dependence for object   <br /> */
	MIDGARD_GENERIC_ERROR_TREE_IS_CIRCULAR = -26, /**< Circular reference found in object's tree <br />*/
	MIDGARD_GENERIC_ERROR_OBJECT_IS_LOCKED = -27 /**< Object is locked */
} MidgardGenericError;


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)