The yangdump-pro program will automatically generate functions to queue a specific notification type for processing.  It is up to the SIL callback code to invoke this function when the notification event needs to be generated.  The SIL code is expected to provide the value nodes that are needed for any notification payload objects.

The function to generate a notification control block and queue it for notification replay and delivery is generated by the yangdump-pro program.  A function parameter will exist for each top-level data node defined in the YANG notification definition.   

 

In the example below, the 'restart-notification' notification event contains one container and a list nodes.


module notif-example {

  namespace "http://netconfcentral.org/ns/notif-example";
  prefix "notif-example";

  contact
    "Andy Bierman <andy@netconfcentral.org>";

  revision 2019-01-01 {
    description "Notification test module in progress.";
  }

  grouping resource {

    container resource {
      choice resource {
        case circuit-pack {
          leaf circuit-pack-name {
            type string;
          }
        }
        case port {
          container port {
            leaf port-name {
              type string;
            }
          }
        }
        case connection {
          leaf connection-name {
            type string;
          }
        }
      }
    }

    list target {
      leaf target-name {
        type instance-identifier;
      }
    } // list edit
  }

  notification restart-notification {
    uses resource;
  }

}



The callback function with notification Payload may look as follow:


/********************************************************************
* FUNCTION u_notif_example_restart_notification_send
*
* Send a u_notif_example_restart_notification notification
* Called by your code when notification event occurs
*
********************************************************************/
void
    restart_notification_send (notification_resource *v_resource,
                               notification_target *v_resourceTarget)
{
    val_value_t *parmval = NULL;
    status_t res = NO_ERR;

    if (!agt_notifications_enabled()) {
        log_debug2("\nSkipping <restart-notification> notification; disabled");
        return;
    }

    if (LOGDEBUG) {
        log_debug("\nGenerating <restart-notification> notification");
    }

    /* Get the notification module and the notification object.
     * These steps usually done in Init Phase 1,
     * here is just an example.
     */
    ncx_module_t *notif_example_mod =
        ncx_find_module((const xmlChar *)"notif-example"), NULL);
    if (notif_example_mod == NULL) {
        return ERR_NCX_OPERATION_FAILED;
    }

    /* Get the notification object */
    obj_template_t *restart_notification_obj =
        ncx_find_object(notif_example_mod, // loaded module in the Init 1 Phase
                        (const xmlChar *)"restart-notification");
    if (restart_notification_obj == NULL) {
        return;
    }

    /* Create a new notification structure */
    agt_not_msg_t *notif =
        agt_not_new_notification(restart_notification_obj);
    if (notif == NULL) {
        log_error("\nError: malloc failed, cannot send "
        "<restart-notification> notification");
        return;
    }

    /* add container resource to payload */
    val_value_t *resource_val =
        agt_make_object(restart_notification_obj,
                        (const xmlChar *)"resource",
                        &res);
    if (!resource_val) {
        log_error("\nError: make container failed (%s), cannot send "
                  "<resourse> parameter",
                  get_error_string(res));
        res = NO_ERR;
    } else {
        /* pass off resource_val malloc here */
        agt_not_add_to_payload(notif, resource_val);
    }

    /* create a child of a container and then add it to container */
    val_value_t *leafval =
        agt_make_leaf(VAL_OBJ(resource_val),
                      (const xmlChar *)"connection-name",
                      (const xmlChar *)"connection-1",
                      &res);
    if (leafval) {
        res = val_child_add(leafval, resource_val);
        if (res != NO_ERR) {
            val_free_value(leafval);
        }
    }

    /* add 'target' list nodes
     * In this example we use custom audit records that
     * are createad by the server. The record structure is just an
     * example and is out of the scope of this example code.
     * Use your own data or structure or other source of the data
     * to generate list entries.
     *
     * Here we loop through the data massive and generate the
     * notification list values.
     */
    agt_cfg_audit_rec_t *auditrec;
    for (auditrec = (agt_cfg_audit_rec_t *)dlq_firstEntry(auditrecQ);
         auditrec != NULL;
         auditrec = (agt_cfg_audit_rec_t *)dlq_nextEntry(auditrec)) {

        /* add restart-notification/target list */
        val_value_t *listval =
            agt_make_object(restart_notification_obj,
                            (const xmlChar *)"target",
                            &res);
        if (listval == NULL) {
            log_error("\nError: make list failed (%s), cannot send "
                      "<target> parameter",
                      get_error_string(res));
            continue;
        }

        /* pass off listval malloc here */
        agt_not_add_to_payload(notif, listval);

        /* add restart-notification/target/target-name */
        val_value_t *leafval =
            agt_make_leaf(VAL_OBJ(listval),
                          (const xmlChar *)"target-name",
                          (const xmlChar *)"somename",
                          &res);
        if (leafval) {
            res = val_child_add(leafval, listval);
            if (res != NO_ERR) {
                val_free_value(leafval);
            }
        } else {
            log_error("\nError: make leaf failed (%s), cannot send "
                      "<target-name> parameter",
                      get_error_string(res));
        }
    }

    agt_not_queue_notification(notif);

} /* u_notif_example_restart_notification_send */


For more example on how to construct different YANG Data nodes refer to the Section YANG Data Tree Handling