/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * bbfdm_plugin.h - header file for data model plugin.
 *
 * Copyright (C) 2023-2024 IOPSYS Software Solutions AB. All rights reserved.
 * Copyright (C) 2025-2026 Genexis AB.
 *
 *
 * See LICENSE file for license related information.
 *
 * Author: Amin Ben Romdhane <amin.benromdhane@iopsys.eu>
 *
 */

#ifndef BBFDM_PLUGIN_H
#define BBFDM_PLUGIN_H

/**
 * bbfdm_plugin_init - Initialize the TR-181 data model plugin.
 *
 * Sets up the module-private bbfdm context: registers the service
 * name, configures the log level, and loads the static data model
 * object table.
 *
 * When @dm_type is greater than zero the function prints the data
 * model schema to stdout and calls exit(), so it does not return in
 * that case.  This mirrors the --dm-type command-line option used for
 * schema introspection.
 *
 * Must be called before wifimngr_init() so that the data model is
 * ready before any ubus objects are registered.
 *
 * @dm_type:  Data model schema type selector passed from the command
 *            line (opts->dm_type).  Pass 0 for normal operation.
 * @loglevel: Verbosity level from the command line (opts->loglevel).
 *            The bbfdm layer applies an internal offset to this value.
 *
 * Return: 0 on success, negative errno on failure.
 *         Does not return when @dm_type > 0.
 */
int bbfdm_plugin_init(int dm_type, int loglevel);

/**
 * bbfdm_plugin_register - Register the data model on ubus.
 *
 * Binds the bbfdm context to the live ubus connection that was opened
 * by wifimngr_init(), stores a pointer to the wifimngr instance for
 * use by TR-181 handler callbacks, and calls bbfdm_ubus_register_init()
 * to publish all TR-181 objects on the bus.
 *
 * Must be called after wifimngr_init() has succeeded so that
 * @w->ubus_ctx is valid.
 *
 * @w: Pointer to the fully initialised wifimngr instance.
 *     Must not be NULL.
 *
 * Return: 0 on success, negative value on failure (the ubus
 *         registration failed and the data model is not active).
 */
int bbfdm_plugin_register(struct wifimngr *w);

/**
 * bbfdm_plugin_free - Release all resources held by the plugin.
 *
 * Deregisters all bbfdm ubus objects and frees the internal bbfdm
 * context.
 *
 * Must be called after wifimngr_run() returns and before
 * wifimngr_exit(), so that the ubus context in @w is still valid
 * during teardown.
 *
 * @w: Pointer to the wifimngr instance passed to bbfdm_plugin_register().
 *     Currently unused but kept for API symmetry and future use.
 *
 * Return: 0 (always succeeds).
 */
int bbfdm_plugin_free(struct wifimngr *w);

#endif /* BBFDM_PLUGIN_H */
