junos_init.h File Reference

Daemon initialization APIs for use by JUNOS SDK applications. More...


Typedefs

typedef option option_t
 Command line option entry.
typedef int(* junos_app_cb_config_read_t )(int)
 Configuration database read callback.
typedef int(* junos_app_cb_init_t )(evContext)
 Application initialization callback.
typedef int(* junos_app_cb_cmd_line_opts_t )(char, char *)
 Command line option processing callback.
typedef void(* junos_app_cb_mastership_switch_t )(bool)
 Mastership switch notifcation callback.
typedef void(* junos_app_cb_mgmt_sock_close_t )(mgmt_sock_t *)
 UI management socket close callback.
typedef void * junos_sdk_app_ctx_t
 JUNOS SDK application context.

Functions

int junos_app_init (junos_sdk_app_ctx_t ctx)
 Initializes the JUNOS SDK application's environment.
junos_sdk_app_ctx_t junos_create_app_ctx (int argc, char **argv, const char *app_name, const parse_menu_t *master_menu, const char *package_name, unsigned seq_no)
 Creates an application context object for a deamon.
int junos_destroy_app_ctx (junos_sdk_app_ctx_t app_ctx)
 Destroy an application context object.
int junos_get_cmd_line_args (junos_sdk_app_ctx_t app_ctx, int *argc_p, char ***argv_p)
 Return the arguments passed to the application on the command line.
int junos_reg_cmd_line_opts (junos_sdk_app_ctx_t app_ctx, const option_t *longopts)
 call this API to register the command line options interested.
int junos_set_app_cb_config_read (junos_sdk_app_ctx_t app_ctx, junos_app_cb_config_read_t config_read)
 Set a function to be used as a call back to handle reading application- specific configuration.
int junos_set_app_cb_cmd_line_opts (junos_sdk_app_ctx_t app_ctx, junos_app_cb_cmd_line_opts_t cmd_line_proc)
 Set a function be be used as a call back for command line option processing.
int junos_set_app_cb_init (junos_sdk_app_ctx_t ctx, junos_app_cb_init_t app_init)
 Set a function to be used as a call back for application-specific initialization.
int junos_set_app_cb_mastership_switch (junos_sdk_app_ctx_t ctx, junos_app_cb_mastership_switch_t mastership_switch)
 Set a function be be used as a call back to notify when mastership switches.
int junos_set_app_cb_mgmt_sock (junos_sdk_app_ctx_t ctx, junos_app_cb_mgmt_sock_close_t mgmt_sock_close)
 Register management socket close callback.
int junos_set_app_cfg_trace_path (junos_sdk_app_ctx_t app_ctx, const char **sdk_trace_path)
 Sets the configuration path to use when reading traceoptions.
void junos_sig_register (int32_t signo, void(*sig_handler)(int))
 Registers a signal handler with the JUNOS signal infrastructure.
int junos_app_log_enable (junos_sdk_app_ctx_t app_ctx)
 Sets the flag to indicate that non-daemon application requires logging.
int junos_app_event_loop_enable (junos_sdk_app_ctx_t app_ctx)
 Sets the flag to indicate that non- daemon application uses event loop.
int junos_set_app_event_ctx (junos_sdk_app_ctx_t app_ctx, evContext app_event_ctx)
 Sets event context provided by the application.
junos_sdk_app_ctx_t junos_app_create_non_daemon_ctx (int argc, char **argv, const char *app_name, const char *package_name, unsigned seq_no)
 Creates a non-daemon application context.


Detailed Description

Daemon initialization APIs for use by JUNOS SDK applications.

The functions in this file simplify and streamline the initialization and operation of daemons within JUNOS.


Function Documentation

junos_sdk_app_ctx_t junos_app_create_non_daemon_ctx int  argc,
char **  argv,
const char *  app_name,
const char *  package_name,
unsigned  seq_no
 

Creates a non-daemon application context.

The junos_app_create_non_daemon_ctx() is the first function that should be called by a non-daemon application. Called directly from main(), junos_app_create_non_daemon_ctx() allocates memory for context and then sets the non-daemon flag and disables logging, tracing and event loops for JUNOS non-daemon applications.

