#include "module_mgmt.h"
#include <dlfcn.h>
#include <stdlib.h>
#include <unistd.h>
#include <amxc/amxc_macros.h>
#include <amxc/amxc.h>
#include <amxm/amxm.h>
#include <amxp/amxp_dir.h>
#include "data_model.h"
#include "pon_stat.h"
#include "pon_cfg.h"
#include "xpon_trace.h"
Go to the source code of this file.
◆ MOD_PON_CFG
◆ MOD_PON_STAT
#define MOD_PON_STAT "pon_stat" |
◆ pon_stat_function_t
◆ find_vendor_module()
static bool find_vendor_module |
( |
void |
| ) |
|
|
static |
Find vendor module in MODULES_PATH and assign its name to s_module_name.
Definition at line 213 of file module_mgmt.c.
215 const char*
const filter =
"d_type == DT_REG && d_name matches 'mod-xpon-.*\\.so'";
223 SAH_TRACEZ_ERROR(
ME,
"Failed to find vendor module");
static amxc_string_t s_module_name
static const char *const MODULES_PATH
static int handle_vendor_module_match(const char *name, void *priv UNUSED)
◆ handle_vendor_module_match()
static int handle_vendor_module_match |
( |
const char * |
name, |
|
|
void *priv |
UNUSED |
|
) |
| |
|
static |
Handle a module found by amxp_dir_scan() in find_vendor_module().
- Parameters
-
[in] | name | path to the vendor module, e.g., "/usr/lib/amx/tr181-xpon/modules/mod-xpon-prpl.so" |
- Returns
- 0 on success: amxp_dir_scan() should continue scanning
-
1 on error: amxp_dir_scan() should stop scanning
Definition at line 183 of file module_mgmt.c.
188 amxc_string_t module;
189 amxc_string_init(&module, 0);
190 amxc_string_setf(&module,
"%s", name);
192 amxc_string_replace(&module,
".so",
"", 1);
193 const char*
const module_cstr = amxc_string_get(&module, 0);
200 SAH_TRACEZ_ERROR(
ME,
"Found more than one vendor module");
201 SAH_TRACEZ_ERROR(
ME,
" modules found: %s.so, %s.so",
206 amxc_string_clean(&module);
void dm_set_vendor_module(const char *name)
#define SAH_TRACEZ_DEBUG(zone, format,...)
◆ load_vendor_module()
static bool load_vendor_module |
( |
void |
| ) |
|
|
static |
Find module with pattern 'mod-xpon-*.so' in MODULES_PATH and load it.
If the function finds a module:
- set s_module_name to the name of the module found, e.g. 'mod-xpon-prpl' if the function found 'mod-xpon-prpl.so' as vendor module in MODULES_PATH.
- set XPON.ModuleName in DM to the same name.
Set XPON.ModuleError to true if the function encounters one of the following errors:
- It fails to find a vendor module.
- It finds more than one vendor module. An image must only install 1 vendor module.
- It fails to load the module.
- Returns
- true on success, else false
Definition at line 246 of file module_mgmt.c.
250 amxc_string_t mod_path;
251 amxc_string_init(&mod_path, 0);
256 const char*
const module = amxc_string_get(&
s_module_name, 0);
257 amxc_string_setf(&mod_path,
"%s%s.so",
MODULES_PATH, module);
259 const char*
const path_to_so = amxc_string_get(&mod_path, 0);
261 if(access(path_to_so, F_OK) != 0) {
262 SAH_TRACEZ_ERROR(
ME,
"%s does not exist", path_to_so);
266 if(amxm_so_open(&
s_module_so, module, path_to_so)) {
267 const char* error = dlerror();
268 SAH_TRACEZ_ERROR(
ME,
"Failed to load %s module", module);
269 SAH_TRACEZ_ERROR(
ME,
"dlerror(): '%s'", error ? error :
"No error");
279 amxc_string_clean(&mod_path);
void dm_set_module_error(void)
static amxm_shared_object_t * s_module_so
static bool find_vendor_module(void)
◆ mod_get_vendor_module_loaded()
const char* mod_get_vendor_module_loaded |
( |
void |
| ) |
|
Return the name of the vendor module the plugin loaded at startup.
- Returns
- the name of that vendor module upon success
-
NULL if the plugin failed to load the vendor module at startup
Definition at line 326 of file module_mgmt.c.
◆ mod_module_mgmt_cleanup()
void mod_module_mgmt_cleanup |
( |
void |
| ) |
|
Clean up the module_mgmt part of this plugin.
The function does the reverse of mod_module_mgmt_init():
- unload the vendor module
- unregisters the namespaces 'pon_stat' and 'pon_cfg'
The plugin must call this function once when stopping.
Definition at line 340 of file module_mgmt.c.
344 SAH_TRACEZ_ERROR(
ME,
"Failed to close module");
static amxm_module_t * s_pon_cfg_module
static amxm_module_t * s_pon_stat_module
◆ mod_module_mgmt_init()
bool mod_module_mgmt_init |
( |
bool * |
module_error | ) |
|
Initialize the module_mgmt part of this plugin.
The function:
- registers the namespaces 'pon_stat' and 'pon_cfg'. The namespaces have functions which can be called by the vendor module.
- loads the vendor module.
The plugin must call this function once at startup.
- Parameters
-
[in,out] | module_error | the function sets it to true if it encounters an error regarding (the loading of) the vendor module |
- Returns
- true on success, else false
Definition at line 299 of file module_mgmt.c.
313 *module_error =
true;
static bool load_vendor_module(void)
static bool register_pon_cfg_module(void)
static bool register_pon_stat_module(void)
◆ register_pon_cfg_module()
static bool register_pon_cfg_module |
( |
void |
| ) |
|
|
static |
Definition at line 145 of file module_mgmt.c.
148 amxm_shared_object_t* so = amxm_get_so(
"self");
150 SAH_TRACEZ_ERROR(
ME,
"Failed to get amxm_shared_object_t for self");
155 SAH_TRACEZ_ERROR(
ME,
"Failed to register %s module namespace",
MOD_PON_CFG);
163 SAH_TRACEZ_ERROR(
ME,
"Failed to register self.%s.%s()",
MOD_PON_CFG,
static const pon_stat_function_t PON_CFG_FUNCTIONS[]
◆ register_pon_stat_module()
static bool register_pon_stat_module |
( |
void |
| ) |
|
|
static |
Definition at line 117 of file module_mgmt.c.
120 amxm_shared_object_t* so = amxm_get_so(
"self");
122 SAH_TRACEZ_ERROR(
ME,
"Failed to get amxm_shared_object_t for self");
127 SAH_TRACEZ_ERROR(
ME,
"Failed to register %s module namespace",
MOD_PON_STAT);
135 SAH_TRACEZ_ERROR(
ME,
"Failed to register self.%s.%s()",
MOD_PON_STAT,
static const pon_stat_function_t PON_STAT_FUNCTIONS[]
◆ MODULES_PATH
const char* const MODULES_PATH = "/usr/lib/amx/tr181-xpon/modules/" |
|
static |
◆ PON_CFG_FUNCTIONS
Initial value:= {
{ .name = NULL, .impl = NULL }
}
int pon_cfg_get_param_value(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
Definition at line 111 of file module_mgmt.c.
◆ PON_STAT_FUNCTIONS
Initial value:= {
{ .name = NULL, .impl = NULL }
}
int dm_instance_added(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
int watch_file_descriptor_start(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
int dm_object_changed(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
int dm_instance_removed(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
int dm_add_or_change_instance(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
int watch_file_descriptor_stop(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
int dm_set_xpon_parameter(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
int omci_reset_mib(const char *function_name, amxc_var_t *args, amxc_var_t *ret)
Definition at line 98 of file module_mgmt.c.
◆ s_module_name
amxc_string_t s_module_name |
|
static |
◆ s_module_so
amxm_shared_object_t* s_module_so = NULL |
|
static |
◆ s_pon_cfg_module
amxm_module_t* s_pon_cfg_module = NULL |
|
static |
◆ s_pon_stat_module
amxm_module_t* s_pon_stat_module = NULL |
|
static |