1registry(3) C Library Functions registry(3)
2
3
4
6 registry - Store and back up key-value pairs.
7
9 Note:
10 This functionality is deprecated as of OTP 23, and will be removed in
11 OTP 24. Reasonably new gcc compilers will issue deprecation warnings.
12 In order to disable these warnings, define the macro EI_NO_DEPR_WARN.
13
14
15 This module provides support for storing key-value pairs in a table
16 known as a registry, backing up registries to Mnesia in an atomic man‐
17 ner, and later restoring the contents of a registry from Mnesia.
18
20 int ei_reg_close(reg)
21
22 Types:
23
24 ei_reg *reg;
25
26 A registry that has previously been created with ei_reg_open()
27 is closed, and all the objects it contains are freed.
28
29 reg is the registry to close.
30
31 Returns 0.
32
33 int ei_reg_delete(reg,key)
34
35 Types:
36
37 ei_reg *reg;
38 const char *key;
39
40 Deletes an object from the registry. The object is not removed
41 from the registry, it is only marked for later removal so that
42 on later backups to Mnesia, the corresponding object can be re‐
43 moved from the Mnesia table as well. If another object is later
44 created with the same key, the object will be reused.
45
46 The object is removed from the registry after a call to
47 ei_reg_dump() or ei_reg_purge().
48
49 * reg is the registry containing key.
50
51 * key is the object to remove.
52
53 Returns 0 on success, otherwise -1.
54
55 int ei_reg_dump(fd,reg,mntab,flags)
56
57 Types:
58
59 int fd;
60 ei_reg *reg;
61 const char *mntab;
62 int flags;
63
64 Dumps the contents of a registry to a Mnesia table in an atomic
65 manner, that is, either all data or no data is updated. If any
66 errors are encountered while backing up the data, the entire op‐
67 eration is aborted.
68
69 * fd is an open connection to Erlang. Mnesia 3.0 or later must
70 be running on the Erlang node.
71
72 * reg is the registry to back up.
73
74 * mntab is the name of the Mnesia table where the backed up
75 data is to be placed. If the table does not exist, it is
76 created automatically using configurable defaults. For in‐
77 formation about configuring this behavior, see Mnesia.
78
79 If flags is 0, the backup includes only those objects that have
80 been created, modified, or deleted since the last backup or re‐
81 store (that is, an incremental backup). After the backup, any
82 objects that were marked dirty are now clean, and any objects
83 that had been marked for deletion are deleted.
84
85 Alternatively, setting flags to EI_FORCE causes a full backup to
86 be done, and EI_NOPURGE causes the deleted objects to be left in
87 the registry afterwards. These can be bitwise OR'ed together if
88 both behaviors are desired. If EI_NOPURGE was specified,
89 ei_reg_purge() can be used to explicitly remove the deleted
90 items from the registry later.
91
92 Returns 0 on success, otherwise -1.
93
94 double ei_reg_getfval(reg,key)
95
96 Types:
97
98 ei_reg *reg;
99 const char *key;
100
101 Gets the value associated with key in the registry. The value
102 must be a floating point type.
103
104 * reg is the registry where the object will be looked up.
105
106 * key is the name of the object to look up.
107
108 On success, the function returns the value associated with key.
109 If the object is not found or if it is not a floating point ob‐
110 ject, -1.0 is returned. To avoid problems with in-band error re‐
111 porting (that is, if you cannot distinguish between -1.0 and a
112 valid result), use the more general function ei_reg_getval() in‐
113 stead.
114
115 int ei_reg_getival(reg,key)
116
117 Types:
118
119 ei_reg *reg;
120 const char *key;
121
122 Gets the value associated with key in the registry. The value
123 must be an integer.
124
125 * reg is the registry where the object will be looked up.
126
127 * key is the name of the object to look up.
128
129 On success, the function returns the value associated with key.
130 If the object is not found or if it is not an integer object, -1
131 is returned. To avoid problems with in-band error reporting
132 (that is, if you cannot distinguish between -1 and a valid re‐
133 sult), use the more general function ei_reg_getval() instead.
134
135 const void *ei_reg_getpval(reg,key,size)
136
137 Types:
138
139 ei_reg *reg;
140 const char *key;
141 int size;
142
143 Gets the value associated with key in the registry. The value
144 must be a binary (pointer) type.
145
146 * reg is the registry where the object will be looked up.
147
148 * key is the name of the object to look up.
149
150 * size is initialized to contain the length in bytes of the
151 object, if it is found.
152
153 On success, the function returns the value associated with key
154 and indicates its length in size. If the object is not found or
155 if it is not a binary object, NULL is returned. To avoid prob‐
156 lems with in-band error reporting (that is, if you cannot dis‐
157 tinguish between NULL and a valid result), use the more general
158 function ei_reg_getval() instead.
159
160 const char *ei_reg_getsval(reg,key)
161
162 Types:
163
164 ei_reg *reg;
165 const char *key;
166
167 Gets the value associated with key in the registry. The value
168 must be a string.
169
170 * reg is the registry where the object will be looked up.
171
172 * key is the name of the object to look up.
173
174 On success, the function returns the value associated with key.
175 If the object is not found or if it is not a string, NULL is re‐
176 turned. To avoid problems with in-band error reporting (that is,
177 if you cannot distinguish between NULL and a valid result), use
178 the more general function ei_reg_getval() instead.
179
180 int ei_reg_getval(reg,key,flags,v,...)
181
182 Types:
183
184 ei_reg *reg;
185 const char *key;
186 int flags;
187 void *v (see below)
188
189 A general function for retrieving any kind of object from the
190 registry.
191
192 * reg is the registry where the object will be looked up.
193
194 * key is the name of the object to look up.
195
196 * flags indicates the type of object that you are looking for.
197 If flags is 0, any kind of object is returned. If flags is
198 EI_INT, EI_FLT, EI_STR, or EI_BIN, then only values of that
199 kind are returned.
200
201 The buffer pointed to by v must be large enough to hold the
202 return data, that is, it must be a pointer to one of int,
203 double, char*, or void*, respectively.
204
205 If flags is EI_BIN, a fifth argument int *size is required,
206 so that the size of the object can be returned.
207
208 On success, v (and size if the object is binary) is initialized
209 with the value associated with key, and the function returns
210 EI_INT, EI_FLT, EI_STR, or EI_BIN, indicating the type of ob‐
211 ject. On failure, -1 is returned and the arguments are not up‐
212 dated.
213
214 int ei_reg_markdirty(reg,key)
215
216 Types:
217
218 ei_reg *reg;
219 const char *key;
220
221 Marks a registry object as dirty. This ensures that it is in‐
222 cluded in the next backup to Mnesia. Normally this operation is
223 not necessary, as all of the normal registry 'set' functions do
224 this automatically. However, if you have retrieved the value of
225 a string or binary object from the registry and modified the
226 contents, then the change is invisible to the registry and the
227 object is assumed to be unmodified. This function allows you to
228 make such modifications and then let the registry know about
229 them.
230
231 * reg is the registry containing the object.
232
233 * key is the name of the object to mark.
234
235 Returns 0 on success, otherwise -1.
236
237 ei_reg *ei_reg_open(size)
238
239 Types:
240
241 int size;
242
243 Opens (creates) a registry, which initially is empty. To close
244 the registry later, use ei_reg_close().
245
246 size is the approximate number of objects you intend to store in
247 the registry. As the registry uses a hash table with collision
248 chaining, no absolute upper limit exists on the number of ob‐
249 jects that can be stored in it. However, for reasons of effi‐
250 ciency, it is a good idea to choose a number that is appropriate
251 for your needs. To change the size later, use ei_reg_resize().
252 Notice that the number you provide is increased to the nearest
253 larger prime number.
254
255 Returns an empty registry on success, otherwise NULL.
256
257 int ei_reg_purge(reg)
258
259 Types:
260
261 ei_reg *reg;
262
263 Removes all objects marked for deletion. When objects are
264 deleted with ei_reg_delete() they are not removed from the reg‐
265 istry, only marked for later removal. On a later backup to Mne‐
266 sia, the objects can also be removed from the Mnesia table. If
267 you are not backing up to Mnesia, you may wish to remove the ob‐
268 jects manually with this function.
269
270 reg is a registry containing objects marked for deletion.
271
272 Returns 0 on success, otherwise -1.
273
274 int ei_reg_resize(reg,newsize)
275
276 Types:
277
278 ei_reg *reg;
279 int newsize;
280
281 Changes the size of a registry.
282
283 newsize is the new size to make the registry. The number is in‐
284 creased to the nearest larger prime number.
285
286 On success, the registry is resized, all contents rehashed, and
287 0 is returned. On failure, the registry is left unchanged and -1
288 is returned.
289
290 int ei_reg_restore(fd,reg,mntab)
291
292 Types:
293
294 int fd;
295 ei_reg *reg;
296 const char *mntab;
297
298 The contents of a Mnesia table are read into the registry.
299
300 * fd is an open connection to Erlang. Mnesia 3.0 or later must
301 be running on the Erlang node.
302
303 * reg is the registry where the data is to be placed.
304
305 * mntab is the name of the Mnesia table to read data from.
306
307 Notice that only tables of a certain format can be restored,
308 that is, those that have been created and backed up to with
309 ei_reg_dump(). If the registry was not empty before the opera‐
310 tion, the contents of the table are added to the contents of the
311 registry. If the table contains objects with the same keys as
312 those already in the registry, the registry objects are over‐
313 written with the new values. If the registry contains objects
314 that were not in the table, they are unchanged by this opera‐
315 tion.
316
317 After the restore operation, the entire contents of the registry
318 is marked as unmodified. Notice that this includes any objects
319 that were modified before the restore and not overwritten by the
320 restore.
321
322 Returns 0 on success, otherwise -1.
323
324 int ei_reg_setfval(reg,key,f)
325
326 Types:
327
328 ei_reg *reg;
329 const char *key;
330 double f;
331
332 Creates a key-value pair with the specified key and floating
333 point value f. If an object already exists with the same key,
334 the new value replaces the old one. If the previous value was a
335 binary or string, it is freed with free().
336
337 * reg is the registry where the object is to be placed.
338
339 * key is the object name.
340
341 * f is the floating point value to assign.
342
343 Returns 0 on success, otherwise -1.
344
345 int ei_reg_setival(reg,key,i)
346
347 Types:
348
349 ei_reg *reg;
350 const char *key;
351 int i;
352
353 Creates a key-value pair with the specified key and integer
354 value i. If an object already exists with the same key, the new
355 value replaces the old one. If the previous value was a binary
356 or string, it is freed with free().
357
358 * reg is the registry where the object is to be placed.
359
360 * key is the object name.
361
362 * i is the integer value to assign.
363
364 Returns 0 on success, otherwise -1.
365
366 int ei_reg_setpval(reg,key,p,size)
367
368 Types:
369
370 ei_reg *reg;
371 const char *key;
372 const void *p;
373 int size;
374
375 Creates a key-value pair with the specified key whose "value" is
376 the binary object pointed to by p. If an object already exists
377 with the same key, the new value replaces the old one. If the
378 previous value was a binary or string, it is freed with free().
379
380 * reg is the registry where the object is to be placed.
381
382 * key is the object name.
383
384 * p is a pointer to the binary object. The object itself must
385 have been created through a single call to malloc() or a
386 similar function, so that the registry can later delete it
387 if necessary by calling free().
388
389 * size is the length in bytes of the binary object.
390
391 Returns 0 on success, otherwise -1.
392
393 int ei_reg_setsval(reg,key,s)
394
395 Types:
396
397 ei_reg *reg;
398 const char *key;
399 const char *s;
400
401 Creates a key-value pair with the specified key whose "value" is
402 the specified string s. If an object already exists with the
403 same key, the new value replaces the old one. If the previous
404 value was a binary or string, it is freed with free().
405
406 * reg is the registry where the object is to be placed.
407
408 * key is the object name.
409
410 * s is the string to assign. The string itself must have been
411 created through a single call to malloc() or similar a func‐
412 tion, so that the registry can later delete it if necessary
413 by calling free().
414
415 Returns 0 on success, otherwise -1.
416
417 int ei_reg_setval(reg,key,flags,v,...)
418
419 Types:
420
421 ei_reg *reg;
422 const char *key;
423 int flags;
424 v (see below)
425
426 Creates a key-value pair with the specified key whose value is
427 specified by v. If an object already exists with the same key,
428 the new value replaces the old one. If the previous value was a
429 binary or string, it is freed with free().
430
431 * reg is the registry where the object is to be placed.
432
433 * key is the object name.
434
435 * flags indicates the type of the object specified by v. Flags
436 must be one of EI_INT, EI_FLT, EI_STR, and EI_BIN, indicat‐
437 ing whether v is int, double, char*, or void*.
438
439 If flags is EI_BIN, a fifth argument size is required, indi‐
440 cating the size in bytes of the object pointed to by v.
441
442 If you wish to store an arbitrary pointer in the registry, spec‐
443 ify a size of 0. In this case, the object itself is not trans‐
444 ferred by an ei_reg_dump() operation, only the pointer value.
445
446 Returns 0 on success, otherwise -1.
447
448 int ei_reg_stat(reg,key,obuf)
449
450 Types:
451
452 ei_reg *reg;
453 const char *key;
454 struct ei_reg_stat *obuf;
455
456 Returns information about an object.
457
458 * reg is the registry containing the object.
459
460 * key is the object name.
461
462 * obuf is a pointer to an ei_reg_stat structure, defined as
463 follows:
464
465 struct ei_reg_stat {
466 int attr;
467 int size;
468 };
469
470
471 In attr the attributes of the object are stored as the logical
472 OR of its type (one of EI_INT, EI_FLT, EI_BIN, and EI_STR),
473 whether it is marked for deletion (EI_DELET), and whether it has
474 been modified since the last backup to Mnesia (EI_DIRTY).
475
476 Field size indicates the size in bytes required to store EI_STR
477 (including the terminating 0) and EI_BIN objects, or 0 for
478 EI_INT and EI_FLT.
479
480 Returns 0 and initializes obuf on success, otherwise -1.
481
482 int ei_reg_tabstat(reg,obuf)
483
484 Types:
485
486 ei_reg *reg;
487 struct ei_reg_tabstat *obuf;
488
489 Returns information about a registry. Using information returned
490 by this function, you can see whether the size of the registry
491 is suitable for the amount of data it contains.
492
493 * reg is the registry to return information about.
494
495 * obuf is a pointer to an ei_reg_tabstat structure, defined as
496 follows:
497
498 struct ei_reg_tabstat {
499 int size;
500 int nelem;
501 int npos;
502 int collisions;
503 };
504
505
506 Field size indicates the number of hash positions in the reg‐
507 istry. This is the number you provided when you created or last
508 resized the registry, rounded up to the nearest prime number.
509
510 * nelem indicates the number of elements stored in the reg‐
511 istry. It includes objects that are deleted but not purged.
512
513 * npos indicates the number of unique positions that are occu‐
514 pied in the registry.
515
516 * collisions indicates how many elements are sharing positions
517 in the registry.
518
519 On success, 0 is returned and obuf is initialized to contain ta‐
520 ble statistics, otherwise -1 is returned.
521
522
523
524Ericsson AB erl_interface 4.0.3.1 registry(3)