Parameters:
[in] argc Number of arguments passed to main()
[in] argv Pointer to array of argument values (also passed to main())
[in] app_name Name of application as a string in quotation marks
[in] package_name Optional: NULL may be specified.
[in] seq_no The configuration database sequence number.
Returns:
Pointer a junos_sdk_app_ctx_t object, not NULL indicating success; NULL indicating failure.

int junos_app_event_loop_enable junos_sdk_app_ctx_t  app_ctx  ) 
 

Sets the flag to indicate that non- daemon application uses event loop.

Note:
This should not be called for daemon applications as this flag will be set by default.
Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx.
Returns:
0 indicating success; -1 indicating failure.

int junos_app_init junos_sdk_app_ctx_t  app_ctx  ) 
 

Initializes the JUNOS SDK application's environment.

The junos_app_init() function provides an environment required for a JUNOS daemon. Called directly from main(), junos_app_init() performs initialization operations required of all daemons within JUNOS. This API should be called by the main thread. In multithreaded applications, no threads must be created prior to calling this function. Daemon applications may create threads in the initialization callback function. Non-daemon applications may create threads after this function returns.

The order of operations performed are as follows:

  • If a DDL traceoptions path has been set, the configuration database is opened and traceoptions are read at the specified path.
  • If an initialization callback has been set, it will be called to perform any additional initialization needed by the daemon.
  • If a configuration read callback has been set, the configuration database is opened and the callback function is called to read and apply the application's configuration.
  • Lastly, the process is converted into a daemon and enters the ISC event loop.
Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
Returns:
0 indicating success; -1 indicating failure.
See also:
junos_set_app_cb_init

int junos_app_log_enable junos_sdk_app_ctx_t  app_ctx  ) 
 

Sets the flag to indicate that non-daemon application requires logging.

Note:
This should not be called for daemon applications as this flag will be set by default.
Parameters:
[in] app_ctx Pointer to the application context object
Returns:
0 indicating success; -1 indicating failure.

junos_sdk_app_ctx_t junos_create_app_ctx int  argc,
char **  argv,
const char *  app_name,
const parse_menu_t *  master_menu,
const char *  package_name,
unsigned  seq_no
 

Creates an application context object for a deamon.

This is the first call that should be made by a daemon application (exception is when you need to call patricia_set_allocator). It creates an application context object which will be used to store all information related to an application or daemon. This API should be called by the main thread.

Parameters:
[in] argc Number of arguments passed to main()
[in] argv Pointer to array of argument values (also passed to main())
[in] app_name Name of application as a string in quotation marks
[in] master_menu An array specifying functions to be run on CLI command mode requests.
[in] package_name Optional: NULL may be specified.
[in] seq_no The configuration database sequence number.
Returns:
Pointer a junos_sdk_app_ctx_t object, not NULL indicating success; NULL indicating failure.

int junos_destroy_app_ctx junos_sdk_app_ctx_t  app_ctx  ) 
 

Destroy an application context object.

This should be called to free up memory allocated by junos_create_app_ctx() when it is no longer needed. This should be called by the main thread.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
Returns:
always return 0

int junos_get_cmd_line_args junos_sdk_app_ctx_t  app_ctx,
int *  argc_p,
char ***  argv_p
 

Return the arguments passed to the application on the command line.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx.
[out] argc_p Pointer to location to store the number of string arguments in the array pointer stored in the location provided by argv_p
[out] argv_p Pointer to location to store a pointer to the array of argument strings.
Returns:
0 indicating success; -1 indicating failure. On failure, errno will be set to one of the following:
  • EINVAL Invalid argument

int junos_reg_cmd_line_opts junos_sdk_app_ctx_t  app_ctx,
const option_t longopts
 

call this API to register the command line options interested.

This API should be called by the main thread.

