Ejemplo n.º 1
0
Archivo: core.c Proyecto: plundstr/ngfd
NEvent*
n_core_evaluate_request (NCore *core, NRequest *request)
{
    g_assert (core != NULL);
    g_assert (request != NULL);

    NEvent *event      = NULL;
    NEvent *found      = NULL;
    GList  *event_list = NULL;
    GList  *iter       = NULL;

    NEventMatchResult result;

    N_DEBUG (LOG_CAT "evaluating events for request '%s'",
        request->name);

    /* find the list of events that have the same name. */

    event_list = (GList*) g_hash_table_lookup (core->event_table, request->name);
    if (!event_list)
        return NULL;

    /* for each event, match the properties. */

    for (iter = g_list_first (event_list); iter; iter = g_list_next (iter)) {
        event = (NEvent*) iter->data;

        /* default event with no properties, accept. */

        if (n_proplist_size (event->rules) == 0) {
            found = event;
            break;
        }

        result.request    = request;
        result.context    = core->context;
        result.has_match  = FALSE;
        result.skip_rest  = FALSE;

        n_proplist_foreach (event->rules, n_core_match_event_rule_cb, &result);

        if (result.has_match) {
            found = event;
            break;
        }
    }

    if (found) {
        N_DEBUG (LOG_CAT "evaluated to '%s'", found->name);
        n_proplist_foreach (event->rules, n_core_dump_value_cb, NULL);
    }

    return found;
}
Ejemplo n.º 2
0
Archivo: core.c Proyecto: plundstr/ngfd
void
n_core_add_event (NCore *core, NEvent *event)
{
    g_assert (core != NULL);
    g_assert (event != NULL);

    GList  *event_list = NULL;
    GList  *iter       = NULL;
    NEvent *found      = NULL;

    /* get the event list for the specific event name. */

    event_list = g_hash_table_lookup (core->event_table, event->name);

    /* iterate through the event list and try to find an event that has the
       same rules. */

    for (iter = g_list_first (event_list); iter; iter = g_list_next (iter)) {
        found = (NEvent*) iter->data;

        if (n_proplist_match_exact (found->rules, event->rules)) {
            /* match found. merge the properties to the pre-existing event
               and free the new one. */

            N_DEBUG (LOG_CAT "merging event '%s'", event->name);
            n_proplist_foreach (event->rules, n_core_dump_value_cb, NULL);

            n_proplist_merge (found->properties, event->properties);
            n_event_free (event);

            return;
        }
    }

    /* completely new event, add it to the list and sort it. */

    N_DEBUG (LOG_CAT "new event '%s'", event->name);
    if (n_proplist_size (event->rules) > 0)
        n_proplist_foreach (event->rules, n_core_dump_value_cb, NULL);
    else
        N_DEBUG (LOG_CAT "+ default");

    N_DEBUG (LOG_CAT "properties");
    n_proplist_foreach (event->properties, n_core_dump_value_cb, NULL);

    event_list = g_list_append (event_list, event);
    event_list = g_list_sort (event_list, n_core_sort_event_cb);
    g_hash_table_replace (core->event_table, g_strdup (event->name), event_list);

    core->event_list = g_list_append (core->event_list, event);
}
Ejemplo n.º 3
0
static void
find_profile_entries (NCore *core)
{
    GList     *event_list = NULL;
    GList     *iter       = NULL;
    NEvent    *event      = NULL;
    NProplist *props      = NULL;

    event_list = n_core_get_events (core);
    for (iter = g_list_first (event_list); iter; iter = g_list_next (iter)) {
        event = (NEvent*) iter->data;
        props = (NProplist*) n_event_get_properties (event);

        N_DEBUG (LOG_CAT "searching profile entries from event '%s'",
            n_event_get_name (event));

        n_proplist_foreach (props, find_entries_within_event_cb, NULL);
    }
}
Ejemplo n.º 4
0
Archivo: plugin.c Proyecto: jusa/ngfd
static int
canberra_sink_play (NSinkInterface *iface, NRequest *request)
{
    CanberraData *data = (CanberraData*) n_request_get_data (request, CANBERRA_KEY);
    (void) iface;

    N_DEBUG (LOG_CAT "sink play");

    g_assert (data != NULL);

    if (!data->sound_enabled)
        goto complete;

    if (canberra_connect () == FALSE)
        return FALSE;

    static GHashTable *cached_samples = NULL;
    if (!cached_samples) {
        cached_samples = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
    }

    NProplist *props = props = (NProplist*) n_request_get_properties (request);
    ca_proplist *ca_props = 0;
    int error;
    ca_proplist_create (&ca_props);

    /* TODO: don't hardcode */
    ca_proplist_sets (ca_props, CA_PROP_CANBERRA_XDG_THEME_NAME, "jolla-ambient");
    ca_proplist_sets (ca_props, CA_PROP_EVENT_ID, data->filename);

    /* convert all properties within the request that begin with
       "sound.stream." prefix. */
    n_proplist_foreach (props, proplist_to_structure_cb, ca_props);

    if (g_hash_table_lookup_extended (cached_samples, data->filename, NULL, NULL) == FALSE) {
        N_DEBUG (LOG_CAT "caching sample %s", data->filename);
        error = ca_context_cache_full (c_context, ca_props);
        if (error) {
            N_WARNING (LOG_CAT "canberra couldn't cache sample %s", data->filename);
            return FALSE;
        }

        g_hash_table_add (cached_samples, strdup(data->filename));
    } else {
        N_DEBUG (LOG_CAT "sample %s is cached", data->filename);
    }

    error = ca_context_play_full (c_context, 0, ca_props, NULL, NULL);
    ca_proplist_destroy (ca_props);

    if (error) {
        N_WARNING (LOG_CAT "sink play had a warning: %s", ca_strerror (error));

        if (error == CA_ERROR_NOTAVAILABLE ||
                error == CA_ERROR_DISCONNECTED ||
                error == CA_ERROR_STATE ||
                error == CA_ERROR_DESTROYED) {
            ca_context_destroy (c_context);
            c_context = 0;
        }

        return FALSE;
    }

complete:
    /* We do not know how long our samples play, but let's guess we
     * are done in 200ms. */
    data->complete_cb_id = g_timeout_add (200, canberra_complete_cb, data);

    return TRUE;
}