Initialization and termination activities

Before it can synchronize metadata and play content, mm-pnp must parse its configuration file, configure other services, and start child threads. When the main thread receives the termination signal, it stops the child threads and cleans up resources.

By understanding these initialization and termination activities, you can modify mm-pnp to log different information or support new configuration options. Or, you can use the code as a reference for writing your own apps.

The main thread of mm-pnp performs the following tasks:
  1. Setting up logging

    At startup, the main thread initializes the logging service and sets the verbosity based on the -v command-line options. Messages outputted to sloginfo are tagged with "mm-pnp".

  2. Parsing the configuration file

    The main thread parses the configuration file and stores the various option settings. The program uses separate symbol tables when parsing different file sections to remember which settings apply globally and which ones apply to specific device types (see "Configuring mm-pnp" for details).

  3. Setting up multimedia services

    To enable media synchronization and playback, mm-pnp connects to QDB, mm-sync, and mm-renderer. It also creates lists to hold the information needed by these services, which includes:
    • mediastore profiles, which store the mountpoints and device types of attached mediastores
    • details on pending and on active synchronizations
    • playlists ready to be played
  4. Launching child threads

    When the program setup is complete, the main thread launches three child threads:
    Device monitoring thread
    Reads a PPS object to obtain mountpoint information about newly attached devices, then passes this information to QDB to load media databases.
    Database monitoring thread
    Monitors QDB status objects to learn when databases finish loading. In response, the thread runs mm-sync to synchronize the media information on the corresponding devices.
    Synchronization event-processing thread
    Reads mm-sync events to learn when media file information has been synchronized. In response, the thread creates playlists based on the synchronized information and invokes mm-renderer to play them.

    The child threads work with other services to extract media information and play media files when the user attaches a device (for details, see "Device monitoring, synchronization, and playback"). After launching the child threads, the main thread begins monitoring signals to wait for the termination request.

  5. Shutting down

    The mm-pnp programs runs until you issue the termination signal by using CtrlC or the kill() command. When you tell it to shut down, the main thread:
    • terminates the child threads
    • disconnects from the multimedia services
    • destroys the lists that store mediastore, synchronization, and playlist information