vgl 1.0.0
Virtual Globe Library: API reference
Loading...
Searching...
No Matches
defaults.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2026 Jeremiah van Oosten
4 *
5 * vgl defaults: a thread pool, a filesystem reader, an HTTP reader and a disk cache that
6 * implement the task and I/O interfaces of vgl/foundation.h, so that the common case needs no
7 * callbacks (design document, section 7.5). This module is optional and linked separately, as
8 * vgl_defaults: unlike the core library, it creates threads, opens files and connects to servers.
9 *
10 * A minimal host:
11 *
12 * vgl_thread_pool* pool;
13 * vgl_thread_pool_create(NULL, &pool);
14 * vgl_file_reader_create_info reader_info = {.struct_size = sizeof(reader_info)};
15 * reader_info.pool = pool;
16 * vgl_file_reader* reader;
17 * vgl_file_reader_create(&reader_info, &reader);
18 *
19 * vgl_task_interface tasks;
20 * vgl_io_interface io;
21 * vgl_thread_pool_task_interface_get(pool, &tasks);
22 * vgl_file_reader_io_interface_get(reader, &io);
23 * vgl_context_create_info info = {.struct_size = sizeof(info)};
24 * info.tasks = &tasks;
25 * info.io = &io;
26 * ...
27 * vgl_context_destroy(context);
28 * vgl_file_reader_destroy(reader);
29 * vgl_thread_pool_destroy(pool);
30 *
31 * Destroy the context first, then the reader, then the pool.
32 */
33#ifndef VGL_DEFAULTS_H
34#define VGL_DEFAULTS_H
35
36#include <vgl/base.h>
37#include <vgl/foundation.h>
38
39/* Symbol visibility of the defaults library, which is shared when vgl is. */
40#if defined(VGL_SHARED)
41# if defined(_WIN32)
42# if defined(VGL_DEFAULTS_BUILDING)
43# define VGL_DEFAULTS_API __declspec(dllexport)
44# else
45# define VGL_DEFAULTS_API __declspec(dllimport)
46# endif
47# else
48# define VGL_DEFAULTS_API __attribute__((visibility("default")))
49# endif
50#else
51# define VGL_DEFAULTS_API
52#endif
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58/* ---------------------------------------------------------------------------------------- */
59/* Thread pool */
60/* ---------------------------------------------------------------------------------------- */
61
64
74
91 vgl_thread_pool** out_pool);
92
105
120 vgl_task_interface* out_interface);
121
122/* ---------------------------------------------------------------------------------------- */
123/* File reader */
124/* ---------------------------------------------------------------------------------------- */
125
133
148
165 vgl_file_reader** out_reader);
166
178
193 vgl_io_interface* out_interface);
194
195/* ---------------------------------------------------------------------------------------- */
196/* HTTP reader */
197/* ---------------------------------------------------------------------------------------- */
198
223
225{
226 uint32_t struct_size;
231 VGL_POINTER_PADDING(allocator_padding)
236 const vgl_io_interface* fallback;
237 VGL_POINTER_PADDING(fallback_padding)
239 double timeout;
242 const char* user_agent;
243 VGL_POINTER_PADDING(user_agent_padding)
245
266 vgl_http_reader** out_reader);
267
280
295 vgl_io_interface* out_interface);
296
297/* ---------------------------------------------------------------------------------------- */
298/* Disk cache */
299/* ---------------------------------------------------------------------------------------- */
300
319
321{
322 uint32_t struct_size;
323 uint32_t reserved;
325 const char* directory;
326 VGL_POINTER_PADDING(directory_padding)
331 const vgl_io_interface* source;
332 VGL_POINTER_PADDING(source_padding)
334 uint64_t budget;
338 VGL_POINTER_PADDING(pool_padding)
341 VGL_POINTER_PADDING(allocator_padding)
343
346{
347 uint32_t struct_size;
348 uint32_t reserved;
349 uint64_t hits;
350 uint64_t misses;
351 uint64_t offline_hits;
352 uint64_t entries;
353 uint64_t bytes;
354 uint64_t budget;
355 uint64_t evictions;
357
377 vgl_disk_cache** out_cache);
378
392
407 vgl_io_interface* out_interface);
408
424
439
440#ifdef __cplusplus
441}
442#endif
443
444#endif /* VGL_DEFAULTS_H */
vgl_result
Definition base.h:98
#define VGL_POINTER_PADDING(name)
Definition base.h:46
vgl_result vgl_http_reader_io_interface_get(vgl_http_reader *reader, vgl_io_interface *out_interface)
vgl_result vgl_disk_cache_clear(vgl_disk_cache *cache)
vgl_result vgl_file_reader_io_interface_get(vgl_file_reader *reader, vgl_io_interface *out_interface)
vgl_result vgl_thread_pool_task_interface_get(vgl_thread_pool *pool, vgl_task_interface *out_interface)
vgl_result vgl_thread_pool_destroy(vgl_thread_pool *pool)
vgl_result vgl_disk_cache_io_interface_get(vgl_disk_cache *cache, vgl_io_interface *out_interface)
struct vgl_http_reader vgl_http_reader
Definition defaults.h:222
vgl_result vgl_disk_cache_statistics_get(vgl_disk_cache *cache, vgl_disk_cache_statistics *out_statistics)
vgl_result vgl_file_reader_destroy(vgl_file_reader *reader)
vgl_result vgl_thread_pool_create(const vgl_thread_pool_create_info *info, vgl_thread_pool **out_pool)
vgl_result vgl_disk_cache_destroy(vgl_disk_cache *cache)
vgl_result vgl_http_reader_create(const vgl_http_reader_create_info *info, vgl_http_reader **out_reader)
struct vgl_thread_pool vgl_thread_pool
Definition defaults.h:63
vgl_result vgl_http_reader_destroy(vgl_http_reader *reader)
struct vgl_file_reader vgl_file_reader
Definition defaults.h:132
#define VGL_DEFAULTS_API
Definition defaults.h:51
struct vgl_disk_cache vgl_disk_cache
Definition defaults.h:318
vgl_result vgl_file_reader_create(const vgl_file_reader_create_info *info, vgl_file_reader **out_reader)
vgl_result vgl_disk_cache_create(const vgl_disk_cache_create_info *info, vgl_disk_cache **out_cache)
Definition foundation.h:49
Definition defaults.h:321
const char * directory
Definition defaults.h:325
uint32_t reserved
Definition defaults.h:323
uint32_t struct_size
Definition defaults.h:322
Definition defaults.h:346
uint64_t hits
Definition defaults.h:349
uint32_t struct_size
Definition defaults.h:347
uint64_t misses
Definition defaults.h:350
uint64_t budget
Definition defaults.h:354
uint64_t evictions
Definition defaults.h:355
uint64_t bytes
Definition defaults.h:353
uint64_t entries
Definition defaults.h:352
uint32_t reserved
Definition defaults.h:348
uint64_t offline_hits
Definition defaults.h:351
Definition defaults.h:135
vgl_thread_pool * pool
Definition defaults.h:142
const vgl_allocator_interface * allocator
Definition defaults.h:145
uint32_t reserved
Definition defaults.h:137
uint32_t struct_size
Definition defaults.h:136
Definition defaults.h:225
uint32_t struct_size
Definition defaults.h:226
const vgl_allocator_interface * allocator
Definition defaults.h:230
uint32_t max_connection_count
Definition defaults.h:228
Definition foundation.h:102
Definition foundation.h:232
Definition defaults.h:66
uint32_t struct_size
Definition defaults.h:67
const vgl_allocator_interface * allocator
Definition defaults.h:71
uint32_t thread_count
Definition defaults.h:69