From: Michael Tremer Date: Fri, 3 Oct 2025 11:14:11 +0000 (+0000) Subject: modules: Rename methods to impl X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91b02c7beb8af3cbbb3d59b11625aaadbc7d7830;p=telemetry.git modules: Rename methods to impl Signed-off-by: Michael Tremer --- diff --git a/src/daemon/module.c b/src/daemon/module.c index fc21b83..707ddc8 100644 --- a/src/daemon/module.c +++ b/src/daemon/module.c @@ -70,8 +70,8 @@ struct collecty_module { // Daemon collecty_daemon* daemon; - // Methods - const collecty_module_methods* methods; + // Implementation + const collecty_module_impl* impl; // Event Loop sd_event* loop; @@ -89,7 +89,7 @@ static int collecty_module_heartbeat(sd_event_source* source, uint64_t usec, voi DEBUG(self->ctx, "Heartbeat called for %s\n", collecty_module_name(self)); // Call the collect method - r = self->methods->collect(self->ctx, self); + r = self->impl->collect(self->ctx, self); if (r < 0) { ERROR(self->ctx, "collect() failed for %s: %s\n", collecty_module_name(self), strerror(-r)); @@ -112,7 +112,7 @@ static int collecty_module_register_heartbeat(collecty_module* self) { int r; // No need to do this if we don't have a collect method - if (!self->methods->collect) + if (!self->impl->collect) return 0; // Call the heartbeat function immediately @@ -130,11 +130,11 @@ static int collecty_module_init(collecty_module* self) { int r; // Do nothing if there is no init function - if (!self->methods->init) + if (!self->impl->init) return 0; // Initialize the module - r = self->methods->init(self->ctx); + r = self->impl->init(self->ctx); if (r < 0) { ERROR(self->ctx, "Failed to initialize %s: %s\n", collecty_module_name(self), strerror(-r)); @@ -144,8 +144,8 @@ static int collecty_module_init(collecty_module* self) { } static void collecty_module_free(collecty_module* self) { - if (self->methods->free) - self->methods->free(self->ctx); + if (self->impl->free) + self->impl->free(self->ctx); if (self->events.heartbeat) sd_event_source_unref(self->events.heartbeat); if (self->loop) @@ -158,7 +158,7 @@ static void collecty_module_free(collecty_module* self) { } int collecty_module_create(collecty_module** module, - collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_methods* methods) { + collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_impl* impl) { collecty_module* self = NULL; int r; @@ -179,8 +179,8 @@ int collecty_module_create(collecty_module** module, // Fetch a reference to the event loop self->loop = collecty_daemon_loop(daemon); - // Store the methods - self->methods = methods; + // Store the implementation + self->impl = impl; // Register heartbeat r = collecty_module_register_heartbeat(self); @@ -217,7 +217,7 @@ collecty_module* collecty_module_unref(collecty_module* self) { } const char* collecty_module_name(collecty_module* self) { - return self->methods->name; + return self->impl->name; } #define collecty_module_path(module, object, path) \ @@ -278,7 +278,7 @@ static int collecty_module_create_database(collecty_module* self, const char* pa goto ERROR; // Add all data sources - for (const collecty_rrd_ds* ds = self->methods->rrd_dss; ds->field; ds++) { + for (const collecty_rrd_ds* ds = self->impl->rrd_dss; ds->field; ds++) { // Format the minimum value r = collecty_format_number(min, ds->min); if (r < 0) @@ -304,7 +304,7 @@ static int collecty_module_create_database(collecty_module* self, const char* pa } // Add all custom round-robin archives - for (const collecty_rrd_rra* rra = self->methods->rrd_rras; rra->type; rra++) { + for (const collecty_rrd_rra* rra = self->impl->rrd_rras; rra->type; rra++) { r = collecty_args_push(args, "RRA:%s:%.2f:%s:%s", rra->type, XFF, rra->steps, rra->rows); if (r < 0) goto ERROR; @@ -424,7 +424,7 @@ int collecty_module_render(collecty_module* self, collecty_args* args, const cha return r; // Add all data sources - for (const collecty_rrd_ds* ds = self->methods->rrd_dss; ds->field; ds++) { + for (const collecty_rrd_ds* ds = self->impl->rrd_dss; ds->field; ds++) { r = collecty_module_render_add_DEF(self, args, path, ds, object); if (r < 0) return r; diff --git a/src/daemon/module.h b/src/daemon/module.h index c4db559..8be7c72 100644 --- a/src/daemon/module.h +++ b/src/daemon/module.h @@ -53,7 +53,7 @@ typedef struct collecty_rrd_rra { const char* rows; } collecty_rrd_rra; -typedef struct collecty_module_methods { +typedef struct collecty_module_impl { const char* name; // RRD Schema @@ -68,10 +68,10 @@ typedef struct collecty_module_methods { // Collect int (*collect)(collecty_ctx* ctx, collecty_module* module); -} collecty_module_methods; +} collecty_module_impl; int collecty_module_create(collecty_module** module, - collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_methods* methods); + collecty_ctx* ctx, collecty_daemon* daemon, const collecty_module_impl* impl); collecty_module* collecty_module_ref(collecty_module* self); collecty_module* collecty_module_unref(collecty_module* self); diff --git a/src/daemon/modules.c b/src/daemon/modules.c index 24c5eee..6634cd0 100644 --- a/src/daemon/modules.c +++ b/src/daemon/modules.c @@ -33,7 +33,7 @@ #include "modules/loadavg.h" // Register all modules -static const collecty_module_methods* module_impls[] = { +static const collecty_module_impl* module_impls[] = { &conntrack_module, &contextswitches_module, &loadavg_module, @@ -59,7 +59,7 @@ static int collecty_modules_init(collecty_modules* self) { int r; // Initialize all modules - for (const collecty_module_methods** impl = module_impls; *impl; impl++) { + for (const collecty_module_impl** impl = module_impls; *impl; impl++) { r = collecty_module_create(&module, self->ctx, self->daemon, *impl); if (r < 0) return r; diff --git a/src/daemon/modules/conntrack.c b/src/daemon/modules/conntrack.c index 0ecb5cd..dda367a 100644 --- a/src/daemon/modules/conntrack.c +++ b/src/daemon/modules/conntrack.c @@ -50,7 +50,7 @@ static int conntrack_collect(collecty_ctx* ctx, collecty_module* module) { return collecty_module_submit(module, NULL, "%" PRIu64 ":%" PRIu64, count, max); } -const collecty_module_methods conntrack_module = { +const collecty_module_impl conntrack_module = { .name = "conntrack", // RRD Data Sources diff --git a/src/daemon/modules/conntrack.h b/src/daemon/modules/conntrack.h index 60bdc07..68d555e 100644 --- a/src/daemon/modules/conntrack.h +++ b/src/daemon/modules/conntrack.h @@ -23,6 +23,6 @@ #include "../module.h" -extern const collecty_module_methods conntrack_module; +extern const collecty_module_impl conntrack_module; #endif /* COLLECTY_MODULE_CONNTRACK_H */ diff --git a/src/daemon/modules/contextswitches.c b/src/daemon/modules/contextswitches.c index 4b1cc72..bb3cf2a 100644 --- a/src/daemon/modules/contextswitches.c +++ b/src/daemon/modules/contextswitches.c @@ -117,7 +117,7 @@ static int contextswitches_collect(collecty_ctx* ctx, collecty_module* module) { return collecty_module_submit(module, NULL, "%lld", total); } -const collecty_module_methods contextswitches_module = { +const collecty_module_impl contextswitches_module = { .name = "contextswitches", // RRD Data Sources diff --git a/src/daemon/modules/contextswitches.h b/src/daemon/modules/contextswitches.h index d363de6..9753c7a 100644 --- a/src/daemon/modules/contextswitches.h +++ b/src/daemon/modules/contextswitches.h @@ -23,6 +23,6 @@ #include "../module.h" -extern const collecty_module_methods contextswitches_module; +extern const collecty_module_impl contextswitches_module; #endif /* COLLECTY_MODULE_CONTEXTSWITCHES_H */ diff --git a/src/daemon/modules/loadavg.c b/src/daemon/modules/loadavg.c index 15f9638..8579405 100644 --- a/src/daemon/modules/loadavg.c +++ b/src/daemon/modules/loadavg.c @@ -38,7 +38,7 @@ static int loadavg_collect(collecty_ctx* ctx, collecty_module* module) { "%f:%f:%f", loadavg[0], loadavg[1], loadavg[2]); } -const collecty_module_methods loadavg_module = { +const collecty_module_impl loadavg_module = { .name = "loadavg", // RRD Data Sources diff --git a/src/daemon/modules/loadavg.h b/src/daemon/modules/loadavg.h index 679a978..79083f7 100644 --- a/src/daemon/modules/loadavg.h +++ b/src/daemon/modules/loadavg.h @@ -23,6 +23,6 @@ #include "../module.h" -extern const collecty_module_methods loadavg_module; +extern const collecty_module_impl loadavg_module; #endif /* COLLECTY_MODULE_LOADAVG_H */