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

Developer

resources

Using public .ini-based settings

A settings .ini file contains the following:

  • One or more sections, which contain settings

    The section name is enclosed in brackets, for example [general].

  • Settings, which are specified as follows:
    setting=value
Development:

Do the following:

  1. Add a CIF file entry to register the .ini 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. SettingsReg reads the MIF file entry. According to this entry, the Settings subtree should register itself as an ini-based store at the specified path in the global settings registry.
  3. Based on the entry, SettingsReg creates an instance of the iniStoreFactory which exposes an ISettings implementation. All ISettings requests will be handled by this implementation.

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

  1. Create an .ini file using a text editor and place it into your application or component directory in EFS.

    The following .ini file example contains one section, with one setting:

    [section1]
    setting1=value1

  2. Register the store with the system by adding information about the store to your CIF. For example:
    local s = require 'SettingsCIFHelpers'
    
    -- register my settings at "/myApp/myIniSettings/..."
    s:RegisterIniFile {
       owner = 0x12345678,           -- class id of my component
       key = "/myApp/myIniSettings",
       file = "mysettings.ini",
       
    }

    This example shows a CIF entry with optional ACLs:

    local s = require 'SettingsCIFHelpers'
    
    -- register my settings at "/myApp/myIniSettings/..."
    s:RegisterIniFile {
       owner = 0x12345678,           -- class id of my component
       key = "/myApp/myIniSettings",
       file = "mysettings.ini",
       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/myIniSettings"
          },
       }
    }

  3. To access your settings from a component or an application, use code similar to the following example, which shows how to create an instance of the Settings Registry and get the value of a setting:
    {
       ISettings *piSettings = NULL;
       if (SUCCESS == IEnv_CreateInstance(piEnv,
                    AEECLSID_SettingsReg,
                    (void**) &piSettings)) {
          char outbuf[32];
          int result;
          result = ISettings_Get(
             piSettings,
             "/myApp/myIniSettings/section1/setting1",
             outbuf,
             sizeof(outbuf),
             NULL
          );
          if (SUCCESS == result) {
             // outbuf will contain "value1"
          }
          ISettings_Release(piSettings);
          pSettings = NULL;
       }
    }