Device insertion handling

When mm-detect learns of a device insertion, it reads the device's information through PPS and then spawns a thread for synchronizing the device's media metadata and publishing synchronization status updates through PPS. These actions ensure that client applications can read up-to-date device status and media metadata from the databases and PPS.

The mm-detect process performs the following actions in response to a device insertion:

  1. PPS object parsing

    When the user inserts a device, the appropriate device publisher detects the insertion and then writes a PPS object to the device listings directory. The content of this new PPS object is immediately added to the PPS devices information object (the .all object) and is returned by the mm-detect call to open().

    This new content includes:

    • the unique ID of the device
    • the device mountpoint
    • the volume name
    • the filesystem type
  2. Mountpoint linking

    For each newly inserted device, mm-detect creates a symbolic link whose target is the device's mountpoint. The link source (i.e., the referring filesystem entry) is given a path of: /apps/mediasources/db<UID>, where <UID> is the device's unique ID. Creating these links offers client media applications the convenience of accessing the filesystems of any attached device from a standard location.
  3. Database loading

    The unique ID field is used as the name of the database's configuration object, which mm-detect writes to the PPS database configuration directory (/pps/qnx/qdb/config/). When a PPS object is added to the configuration directory, the QDB database server attempts to load the database with the same name as the object; if necessary, QDB creates that database. For more details on QDB's operation, see the QDB Developer's Guide.

    After writing the database configuration object, mm-detect begins monitoring changes in the PPS database status directory (/pps/qnx/qdb/status/). When an object with the same name as the newly inserted device is created or updated, mm-detect checks if that object's Status attribute is set to Valid. If so, it proceeds to the next step. Otherwise, mm-detect resumes monitoring the status directory to wait for the device's database to be loaded successfully.
    Note: The mm-detect process keeps track of which device databases are loaded. If an existing PPS object in the device listings directory is updated, for example due to a changed mountpoint, mm-detect recognizes from the extracted unique ID that the device's database is already loaded and so avoids unnecessarily rewriting the device's database configuration object.
  4. Media synchronization

    Once the device's database is loaded, mm-detect spawns a new thread that oversees the synchronization of the device's media metadata. This thread starts synchronizing information on media files stored over the entire device and then updates the PPS synchronization status object when specific phases of synchronization complete. For details of all the actions done by mm-detect media synchronization threads, see Media synchronization thread actions.

    Creating a dedicated thread for each synchronization ensures responsiveness, because mm-detect can promptly react to other device insertions or removals while still synchronizing a recently attached device.