6   SIL External Interface

Each SIL has 2 initialization functions and 1 cleanup function that must be present.

These are the only SIL functions that the server will invoke directly.  They are generated by yangdump-pro  with the --format parameter, and usually do not require any editing by the developer.

 

Most of the work done by SIL code is through callback functions for specific RPC operations and database objects.  These callback functions are usually registered during the initialization functions.

6.1  Stage 1 Initialization

The stage 1 initialization function is the first function called in the library by the server.

If the netconfd-pro configuration parameters include a 'load' command for the module, then this function will be called during server initialization.  It can also be called if the <load> operation is invoked during server operation.

This function MUST NOT attempt to access any database.  There will not be any configuration databases if this function is called during server initialization.  Use the 'init2' function to adjust the running configuration.

This callback function is expected to perform the following functions:

 

Name Format:

y_<modname>_init

Input:

Returns:

Example function generated by yangdump-pro:

 

 

/********************************************************************

* FUNCTION y_toaster_init

*

* initialize the toaster server instrumentation library

*

* INPUTS:

*    modname == requested module name

*    revision == requested version (NULL for any)

*

* RETURNS:

*     error status

********************************************************************/

status_t

    y_toaster_init (

        const xmlChar *modname,

        const xmlChar *revision)

{

    agt_profile_t *agt_profile;

    status_t res;

 

    y_toaster_init_static_vars();

 

    /* change if custom handling done */

    if (xml_strcmp(modname, y_toaster_M_toaster)) {

        return ERR_NCX_UNKNOWN_MODULE;

    }

 

    if (revision && xml_strcmp(revision, y_toaster_R_toaster)) {

        return ERR_NCX_WRONG_VERSION;

    }

 

    agt_profile = agt_get_profile();

 

    res = ncxmod_load_module(

        y_toaster_M_toaster,

        y_toaster_R_toaster,

        &agt_profile->agt_savedevQ,

        &toaster_mod);

    if (res != NO_ERR) {

        return res;

    }

 

    toaster_obj = ncx_find_object(

        toaster_mod,

        y_toaster_N_toaster);

    if (toaster_mod == NULL) {

        return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);

    }

 

    make_toast_obj = ncx_find_object(

        toaster_mod,

        y_toaster_N_make_toast);

    if (toaster_mod == NULL) {

        return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);

    }

 

    cancel_toast_obj = ncx_find_object(

        toaster_mod,

        y_toaster_N_cancel_toast);

    if (toaster_mod == NULL) {

        return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);

    }

 

    toastDone_obj = ncx_find_object(

        toaster_mod,

        y_toaster_N_toastDone);

    if (toaster_mod == NULL) {

        return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);

    }

 

    res = agt_rpc_register_method(

        y_toaster_M_toaster,

        y_toaster_N_make_toast,

        AGT_RPC_PH_VALIDATE,

        y_toaster_make_toast_validate);

    if (res != NO_ERR) {

        return res;

    }

 

    res = agt_rpc_register_method(

        y_toaster_M_toaster,

        y_toaster_N_make_toast,

        AGT_RPC_PH_INVOKE,

        y_toaster_make_toast_invoke);

    if (res != NO_ERR) {

        return res;

    }

 

    res = agt_rpc_register_method(

        y_toaster_M_toaster,

        y_toaster_N_cancel_toast,

        AGT_RPC_PH_VALIDATE,

        y_toaster_cancel_toast_validate);

    if (res != NO_ERR) {

        return res;

    }

 

    res = agt_rpc_register_method(

        y_toaster_M_toaster,

        y_toaster_N_cancel_toast,

        AGT_RPC_PH_INVOKE,

        y_toaster_cancel_toast_invoke);

    if (res != NO_ERR) {

        return res;

    }

 

    res = agt_cb_register_callback(

        y_toaster_M_toaster,

        (const xmlChar *)"/toaster",

        (const xmlChar *)"2009-11-20",

        y_toaster_toaster_edit);

 

 

    if (res != NO_ERR) {

        return res;

    }

 

    /* put your module initialization code here */

 

    return res;

} /* y_toaster_init */

 

 

 

6.2  Stage 2 Initialization

The stage 2 initialization function is the second function called in the library by the server:

Note that configuration data structures that are loaded during server initialization (load_running_config) will be handled by the database callback functions registered during phase 1 initialization.

Any server-created configuration nodes should be created during phase 2 initialization (this function), after examining the explicitly-provided configuration data.  For example, the top-level /nacm container will be created (by agt_acm.c) if it is not provided in the startup configuration.

 

This callback function is expected to perform the following functions:

Name Format:

y_<modname>_init2

Returns:

Example function generated by yangdump-pro:

 

 

/********************************************************************

* FUNCTION y_toaster_init2

*

* SIL init phase 2: non-config data structures

* Called after running config is loaded

*

* RETURNS:

*     error status

********************************************************************/

 

status_t

    y_toaster_init2 (void)

{

    status_t res = NO_ERR;

 

    toaster_val = agt_init_cache(

        y_toaster_M_toaster,

        y_toaster_N_toaster,

        &res);

    if (res != NO_ERR) {

        return res;

    }

 

    /* put your init2 code here */

 

    return res;

} /* y_toaster_init2 */

 

6.3  Cleanup

The cleanup function is called during server shutdown.  It is only called if the stage 1 initialization function is called.  It will be called right away if either the stage 1 or stage 2 initialization functions return a non-zero error status.

This callback function is expected to perform the following functions:

Name Format:

y_<modname>_cleanup

Example function generated by yangdump-pro:

 

 

/********************************************************************

* FUNCTION y_toaster_cleanup

*    cleanup the server instrumentation library

*

********************************************************************/

void

    y_toaster_cleanup (void)

{

    agt_rpc_unregister_method(

        y_toaster_M_toaster,

        y_toaster_N_make_toast);

 

    agt_rpc_unregister_method(

        y_toaster_M_toaster,

        y_toaster_N_cancel_toast);

 

 

 

   agt_cb_unregister_callbacks(

        y_toaster_M_toaster,

        (const xmlChar *)"/toaster");

 

    /* put your cleanup code here */

 

} /* y_toaster_cleanup */