3  Yangcli Interface

The yangcli-pro client application supports external yangcli functions.

The external callback functions must be registered with yangcli-pro.

 

3.1  External Show Callback Functions

The function ycli_show_extern_register_callbacks in yangcli/yangcli_show_extern.h is used by the external code to register its own show callback functions.  The show  functions are used by the yangcli-pro.

 

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

* FUNCTION ycli_show_extern_register_callbacks

*

* Register the external callbacks for show implementation

*

* INPUTS:

*    module   == YANG module used for this function

*    showfn_keyword == key word used for this function.
*    showfn ==  show function callback
*    cookie == context pointer (may be null)

* RETURNS:

*   status of the function registration.

*

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

extern status_t ycli_show_extern_register_callbacks(

         const xmlChar* module,

         const xmlChar* keyword,

         ycli_show_extern_fn_t showfn,

                                 void *cookie);

 

 

If the external method is selected in the yangcli-pro initialization then the callback function MUST be provided.

The function must be registered:

The following code snippet shows the API template definitions from yangcli/yangcli_show_extern.h.

 

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

*

* Callback yangcli_show_extern_fn_t to handle external show
* functions.

*

* INPUTS:
*   server_name == The current server name.
*   rpc == RPC method for the show commad being processed.
*   line == CLI line input.
*   session_name == The name of the current session.
*   valset == valset filled in with parameters for the specified RPC
*   mode == help_mode_t(none, brief, normal, full)
*   cookie == context pointer passed in register time, (may be null)
*  

* RETURNS:

*   Status: NO_ERR or error.

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

typedef status_t

    (*yangcli_show_extern_fn_t) (const xmlChar *server_name
obj_temp_t    *rpc,

const xmlChar *line,
const xmlChar *session_name
const val_value_t *valset,

                                 help_mode_t mode,

                                 void *cookie);

 

 

3.2  Example External Yangcli

The following example code is available in example-show.c, found in the libshow/src directory.  It shows some dummy external  functions and how they are registered during initialization.

 

/*

 * Copyright (c) 2012, 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.    

 */

/*  FILE: example-show.c

 

  Example External Yangcli Library

 

*********************************************************************

*                                                                   *

*                     I N C L U D E    F I L E S                    *

*                                                                   *

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

 

#include <xmlstring.h>

 

#include "procdefs.h"

#include "yangcli.h"

#include "example_show.h"

#include "yangcli_show_extern.h"

#include "yangcli_util.h"

#include "dlq.h"

#include "example-show.h"

#include "log.h"

#include "ncx.h"

#include "ncxtypes.h"

#include "obj.h"

#include "ses.h"

#include "status.h"

#include "val.h"

#include "val_util.h"

#include "xml_util.h"

 

 

/****************  Example External Hooks *******************/

 

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

* FUNCTION show_fn

*

* Call back function invoked by yangcli-pro application.
*
* INPUTS:
*   server_name == server name to use.
*   rpc == RPC method for the show commad.
*   line == CLI line input.
*   session_name == the current session name.
*   valset == valset filled in with parameters for the specified RPC.
*   mode == help_mode_t(none, brief, normal, full)
*   cookie == context pointer (may be null)
*

* RETURNS: NO_ERROR or error.

*   

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

static status_t show_fn (const xmlChar *server_name,
    obj_temp_t   *rpc,

    const xmlChar *line,
    const xmlChar *session_name,
    const val_value_t *valset,

                         help_mode_t mode,

    void* cookie);

{

    log_debug("\n\nshow_fn is called in external library.");

 

    log_debug("\nshow_extern: return OK\n");

 

    return NO_ERR;

 

} /* show_fn */

 

 

/****************  Required Yancli Show Library Hooks *******************/

 

static ncx_module_t *mymod = NULL;

/* yangcli show init callback

 *

 * INPUTS:

 * RETURNS:

 *  status; error will abort startup

 */

status_t yp_show_init (void)

{

    log_debug("\nyp_show init\n");

    status_t res = NO_ERR;
   
   /* Load example-fan.yang

     * Call ncxmod_load_module(mod_name, mod_revision, NULL, &mymod);

     */

    res = ncxmod_load_module((const xmlChar *)"example-fan",

                             (const xmlChar *)"2014-12-05",

                              NULL, &mymod);

 

    /*

     * Register a show function with yangcli-pro :

     * module name: example-fan for example-fan.yang

     * key word: fan

     * function: show_fan

     */

 

    /* Create a cookie context if any or NULL */

    void* cookie = NULL;

    if (res == NO_ERR){

       ycli_show_extern_register_callbacks (

                        (const xmlChar *)"example-fan",

                        (const xmlChar *)"fan",

                        show_fan,

                        cookie);

    } else {

       log_debug("\n\nyp_show_init: return ERROR\n");

    }

 

    return res;

}

 

 

/* yangcli show cleanup callback

 * this callback is invoked once during yangcli_cleanup

 */

void yp_show_cleanup (void)

{

    log_debug("\nyp_show cleanup\n");

}

 

 

/* END example-show.c */