TR181-XPON  1.4.0
TR-181 PON manager.
persistency.h File Reference
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Functions

void persistency_init (void)
 
void persistency_cleanup (void)
 
const char * persistency_get_folder (void)
 
void persistency_enable (const char *const object, bool enable)
 
bool persistency_is_enabled (const char *const object)
 

Detailed Description

Functionality related to saving and querying the reboot persistent settings. The only read-write parameters in the BBF XPON DM which need to be reboot persistent are:

  • XPON.ONU.{i}.Enable and
  • XPON.ONU.{i}.ANI.{i}.Enable Hence functions in this header are related to saving and querying the values of those parameters. See doc at the top of persistency.c for more info about the implementation, more particularly why the implementation does not use the odl mechanism.

Definition in file persistency.h.

Function Documentation

◆ persistency_cleanup()

void persistency_cleanup ( void  )

Clean up the persistency part.

The plugin must call this function once when stopping.

Definition at line 198 of file persistency.c.

198  {
199  if(s_storage_dir) {
200  free(s_storage_dir);
201  s_storage_dir = NULL;
202  }
203 }
static char * s_storage_dir
Definition: persistency.c:118
Here is the caller graph for this function:

◆ persistency_enable()

void persistency_enable ( const char *const  object,
bool  enable 
)

Save whether object is enabled or disabled.

Parameters
[in]objectpath to object in DM being enabled/disabled, e.g., "XPON.ONU.1"
[in]enabletrue if object is enabled, else false

Definition at line 248 of file persistency.c.

248  {
249 
250  when_null_trace(s_storage_dir, exit, DEBUG, "No persistency");
251  when_null(object, exit);
252 
253  amxc_string_t file_path;
254  amxc_string_init(&file_path, 0);
255  create_enabled_file_path(&file_path, object);
256 
257  const char* const file_path_cstr = amxc_string_get(&file_path, 0);
258 
259  SAH_TRACEZ_DEBUG(ME, "object='%s enable=%d", object, enable);
260 
261  if(enable) {
262  touch_file(file_path_cstr);
263  } else {
264  unlink(file_path_cstr);
265  }
266 
267  amxc_string_clean(&file_path);
268 
269 exit:
270  return;
271 }
static void create_enabled_file_path(amxc_string_t *const file_path, const char *const object)
Definition: persistency.c:234
static void touch_file(const char *const file)
Definition: persistency.c:219
#define SAH_TRACEZ_DEBUG(zone, format,...)
Definition: xpon_trace.h:115
#define ME
Definition: xpon_trace.h:78
Here is the call graph for this function:
Here is the caller graph for this function:

◆ persistency_get_folder()

const char* persistency_get_folder ( void  )

Get the folder for reboot persistent settings for this plugin.

It typically returns "/etc/config/tr181-xpon/".

Definition at line 210 of file persistency.c.

210  {
211  return s_storage_dir;
212 }
Here is the caller graph for this function:

◆ persistency_init()

void persistency_init ( void  )

Initialize the persistency part.

Ask the parser for the storage dir. If the parser returns NULL, take STORAGE_DIR as storage dir. Create the storage dir if it does not exist. Store the selected dir in s_storage_dir upon success, else set s_storage_dir to NULL.

Under normal circumstances the parser returns the storage dir, the dir exists, and this function sets s_storage_dir to that value.

The plugin must call this function once at startup.

mkdir() can not create all folders in a path at once. But we assume that all folders except for the last one in s_storage_dir exist. It's also unlikely we end up here. amxrt normally has already created the folder.

Definition at line 161 of file persistency.c.

161  {
162 
163  char* dir = get_storage_dir();
164  SAH_TRACEZ_DEBUG(ME, "dir='%s'", dir ? dir : "NULL");
165 
166  s_storage_dir = strdup(dir ? dir : STORAGE_DIR);
167 
168  when_null_trace(s_storage_dir, exit, ERROR,
169  "Failed to allocate mem for s_storage_dir");
170 
171  if(access(s_storage_dir, R_OK | W_OK | X_OK) == 0) {
172  goto exit;
173  }
174 
175  SAH_TRACEZ_DEBUG(ME, "Create %s", s_storage_dir);
176 
183  if(mkdir(s_storage_dir, 0777) == -1) {
184  SAH_TRACEZ_ERROR(ME, "Failed to create %s", s_storage_dir);
185  free(s_storage_dir);
186  s_storage_dir = NULL;
187  }
188 
189 exit:
190  free(dir);
191 }
static char * get_storage_dir(void)
Definition: persistency.c:127
static const char *const STORAGE_DIR
Definition: persistency.c:115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ persistency_is_enabled()

bool persistency_is_enabled ( const char *const  object)

Return true if object identified by 'object' is enabled.

Parameters
[in]objectpath to object in DM being queried, e.g. "XPON.ONU.1".
Returns
true if object is enabled, else false.

Definition at line 280 of file persistency.c.

280  {
281 
282  bool rv = false;
283  when_null_trace(s_storage_dir, exit, DEBUG, "No persistency");
284  when_null(object, exit);
285 
286  amxc_string_t file_path;
287  amxc_string_init(&file_path, 0);
288  create_enabled_file_path(&file_path, object);
289 
290  const char* const file_path_cstr = amxc_string_get(&file_path, 0);
291 
292  rv = (access(file_path_cstr, F_OK) == 0) ? true : false;
293 
294  amxc_string_clean(&file_path);
295 
296 exit:
297  return rv;
298 }
Here is the call graph for this function:
Here is the caller graph for this function: