|
MapLibre Native C API
Public C ABI for the MapLibre Native wrapper.
|
Go to the source code of this file.
Data Structures | |
| struct | mln_adapter_resource_rewrite_rule |
| struct | mln_adapter_resource_rewrite_rules |
| struct | mln_adapter_resource_provider_rule |
| struct | mln_adapter_resource_provider_rules |
| struct | mln_adapter_queued_resource_provider_route |
| struct | mln_adapter_queued_resource_provider |
| struct | mln_adapter_queued_resource_request |
| struct | mln_adapter_log_callback_state |
| struct | mln_adapter_log_record |
Macros | |
| #define | MLN_ADAPTER_RESOURCE_KIND_ANY UINT32_MAX |
Typedefs | |
| typedef void(* | mln_adapter_queued_resource_request_listener) (void *request) |
| typedef void(* | mln_adapter_log_record_listener) (void *record) |
Public C API declarations for adapting native callbacks to host runtimes that cannot run user code on a native callback thread.
MapLibre callback contracts are synchronous: logging and resource providers return an immediate decision, and borrowed request payloads expire when the callback returns. Some host runtimes cannot meet that contract. A host whose callbacks are delivered asynchronously and return void has no way to answer synchronously, and no way to read a payload that is already gone by the time its user code runs.
This layer answers on the host's behalf. It copies borrowed payloads into native-owned records the host releases explicitly, applies native-owned routing rules when a decision is needed immediately, and hands records to the host through void listener functions. Host user code therefore runs on its own execution context rather than on MapLibre worker, network, logging, or render threads.
A host that compiles its own native code writes this adaptation there instead, in whatever form its runtime prefers. This header serves hosts that consume the shared library through a pure foreign-function interface and have no native compilation unit of their own.
This header is not part of the maplibre_native_c.h umbrella. Include it directly when a binding needs it.
This header targets C23.
| #define MLN_ADAPTER_RESOURCE_KIND_ANY UINT32_MAX |
Rule kind that matches every resource kind.
| typedef void(* mln_adapter_log_record_listener) (void *record) |
Receives a log record as a native-owned mln_adapter_log_record, or null when the callback retires.
The listener returns void and may be invoked from any MapLibre logging or worker thread. It takes ownership of the record and releases it with mln_adapter_log_record_destroy() once the host has read it.
| typedef void(* mln_adapter_queued_resource_request_listener) (void *request) |
Receives a queued request as a native-owned mln_adapter_queued_resource_request, or null when the provider retires.
The listener returns void and may be invoked from any MapLibre thread. It takes ownership of the record and releases it with mln_adapter_resource_provider_request_destroy() once the host has read it.
| void mln_adapter_custom_geometry_callbacks_retire | ( | mln_custom_geometry_source_tile_callback | fetch_tile, |
| mln_custom_geometry_source_tile_callback | cancel_tile, | ||
| void * | user_data ) |
Invokes custom geometry tile callbacks once with a retirement tile id.
The retirement tile id uses z = UINT8_MAX, which no real tile uses, so a host listener recognizes it and releases the state behind the callbacks.
| void mln_adapter_handle_leak_report | ( | void * | token | ) |
Reports a leaked handle on stderr and releases the token.
| void * mln_adapter_handle_leak_token_create | ( | const char * | type_name, |
| void * | handle ) |
Creates a token describing a handle the host has not closed yet.
The token copies type_name and does not retain handle. Hosts attach the token to a finalizer so an unclosed handle can be reported from a context that can no longer touch the handle itself.
Returns null when the token cannot be allocated.
| void mln_adapter_handle_leak_token_destroy | ( | void * | token | ) |
Releases a leak token without reporting it.
| uint32_t mln_adapter_log_callback | ( | void * | user_data, |
| uint32_t | severity, | ||
| uint32_t | event, | ||
| int64_t | code, | ||
| const char * | message ) |
The mln_log_callback implementation this layer registers.
Copies the record, hands it to the registered listener, and reports the registration's fixed consume value. The user_data pointer is the mln_adapter_log_callback_state passed to mln_adapter_log_set_callback().
| void mln_adapter_log_record_destroy | ( | void * | record | ) |
Releases a log record delivered to a listener.
| mln_status mln_adapter_log_set_callback | ( | mln_adapter_log_callback_state * | state | ) |
Installs state as the process-global log callback, or clears the current callback when state is null.
A registration this call replaces receives one final null record through its listener once its in-flight dispatches finish.
Returns:
| uint32_t mln_adapter_queued_resource_provider_callback | ( | void * | user_data, |
| const mln_resource_request * | request, | ||
| mln_resource_request_handle * | handle ) |
The mln_resource_provider_callback implementation for queued providers.
The user_data pointer is an mln_adapter_queued_resource_provider. A request matching one of the provider's routes is copied and handed to the listener, and reports MLN_RESOURCE_PROVIDER_DECISION_HANDLE. Other requests pass through. A request that cannot be copied is completed with an error response rather than left outstanding.
| void mln_adapter_queued_resource_provider_retire | ( | mln_adapter_queued_resource_provider * | provider | ) |
Delivers one null record to a queued provider's listener.
Hosts call this after the provider is no longer registered so the listener can release the host-side state that backed it.
| void mln_adapter_resource_provider_request_destroy | ( | void * | request | ) |
Releases a queued request record delivered to a listener.
| uint32_t mln_adapter_resource_provider_rules_callback | ( | void * | user_data, |
| const mln_resource_request * | request, | ||
| mln_resource_request_handle * | handle ) |
The mln_resource_provider_callback implementation for provider rules.
The user_data pointer is an mln_adapter_resource_provider_rules table. A matching request is completed inline with the rule's response and reports MLN_RESOURCE_PROVIDER_DECISION_HANDLE. Other requests pass through.
| mln_status mln_adapter_resource_request_token_cancelled | ( | uint64_t | token, |
| bool * | out_cancelled ) |
Reports whether the request behind token was cancelled.
Returns:
| mln_status mln_adapter_resource_request_token_complete | ( | uint64_t | token, |
| const mln_resource_response * | response ) |
Completes the request behind token and retires the token.
Returns:
| uint64_t mln_adapter_resource_request_token_create | ( | mln_resource_request_handle * | handle | ) |
Registers handle under an integer token the host carries across execution contexts.
The token owns the handle from this point: complete it with mln_adapter_resource_request_token_complete() or drop it with mln_adapter_resource_request_token_release(), and leave the handle itself alone.
Returns 0 when handle is null or the token cannot be recorded.
| mln_status mln_adapter_resource_request_token_release | ( | uint64_t | token | ) |
Releases the request behind token without completing it, and retires the token.
Returns:
| mln_status mln_adapter_resource_request_token_wait | ( | uint64_t | token | ) |
Blocks until token is completed or released.
Hosts use this to drain outstanding requests during teardown. Call it from a context that is not responsible for completing the token.
Returns:
| mln_status mln_adapter_resource_transform_rewrite_callback | ( | void * | user_data, |
| uint32_t | kind, | ||
| const char * | url, | ||
| mln_resource_transform_response * | out_response ) |
The mln_resource_transform_callback implementation for rewrite rules.
The user_data pointer is an mln_adapter_resource_rewrite_rules table. The first matching rule replaces the URL, and a request that matches no rule passes through unchanged.