The input data from an RPC operation is parsed by the server into val_value_t structures. 

The schema used is the "input" section of the "rpc" statement for the RPC operation.


In the example below, the <set-my-session> operation takes up to 3 input parameters

  • linesize
  • with-defaults
  • message-indent


  grouping session-params {
    uses appcmn:IndentParm;
      
    leaf linesize {
      description
        "The desired maximum number of characters printed
         per line.  The server may exceed this number.
         It is only a suggestion, not a hard limit.";
      type uint32 { range "40 .. 1024"; }
      default 72;
    }
    leaf with-defaults {
      description
        "The desired maximum number of characters printed
         per line.  The server may exceed this number.
         It is only a suggestion, not a hard limit.";
      type wd:with-defaults-mode;
    }
    leaf message-indent {
      type int8 {
        range "-1 .. 9";
      }
      default -1;
      description
        "The number of spaces to indent for each level of
         output in a protocol message, e.g. NETCONF request.
         The value zero means no indent, just line feeds.
         The value -1 means no indent and no line feeds either.";
    }
  }

  rpc get-my-session {
    description
      "Get the customization settings for this session";
    output {
      uses session-params;
    }
  }        

  rpc set-my-session {
    description
      "Set the customization settings for this session.
       This is like a merge operation.  Only the values that
       are present will be used to overwrite the existing
       settings.";
    input {
      uses session-params;
    }
  }        



The <set-my-session> SIL callback code does not need to do any validation other than the YANG validation done by the server, so there is no RPC validate callback needed in this case. The RPC invoke function is also allowed to return an error (e.g., resource not available).  This function gets the input parameters from the message and then modifies the current session with these parameters.


/********************************************************************
* FUNCTION set_my_session_invoke
*
* set-my-session : invoke params callback
*
* INPUTS:
*    see rpc/agt_rpc.h
* RETURNS:
*    status
*********************************************************************/
static status_t
    set_my_session_invoke (ses_cb_t *scb,
                           rpc_msg_t *msg,
                           xml_node_t *methnode)
{
    (void)methnode;

   /* get the input value, either already set or in the rpc_inputQ
    * expecting only 1 node in the Q even though valid JSON could
    * send more than 1 top-level object to edit
    */

    val_value_t *inputval = msg->rpc_input;
    if (!dlq_empty(&msg->rpc_inputQ)) {
        inputval = (val_value_t *)dlq_firstEntry(&msg->rpc_inputQ);
    }

    /* get the indent parameter */
    val_value_t *childval =
        val_find_child(inputval, AGT_SES_MODULE, NCX_EL_INDENT);
    if (childval && childval->res == NO_ERR) {
        scb->indent = VAL_INT8(childval);
    }

    /* get the linesize parameter */
    childval = val_find_child(inputval, AGT_SES_MODULE, NCX_EL_LINESIZE);
    if (childval && childval->res == NO_ERR) {
        scb->linesize = VAL_UINT32(childval);
    }

    /* get the with-defaults parameter */
    childval = val_find_child(inputval, AGT_SES_MODULE,
                              NCX_EL_WITH_DEFAULTS);
    if (childval && childval->res == NO_ERR) {
        scb->withdef =
            ncx_get_withdefaults_enum(VAL_ENUM_NAME(childval));
    }

    /* get the message-indent parameter */
    childval = val_find_child(inputval, AGT_SES_MODULE,
                              NCX_EL_MESSAGE_INDENT);
    if (childval && childval->res == NO_ERR) {
        scb->msg_indent = VAL_INT8(childval);
    }

    return NO_ERR;

} /* set_my_session_invoke */