# Object Manager

The ObjectManager (binding for `WpObjectManager`) provides a way to collect a set of objects and be notified when objects that fulfill a certain set of criteria are created or destroyed.

To start an object manager, you first need to declare interest in a certain kind of object specifying a set of Interests in the constructor and then you need to activate it by calling `ObjectManager.activate()`

Upon activating an ObjectManager, any pre-existing objects that match the specified interests will immediately become available to get through `ObjectManager.iterate()` and the `WpObjectManager` "object-added" signal will be emitted for all of them.

## Constructors

ObjectManager(interest_list)

  Constructs a new object manager.

  Combines `wp_object_manager_new()` and `wp_object_manager_add_interest_full()`

  The argument needs to be a table that contains one or more Interest objects. The object manager will then contain all objects that match any one of the supplied interests.

  Example:

      streams_om = ObjectManager {
        -- match stream nodes
        Interest {
          type = "node",
          Constraint { "media.class", "matches", "Stream/*", type = "pw-global" },
        },
        -- and device nodes that are not associated with any routes
        Interest {
          type = "node",
          Constraint { "media.class", "matches", "Audio/*", type = "pw-global" },
          Constraint { "device.routes", "equals", "0", type = "pw" },
        },
        Interest {
          type = "node",
          Constraint { "media.class", "matches", "Audio/*", type = "pw-global" },
          Constraint { "device.routes", "is-absent", type = "pw" },
        },
      }

  The above example will create an ObjectManager that matches all nodes with a "media.class" global property that starts with the string "Stream/" and additionally all those whose "media.class" starts with "Audio/" and they have either a "device.routes" property that equals zero or they don't have a "device.routes" property at all.

  Parameters:

    interest_list (table) -- a list of interests to objects

  Returns:

    a new object manager

  Return type:

    ObjectManager (`WpObjectManager`)

## Methods

ObjectManager.activate(self)

  Activates the object manager. Binds `wp_core_install_object_manager()`.

  Parameters:

    self -- the object manager

ObjectManager.get_n_objects(self)

  > Binds `wp_object_manager_get_n_objects()`

  Parameters:

    self -- the object manager

  Returns:

    the number of objects managed by the object manager

  Return type:

    integer

ObjectManager.iterate(self, interest)

  Binds `wp_object_manager_new_filtered_iterator_full()`

  Parameters:

    - self -- the object manager

    - interest (Interest or nil or none) -- an interest to filter objects

  Returns:

    all the managed objects that match the interest

  Return type:

    Iterator; the iteration items are of type GObject

ObjectManager.lookup(self, interest)

  Binds `wp_object_manager_lookup()`

  Parameters:

    - self -- the object manager

    - interest (Interest or nil or none) -- the interest to use for the lookup

  Returns:

    the first managed object that matches the interest

  Return type:

    GObject