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

Developer

resources

Declaring and Using a Singleton

Base version:

Brew MP 1.0

Tested version:

Brew MP 1.0

Phone tested:

Yes

When a class is instantiated as a singleton in Brew® Mobile Platform (Brew MP), there can be only one instance of the class within a certain scope. The scope is determined by the environment (or Env) of the caller, or the entire Brew MP system, depending on the type of singleton class instantiated.

Objective

This document describes how to declare a singleton in-process class or singleton service class in the CIF and use it in a Brew MP application. For information on the usage of ISingleton, see the C/C++ API Reference.

Requirements

To use a singleton in-process class, do the following:

  • Add a Singleton declaration to your application's CIF
  • Call IEnv_CreateInstance() with the ClassID of the singleton in-process class
  • Call the appropriate functions supported by the in-process class

To use a singleton service class, do the following:

  • Add Service and Singleton declarations to your application's CIF
  • Call IEnv_CreateInstance() with the ServiceID of the singleton service
  • Call the appropriate functions supported by the service

Sample code location

The ZIP file contains two example applications: c_appio and c_appio2. The c_appio application demonstrates the use of a singleton service. c_appio2 demonstrates the use of a singleton in-process class and the use of a non-singleton in-process class.

ZIP filename

Location

Run app

singleton_samples

Brew MP Resources

  • Download and extract the ZIP file.

  • Compile an app.

  • Run it on the Brew MP Simulator.