- engine_session_new/fetch/free: cookie e cache di sessione condivisi da documenti, sotto-risorse e fetch - engine_doc_new_session: il documento usa la sessione anche per le sotto-risorse - engine_doc_requests_json / engine_doc_deliver: le richieste accodate dagli script le esegue il guscio, che sa fare rete; il motore consegna le risposte - engine_risolvi_url: i riferimenti relativi delle fetch si risolvono sul documento Il guscio Sailfish crea una sessione per tutta la navigazione, carica i documenti attraverso di essa e serve le fetch nello stesso QTimer dei timer. La sessione è un shared_ptr perché il thread del caricamento la usa mentre la finestra potrebbe chiudersi.
120 lines
5.1 KiB
C
120 lines
5.1 KiB
C
/* API C del motore di rendering — M0.
|
|
* Unico confine fra il motore (Rust) e il guscio (C++/Qt).
|
|
* Ogni immagine restituita va liberata con engine_image_free(). */
|
|
#ifndef ENGINE_H
|
|
#define ENGINE_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct EngineImage {
|
|
uint32_t width;
|
|
uint32_t height;
|
|
uint8_t *pixels; /* RGBA8, len byte; NULL in caso di errore */
|
|
uintptr_t len;
|
|
char *error; /* messaggio di errore o NULL */
|
|
char *controls; /* JSON [{key,kind,x,y,w,h}], pixel CSS; NULL se nessuno */
|
|
} EngineImage;
|
|
|
|
const char *engine_version(void);
|
|
|
|
/* Renderizza html/css nel viewport indicato. Non fa I/O di rete e non tocca il DOM
|
|
* del guscio: è una funzione pura byte -> pixel.
|
|
* scale: pixel CSS -> pixel dispositivo (zoom/DPI).
|
|
* auto_height: se diverso da 0 l'immagine cresce fino all'altezza del documento
|
|
* (height diventa il minimo), così il guscio può scorrere il contenuto.
|
|
* font_path deve puntare a un TTF leggibile dal processo.
|
|
* base_dir è la cartella con cui si risolvono i `src` relativi delle immagini
|
|
* (stringa vuota = directory corrente). */
|
|
EngineImage *engine_render(const char *html, const char *css,
|
|
uint32_t width, uint32_t height,
|
|
float scale, int auto_height,
|
|
const char *font_path, const char *base_dir);
|
|
|
|
/* Come engine_render, con lo stato dei moduli.
|
|
* state_json: {"values": {"chiave": "valore"}, "focus": "chiave"} oppure NULL.
|
|
* Nel risultato, `controls` elenca i controlli con tipo e rettangolo in pixel CSS. */
|
|
EngineImage *engine_render_form(const char *html, const char *css,
|
|
uint32_t width, uint32_t height,
|
|
float scale, int auto_height,
|
|
const char *font_path, const char *base_dir,
|
|
const char *state_json);
|
|
|
|
void engine_image_free(EngineImage *img);
|
|
|
|
/* Scarica un documento (http:// o https://) e ne restituisce il testo UTF-8.
|
|
* Liberare con engine_string_free(). In caso di errore restituisce NULL e scrive
|
|
* il messaggio in *error (anch'esso da liberare). *status riceve il codice HTTP,
|
|
* 0 se la richiesta non è arrivata a risposta. */
|
|
char *engine_fetch(const char *url, int *status, char **error);
|
|
|
|
/* Libera una stringa restituita da engine_fetch(). */
|
|
void engine_string_free(char *s);
|
|
|
|
/* --- Documento con stato (M2.6): DOM, JavaScript, timer -------------------
|
|
*
|
|
* Un guscio grafico crea il documento una volta e poi rasterizza, consegna
|
|
* clic e fa avanzare i timer. Le stringhe restituite si liberano con
|
|
* engine_string_free(); il documento con engine_doc_free().
|
|
*/
|
|
typedef struct EngineDoc EngineDoc;
|
|
|
|
/* Crea il documento ed esegue gli script (inline ed esterni).
|
|
* `base_url` può essere NULL per i documenti locali. NULL in caso di errore. */
|
|
EngineDoc *engine_doc_new(const char *html, const char *css,
|
|
const char *base_dir, const char *base_url);
|
|
void engine_doc_free(EngineDoc *doc);
|
|
|
|
/* Rasterizza lo stato corrente. `state_json` è lo stesso di engine_render_form. */
|
|
EngineImage *engine_doc_render(EngineDoc *doc, uint32_t width, uint32_t height,
|
|
float scale, int auto_height,
|
|
const char *font_path, const char *state_json);
|
|
|
|
/* Consegna un clic alle coordinate CSS: `submit` se il bersaglio è un pulsante,
|
|
* poi `click` con propagazione. Restituisce quanti gestori hanno reagito. */
|
|
int engine_doc_click(EngineDoc *doc, float css_x, float css_y);
|
|
|
|
/* Fa avanzare i timer fino a now_ms; restituisce quanti ne ha eseguiti. */
|
|
int engine_doc_pump(EngineDoc *doc, uint64_t now_ms);
|
|
|
|
/* Prima scadenza dei timer in ms, oppure -1. */
|
|
int64_t engine_doc_next_timer(EngineDoc *doc);
|
|
|
|
/* Errori degli script e messaggi di console.log, una voce per riga. */
|
|
char *engine_doc_errors(EngineDoc *doc);
|
|
|
|
/* --- Sessione di rete: cookie e cache ------------------------------------ */
|
|
typedef struct EngineSession EngineSession;
|
|
|
|
EngineSession *engine_session_new(void);
|
|
void engine_session_free(EngineSession *sessione);
|
|
|
|
/* Richiesta con la sessione (cookie vanno e vengono, cache rispettata).
|
|
* Restituisce il corpo da liberare con engine_string_free(), o NULL; *status
|
|
* riceve il codice HTTP (0 se non c'è stata risposta). */
|
|
char *engine_session_fetch(EngineSession *sessione, const char *url,
|
|
const char *metodo, const char *corpo, int *status);
|
|
|
|
/* Indirizzo assoluto di un riferimento rispetto al documento (NULL se non è rete). */
|
|
char *engine_risolvi_url(const char *base, const char *riferito);
|
|
|
|
/* Documento che usa la sessione anche per le sotto-risorse. */
|
|
EngineDoc *engine_doc_new_session(EngineSession *sessione, const char *html,
|
|
const char *css, const char *base_dir,
|
|
const char *base_url);
|
|
|
|
/* Richieste fetch in attesa, JSON: [{id, url, metodo, corpo}]. */
|
|
char *engine_doc_requests_json(EngineDoc *doc);
|
|
|
|
/* Consegna la risposta di una fetch (status < 0 = fallita). */
|
|
int engine_doc_deliver(EngineDoc *doc, uint64_t id, int status, const char *body);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* ENGINE_H */
|