1#include "sensor/sensor_loader.h"
11int sensor_module_load(
const char *path,
SensorModule *out) {
12 if (!path || !out || !path[0])
15 memset(out, 0,
sizeof(*out));
18 HMODULE h = LoadLibraryA(path);
20 fprintf(stderr,
"Failed to load sensor module: %s\n", path);
25 fprintf(stderr,
"Symbol sensor_plugin not found in %s\n", path);
29 out->handle = (
void *)h;
32 void *h = dlopen(path, RTLD_NOW);
34 fprintf(stderr,
"Failed to load sensor module %s: %s\n", path, dlerror());
39 fprintf(stderr,
"Symbol sensor_plugin not found in %s: %s\n", path, dlerror());
47 if (out->plugin->
api_version != SENSOR_PLUGIN_API_VERSION) {
48 fprintf(stderr,
"Plugin ABI mismatch in %s (got %d, expected %d)\n", path, out->plugin->
api_version,
49 SENSOR_PLUGIN_API_VERSION);
50 sensor_module_unload(out);
56 fprintf(stderr,
"Invalid plugin ABI in %s\n", path);
57 sensor_module_unload(out);
65 if (!module || !module->handle)
69 FreeLibrary((HMODULE)module->handle);
71 dlclose(module->handle);
73 module->handle = NULL;
74 module->plugin = NULL;
A dynamically loaded sensor plugin and its OS-level handle.
Runtime contract every sensor plugin (.so/.dylib/.dll) must implement.
const char * description
Short description shown in sensor info/listing screens.
int(* read_sample)(AirQualityData *out)
Reads one sample into *out.
int api_version
Must equal SENSOR_PLUGIN_API_VERSION at build time.
int(* shutdown)(void)
Called once before unloading, for cleanup.
const char * plugin_version
Plugin version string, e.g.
const char * name
Human-readable sensor name, e.g.
int(* init)(void)
Called once after loading.