Rename libdax_* message system to libiso_*

This commit is contained in:
Vreixo Formoso Lopes 2007-09-24 11:53:22 +00:00
parent 9639d45b35
commit 0071d733fd
5 changed files with 196 additions and 182 deletions

View File

@ -1,6 +1,6 @@
/* libdax_msgs
Message handling facility of libdax.
/* libiso_msgs
Message handling facility of libiso.
Copyright (C) 2006 Thomas Schmitt <scdbackup@gmx.net>, provided under GPL
*/
@ -13,25 +13,25 @@
#include <sys/time.h>
/* Only this single source module is entitled to do this */
#define LIBDAX_MSGS_H_INTERNAL 1
#define LIBISO_MSGS_H_INTERNAL 1
/* All participants in the messaging system must do this */
#include "libdax_msgs.h"
#include "libiso_msgs.h"
/* ----------------------------- libdax_msgs_item ------------------------- */
/* ----------------------------- libiso_msgs_item ------------------------- */
static int libdax_msgs_item_new(struct libdax_msgs_item **item,
struct libdax_msgs_item *link, int flag)
static int libiso_msgs_item_new(struct libiso_msgs_item **item,
struct libiso_msgs_item *link, int flag)
{
int ret;
struct libdax_msgs_item *o;
struct libiso_msgs_item *o;
struct timeval tv;
struct timezone tz;
(*item)= o=
(struct libdax_msgs_item *) malloc(sizeof(struct libdax_msgs_item));
(struct libiso_msgs_item *) malloc(sizeof(struct libiso_msgs_item));
if(o==NULL)
return(-1);
o->timestamp= 0.0;
@ -40,8 +40,8 @@ static int libdax_msgs_item_new(struct libdax_msgs_item **item,
o->timestamp= tv.tv_sec+0.000001*tv.tv_usec;
o->process_id= getpid();
o->driveno= -1;
o->severity= LIBDAX_MSGS_SEV_ALL;
o->priority= LIBDAX_MSGS_PRIO_ZERO;
o->severity= LIBISO_MSGS_SEV_ALL;
o->priority= LIBISO_MSGS_PRIO_ZERO;
o->error_code= 0;
o->msg_text= NULL;
o->os_errno= 0;
@ -60,9 +60,9 @@ static int libdax_msgs_item_new(struct libdax_msgs_item **item,
/** Detaches item from its queue and eventually readjusts start, end pointers
of the queue */
int libdax_msgs_item_unlink(struct libdax_msgs_item *o,
struct libdax_msgs_item **chain_start,
struct libdax_msgs_item **chain_end, int flag)
int libiso_msgs_item_unlink(struct libiso_msgs_item *o,
struct libiso_msgs_item **chain_start,
struct libiso_msgs_item **chain_end, int flag)
{
if(o->prev!=NULL)
o->prev->next= o->next;
@ -79,15 +79,15 @@ int libdax_msgs_item_unlink(struct libdax_msgs_item *o,
}
int libdax_msgs_item_destroy(struct libdax_msgs_item **item,
int libiso_msgs_item_destroy(struct libiso_msgs_item **item,
int flag)
{
struct libdax_msgs_item *o;
struct libiso_msgs_item *o;
o= *item;
if(o==NULL)
return(0);
libdax_msgs_item_unlink(o,NULL,NULL,0);
libiso_msgs_item_unlink(o,NULL,NULL,0);
if(o->msg_text!=NULL)
free((char *) o->msg_text);
free((char *) o);
@ -96,7 +96,7 @@ int libdax_msgs_item_destroy(struct libdax_msgs_item **item,
}
int libdax_msgs_item_get_msg(struct libdax_msgs_item *item,
int libiso_msgs_item_get_msg(struct libiso_msgs_item *item,
int *error_code, char **msg_text, int *os_errno,
int flag)
{
@ -107,7 +107,7 @@ int libdax_msgs_item_get_msg(struct libdax_msgs_item *item,
}
int libdax_msgs_item_get_origin(struct libdax_msgs_item *item,
int libiso_msgs_item_get_origin(struct libiso_msgs_item *item,
double *timestamp, pid_t *process_id, int *driveno,
int flag)
{
@ -118,7 +118,7 @@ int libdax_msgs_item_get_origin(struct libdax_msgs_item *item,
}
int libdax_msgs_item_get_rank(struct libdax_msgs_item *item,
int libiso_msgs_item_get_rank(struct libiso_msgs_item *item,
int *severity, int *priority, int flag)
{
*severity= item->severity;
@ -127,24 +127,24 @@ int libdax_msgs_item_get_rank(struct libdax_msgs_item *item,
}
/* ------------------------------- libdax_msgs ---------------------------- */
/* ------------------------------- libiso_msgs ---------------------------- */
int libdax_msgs_new(struct libdax_msgs **m, int flag)
int libiso_msgs_new(struct libiso_msgs **m, int flag)
{
struct libdax_msgs *o;
struct libiso_msgs *o;
(*m)= o= (struct libdax_msgs *) malloc(sizeof(struct libdax_msgs));
(*m)= o= (struct libiso_msgs *) malloc(sizeof(struct libiso_msgs));
if(o==NULL)
return(-1);
o->oldest= NULL;
o->youngest= NULL;
o->count= 0;
o->queue_severity= LIBDAX_MSGS_SEV_ALL;
o->print_severity= LIBDAX_MSGS_SEV_NEVER;
strcpy(o->print_id,"libdax: ");
o->queue_severity= LIBISO_MSGS_SEV_ALL;
o->print_severity= LIBISO_MSGS_SEV_NEVER;
strcpy(o->print_id,"libiso: ");
#ifndef LIBDAX_MSGS_SINGLE_THREADED
#ifndef LIBISO_MSGS_SINGLE_THREADED
pthread_mutex_init(&(o->lock_mutex),NULL);
#endif
@ -152,16 +152,16 @@ int libdax_msgs_new(struct libdax_msgs **m, int flag)
}
int libdax_msgs_destroy(struct libdax_msgs **m, int flag)
int libiso_msgs_destroy(struct libiso_msgs **m, int flag)
{
struct libdax_msgs *o;
struct libdax_msgs_item *item, *next_item;
struct libiso_msgs *o;
struct libiso_msgs_item *item, *next_item;
o= *m;
if(o==NULL)
return(0);
#ifndef LIBDAX_MSGS_SINGLE_THREADED
#ifndef LIBISO_MSGS_SINGLE_THREADED
if(pthread_mutex_destroy(&(o->lock_mutex))!=0) {
pthread_mutex_unlock(&(o->lock_mutex));
pthread_mutex_destroy(&(o->lock_mutex));
@ -170,7 +170,7 @@ int libdax_msgs_destroy(struct libdax_msgs **m, int flag)
for(item= o->oldest; item!=NULL; item= next_item) {
next_item= item->next;
libdax_msgs_item_destroy(&item,0);
libiso_msgs_item_destroy(&item,0);
}
free((char *) o);
*m= NULL;
@ -178,7 +178,7 @@ int libdax_msgs_destroy(struct libdax_msgs **m, int flag)
}
int libdax_msgs_set_severities(struct libdax_msgs *m, int queue_severity,
int libiso_msgs_set_severities(struct libiso_msgs *m, int queue_severity,
int print_severity, char *print_id, int flag)
{
m->queue_severity= queue_severity;
@ -189,10 +189,10 @@ int libdax_msgs_set_severities(struct libdax_msgs *m, int queue_severity,
}
static int libdax_msgs_lock(struct libdax_msgs *m, int flag)
static int libiso_msgs_lock(struct libiso_msgs *m, int flag)
{
#ifndef LIBDAX_MSGS_SINGLE_THREADED
#ifndef LIBISO_MSGS_SINGLE_THREADED
int ret;
ret= pthread_mutex_lock(&(m->lock_mutex));
@ -204,10 +204,10 @@ static int libdax_msgs_lock(struct libdax_msgs *m, int flag)
}
static int libdax_msgs_unlock(struct libdax_msgs *m, int flag)
static int libiso_msgs_unlock(struct libiso_msgs *m, int flag)
{
#ifndef LIBDAX_MSGS_SINGLE_THREADED
#ifndef LIBISO_MSGS_SINGLE_THREADED
int ret;
ret= pthread_mutex_unlock(&(m->lock_mutex));
@ -219,38 +219,38 @@ static int libdax_msgs_unlock(struct libdax_msgs *m, int flag)
}
int libdax_msgs__text_to_sev(char *severity_name, int *severity,
int libiso_msgs__text_to_sev(char *severity_name, int *severity,
int flag)
{
if(strncmp(severity_name,"NEVER",5)==0)
*severity= LIBDAX_MSGS_SEV_NEVER;
*severity= LIBISO_MSGS_SEV_NEVER;
else if(strncmp(severity_name,"ABORT",5)==0)
*severity= LIBDAX_MSGS_SEV_ABORT;
*severity= LIBISO_MSGS_SEV_ABORT;
else if(strncmp(severity_name,"FATAL",5)==0)
*severity= LIBDAX_MSGS_SEV_FATAL;
*severity= LIBISO_MSGS_SEV_FATAL;
else if(strncmp(severity_name,"SORRY",5)==0)
*severity= LIBDAX_MSGS_SEV_SORRY;
*severity= LIBISO_MSGS_SEV_SORRY;
else if(strncmp(severity_name,"WARNING",7)==0)
*severity= LIBDAX_MSGS_SEV_WARNING;
*severity= LIBISO_MSGS_SEV_WARNING;
else if(strncmp(severity_name,"HINT",4)==0)
*severity= LIBDAX_MSGS_SEV_HINT;
*severity= LIBISO_MSGS_SEV_HINT;
else if(strncmp(severity_name,"NOTE",4)==0)
*severity= LIBDAX_MSGS_SEV_NOTE;
*severity= LIBISO_MSGS_SEV_NOTE;
else if(strncmp(severity_name,"UPDATE",6)==0)
*severity= LIBDAX_MSGS_SEV_UPDATE;
*severity= LIBISO_MSGS_SEV_UPDATE;
else if(strncmp(severity_name,"DEBUG",5)==0)
*severity= LIBDAX_MSGS_SEV_DEBUG;
*severity= LIBISO_MSGS_SEV_DEBUG;
else if(strncmp(severity_name,"ALL",3)==0)
*severity= LIBDAX_MSGS_SEV_ALL;
*severity= LIBISO_MSGS_SEV_ALL;
else {
*severity= LIBDAX_MSGS_SEV_NEVER;
*severity= LIBISO_MSGS_SEV_NEVER;
return(0);
}
return(1);
}
int libdax_msgs__sev_to_text(int severity, char **severity_name,
int libiso_msgs__sev_to_text(int severity, char **severity_name,
int flag)
{
if(flag&1) {
@ -259,25 +259,25 @@ int libdax_msgs__sev_to_text(int severity, char **severity_name,
return(1);
}
*severity_name= "";
if(severity>=LIBDAX_MSGS_SEV_NEVER)
if(severity>=LIBISO_MSGS_SEV_NEVER)
*severity_name= "NEVER";
else if(severity>=LIBDAX_MSGS_SEV_ABORT)
else if(severity>=LIBISO_MSGS_SEV_ABORT)
*severity_name= "ABORT";
else if(severity>=LIBDAX_MSGS_SEV_FATAL)
else if(severity>=LIBISO_MSGS_SEV_FATAL)
*severity_name= "FATAL";
else if(severity>=LIBDAX_MSGS_SEV_SORRY)
else if(severity>=LIBISO_MSGS_SEV_SORRY)
*severity_name= "SORRY";
else if(severity>=LIBDAX_MSGS_SEV_WARNING)
else if(severity>=LIBISO_MSGS_SEV_WARNING)
*severity_name= "WARNING";
else if(severity>=LIBDAX_MSGS_SEV_HINT)
else if(severity>=LIBISO_MSGS_SEV_HINT)
*severity_name= "HINT";
else if(severity>=LIBDAX_MSGS_SEV_NOTE)
else if(severity>=LIBISO_MSGS_SEV_NOTE)
*severity_name= "NOTE";
else if(severity>=LIBDAX_MSGS_SEV_UPDATE)
else if(severity>=LIBISO_MSGS_SEV_UPDATE)
*severity_name= "UPDATE";
else if(severity>=LIBDAX_MSGS_SEV_DEBUG)
else if(severity>=LIBISO_MSGS_SEV_DEBUG)
*severity_name= "DEBUG";
else if(severity>=LIBDAX_MSGS_SEV_ALL)
else if(severity>=LIBISO_MSGS_SEV_ALL)
*severity_name= "ALL";
else {
*severity_name= "";
@ -287,13 +287,13 @@ int libdax_msgs__sev_to_text(int severity, char **severity_name,
}
int libdax_msgs_submit(struct libdax_msgs *m, int driveno, int error_code,
int libiso_msgs_submit(struct libiso_msgs *m, int driveno, int error_code,
int severity, int priority, char *msg_text,
int os_errno, int flag)
{
int ret;
char *textpt,*sev_name,sev_text[81];
struct libdax_msgs_item *item= NULL;
struct libiso_msgs_item *item= NULL;
if(severity >= m->print_severity) {
if(msg_text==NULL)
@ -301,28 +301,28 @@ int libdax_msgs_submit(struct libdax_msgs *m, int driveno, int error_code,
else
textpt= msg_text;
sev_text[0]= 0;
ret= libdax_msgs__sev_to_text(severity,&sev_name,0);
ret= libiso_msgs__sev_to_text(severity,&sev_name,0);
if(ret>0)
sprintf(sev_text,"%s : ",sev_name);
fprintf(stderr,"%s%s%s\n",m->print_id,sev_text,textpt);
if(os_errno!=0) {
ret= libdax_msgs_lock(m,0);
ret= libiso_msgs_lock(m,0);
if(ret<=0)
return(-1);
fprintf(stderr,"%s( Most recent system error: %d '%s' )\n",
m->print_id,os_errno,strerror(os_errno));
libdax_msgs_unlock(m,0);
libiso_msgs_unlock(m,0);
}
}
if(severity < m->queue_severity)
return(0);
ret= libdax_msgs_lock(m,0);
ret= libiso_msgs_lock(m,0);
if(ret<=0)
return(-1);
ret= libdax_msgs_item_new(&item,m->youngest,0);
ret= libiso_msgs_item_new(&item,m->youngest,0);
if(ret<=0)
goto failed;
item->driveno= driveno;
@ -340,29 +340,29 @@ int libdax_msgs_submit(struct libdax_msgs *m, int driveno, int error_code,
m->oldest= item;
m->youngest= item;
m->count++;
libdax_msgs_unlock(m,0);
libiso_msgs_unlock(m,0);
/*
fprintf(stderr,"libdax_experimental: message submitted to queue (now %d)\n",
fprintf(stderr,"libiso_experimental: message submitted to queue (now %d)\n",
m->count);
*/
return(1);
failed:;
libdax_msgs_item_destroy(&item,0);
libdax_msgs_unlock(m,0);
libiso_msgs_item_destroy(&item,0);
libiso_msgs_unlock(m,0);
return(-1);
}
int libdax_msgs_obtain(struct libdax_msgs *m, struct libdax_msgs_item **item,
int libiso_msgs_obtain(struct libiso_msgs *m, struct libiso_msgs_item **item,
int severity, int priority, int flag)
{
int ret;
struct libdax_msgs_item *im, *next_im= NULL;
struct libiso_msgs_item *im, *next_im= NULL;
*item= NULL;
ret= libdax_msgs_lock(m,0);
ret= libiso_msgs_lock(m,0);
if(ret<=0)
return(-1);
for(im= m->oldest; im!=NULL; im= next_im) {
@ -370,8 +370,8 @@ int libdax_msgs_obtain(struct libdax_msgs *m, struct libdax_msgs_item **item,
next_im= im->next;
if(im->severity>=severity)
break;
libdax_msgs_item_unlink(im,&(m->oldest),&(m->youngest),0);
libdax_msgs_item_destroy(&im,0); /* severity too low: delete */
libiso_msgs_item_unlink(im,&(m->oldest),&(m->youngest),0);
libiso_msgs_item_destroy(&im,0); /* severity too low: delete */
}
if(im==NULL)
break;
@ -380,25 +380,25 @@ int libdax_msgs_obtain(struct libdax_msgs *m, struct libdax_msgs_item **item,
}
if(im==NULL)
{ret= 0; goto ex;}
libdax_msgs_item_unlink(im,&(m->oldest),&(m->youngest),0);
libiso_msgs_item_unlink(im,&(m->oldest),&(m->youngest),0);
*item= im;
ret= 1;
ex:;
libdax_msgs_unlock(m,0);
libiso_msgs_unlock(m,0);
return(ret);
}
int libdax_msgs_destroy_item(struct libdax_msgs *m,
struct libdax_msgs_item **item, int flag)
int libiso_msgs_destroy_item(struct libiso_msgs *m,
struct libiso_msgs_item **item, int flag)
{
int ret;
ret= libdax_msgs_lock(m,0);
ret= libiso_msgs_lock(m,0);
if(ret<=0)
return(-1);
ret= libdax_msgs_item_destroy(item,0);
libdax_msgs_unlock(m,0);
ret= libiso_msgs_item_destroy(item,0);
libiso_msgs_unlock(m,0);
return(ret);
}

View File

@ -1,25 +1,25 @@
/* libdax_msgs
Message handling facility of libdax.
/* libiso_msgs
Message handling facility of libisofs.
Copyright (C) 2006-2007 Thomas Schmitt <scdbackup@gmx.net>,
provided under GPL
*/
/*
*Never* set this macro outside libdax_msgs.c !
*Never* set this macro outside libiso_msgs.c !
The entrails of the message handling facility are not to be seen by
the other library components or the applications.
*/
#ifdef LIBDAX_MSGS_H_INTERNAL
#ifdef LIBISO_MSGS_H_INTERNAL
#ifndef LIBDAX_MSGS_SINGLE_THREADED
#ifndef LIBISO_MSGS_SINGLE_THREADED
#include <pthread.h>
#endif
struct libdax_msgs_item {
struct libiso_msgs_item {
double timestamp;
pid_t process_id;
@ -36,47 +36,47 @@ struct libdax_msgs_item {
char *msg_text;
int os_errno;
struct libdax_msgs_item *prev,*next;
struct libiso_msgs_item *prev,*next;
};
struct libdax_msgs {
struct libiso_msgs {
struct libdax_msgs_item *oldest;
struct libdax_msgs_item *youngest;
struct libiso_msgs_item *oldest;
struct libiso_msgs_item *youngest;
int count;
int queue_severity;
int print_severity;
char print_id[81];
#ifndef LIBDAX_MSGS_SINGLE_THREADED
#ifndef LIBISO_MSGS_SINGLE_THREADED
pthread_mutex_t lock_mutex;
#endif
};
#endif /* LIBDAX_MSGS_H_INTERNAL */
#endif /* LIBISO_MSGS_H_INTERNAL */
#ifndef LIBDAX_MSGS_H_INCLUDED
#define LIBDAX_MSGS_H_INCLUDED 1
#ifndef LIBISO_MSGS_H_INCLUDED
#define LIBISO_MSGS_H_INCLUDED 1
#ifndef LIBDAX_MSGS_H_INTERNAL
#ifndef LIBISO_MSGS_H_INTERNAL
/* Public Opaque Handles */
/** A pointer to this is a opaque handle to a message handling facility */
struct libdax_msgs;
struct libiso_msgs;
/** A pointer to this is a opaque handle to a single message item */
struct libdax_msgs_item;
struct libiso_msgs_item;
#endif /* ! LIBDAX_MSGS_H_INTERNAL */
#endif /* ! LIBISO_MSGS_H_INTERNAL */
/* Public Macros */
@ -85,65 +85,65 @@ struct libdax_msgs_item;
/* Registered Severities */
/* It is well advisable to let applications select severities via strings and
forwarded functions libdax_msgs__text_to_sev(), libdax_msgs__sev_to_text().
forwarded functions libiso_msgs__text_to_sev(), libiso_msgs__sev_to_text().
These macros are for use by libdax/libburn only.
*/
/** Use this to get messages of any severity. Do not use for submitting.
*/
#define LIBDAX_MSGS_SEV_ALL 0x00000000
#define LIBISO_MSGS_SEV_ALL 0x00000000
/** Debugging messages not to be visible to normal users by default
*/
#define LIBDAX_MSGS_SEV_DEBUG 0x10000000
#define LIBISO_MSGS_SEV_DEBUG 0x10000000
/** Update of a progress report about long running actions
*/
#define LIBDAX_MSGS_SEV_UPDATE 0x20000000
#define LIBISO_MSGS_SEV_UPDATE 0x20000000
/** Not so usual events which were gracefully handled
*/
#define LIBDAX_MSGS_SEV_NOTE 0x30000000
#define LIBISO_MSGS_SEV_NOTE 0x30000000
/** Possibilities to achieve a better result
*/
#define LIBDAX_MSGS_SEV_HINT 0x40000000
#define LIBISO_MSGS_SEV_HINT 0x40000000
/** Warnings about problems which could not be handled optimally
*/
#define LIBDAX_MSGS_SEV_WARNING 0x50000000
#define LIBISO_MSGS_SEV_WARNING 0x50000000
/** Non-fatal error messages indicating that parts of the action failed
but processing will/should go on
*/
#define LIBDAX_MSGS_SEV_SORRY 0x60000000
#define LIBISO_MSGS_SEV_SORRY 0x60000000
/** An error message which puts the whole operation of libdax in question
*/
#define LIBDAX_MSGS_SEV_FATAL 0x70000000
#define LIBISO_MSGS_SEV_FATAL 0x70000000
/** A message from an abort handler which will finally finish libburn
*/
#define LIBDAX_MSGS_SEV_ABORT 0x71000000
#define LIBISO_MSGS_SEV_ABORT 0x71000000
/** A severity to exclude resp. discard any possible message.
Do not use this severity for submitting.
*/
#define LIBDAX_MSGS_SEV_NEVER 0x7fffffff
#define LIBISO_MSGS_SEV_NEVER 0x7fffffff
/* Registered Priorities */
/* Priorities are to be used by libburn/libdax only. */
#define LIBDAX_MSGS_PRIO_ZERO 0x00000000
#define LIBDAX_MSGS_PRIO_LOW 0x10000000
#define LIBDAX_MSGS_PRIO_MEDIUM 0x20000000
#define LIBDAX_MSGS_PRIO_HIGH 0x30000000
#define LIBDAX_MSGS_PRIO_TOP 0x7ffffffe
#define LIBISO_MSGS_PRIO_ZERO 0x00000000
#define LIBISO_MSGS_PRIO_LOW 0x10000000
#define LIBISO_MSGS_PRIO_MEDIUM 0x20000000
#define LIBISO_MSGS_PRIO_HIGH 0x30000000
#define LIBISO_MSGS_PRIO_TOP 0x7ffffffe
/* Do not use this priority for submitting */
#define LIBDAX_MSGS_PRIO_NEVER 0x7fffffff
#define LIBISO_MSGS_PRIO_NEVER 0x7fffffff
/* Public Functions */
@ -155,7 +155,7 @@ struct libdax_msgs_item;
@param flag Bitfield for control purposes (unused yet, submit 0)
@return >0 success, <=0 failure
*/
int libdax_msgs_new(struct libdax_msgs **m, int flag);
int libiso_msgs_new(struct libiso_msgs **m, int flag);
/** Destroy a message handling facility and all its eventual messages.
@ -163,7 +163,7 @@ int libdax_msgs_new(struct libdax_msgs **m, int flag);
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 for success, 0 for pointer to NULL
*/
int libdax_msgs_destroy(struct libdax_msgs **m, int flag);
int libiso_msgs_destroy(struct libiso_msgs **m, int flag);
/** Submit a message to a message handling facility.
@ -173,14 +173,14 @@ int libdax_msgs_destroy(struct libdax_msgs **m, int flag);
occasions but those should be equivalent out of the view
of a libdax application. (E.g. "cannot open ATA drive"
versus "cannot open SCSI drive" would be equivalent.)
@param severity The LIBDAX_MSGS_SEV_* of the event.
@param priority The LIBDAX_MSGS_PRIO_* number of the event.
@param severity The LIBISO_MSGS_SEV_* of the event.
@param priority The LIBISO_MSGS_PRIO_* number of the event.
@param msg_text Printable and human readable message text.
@param os_errno Eventual error code from operating system (0 if none)
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 on success, 0 on rejection, <0 for severe errors
*/
int libdax_msgs_submit(struct libdax_msgs *m, int driveno, int error_code,
int libiso_msgs_submit(struct libiso_msgs *m, int driveno, int error_code,
int severity, int priority, char *msg_text,
int os_errno, int flag);
@ -193,7 +193,7 @@ int libdax_msgs_submit(struct libdax_msgs *m, int driveno, int error_code,
bit0= list all severity names in a newline separated string
@return >0 success, <=0 failure
*/
int libdax_msgs__sev_to_text(int severity, char **severity_name,
int libiso_msgs__sev_to_text(int severity, char **severity_name,
int flag);
@ -201,19 +201,19 @@ int libdax_msgs__sev_to_text(int severity, char **severity_name,
@param flag Bitfield for control purposes (unused yet, submit 0)
@return >0 success, <=0 failure
*/
int libdax_msgs__text_to_sev(char *severity_name, int *severity,
int libiso_msgs__text_to_sev(char *severity_name, int *severity,
int flag);
/** Set minimum severity for messages to be queued (default
LIBDAX_MSGS_SEV_ALL) and for messages to be printed directly to stderr
(default LIBDAX_MSGS_SEV_NEVER).
LIBISO_MSGS_SEV_ALL) and for messages to be printed directly to stderr
(default LIBISO_MSGS_SEV_NEVER).
@param print_id A text of at most 80 characters to be printed before
any eventually printed message (default is "libdax: ").
@param flag Bitfield for control purposes (unused yet, submit 0)
@return always 1 for now
*/
int libdax_msgs_set_severities(struct libdax_msgs *m, int queue_severity,
int libiso_msgs_set_severities(struct libiso_msgs *m, int queue_severity,
int print_severity, char *print_id, int flag);
@ -224,48 +224,48 @@ int libdax_msgs_set_severities(struct libdax_msgs *m, int queue_severity,
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 if a matching item was found, 0 if not, <0 for severe errors
*/
int libdax_msgs_obtain(struct libdax_msgs *m, struct libdax_msgs_item **item,
int libiso_msgs_obtain(struct libiso_msgs *m, struct libiso_msgs_item **item,
int severity, int priority, int flag);
/** Destroy a message item obtained by libdax_msgs_obtain(). The submitted
/** Destroy a message item obtained by libiso_msgs_obtain(). The submitted
pointer gets set to NULL.
Caution: Copy eventually obtained msg_text before destroying the item,
if you want to use it further.
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 for success, 0 for pointer to NULL, <0 for severe errors
*/
int libdax_msgs_destroy_item(struct libdax_msgs *m,
struct libdax_msgs_item **item, int flag);
int libiso_msgs_destroy_item(struct libiso_msgs *m,
struct libiso_msgs_item **item, int flag);
/** Obtain from a message item the three application oriented components as
submitted with the originating call of libdax_msgs_submit().
submitted with the originating call of libiso_msgs_submit().
Caution: msg_text becomes a pointer into item, not a copy.
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 on success, 0 on invalid item, <0 for servere errors
*/
int libdax_msgs_item_get_msg(struct libdax_msgs_item *item,
int libiso_msgs_item_get_msg(struct libiso_msgs_item *item,
int *error_code, char **msg_text, int *os_errno,
int flag);
/** Obtain from a message item the submitter identification submitted
with the originating call of libdax_msgs_submit().
with the originating call of libiso_msgs_submit().
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 on success, 0 on invalid item, <0 for servere errors
*/
int libdax_msgs_item_get_origin(struct libdax_msgs_item *item,
int libiso_msgs_item_get_origin(struct libiso_msgs_item *item,
double *timestamp, pid_t *process_id, int *driveno,
int flag);
/** Obtain from a message item severity and priority as submitted
with the originating call of libdax_msgs_submit().
with the originating call of libiso_msgs_submit().
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 on success, 0 on invalid item, <0 for servere errors
*/
int libdax_msgs_item_get_rank(struct libdax_msgs_item *item,
int libiso_msgs_item_get_rank(struct libiso_msgs_item *item,
int *severity, int *priority, int flag);
@ -275,13 +275,13 @@ int libdax_msgs_item_get_rank(struct libdax_msgs_item *item,
/* Registered Error Codes */
Format: error_code (LIBDAX_MSGS_SEV_*,LIBDAX_MSGS_PRIO_*) = explanation
Format: error_code (LIBISO_MSGS_SEV_*,LIBISO_MSGS_PRIO_*) = explanation
If no severity or priority are fixely associates, use "(,)".
------------------------------------------------------------------------------
Range "libdax_msgs" : 0x00000000 to 0x0000ffff
Range "libiso_msgs" : 0x00000000 to 0x0000ffff
0x00000000 (ALL,ZERO) = Initial setting in new libdax_msgs_item
0x00000000 (ALL,ZERO) = Initial setting in new libiso_msgs_item
0x00000001 (DEBUG,ZERO) = Test error message
0x00000002 (DEBUG,ZERO) = Debugging message
@ -373,7 +373,7 @@ Range "scdbackup" : 0x00020000 to 0x0002ffff
0x0002013f (DEBUG,LOW) = Reporting total time spent with waiting for buffer
libdax_audioxtr:
libiso_audioxtr:
0x00020200 (SORRY,HIGH) = Cannot open audio source file
0x00020201 (SORRY,HIGH) = Audio source file has unsuitable format
0x00020202 (SORRY,HIGH) = Failed to prepare reading of audio data
@ -418,16 +418,16 @@ Range "vreixo" : 0x00030000 to 0x0003ffff
#ifdef LIBDAX_MSGS_H_INTERNAL
#ifdef LIBISO_MSGS_H_INTERNAL
/* Internal Functions */
/** Lock before doing side effect operations on m */
static int libdax_msgs_lock(struct libdax_msgs *m, int flag);
static int libiso_msgs_lock(struct libiso_msgs *m, int flag);
/** Unlock after effect operations on m are done */
static int libdax_msgs_unlock(struct libdax_msgs *m, int flag);
static int libiso_msgs_unlock(struct libiso_msgs *m, int flag);
/** Create new empty message item.
@ -435,18 +435,18 @@ static int libdax_msgs_unlock(struct libdax_msgs *m, int flag);
@param flag Bitfield for control purposes (unused yet, submit 0)
@return >0 success, <=0 failure
*/
static int libdax_msgs_item_new(struct libdax_msgs_item **item,
struct libdax_msgs_item *link, int flag);
static int libiso_msgs_item_new(struct libiso_msgs_item **item,
struct libiso_msgs_item *link, int flag);
/** Destroy a message item obtained by libdax_msgs_obtain(). The submitted
/** Destroy a message item obtained by libiso_msgs_obtain(). The submitted
pointer gets set to NULL.
@param flag Bitfield for control purposes (unused yet, submit 0)
@return 1 for success, 0 for pointer to NULL
*/
static int libdax_msgs_item_destroy(struct libdax_msgs_item **item, int flag);
static int libiso_msgs_item_destroy(struct libiso_msgs_item **item, int flag);
#endif /* LIBDAX_MSGS_H_INTERNAL */
#endif /* LIBISO_MSGS_H_INTERNAL */
#endif /* ! LIBDAX_MSGS_H_INCLUDED */
#endif /* ! LIBISO_MSGS_H_INCLUDED */

View File

@ -1123,4 +1123,12 @@ int iso_msgs_obtain(char *minimum_severity,
int *error_code, char msg_text[], int *os_errno,
char severity[]);
/** Return the messenger object handle used by libisofs. This handle
may be used by related libraries to replace their own compatible
messenger objects and thus to direct their messages to the libisofs
message queue. See also: libburn, API function burn_set_messenger().
@return the handle. Do only use with compatible
*/
void *iso_get_messenger(void);
#endif /* LIBISO_LIBISOFS_H */

View File

@ -4,63 +4,63 @@
#include "libisofs.h"
#include "messages.h"
struct libdax_msgs *libdax_messenger = NULL;
struct libiso_msgs *libiso_messenger = NULL;
int iso_init()
{
if (libdax_messenger == NULL) {
if (libdax_msgs_new(&libdax_messenger, 0) <= 0)
if (libiso_messenger == NULL) {
if (libiso_msgs_new(&libiso_messenger, 0) <= 0)
return 0;
}
libdax_msgs_set_severities(libdax_messenger, LIBDAX_MSGS_SEV_NEVER,
LIBDAX_MSGS_SEV_FATAL, "libisofs: ", 0);
libiso_msgs_set_severities(libiso_messenger, LIBISO_MSGS_SEV_NEVER,
LIBISO_MSGS_SEV_FATAL, "libisofs: ", 0);
return 1;
}
void iso_finish()
{
libdax_msgs_destroy(&libdax_messenger,0);
libiso_msgs_destroy(&libiso_messenger,0);
}
void iso_msg_debug(char *msg_text)
{
libdax_msgs_submit(libdax_messenger, -1, 0x00000002,
LIBDAX_MSGS_SEV_DEBUG, LIBDAX_MSGS_PRIO_ZERO,
libiso_msgs_submit(libiso_messenger, -1, 0x00000002,
LIBISO_MSGS_SEV_DEBUG, LIBISO_MSGS_PRIO_ZERO,
msg_text, 0, 0);
}
void iso_msg_note(int error_code, char *msg_text)
{
libdax_msgs_submit(libdax_messenger, -1, error_code,
LIBDAX_MSGS_SEV_NOTE, LIBDAX_MSGS_PRIO_MEDIUM,
libiso_msgs_submit(libiso_messenger, -1, error_code,
LIBISO_MSGS_SEV_NOTE, LIBISO_MSGS_PRIO_MEDIUM,
msg_text, 0, 0);
}
void iso_msg_hint(int error_code, char *msg_text)
{
libdax_msgs_submit(libdax_messenger, -1, error_code,
LIBDAX_MSGS_SEV_HINT, LIBDAX_MSGS_PRIO_MEDIUM,
libiso_msgs_submit(libiso_messenger, -1, error_code,
LIBISO_MSGS_SEV_HINT, LIBISO_MSGS_PRIO_MEDIUM,
msg_text, 0, 0);
}
void iso_msg_warn(int error_code, char *msg_text)
{
libdax_msgs_submit(libdax_messenger, -1, error_code,
LIBDAX_MSGS_SEV_WARNING, LIBDAX_MSGS_PRIO_MEDIUM,
libiso_msgs_submit(libiso_messenger, -1, error_code,
LIBISO_MSGS_SEV_WARNING, LIBISO_MSGS_PRIO_MEDIUM,
msg_text, 0, 0);
}
void iso_msg_sorry(int error_code, char *msg_text)
{
libdax_msgs_submit(libdax_messenger, -1, error_code,
LIBDAX_MSGS_SEV_SORRY, LIBDAX_MSGS_PRIO_HIGH,
libiso_msgs_submit(libiso_messenger, -1, error_code,
LIBISO_MSGS_SEV_SORRY, LIBISO_MSGS_PRIO_HIGH,
msg_text, 0, 0);
}
void iso_msg_fatal(int error_code, char *msg_text)
{
libdax_msgs_submit(libdax_messenger, -1, error_code,
LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH,
libiso_msgs_submit(libiso_messenger, -1, error_code,
LIBISO_MSGS_SEV_FATAL, LIBISO_MSGS_PRIO_HIGH,
msg_text, 0, 0);
}
@ -82,13 +82,13 @@ int iso_msgs_set_severities(char *queue_severity,
{
int ret, queue_sevno, print_sevno;
ret = libdax_msgs__text_to_sev(queue_severity, &queue_sevno, 0);
ret = libiso_msgs__text_to_sev(queue_severity, &queue_sevno, 0);
if (ret <= 0)
return 0;
ret = libdax_msgs__text_to_sev(print_severity, &print_sevno, 0);
ret = libiso_msgs__text_to_sev(print_severity, &print_sevno, 0);
if (ret <= 0)
return 0;
ret = libdax_msgs_set_severities(libdax_messenger, queue_sevno,
ret = libiso_msgs_set_severities(libiso_messenger, queue_sevno,
print_sevno, print_id, 0);
if (ret <= 0)
return 0;
@ -119,16 +119,16 @@ int iso_msgs_obtain(char *minimum_severity,
{
int ret, minimum_sevno, sevno, priority;
char *textpt, *sev_name;
struct libdax_msgs_item *item = NULL;
struct libiso_msgs_item *item = NULL;
ret = libdax_msgs__text_to_sev(minimum_severity, &minimum_sevno, 0);
ret = libiso_msgs__text_to_sev(minimum_severity, &minimum_sevno, 0);
if (ret <= 0)
return 0;
ret = libdax_msgs_obtain(libdax_messenger, &item, minimum_sevno,
LIBDAX_MSGS_PRIO_ZERO, 0);
ret = libiso_msgs_obtain(libiso_messenger, &item, minimum_sevno,
LIBISO_MSGS_PRIO_ZERO, 0);
if (ret <= 0)
goto ex;
ret = libdax_msgs_item_get_msg(item, error_code, &textpt, os_errno, 0);
ret = libiso_msgs_item_get_msg(item, error_code, &textpt, os_errno, 0);
if (ret <= 0)
goto ex;
strncpy(msg_text, textpt, ISO_MSGS_MESSAGE_LEN-1);
@ -136,16 +136,22 @@ int iso_msgs_obtain(char *minimum_severity,
msg_text[ISO_MSGS_MESSAGE_LEN-1] = 0;
severity[0]= 0;
ret = libdax_msgs_item_get_rank(item, &sevno, &priority, 0);
ret = libiso_msgs_item_get_rank(item, &sevno, &priority, 0);
if(ret <= 0)
goto ex;
ret = libdax_msgs__sev_to_text(sevno, &sev_name, 0);
ret = libiso_msgs__sev_to_text(sevno, &sev_name, 0);
if(ret <= 0)
goto ex;
strcpy(severity,sev_name);
ret = 1;
ex:
libdax_msgs_destroy_item(libdax_messenger, &item, 0);
libiso_msgs_destroy_item(libiso_messenger, &item, 0);
return ret;
}
void *iso_get_messenger(void)
{
return libiso_messenger;
}

View File

@ -5,7 +5,7 @@
#ifndef MESSAGES_H_
#define MESSAGES_H_
#include "libdax_msgs.h"
#include "libiso_msgs.h"
/** Can't read file (ignored) */
#define LIBISO_CANT_READ_FILE 0x00031001