]> granicus.if.org Git - imagemagick/commitdiff
Add method to set a function pointer that will be called when something is being...
authordirk <dirk@git.imagemagick.org>
Fri, 3 Jan 2014 05:56:32 +0000 (05:56 +0000)
committerdirk <dirk@git.imagemagick.org>
Fri, 3 Jan 2014 05:56:32 +0000 (05:56 +0000)
MagickCore/log.c
MagickCore/log.h

index 3b92cd7a677a840f24b6b37af2e3950d15f442eb..5029b96b80f399249187896459635ccd62a7eabf 100644 (file)
@@ -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,"   <event>%s</event>\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);
+}
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
index d58715df2924a42b439ef215890e7831915a3841..d5ab7b8cd85cd12aeabf9075b6a5d13e652330f5 100644 (file)
@@ -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)
 }