43#include "MagickCore/studio.h"
44#include "MagickCore/exception.h"
45#include "MagickCore/exception-private.h"
46#include "MagickCore/image.h"
47#include "MagickCore/list.h"
48#include "MagickCore/memory_.h"
49#include "MagickCore/memory-private.h"
50#include "MagickCore/registry.h"
51#include "MagickCore/registry-private.h"
52#include "MagickCore/splay-tree.h"
53#include "MagickCore/string_.h"
54#include "MagickCore/string-private.h"
55#include "MagickCore/timer-private.h"
56#include "MagickCore/utility.h"
109MagickExport MagickBooleanType DefineImageRegistry(
const RegistryType type,
113 key[MagickPathExtent],
114 value[MagickPathExtent];
119 assert(option != (
const char *) NULL);
120 (void) CopyMagickString(key,option,MagickPathExtent);
121 for (p=key; *p !=
'\0'; p++)
126 (void) CopyMagickString(value,p+1,MagickPathExtent);
128 return(SetImageRegistry(type,key,value,exception));
153MagickExport MagickBooleanType DeleteImageRegistry(
const char *key)
155 assert(key != (
const char *) NULL);
156 if (IsEventLogging() != MagickFalse)
157 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",key);
158 if (registry == (
void *) NULL)
160 return(DeleteNodeFromSplayTree(registry,key));
190MagickExport
void *GetImageRegistry(
const RegistryType type,
const char *key,
199 assert(key != (
const char *) NULL);
200 if (IsEventLogging() != MagickFalse)
201 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",key);
202 if (registry == (
void *) NULL)
203 return((
void *) NULL);
204 registry_info=(
RegistryInfo *) GetValueFromSplayTree(registry,key);
205 if (registry_info == (
void *) NULL)
206 return((
void *) NULL);
210 case ImageRegistryType:
212 if (type == registry_info->type)
213 value=(
void *) CloneImageList((
Image *) registry_info->value,exception);
216 case ImageInfoRegistryType:
218 if (type == registry_info->type)
219 value=(
void *) CloneImageInfo((
ImageInfo *) registry_info->value);
222 case StringRegistryType:
224 switch (registry_info->type)
226 case ImageRegistryType:
229 registry_info->value)->filename);
232 case ImageInfoRegistryType:
235 registry_info->value)->filename);
238 case StringRegistryType:
240 value=(
void *) ConstantString((
char *) registry_info->value);
272MagickExport
char *GetNextImageRegistry(
void)
274 if (IsEventLogging() != MagickFalse)
275 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
276 if (registry == (
void *) NULL)
277 return((
char *) NULL);
278 return((
char *) GetNextKeyInSplayTree(registry));
299MagickPrivate MagickBooleanType RegistryComponentGenesis(
void)
302 registry_semaphore=AcquireSemaphoreInfo();
324MagickPrivate
void RegistryComponentTerminus(
void)
327 ActivateSemaphoreInfo(®istry_semaphore);
328 LockSemaphoreInfo(registry_semaphore);
329 if (IsEventLogging() != MagickFalse)
330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
331 if (registry != (
void *) NULL)
332 registry=DestroySplayTree(registry);
333 UnlockSemaphoreInfo(registry_semaphore);
334 RelinquishSemaphoreInfo(®istry_semaphore);
360MagickExport
void *RemoveImageRegistry(
const char *key)
362 assert(key != (
const char *) NULL);
363 if (IsEventLogging() != MagickFalse)
364 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",key);
365 if (registry == (
void *) NULL)
366 return((
void *) NULL);
367 return(RemoveNodeFromSplayTree(registry,key));
390MagickExport
void ResetImageRegistryIterator(
void)
392 if (IsEventLogging() != MagickFalse)
393 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
394 if (registry == (
void *) NULL)
396 ResetSplayTreeIterator(registry);
429static void *DestroyRegistryNode(
void *registry_info)
437 case StringRegistryType:
440 p->value=RelinquishMagickMemory(p->value);
443 case ImageRegistryType:
445 p->value=(
void *) DestroyImageList((
Image *) p->value);
448 case ImageInfoRegistryType:
450 p->value=(
void *) DestroyImageInfo((
ImageInfo *) p->value);
454 return(RelinquishMagickMemory(p));
457MagickExport MagickBooleanType SetImageRegistry(
const RegistryType type,
466 assert(key != (
const char *) NULL);
467 if (IsEventLogging() != MagickFalse)
468 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",key);
469 if (value == (
const void *) NULL)
471 clone_value=(
void *) NULL;
474 case StringRegistryType:
480 string=(
const char *) value;
481 if (LocaleCompare(key,
"date:precision") == 0)
482 SetMagickDatePrecision((
size_t) StringToInteger(
string));
483 clone_value=(
void *) ConstantString(
string);
486 case ImageRegistryType:
491 image=(
const Image *) value;
492 if ((image == (
const Image *) NULL) ||
493 (image->signature != MagickCoreSignature))
495 (void) ThrowMagickException(exception,GetMagickModule(),RegistryError,
496 "UnableToSetRegistry",
"%s",key);
499 clone_value=(
void *) CloneImageList(image,exception);
502 case ImageInfoRegistryType:
508 if ((image_info == (
const ImageInfo *) NULL) ||
509 (image_info->signature != MagickCoreSignature))
511 (void) ThrowMagickException(exception,GetMagickModule(),RegistryError,
512 "UnableToSetRegistry",
"%s",key);
515 clone_value=(
void *) CloneImageInfo(image_info);
519 if (clone_value == (
void *) NULL)
521 registry_info=(
RegistryInfo *) AcquireCriticalMemory(
sizeof(*registry_info));
522 (void) memset(registry_info,0,
sizeof(*registry_info));
523 registry_info->type=type;
524 registry_info->value=clone_value;
525 registry_info->signature=MagickCoreSignature;
529 ActivateSemaphoreInfo(®istry_semaphore);
530 LockSemaphoreInfo(registry_semaphore);
532 registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
533 DestroyRegistryNode);
534 UnlockSemaphoreInfo(registry_semaphore);
536 return(AddValueToSplayTree(registry,ConstantString(key),registry_info));