/* * spnh.h — scorpiox-scorpioplayer-native-handler-registry (SCORPIO PLAYER 2027, row 22) * * The NativeHandler boundary: the named-function escape hatch a server-authored * SetttingsGroup template uses to ask the app to DO something. * C twin of `ConstantValues.NativeHandlers[""] = async c => NativeHandlerInvokeResult` * (bosxixi.ScorpioPlayer.Core/Toolkit14/TableView.cs:549-580). See SPEC.md. * * - a registry (name -> C function), with built-in reference handlers for the handlers * that need no transport, and a 134-name inventory measured from the live bundle * - an invoke contract: RuntimeSettings in (mutable), SelectedItem in, intent out * - injected alert / translate / indicator / uuid / validation callbacks. * Nothing here dials a host, touches a file or formats UI text on its own. * * Threading: one global registry, call from one thread. Strings returned are owned by * the library and stay valid until the next spnh_invoke_begin / spnh_scan_reset / * spnh_shutdown (or, for spnh_*_json, the next call to the same function). */ #ifndef SPNH_H #define SPNH_H #ifdef __cplusplus extern "C" { #endif #if defined(SPNH_STATIC) # define SPNH_API #elif defined(_WIN32) # if defined(SPNH_BUILD) # define SPNH_API __declspec(dllexport) # else # define SPNH_API __declspec(dllimport) # endif #else # define SPNH_API __attribute__((visibility("default"))) #endif /* ---- error taxonomy (SPEC §6) ---- */ #define SPNH_OK 0 #define SPNH_ERR_NOT_REGISTERED -1 /* no handler with that name (C#: ContainsKey false) */ #define SPNH_ERR_BAD_ARGS -2 /* handler ran, its inputs were unusable (C#: NRE/throw) */ #define SPNH_ERR_HANDLER_FAILED -3 /* handler ran and said no (C#: AlertCallback + null) */ #define SPNH_ERR_NO_CALLBACK -4 /* handler needs an injected capability that is missing */ #define SPNH_ERR_INVALID_ARG -5 /* API misuse: NULL name, no invoke_begin, bad JSON, index */ #define SPNH_ERR_OOM -6 /* handler kinds (spnh_known_kind) */ #define SPNH_KIND_BUILTIN "builtin" /* implemented here */ #define SPNH_KIND_CONNECTION "connection" /* Test/Connect/ScanConnection: its engine's */ #define SPNH_KIND_SERVICE "service" /* logic that needs a backend: its client engine's */ #define SPNH_KIND_SHELL "shell" /* navigation / UI: the platform shell's */ /* a handler. `name` is the invoked name. It reads its inputs with spnh_in_* / spnh_item_get * and writes RuntimeSettings with spnh_set, the log with spnh_log_add and intent with * spnh_result_set_*. Returns SPNH_OK or one SPNH_ERR_*. Callable from C#/Swift. */ typedef int (*spnh_fn)(const char *name, void *ctx); typedef void (*spnh_alert_fn)(const char *text, void *ctx); /* key + default text -> translated text, or NULL for "use the default" */ typedef const char *(*spnh_translate_fn)(const char *key, const char *display, void *ctx); typedef void (*spnh_indicator_fn)(int on, void *ctx); /* Indicator.Start/Stop */ /* write a new identifier (Guid.NewGuid().ToString()) into out; return 0 */ typedef int (*spnh_uuid_fn)(char *out, int cap, void *ctx); /* IInstantDebridService.ValidationAsync / IInstantMediaServer.ValidationAsync. * service = "debrid" | "mediaserver"; request = DebridValidationPayload JSON. * return 0 and write the response JSON into out; <0 = C# null; >0 = needed capacity. */ typedef int (*spnh_validation_fn)(const char *service, const char *request_json, char *out, int cap, void *ctx); /* ---- lifecycle ---- */ SPNH_API int spnh_init(void); /* idempotent: resets, registers the built-ins */ SPNH_API void spnh_shutdown(void); SPNH_API const char *spnh_version(void); /* "1.0.0" */ SPNH_API const char *spnh_last_error(void); SPNH_API const char *spnh_strerror(int code); SPNH_API int spnh_warning_count(void); SPNH_API const char *spnh_warning(int i); /* ---- registry ---- */ SPNH_API int spnh_register(const char *name, spnh_fn fn, void *ctx); /* replaces */ SPNH_API int spnh_unregister(const char *name); SPNH_API int spnh_is_registered(const char *name); /* 1 / 0 */ SPNH_API int spnh_is_builtin(const char *name); /* 1 if the registered fn is ours */ SPNH_API int spnh_count(void); SPNH_API const char *spnh_name(int i); /* ---- inventory: the 134 names the live bundle references (2026-09-26) ---- */ SPNH_API int spnh_known_count(void); SPNH_API const char *spnh_known_name(int i); SPNH_API const char *spnh_known_kind(const char *name); /* SPNH_KIND_* or NULL */ /* ---- offline coverage: which handlers do these templates need? ---- */ SPNH_API void spnh_scan_reset(void); SPNH_API int spnh_scan_template(const char *template_json); /* >=0 nodes found (accumulates) */ SPNH_API int spnh_scan_node_count(void); /* NativeHandler* nodes seen */ SPNH_API int spnh_scan_empty_count(void); /* ... of which had no DefaultValue */ SPNH_API int spnh_required_count(void); SPNH_API const char *spnh_required(int i); /* sorted ordinal */ SPNH_API int spnh_required_refs(const char *name); SPNH_API int spnh_missing_count(void); /* referenced but not registered */ SPNH_API const char *spnh_missing(int i); /* ---- invocation (caller side) ---- */ SPNH_API int spnh_invoke_begin(const char *name); SPNH_API int spnh_arg_set(const char *key, const char *value); /* value NULL = C# null */ SPNH_API int spnh_arg_set_json(const char *settings_json); /* merge a {k:v} object */ SPNH_API int spnh_arg_set_item(const char *item_json); /* SetttingsGroup.Item */ SPNH_API int spnh_invoke(void); /* ---- inside a handler (handler side; valid only during spnh_invoke) ---- */ SPNH_API const char *spnh_in_get(const char *key); /* current value, NULL absent/null */ SPNH_API int spnh_set(const char *key, const char *value); /* c.RuntimeSettings[k]=v */ SPNH_API const char *spnh_item_get(const char *field); /* Key DisplayName Type DefaultValue AdvanceMenu.NativeHandlerCode ... */ SPNH_API int spnh_item_set(const char *field, const char *value); SPNH_API const char *spnh_context_get(const char *key); SPNH_API int spnh_log_add(const char *key, const char *display); /* ITranslatable logger */ SPNH_API int spnh_indicator(int on); SPNH_API const char *spnh_mint_id(void); /* ID ||= uuid(); returns the ID */ SPNH_API int spnh_commit_connection(const char *runtime_type, const char *url); SPNH_API int spnh_result_set_ok(int ok); SPNH_API int spnh_result_set_message(const char *key, const char *display); SPNH_API int spnh_result_set_intent(const char *intent, int on); SPNH_API int spnh_result_set_new_page(const char *group_json); SPNH_API int spnh_result_set_item(const char *item_json); SPNH_API int spnh_result_add_setting(const char *setting_json); /* ---- result (caller side, after spnh_invoke) ---- */ SPNH_API int spnh_result_ok(void); SPNH_API const char *spnh_result_message(void); /* translated text, NULL = none */ SPNH_API const char *spnh_result_message_key(void); SPNH_API int spnh_result_intent(const char *intent); SPNH_API int spnh_result_dismiss(void); /* DismissViewController */ SPNH_API int spnh_result_go_back(void); /* GoBack */ SPNH_API int spnh_result_reload(void); /* Events.RaiseReloadNeed */ SPNH_API const char *spnh_result_new_page(void); /* SetttingsGroup JSON, NULL = none */ SPNH_API const char *spnh_result_item(void); /* follow-up Item JSON, NULL = none */ SPNH_API int spnh_result_setting_count(void); SPNH_API const char *spnh_result_setting(int i); SPNH_API const char *spnh_result_json(void); /* RuntimeSettings out: the real output of the C# handlers */ SPNH_API int spnh_out_count(void); SPNH_API const char *spnh_out_key(int i); SPNH_API const char *spnh_out_value(const char *key); SPNH_API int spnh_out_changed(const char *key); /* 1 added/changed/removed, 0 same, -1 bad */ SPNH_API int spnh_out_removed_count(void); SPNH_API const char *spnh_out_json(void); SPNH_API const char *spnh_out_item_json(void); /* SelectedItem after the handler */ /* diagnostics: the List the handler logged */ SPNH_API int spnh_log_count(void); SPNH_API const char *spnh_log_key(int i); SPNH_API const char *spnh_log_text(int i); /* ---- injected capabilities ---- */ SPNH_API int spnh_set_alert_cb(spnh_alert_fn fn, void *ctx); SPNH_API int spnh_set_translate_cb(spnh_translate_fn fn, void *ctx); SPNH_API int spnh_set_indicator_cb(spnh_indicator_fn fn, void *ctx); SPNH_API int spnh_set_uuid_cb(spnh_uuid_fn fn, void *ctx); SPNH_API int spnh_set_validation_cb(spnh_validation_fn fn, void *ctx); SPNH_API int spnh_set_context(const char *key, const char *value); /* AppVersion Platform TotalUsers UserID ProfileID */ #ifdef __cplusplus } #endif #endif