yp-system

The following API functions should be defined in all yp-library implementations:

  • yp_system_init_profile: Change default settings in the server profile defined in agt/agt.h

  • yp_system_init1: Phase 1 initialization function

  • yp_system_init2: Phase 2 initialization function

  • yp_system_cleanup: Server cleanup function

The following example shows example-system.h contents from the libsystem/src directory:

#ifndef _H_example_system
#define _H_example_system
/* 
 * Copyright (c) 2012 - 2014, YumaWorks, Inc., All Rights Reserved.
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */

#ifndef _H_agt
#include "agt.h"
#endif

#ifndef _H_status
#include "status.h"
#endif


/* system init server profile callback
 *
 * Initialize the server profile if needed
 *
 * INPUTS:
 *  profile == server profile to change if needed
 */
extern void yp_system_init_profile (agt_profile_t *profile);


/* system init1 callback
 * init1 system call
 * this callback is invoked twice; before and after CLI processing
 * INPUTS:
 * pre_cli == TRUE if this call is before the CLI parameters
 *            have been read
 *            FALSE if this call is after the CLI parameters
 *            have been read
 * RETURNS:
 *  status; error will abort startup
 */
extern status_t yp_system_init1 (boolean pre_cli);


/* system init2 callback
 * init2 system call
 * this callback is invoked twice; before and after 
 * load_running_config processing
 *
 * INPUTS:
 * pre_load == TRUE if this call is before the running config
 *            has been loaded
 *            FALSE if this call is after the running config
 *            has been loaded
 * RETURNS:
 *  status; error will abort startup
 */
extern status_t yp_system_init2 (boolean pre_load);


/* system cleanup callback
 * this callback is invoked once during agt_cleanup
 */
extern void yp_system_cleanup (void);


#endif

yp_system_init_profile

This function is used to modify the defaults in the agt_profile_t Struct used by the server. This allows features and various behavior to be configured. Many of these settings have associated CLI/conf parameters that can change the default at run-time. Refer to the agt_profile_t Struct section for details on the contents of the Agent Profile structure.

typedef void (*agt_system_init_profile_fn_t)(agt_profile_t *profile)

system init server profile callback

Initialize the server profile if needed

Param profile

server profile to change if needed

The contents of this function should set profile fields as needed.

Note that if the field has a CLI override parameter with a default value, then the YANG default for that parameter needs to be changed if the profile default is changed.

Example Profile Initialization Function

This example profile initialization function shows how to disable all the Yuma YANG modules:

void yp_system_init_profile (agt_profile_t *profile);
{

    profile->agt_use_yuma_arp = false;
    profile->agt_use_yuma_if = false;
    profile->agt_use_yuma_mysession = false;
    profile->agt_use_yuma_proc = false;
    profile->agt_use_yuma_proc = false;

} /* yp_system_init_profile */

yp_system_init1

This function is used to initialize the server during phase 1 initialization.

This function is called twice during system initialization:

  1. pre_cli = TRUE: Called before the CLI and conf file parameters have been processed

  2. pre_cli = FALSE: Called after the CLI and conf file parameters have been processed

typedef status_t (*agt_system_init1_fn_t)(boolean pre_cli)

system init1 callback

init1 system call this callback is invoked twice; before and after CLI processing

Param pre_cli

TRUE if this call is before the CLI parameters have been read

FALSE if this call is after the CLI parameters have been read

Return

status; error will abort startup

This function should register system callback functions and setup the system.

The first time the function is called the pre_cli flag is true. This is before the CLI and config file parameters have been applied. The second time the function is called the pre_cli flag is false. This is after the CLI and config file parameters have been applied.

Example Phase 1 Initialization Function

This example phase 1 initialization function shows setup of external vendor logging and external access control model callbacks :

/* system init1 callback
 * init1 system call
 * this callback is invoked twice; before and after CLI processing
 * INPUTS:
 * pre_cli == TRUE if this call is before the CLI parameters
 *            have been read
 *            FALSE if this call is after the CLI parameters
 *            have been read
 * RETURNS:
 *  status; error will abort startup
 */
status_t yp_system_init1 (boolean pre_cli)
{
    if (pre_cli) {
        // example -- register vendor callback to consume logging output.
        log_vendor_extern_register_send_fn(log_vendor_send_fn);
    } else {
        // example -- external NACM callbacks
        // load module for external module
        // with ncxmod_load_module

        // register the external ACM callbacks
        // this will have no affect unless the
        // yp_system_init_profile fn sets the
        // agt_acm_model to AGT_ACM_MODEL_EXTERNAL
        agt_acm_extern_register_callbacks(acm_extern_rpc,
                                          acm_extern_notif,
                                          acm_extern_write,
                                          acm_extern_read);
    }
    return NO_ERR;
}  /* yp_system_init1 */

yp_system_init2

This function is used to initialize the server during phase 2 initialization. This function is invoked after all phase 1 initialization has been successfully completed.

The first time the function is called the pre_load flag is true. This is before the running configuration has been initialized. The second time the function is called the pre_load flag is false. This is after the running configuration has been initialized with configuration from non-volatile storage and YANG defaults.

This function should initialize global callbacks based configuration settings.

typedef status_t (*agt_system_init2_fn_t)(boolean pre_load)

system init2 callback

init2 system call this callback is invoked twice; before and after load_running_config processing

Param pre_load

TRUE if this call is before the running config has been loaded

FALSE if this call is after the running config has been loaded

Return

status; error will abort startup

Example Phase 2 Initialization Function

This example phase 2 initialization function shows the general structure of the code for this function.

/* system init2 callback
 * init2 system call
 * this callback is invoked twice; before and after
 * load_running_config processing
 *
 * INPUTS:
 * pre_load == TRUE if this call is before the running config
 *            has been loaded
 *            FALSE if this call is after the running config
 *            has been loaded
 * RETURNS:
 *  status; error will abort startup
 */

status_t yp_system_init2 (boolean pre_load)
{
    log_debug("\nyp_system init2\n");

    if (pre_load) {
        ;
    } else {
        ;
    }
    return NO_ERR;
}

yp_system_cleanup

This function is used to cleanup the system when the server is shutting down or restarting.

typedef void (*agt_system_cleanup_fn_t)(void)

system cleanup callback

this callback is invoked once during agt_cleanup

Example Phase 2 Initialization Function

This example cleanup function shows the general structure of the code for this function.

/* system cleanup callback
 * this callback is invoked once during agt_cleanup
 */
void yp_system_cleanup (void)
{
    log_debug("\nyp_system cleanup\n");

    /* put your cleanup function calls here */

} /* system cleanup callback */