Volksdata 1.0b10
RDF library
Loading...
Searching...
No Matches
environment.c
Go to the documentation of this file.
3
4
8
9/* TODO
10typedef struct store_reg_entry {
11 char *id;
12 void *env;
13} StoreRegEntry;
14*/
15
16
20static int nsmap_comp_fn (const void *a, const void *b, void *_unused)
21{
22 (void) _unused;
23
24 const NSEntry *nsa = a;
25 const NSEntry *nsb = b;
26
27 return strncmp (nsa->pfx, nsb->pfx, PFX_LEN);
28}
29
30static uint64_t nsmap_hash_fn (
31 const void *item, uint64_t seed0, uint64_t _unused)
32{
33 (void) _unused;
34 const NSEntry *nse = item;
35
36 return (uint64_t) VOLK_HASH64 (nse->pfx, strlen (nse->pfx), seed0);
37}
38
39static void nsmap_free_fn (void *item)
40{ free (((NSEntry *) item)->ns); }
41
42
43/* TODO
44static int store_reg_comp_fn (const void *a, const void *b, void *_unused)
45{
46 (void) _unused;
47 const StoreRegEntry *ela = a;
48 const StoreRegEntry *elb = b;
49
50 return strcmp (ela->id, elb->id);
51}
52
53static uint64_t store_reg_hash_fn (
54 const void *item, uint64_t seed0, uint64_t _unused)
55{
56 (void) _unused;
57
58 const StoreRegEntry *el = item;
59 return (uint64_t) VOLK_HASH64 (el->id, strlen (el->id), seed0);
60}
61*/
62
63
64/*
65 * API
66 */
67
70{
71 if (VOLK_env_is_init) {
73 return VOLK_NOACTION;
74 }
75
76 char *_loglevel = getenv ("VOLK_LOGLEVEL");
77 log_set_level ((_loglevel == NULL) ? LOG_INFO : atoi (_loglevel));
78
79 // Default namespace map.
80 VOLK_default_nsm = hashmap_new (
81 sizeof (NSEntry), 0, VOLK_HASH_SEED, 0,
82 nsmap_hash_fn, nsmap_comp_fn, nsmap_free_fn, NULL);
83 if (hashmap_oom (VOLK_default_nsm)) return VOLK_MEM_ERR;
84
85
87 for (int i = 0; init_nsmap[i][0] != NULL; i++)
89
90 // Default context URI.
91 const char *default_ctx_str = getenv ("VOLK_DEFAULT_CTX");
92 if (!default_ctx_str) default_ctx_str = DEFAULT_CTX_LABEL;
93 VOLK_default_ctx = VOLK_iriref_new (default_ctx_str);
97
98 // Initialize term cache.
101 // Create and cache default literal datatype key.
105
106 // Create hashmap for store registry.
107 /* TODO
108 VOLK_store_reg = hashmap_new (
109 sizeof (StoreRegEntry), 1, VOLK_HASH_SEED, 0,
110 store_reg_hash_fn, store_reg_comp_fn, NULL, NULL);
111 if (hashmap_oom (VOLK_store_reg)) return VOLK_MEM_ERR;
112 */
113
114 VOLK_env_is_init = true;
115 log_info ("Volksdata environment initialized.");
116
117 // Set automatic teardown.
118 atexit (VOLK_done);
119
120 return VOLK_OK;
121}
122
123
124void
126{
127 if (!VOLK_env_is_init) return;
128
129 // Free default NS map and context.
132 hashmap_free (VOLK_default_nsm);
133
134 // Free ID cache, including default literal datatype.
135 hashmap_free (VOLK_term_cache);
136 VOLK_env_is_init = false;
137
138 // Free store registry.
139
140 log_info ("Volksdata environment torn down.");
141}
142
143
144/*
145 * Externals.
146 */
147
148struct hashmap *VOLK_store_reg = NULL;
const char * init_nsmap[][2]
Initial namespace map.
Definition bootstrap.h:6
#define UNLIKELY(x)
Definition core.h:39
Handle LSUP environment initialization and teardown.
#define VOLK_HASH_SEED
Seed used for all hashing. Compile-time configurable.
Definition core.h:189
#define VOLK_HASH64(buf, size, seed)
Default 64-bit hashing function.
Definition core.h:195
bool VOLK_env_is_init
Whether the environment is initialized.
Definition core.c:11
#define NLRCCK(exp, _rc)
Return rc return code if exp is NULL.
Definition core.h:370
#define LOG_RC(rc)
Log an error or warning for return codes that are not VOLK_OK.
Definition core.h:305
#define PRCCK(exp)
Return exp return value if it is of VOLK_rc type and negative (=error).
Definition core.h:358
#define VOLK_ERROR
Generic error return code.
Definition core.h:135
#define VOLK_MEM_ERR
Memory allocation error.
Definition core.h:156
#define VOLK_OK
Generic success return code.
Definition core.h:95
#define VOLK_NOACTION
No action taken.
Definition core.h:105
int VOLK_rc
Return code.
Definition core.h:91
VOLK_Term * VOLK_iriref_new(const char *data)
Create an IRI reference.
Definition term.h:191
VOLK_Term * VOLK_default_datatype
Default literal data type URI.
Definition term.c:60
VOLK_TermSet * VOLK_term_set_new()
Create a new term set.
Definition term.c:548
void VOLK_term_free(VOLK_Term *term)
Definition term.c:392
VOLK_Buffer * VOLK_term_serialize(const VOLK_Term *term)
Serialize a term into a buffer.
Definition term.c:298
#define DEFAULT_DTYPE
Default data type for untyped literals (prefixed IRI).
Definition term.h:19
VOLK_Term * VOLK_default_ctx
Default context.
Definition term.c:59
VOLK_rc VOLK_term_set_add(VOLK_TermSet *ts, VOLK_Term *term, VOLK_Term **ins)
Add term to a term set.
Definition term.c:561
VOLK_TermSet * VOLK_term_cache
Global term cache.
Definition term.c:61
VOLK_Buffer * VOLK_default_ctx_buf
Serialized default context.
Definition buffer.c:5
void VOLK_buffer_free(VOLK_Buffer *buf)
Free a buffer.
Definition buffer.c:97
void VOLK_done(void)
Close the default environment.
#define DEFAULT_CTX_LABEL
Default context.
Definition environment.h:43
VOLK_rc VOLK_init(void)
Initialize the default environment.
Definition environment.c:69
struct hashmap * VOLK_store_reg
Internal registry of store handles.
struct hashmap * VOLK_default_nsm
Default namespace prefix map.
Definition namespace.c:38
VOLK_rc VOLK_nsmap_add(const char *pfx, const char *nsstr)
Add a prefix -> namespace pair to the map or update it.
Definition namespace.c:42
#define PFX_LEN
Namespace prefix length, including terminator.
Definition namespace.h:16
Prefix / Namespace pair.
Definition namespace.h:26
VOLK_ns_pfx pfx
Definition namespace.h:27