registry(3erl) | C Library Functions | registry(3erl) |
registry - Store and back up key-value pairs.
This functionality is deprecated as of OTP 23, and will be removed in OTP 24. Reasonably new gcc compilers will issue deprecation warnings. In order to disable these warnings, define the macro EI_NO_DEPR_WARN.
This module provides support for storing key-value pairs in a table known as a registry, backing up registries to Mnesia in an atomic manner, and later restoring the contents of a registry from Mnesia.
int ei_reg_close(reg)
Types:
A registry that has previously been created with ei_reg_open() is closed, and all the objects it contains are freed.
reg is the registry to close.
Returns 0.
int ei_reg_delete(reg,key)
Types:
Deletes an object from the registry. The object is not removed from the registry, it is only marked for later removal so that on later backups to Mnesia, the corresponding object can be removed from the Mnesia table as well. If another object is later created with the same key, the object will be reused.
The object is removed from the registry after a call to ei_reg_dump() or ei_reg_purge().
Returns 0 on success, otherwise -1.
int ei_reg_dump(fd,reg,mntab,flags)
Types:
Dumps the contents of a registry to a Mnesia table in an atomic manner, that is, either all data or no data is updated. If any errors are encountered while backing up the data, the entire operation is aborted.
If flags is 0, the backup includes only those objects that have been created, modified, or deleted since the last backup or restore (that is, an incremental backup). After the backup, any objects that were marked dirty are now clean, and any objects that had been marked for deletion are deleted.
Alternatively, setting flags to EI_FORCE causes a full backup to be done, and EI_NOPURGE causes the deleted objects to be left in the registry afterwards. These can be bitwise OR'ed together if both behaviors are desired. If EI_NOPURGE was specified, ei_reg_purge() can be used to explicitly remove the deleted items from the registry later.
Returns 0 on success, otherwise -1.
double ei_reg_getfval(reg,key)
Types:
Gets the value associated with key in the registry. The value must be a floating point type.
On success, the function returns the value associated with key. If the object is not found or if it is not a floating point object, -1.0 is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between -1.0 and a valid result), use the more general function ei_reg_getval() instead.
int ei_reg_getival(reg,key)
Types:
Gets the value associated with key in the registry. The value must be an integer.
On success, the function returns the value associated with key. If the object is not found or if it is not an integer object, -1 is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between -1 and a valid result), use the more general function ei_reg_getval() instead.
const void *ei_reg_getpval(reg,key,size)
Types:
Gets the value associated with key in the registry. The value must be a binary (pointer) type.
On success, the function returns the value associated with key and indicates its length in size. If the object is not found or if it is not a binary object, NULL is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between NULL and a valid result), use the more general function ei_reg_getval() instead.
const char *ei_reg_getsval(reg,key)
Types:
Gets the value associated with key in the registry. The value must be a string.
On success, the function returns the value associated with key. If the object is not found or if it is not a string, NULL is returned. To avoid problems with in-band error reporting (that is, if you cannot distinguish between NULL and a valid result), use the more general function ei_reg_getval() instead.
int ei_reg_getval(reg,key,flags,v,...)
Types:
A general function for retrieving any kind of object from the registry.
The buffer pointed to by v must be large enough to hold the return data, that is, it must be a pointer to one of int, double, char*, or void*, respectively.
If flags is EI_BIN, a fifth argument int *size is required, so that the size of the object can be returned.
On success, v (and size if the object is binary) is initialized with the value associated with key, and the function returns EI_INT, EI_FLT, EI_STR, or EI_BIN, indicating the type of object. On failure, -1 is returned and the arguments are not updated.
int ei_reg_markdirty(reg,key)
Types:
Marks a registry object as dirty. This ensures that it is included in the next backup to Mnesia. Normally this operation is not necessary, as all of the normal registry 'set' functions do this automatically. However, if you have retrieved the value of a string or binary object from the registry and modified the contents, then the change is invisible to the registry and the object is assumed to be unmodified. This function allows you to make such modifications and then let the registry know about them.
Returns 0 on success, otherwise -1.
ei_reg *ei_reg_open(size)
Types:
Opens (creates) a registry, which initially is empty. To close the registry later, use ei_reg_close().
size is the approximate number of objects you intend to store in the registry. As the registry uses a hash table with collision chaining, no absolute upper limit exists on the number of objects that can be stored in it. However, for reasons of efficiency, it is a good idea to choose a number that is appropriate for your needs. To change the size later, use ei_reg_resize(). Notice that the number you provide is increased to the nearest larger prime number.
Returns an empty registry on success, otherwise NULL.
int ei_reg_purge(reg)
Types:
Removes all objects marked for deletion. When objects are deleted with ei_reg_delete() they are not removed from the registry, only marked for later removal. On a later backup to Mnesia, the objects can also be removed from the Mnesia table. If you are not backing up to Mnesia, you may wish to remove the objects manually with this function.
reg is a registry containing objects marked for deletion.
Returns 0 on success, otherwise -1.
int ei_reg_resize(reg,newsize)
Types:
Changes the size of a registry.
newsize is the new size to make the registry. The number is increased to the nearest larger prime number.
On success, the registry is resized, all contents rehashed, and 0 is returned. On failure, the registry is left unchanged and -1 is returned.
int ei_reg_restore(fd,reg,mntab)
Types:
The contents of a Mnesia table are read into the registry.
Notice that only tables of a certain format can be restored, that is, those that have been created and backed up to with ei_reg_dump(). If the registry was not empty before the operation, the contents of the table are added to the contents of the registry. If the table contains objects with the same keys as those already in the registry, the registry objects are overwritten with the new values. If the registry contains objects that were not in the table, they are unchanged by this operation.
After the restore operation, the entire contents of the registry is marked as unmodified. Notice that this includes any objects that were modified before the restore and not overwritten by the restore.
Returns 0 on success, otherwise -1.
int ei_reg_setfval(reg,key,f)
Types:
Creates a key-value pair with the specified key and floating point value f. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().
Returns 0 on success, otherwise -1.
int ei_reg_setival(reg,key,i)
Types:
Creates a key-value pair with the specified key and integer value i. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().
Returns 0 on success, otherwise -1.
int ei_reg_setpval(reg,key,p,size)
Types:
Creates a key-value pair with the specified key whose "value" is the binary object pointed to by p. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().
Returns 0 on success, otherwise -1.
int ei_reg_setsval(reg,key,s)
Types:
Creates a key-value pair with the specified key whose "value" is the specified string s. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().
Returns 0 on success, otherwise -1.
int ei_reg_setval(reg,key,flags,v,...)
Types:
Creates a key-value pair with the specified key whose value is specified by v. If an object already exists with the same key, the new value replaces the old one. If the previous value was a binary or string, it is freed with free().
If flags is EI_BIN, a fifth argument size is required, indicating the size in bytes of the object pointed to by v.
If you wish to store an arbitrary pointer in the registry, specify a size of 0. In this case, the object itself is not transferred by an ei_reg_dump() operation, only the pointer value.
Returns 0 on success, otherwise -1.
int ei_reg_stat(reg,key,obuf)
Types:
Returns information about an object.
struct ei_reg_stat {
int attr;
int size; };
In attr the attributes of the object are stored as the logical OR of its type (one of EI_INT, EI_FLT, EI_BIN, and EI_STR), whether it is marked for deletion (EI_DELET), and whether it has been modified since the last backup to Mnesia (EI_DIRTY).
Field size indicates the size in bytes required to store EI_STR (including the terminating 0) and EI_BIN objects, or 0 for EI_INT and EI_FLT.
Returns 0 and initializes obuf on success, otherwise -1.
int ei_reg_tabstat(reg,obuf)
Types:
Returns information about a registry. Using information returned by this function, you can see whether the size of the registry is suitable for the amount of data it contains.
struct ei_reg_tabstat {
int size;
int nelem;
int npos;
int collisions; };
Field size indicates the number of hash positions in the registry. This is the number you provided when you created or last resized the registry, rounded up to the nearest prime number.
On success, 0 is returned and obuf is initialized to contain table statistics, otherwise -1 is returned.
erl_interface 4.0.2 | Ericsson AB |