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

Developer

resources

Using public heap-based settings

Development:

Do the following:

  1. Add a CIF file entry to register the heap store with the global registry.
  2. Write code that creates an instance of SettingsReg, an implementation of ISettings.

Run-time:

  1. An instance of SettingsReg is created.
  2. The SettingsReg instance reads the MIF file entry. According to this entry, this Settings subtree should register itself as a heap-based store at the specified path in the global settings registry.
  3. Based on the entry, SettingsReg creates an instance of the HeapStoreFactory which exposes an ISettings implementation. All ISettings requests will be handled by this implementation.

Follow these steps to add a public heap-based settings store to an application or component:

  1. Register the store with the system by adding information about the store to your CIF.
    local s = require 'SettingsCIFHelpers'
    
    -- register my settings at "/myApp/myHeapSettings/..."
    s:RegisterHeap {
       owner = 0x12345678,           -- class id of my component
       key = "/myApp/myHeapSettings",
       quota = 0x1000,
    }

    This example shows a CIF entry with optional ACLs:

    local s = require 'SettingsCIFHelpers'
    
    -- register my settings at "/myApp/myHeapSettings/..."
    s:RegisterHeap {
       owner = 0x12345678,           -- class id of my component
       key = "/myApp/myHeapSettings",
       quota = 0x1000,
       acls = {
          { -- grant everyone read access to my settings but write access
            -- to only those modules belonging to the 0xdeadd00d group
             {
                groups = {0}, 
                perms = "r/r",
             },
             {
                groups = {0xdeadd00d}, 
                perms = "rw/rw",
             },
             path = "/myApp/myHeapSettings"
          },
       }
    }
  2. To access your settings from a component or an application, use code similar to the following example, which shows how to set the value of a setting:

    Note: A heap-based setting does not exist until ISettings_Set() is called on it.

    {
       ISettings *piSettings = NULL;
       if (SUCCESS == IEnv_CreateInstance(piEnv,
                   AEECLSID_SettingsReg,
                   (void**) &piSettings)) {
          char outbuf[32];
          int result;
          (void) ISettings_Set(piSettings,
                   "/myApp/myHeapSettings/foo",
                   "bar");
          result = ISettings_Get(
             piSettings,
             "/myApp/myHeapSettings/foo",
             outbuf,
             sizeof(outbuf),
             NULL
          );
          if (SUCCESS == result) {
             // outbuf will contain "bar"
          }
          ISettings_Release(piSettings);
          pSettings = NULL;
       }
    }