Note:
When using this API, you should not use the following options "ld:NvXC" as they are used by junos_app_init(). Using any of these as your command options will cause junos_app_init() to fail.
Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
[in] longopts An arrray of command line options the application is interested in parsing.
Returns:
0 indicating success; -1 indicating failure. On failure, errno will be set to one of the following:
  • EALREADY Command line options already set
  • EINVAL Invalid argument
  • ENOMEM Out of memory

int junos_set_app_cb_cmd_line_opts junos_sdk_app_ctx_t  app_ctx,
junos_app_cb_cmd_line_opts_t  cmd_line_proc
 

Set a function be be used as a call back for command line option processing.

This API should be called by the main thread.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
[in] cmd_line_proc Pointer to an application callback function that handles processing application command line options.
Returns:
0 indicating success; -1 indicating failure.

int junos_set_app_cb_config_read junos_sdk_app_ctx_t  app_ctx,
junos_app_cb_config_read_t  config_read
 

Set a function to be used as a call back to handle reading application- specific configuration.

This API should be called by the main thread.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
[in] config_read Pointer to an application callback function that reads the application's portion of the configuration database. This function is called during initialization as well as each time a configuration change affecting the application is committed. Optional: NULL may be specified.
Returns:
0 indicating success; -1 indicating failure.

int junos_set_app_cb_init junos_sdk_app_ctx_t  app_ctx,
junos_app_cb_init_t  app_init
 

Set a function to be used as a call back for application-specific initialization.

The call back function app_init will be called after traceoption reading and before all other configuration reading during application startup. This API should be called by the main thread. Daemon applications may create additional threads in the initialization callback function which is passed as parameter to this function.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
[in] app_init Pointer to an application callback function that carries out initialization activities specific to the application. If the application needs to open any sockets, register for routing socket notifications, etc., these tasks should be done within this function.
Returns:
0 indicating success; -1 indicating failure.

int junos_set_app_cb_mastership_switch junos_sdk_app_ctx_t  app_ctx,
junos_app_cb_mastership_switch_t  mastership_switch
 

Set a function be be used as a call back to notify when mastership switches.

This API should be called by the main thread.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
[in] mastership_switch Pointer to an application callback function that handles processing mastership switch notification.
Returns:
0 indicating success; -1 indicating failure.

int junos_set_app_cb_mgmt_sock junos_sdk_app_ctx_t  app_ctx,
junos_app_cb_mgmt_sock_close_t  mgmt_sock_close_cb
 

Register management socket close callback.

This API should be called by the main thread.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx().
[in] mgmt_sock_close_cb Pointer to the management socket close callback function.
Returns:
0 indicating success; -1 indicating failure.

int junos_set_app_cfg_trace_path junos_sdk_app_ctx_t  app_ctx,
const char **  sdk_trace_path
 

Sets the configuration path to use when reading traceoptions.

This API should be called by the main thread.

Note:
When using this API, you should not call junos_trace_read_config() in your configuration read callback.
Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx.
[in] sdk_trace_path DDL path to traceoptions configuration object
Returns:
0 indicating success; -1 indicating failure. On failure, errno will be set to one of the following:
  • EINVAL Invalid argument
See also:
junos_trace_read_config

int junos_set_app_event_ctx junos_sdk_app_ctx_t  app_ctx,
evContext  app_event_ctx
 

Sets event context provided by the application.

Parameters:
[in] app_ctx Pointer to the application context object returned by junos_create_app_ctx.
[in] app_event_ctx Event context provided by the application
Returns:
0 indicating success; -1 indicating failure.

void junos_sig_register int32_t  signo,
void(*)(int)  sig_handler
 

Registers a signal handler with the JUNOS signal infrastructure.

When the specified signal is received, the handler will be called as soon as possible within the process context.

SIGUP is reserved for use in notifying daemons of configuration changes, therefore it is unavailable for use with this function. This API should be called only by the main thread. All the signals registered with this function and SIGHUP should be masked in any additional threads created by the JUNOS SDK application.

Parameters:
[in] signo Signal number
[in] sig_handler Pointer to the signal handler to be registered for this signal
See also:
pthread_sigmask


2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:23:49 2010 for libjunos-sdk by Doxygen 1.4.5