Coding, Fetching, and Displaying the Output

An SDK daemon calls Output Description Language (ODL) functions to open a management socket and format the message for display.

These functions are declared in the file /src/junos/lib/junoscript/h/junoscript/xmlrpc.h, in your backing sandbox.

The messages are defined in the file /src/lib/input/helloworld.odl, as follows:

/*
 * This odl file defines a DTD called helloworld.dtd
 */
dtd helloworld;

tag messages {
    flag root;
    
    tag message {
        type string;
        help "A small but friendly message";
        description "The message tag will contain a small but friendly
                     message like: hello world.";
        formal-name "Message";
    }
    
    format messages-format {
        header "Current Hello World Message:\\n";
        indent 2;
        line {
            field message flag leading colon;
        }
    }
}

The ODL code is compiled in the makefile and produces output in the directory obj-i386/lib/odl/xmltags. In these output files, the "Message" and "Messages" strings are translated to constants with the preface ODCI_.

The application then uses these output variables with ODL API calls to format and display the message.

Retrieving the Message

In response to the show sync messages command entered by the user, the daemon invokes the helloworld_show_messages() function as specified in the master menu definitions (see Creating the Commands Menu Array).

helloworld_show_messages() fetches messages and uses ODL calls to display them to the user.

The code that fetches the messages follows. The data_entry variable was created by invoking the PATNODE_TO_STRUCT macro (see Creating the Tree and Adding Messages for details about PATNODE_TO_STRUCT.)

helloworld_data_t *data;
     
...
 
  for (data = first_message(); data != NULL; data = next_message(data)) {
         XML_ELT(msp, ODCI_MESSAGE, "%s", data->message);
   }

first_message() and next_message() use the patricia tree APIs as follows to fetch the actual messages from the database:

 helloworld_data_t *
 first_message (void)
 {
     return data_entry(patricia_find_next(&root, NULL));
 }
 
 
 helloworld_data_t *
 next_message (helloworld_data_t * data)
 {
  return data_entry(patricia_find_next(&root, (data ? &(data->node) : NULL)));
 }

Formatting and Displaying the Output

You use ODL calls to read the ODL compiler output and format and display the output to the user. For example, in the following code code:

static int32_t
 helloworld_show_messages (mgmt_sock_t *msp,
                         parse_status_t *csb __unused,
                         char *unparsed __unused)
 {
     helloworld_data_t *data;
     
     XML_OPEN(msp, ODCI_MESSAGES);
 
     for (data = first_message(); data != NULL; data = next_message(data)) {
         XML_ELT(msp, ODCI_MESSAGE, "%s", data->message);
     }
 
     XML_CLOSE(msp, ODCI_MESSAGES);
     
     return 0;
 }

For more information about ODL, see Creating a User Interface with DDL and ODL in the Programming Tasks section. A reference guide, the ODL Guide, is also included with this documentation set.


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:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5