From: dirk Date: Fri, 3 Jan 2014 05:56:32 +0000 (+0000) Subject: Add method to set a function pointer that will be called when something is being... X-Git-Tag: 7.0.1-0~2994 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=834a57918ebe6c5e12fb5f97465a9107f805aae5;p=imagemagick Add method to set a function pointer that will be called when something is being logged. --- diff --git a/MagickCore/log.c b/MagickCore/log.c index 3b92cd7a6..5029b96b8 100644 --- a/MagickCore/log.c +++ b/MagickCore/log.c @@ -80,7 +80,8 @@ typedef enum StderrHandler = 0x0004, FileHandler = 0x0008, DebugHandler = 0x0010, - EventHandler = 0x0020 + EventHandler = 0x0020, + MethodHandler = 0x0040 } LogHandlerType; typedef struct _EventInfo @@ -134,6 +135,9 @@ struct _LogInfo size_t signature; + + MagickLogMethod + method; }; typedef struct _LogMapInfo @@ -1228,6 +1232,11 @@ MagickBooleanType LogMagickEventList(const LogEventType type,const char *module, (void) FormatLocaleFile(log_info->file," %s\n",text); (void) fflush(log_info->file); } + if ((log_info->handler_mask & MethodHandler) != 0) + { + if (log_info->method != (MagickLogMethod) NULL) + log_info->method(type,text); + } if ((log_info->handler_mask & StdoutHandler) != 0) { (void) FormatLocaleFile(stdout,"%s\n",text); @@ -1749,6 +1758,48 @@ MagickExport void SetLogFormat(const char *format) log_info->format=ConstantString(format); UnlockSemaphoreInfo(log_semaphore); } + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % +% S e t L o g M e t h o d % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% SetLogMethod() sets the method that will be called when an event is logged. +% +% The format of the SetLogMethod method is: +% +% void SetLogMethod(MagickLogMethod method) +% +% A description of each parameter follows: +% +% o method: pointer to a method that will be called when LogMagickEvent is +% being called. +% +*/ +MagickExport void SetLogMethod(MagickLogMethod method) +{ + ExceptionInfo + *exception; + + LogInfo + *log_info; + + exception=AcquireExceptionInfo(); + log_info=(LogInfo *) GetLogInfo("*",exception); + exception=DestroyExceptionInfo(exception); + LockSemaphoreInfo(log_semaphore); + log_info=(LogInfo *) GetValueFromLinkedList(log_list,0); + log_info->handler_mask=(LogHandlerType) (log_info->handler_mask | + MethodHandler); + log_info->method=method; + UnlockSemaphoreInfo(log_semaphore); +} /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/MagickCore/log.h b/MagickCore/log.h index d58715df2..d5ab7b8cd 100644 --- a/MagickCore/log.h +++ b/MagickCore/log.h @@ -61,6 +61,9 @@ typedef enum typedef struct _LogInfo LogInfo; +typedef MagickExport void + (*MagickLogMethod)(const LogEventType,const char *); + extern MagickExport char **GetLogList(const char *,size_t *,ExceptionInfo *); @@ -85,7 +88,8 @@ extern MagickExport MagickBooleanType extern MagickExport void CloseMagickLog(void), - SetLogFormat(const char *); + SetLogFormat(const char *), + SetLogMethod(MagickLogMethod); #if defined(__cplusplus) || defined(c_plusplus) }