Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Sharing IShell-Dependent Objects in Brew MP

 

Base version:

Brew MP 1.0.2

Tested version:

Brew MP 1.0.2

Phone tested:

Yes

Use of a singleton is one of the common ways of sharing objects. As discussed in Declaring and Using a Singleton, Brew MP™ currently supports two types of singletons:

  • Singleton in-process class

    A singleton in-process class allows the object to be created as a singleton in the caller's context (Env).

  • Singleton service class

    A singleton service class allows the object to be created as a singleton for the entire Brew MP system.

 

Objective

Each applet resides in its own Env. If multiple applets need to share a single object, the shared object should be implemented as a singleton service. However, the implementation of a service class cannot have any IShell dependencies. If the shared object needs to have access to IShell or any of its dependent classes (such as IBitmap), a singleton service is not directly applicable. For example, multiple applets may want to share one IShell-based object that loads the resources from a BAR file (by calling ISHELL_LoadResXXX()). That shared object can cache the resources in memory and each calling applet can invoke the object to get the resources.

Depending on the implementation of the shared object, the following design choices can be considered:

  • Separation of IShell-dependent functionality and shared data
  • Implementation of a singleton applet service

This document provides information on these two application designs, as well as sample code.

 

Requirements

To separate IShell-dependent functionality and shared data, implement the following:

  1. A singleton service class that contains the shared data.
  2. An in-process class that contains the IShell-based functionality and accesses the singleton service for the shared data.

For more information, see Separation between IShell-dependent functionality and shared data.

To implement a singleton applet service, implement the following three classes:

  1. An applet class that runs in the background as long as the shared object needs to be available.
  2. An in-process class that contains the implementation of the shared object.
  3. A singleton service class that serves as the rendezvous point.

For more information on these classes, see Implemention of a singleton applet service.

 

Sample code location

The ZIP file contains the c_mysingletonappletservice service and c_singletonappletservicetestapp, an application that uses the service.

ZIP filename

Location

Run app

c_mysingletonapplet_sample

Brew MP Resources

  • Download and extract the ZIP file.

  • Compile an app.

  • Run it on the Brew MP Simulator.