--- /dev/null
+/*#############################################################################
+# #
+# collecty - A system statistics collection daemon for IPFire #
+# Copyright (C) 2025 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#include <errno.h>
+#include <stdlib.h>
+
+#include "ctx.h"
+#include "daemon.h"
+
+struct collecty_daemon {
+ collecty_ctx* ctx;
+ int nrefs;
+};
+
+static void collecty_daemon_free(collecty_daemon* daemon) {
+ if (daemon->ctx)
+ collecty_ctx_unref(daemon->ctx);
+}
+
+int collecty_daemon_create(collecty_daemon** daemon, collecty_ctx* ctx) {
+ collecty_daemon* self = NULL;
+
+ // Allocate some memory
+ self = calloc(1, sizeof(*self));
+ if (!self)
+ return -errno;
+
+ // Initialize the reference counter
+ self->nrefs = 1;
+
+ // Store a reference to the context
+ self->ctx = collecty_ctx_ref(ctx);
+
+ // Return the pointer
+ *daemon = self;
+
+ return 0;
+}
+
+collecty_daemon* collecty_daemon_ref(collecty_daemon* daemon) {
+ ++daemon->nrefs;
+ return daemon;
+}
+
+collecty_daemon* collecty_daemon_unref(collecty_daemon* daemon) {
+ if (--daemon->nrefs > 0)
+ return daemon;
+
+ collecty_daemon_free(daemon);
+ return NULL;
+}
--- /dev/null
+/*#############################################################################
+# #
+# collecty - A system statistics collection daemon for IPFire #
+# Copyright (C) 2025 IPFire Development Team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+#############################################################################*/
+
+#ifndef COLLECTY_DAEMON_H
+#define COLLECTY_DAEMON_H
+
+typedef struct collecty_daemon collecty_daemon;
+
+#include "ctx.h"
+
+int collecty_daemon_create(collecty_daemon** daemon, collecty_ctx* ctx);
+
+collecty_daemon* collecty_daemon_ref(collecty_daemon* daemon);
+collecty_daemon* collecty_daemon_unref(collecty_daemon* daemon);
+
+#endif /* COLLECTY_DAEMON_H */