The NV-Save callback function is a user callback that is invoked when the running configuration needs to be saved to non-volatile storage. A configuration filespec is passed to this callback that contains the configuration that needs to be saved to non-volatile storage.
The following function template definition is used for NV-Save callback functions:
/* Typedef of the callback */
typedef status_t
(*agt_nvsave_fn_t) (ncx_display_mode_t encoding,
const xmlChar *filespec);The agt_register_local_nv_handler function is used to declare the NV-Save callback. The registration can be done during the Initialization Phase 2, after the running configuration has been loaded from the startup file.
Initialization function with the NV- Save callback registration may look as follows:
#define EXAMPLECONFIG_SPEC (const xmlChar *)"/tmp/example-config.xml"
/********************************************************************
* FUNCTION interfaces_init2
*
* initialize the server instrumentation library.
* Initialization Phase 2
*
*********************************************************************/
static status_t
interfaces_init2 (void)
{
...
/* register NV-storage handler to load/save config
* uncomment following to enable
*/
res = agt_register_local_nv_handler(nvload_callback,
nvsave_callback);
if (res != NO_ERR) {
return res;
}
...
}There is no cleanup function for this callback. The cleanup will be done automatically by the server.
The following example code illustrates how the NV-Save callback may look like.
/********************************************************************
* FUNCTION nvsave_callback
*
* this callback is invoked when some config needs to be saved
* to non-volatile storage
*
* INPUTS:
* encoding == encoding format for the config (xml only allowed value)
* filespec == filespec containing the config to save
* RETURNS:
* status; error indicates NV-save failed somehow
*
*********************************************************************/
static status_t
example_nvsave (ncx_display_mode_t encoding,
const xmlChar *filespec)
{
status_t res = NO_ERR;
if (filespec == NULL || *filespec == 0) {
res = ERR_NCX_INVALID_VALUE;
} else if (encoding != NCX_DISPLAY_MODE_XML) {
res = ERR_NCX_INVALID_VALUE;
} else {
res = ncxmod_copy_text_file(filespec, EXAMPLE_CONFIG_SPEC);
}
return res;
} /* nvsave_callback */
Now, when some configuration needs to be saved to Non-Volatile storage this callback function will try to save specified configuration into specific Non-Volatile storage.