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.

Related Info

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 "Project Explorer" view, right-click the TV application project or NaCl project, and select "NaCl > Add Messages".

    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.

    Figure 2. Message Template Generator window

  3. To define a new message:

    1. Click "Add".
    2. 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.
    3. To manage message parameters:
      • To add a parameter, define the parameter name, type, and description, and click "Add".

        Figure 3. Add message parameters
      • To modify a parameter, select it from the list, modify the parameter values as needed, and click "Update".
      • To delete a parameter, select it from the list, and click "Delete".
    4. To save the parameters and create the message, click "OK".

      The created message is shown in the "Messages" list.

      Figure 4. Created message
  4. To delete a message, select it from the list, and click "Delete".

  5. 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.