This source file includes following definitions.
- DefineImageRegistry
- DeleteImageRegistry
- GetImageRegistry
- GetNextImageRegistry
- RegistryComponentGenesis
- RegistryComponentTerminus
- RemoveImageRegistry
- ResetImageRegistryIterator
- DestroyRegistryNode
- SetImageRegistry
#include "magick/studio.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/list.h"
#include "magick/memory_.h"
#include "magick/registry.h"
#include "magick/splay-tree.h"
#include "magick/string_.h"
#include "magick/utility.h"
typedef struct _RegistryInfo
{
RegistryType
type;
void
*value;
size_t
signature;
} RegistryInfo;
static SplayTreeInfo
*registry = (SplayTreeInfo *) NULL;
static SemaphoreInfo
*registry_semaphore = (SemaphoreInfo *) NULL;
MagickExport MagickBooleanType DefineImageRegistry(const RegistryType type,
const char *option,ExceptionInfo *exception)
{
char
key[MaxTextExtent],
value[MaxTextExtent];
register char
*p;
assert(option != (const char *) NULL);
(void) CopyMagickString(key,option,MaxTextExtent);
for (p=key; *p != '\0'; p++)
if (*p == '=')
break;
*value='\0';
if (*p == '=')
(void) CopyMagickString(value,p+1,MaxTextExtent);
*p='\0';
return(SetImageRegistry(type,key,value,exception));
}
MagickExport MagickBooleanType DeleteImageRegistry(const char *key)
{
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
if (registry == (void *) NULL)
return(MagickFalse);
return(DeleteNodeFromSplayTree(registry,key));
}
MagickExport void *GetImageRegistry(const RegistryType type,const char *key,
ExceptionInfo *exception)
{
void
*value;
RegistryInfo
*registry_info;
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
if (registry == (void *) NULL)
return((void *) NULL);
registry_info=(RegistryInfo *) GetValueFromSplayTree(registry,key);
if (registry_info == (void *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),RegistryError,
"UnableToGetRegistryID","`%s'",key);
return((void *) NULL);
}
value=(void *) NULL;
switch (type)
{
case ImageRegistryType:
{
if (type == registry_info->type)
value=(void *) CloneImageList((Image *) registry_info->value,exception);
break;
}
case ImageInfoRegistryType:
{
if (type == registry_info->type)
value=(void *) CloneImageInfo((ImageInfo *) registry_info->value);
break;
}
case StringRegistryType:
{
switch (registry_info->type)
{
case ImageRegistryType:
{
value=(Image *) ConstantString(((Image *)
registry_info->value)->filename);
break;
}
case ImageInfoRegistryType:
{
value=(Image *) ConstantString(((ImageInfo *)
registry_info->value)->filename);
break;
}
case StringRegistryType:
{
value=(void *) ConstantString((char *) registry_info->value);
break;
}
default:
break;
}
break;
}
default:
break;
}
return(value);
}
MagickExport char *GetNextImageRegistry(void)
{
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
if (registry == (void *) NULL)
return((char *) NULL);
return((char *) GetNextKeyInSplayTree(registry));
}
MagickExport MagickBooleanType RegistryComponentGenesis(void)
{
if (registry_semaphore == (SemaphoreInfo *) NULL)
registry_semaphore=AllocateSemaphoreInfo();
return(MagickTrue);
}
MagickExport void RegistryComponentTerminus(void)
{
if (registry_semaphore == (SemaphoreInfo *) NULL)
ActivateSemaphoreInfo(®istry_semaphore);
LockSemaphoreInfo(registry_semaphore);
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
if (registry != (void *) NULL)
registry=DestroySplayTree(registry);
UnlockSemaphoreInfo(registry_semaphore);
DestroySemaphoreInfo(®istry_semaphore);
}
MagickExport void *RemoveImageRegistry(const char *key)
{
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
if (registry == (void *) NULL)
return((void *) NULL);
return(RemoveNodeFromSplayTree(registry,key));
}
MagickExport void ResetImageRegistryIterator(void)
{
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
if (registry == (void *) NULL)
return;
ResetSplayTreeIterator(registry);
}
static void *DestroyRegistryNode(void *registry_info)
{
register RegistryInfo
*p;
p=(RegistryInfo *) registry_info;
switch (p->type)
{
case StringRegistryType:
default:
{
p->value=RelinquishMagickMemory(p->value);
break;
}
case ImageRegistryType:
{
p->value=(void *) DestroyImageList((Image *) p->value);
break;
}
case ImageInfoRegistryType:
{
p->value=(void *) DestroyImageInfo((ImageInfo *) p->value);
break;
}
}
return(RelinquishMagickMemory(p));
}
MagickExport MagickBooleanType SetImageRegistry(const RegistryType type,
const char *key,const void *value,ExceptionInfo *exception)
{
MagickBooleanType
status;
RegistryInfo
*registry_info;
void
*clone_value;
if (IsEventLogging() != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
if (value == (const void *) NULL)
return(MagickFalse);
clone_value=(void *) NULL;
switch (type)
{
case StringRegistryType:
default:
{
const char
*string;
string=(const char *) value;
clone_value=(void *) ConstantString(string);
break;
}
case ImageRegistryType:
{
const Image
*image;
image=(const Image *) value;
if (image->signature != MagickSignature)
{
(void) ThrowMagickException(exception,GetMagickModule(),RegistryError,
"UnableToSetRegistry","%s",key);
return(MagickFalse);
}
clone_value=(void *) CloneImageList(image,exception);
break;
}
case ImageInfoRegistryType:
{
const ImageInfo
*image_info;
image_info=(const ImageInfo *) value;
if (image_info->signature != MagickSignature)
{
(void) ThrowMagickException(exception,GetMagickModule(),RegistryError,
"UnableToSetRegistry","%s",key);
return(MagickFalse);
}
clone_value=(void *) CloneImageInfo(image_info);
break;
}
}
if (clone_value == (void *) NULL)
return(MagickFalse);
registry_info=(RegistryInfo *) AcquireMagickMemory(sizeof(*registry_info));
if (registry_info == (RegistryInfo *) NULL)
ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
(void) ResetMagickMemory(registry_info,0,sizeof(*registry_info));
registry_info->type=type;
registry_info->value=clone_value;
registry_info->signature=MagickSignature;
if (registry == (SplayTreeInfo *) NULL)
{
if (registry_semaphore == (SemaphoreInfo *) NULL)
ActivateSemaphoreInfo(®istry_semaphore);
LockSemaphoreInfo(registry_semaphore);
if (registry == (SplayTreeInfo *) NULL)
registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
DestroyRegistryNode);
UnlockSemaphoreInfo(registry_semaphore);
}
status=AddValueToSplayTree(registry,ConstantString(key),registry_info);
return(status);
}