top

Using Message Template Generator

This topic describes how you can use the Message Template Generator in the Tizen Studio to help you implement messaging between the JavaScript and Native Client components in a Native Client application.

In a Native Client (NaCl) application, the NaCl module and the JavaScript component must be able to communicate with each other. The JavaScript component uses the JavaScript messaging API, while the NaCl module uses the PostMessage() function to send messages and the HandleMessage() function to receive them.

The Tizen Studio can generate and insert code stubs for messaging functions, so you can focus on implementing the communication logic. For information on implementing messaging in NaCl applications, see Messaging System.

To generate message handling code templates:

  1. In the Tizen Studio menu, select "NaCl Development > Add messages".

    Figure 1. Open the Message Template Generator

    Figure 1. Open the Message Template Generator

  2. Define the NaCl module name, and the NaCl and JavaScript source files to add code templates to.

    Note

    The NaCl module name must correspond to the id attribute of the <embed> element for the NaCl module.

    Figure 2. Message Template Generator window

    Figure 2. Message Template Generator window

  3. To define a new message, click "Add".

  4. Define the message name and whether the message is sent from the NaCl or the JavaScript component. The message name must be unique among all defined messages.

    Figure 3. Message properties dialog

    Figure 3. Message properties dialog

  5. To manage message parameters:

    1. To add a parameter, define the parameter name, type, and description, and click "Add".
      Figure 4. Add message parameters

      Figure 4. Add message parameters

    2. To modify a parameter, select it from the list, modify the parameter values as needed, and click "Update".
    3. To delete a parameter, select it from the list, and click "Delete".
  6. To save the parameters and create the message, click "OK".
    The created message is shown in the "Messages" list.

    Figure 5. Created message

    Figure 5. Created message

  7. To delete a message, select it from the list, and click "Delete".

  8. To generate and insert the message code templates into the source code, click "Generate".

For each defined message, the Message Template Generator creates the following code:

  • Code for sending messages
    The PostMessage_<message_name>() function is created in the native code, and the send_<message_name>() method is created in the JavaScript code. The function and method can be used in your application logic.

  • Code for handling received messages
    The HandleMessage_<message_name>() function stub is created in the native code, and the onReceive_<message_name>() method stub is created in the JavaScript code. Code is also added to call the function and method. You only need to implement the logic required for handling the received messages.

  • Data structure
    A data structure is generated for the message, defining the message parameters.

The generated code also includes stubs for documentation in Doxygen and JSDoc styles.