Пример #1
0
static void
setup_system_sound_levels (NValue *value)
{
    gchar **split = NULL;
    gchar **iter  = NULL;
    guint   i     = 0;

    if (!value) {
        N_WARNING (LOG_CAT "no system-sound-levels key defined "
                           "in profile.ini!");
        return;
    }

    if (n_value_type (value) != N_VALUE_TYPE_STRING) {
        N_WARNING (LOG_CAT "invalid value type for system sound levels!");
        return;
    }

    split = g_strsplit (n_value_get_string (value), ";", -1);
    for (iter = split; *iter; ++iter)
        ++num_system_sound_levels;

    system_sound_levels = (int*) g_malloc0 (sizeof (int) * num_system_sound_levels);
    for (iter = split, i = 0; *iter; ++iter, ++i) {
        system_sound_levels[i] = atoi (*iter);
        system_sound_levels[i] = CLAMP_VALUE (system_sound_levels[i], 0, 100);
    }

    g_strfreev (split);
}
Пример #2
0
END_TEST

START_TEST (test_string)
{
    NValue *value = NULL;
    value = n_value_new ();
    fail_unless (value != NULL);
    fail_unless (n_value_get_string (value) == NULL);
    const char *str_val = "NGF\0";
    n_value_set_string (value, str_val);
    const char *reply = n_value_get_string (value);
    fail_unless (reply != str_val);
    char *duplicate = n_value_dup_string (value);
    fail_unless (strcmp (duplicate, str_val) == 0);
	
    g_free (duplicate);
    duplicate = NULL;
    n_value_free (value);
    value = NULL;
}
Пример #3
0
END_TEST

START_TEST (test_int)
{
    NValue *value = NULL;
    value = n_value_new ();
    fail_unless (value != NULL);
    fail_unless (n_value_get_string (value) == 0);
    int val = -100;
    n_value_set_int (value, val);
    int reply = n_value_get_int (value);
    fail_unless (reply == val);

    n_value_free (value);
    value = NULL;
}
Пример #4
0
Файл: plugin.c Проект: jusa/ngfd
static void
proplist_to_structure_cb (const char *key, const NValue *value, gpointer userdata)
{
    ca_proplist *target     = (ca_proplist*) userdata;
    const char   *prop_key   = NULL;
    const char   *prop_value = NULL;

    if (!g_str_has_prefix (key, STREAM_PREFIX_KEY))
        return;

    prop_key = key + strlen (STREAM_PREFIX_KEY);
    if (*prop_key == '\0')
        return;

    prop_value = n_value_get_string ((NValue*) value);
    ca_proplist_sets (target, prop_key, prop_value);
}
Пример #5
0
static void
n_core_match_event_rule_cb (const char *key, const NValue *value,
                            gpointer userdata)
{
    NEventMatchResult *result      = (NEventMatchResult*) userdata;
    NRequest          *request     = result->request;
    NValue            *match_value = NULL;
    const char        *context_key = NULL;
    const char        *str         = NULL;

    if (result->skip_rest)
        return;

    /* assume positive result */

    result->has_match = TRUE;

    /* if the key has a context@ prefix, then we will lookup the value from
       the current context. */

    context_key = n_core_match_and_strip_prefix (key, "context@");
    match_value = context_key ?
        (NValue*) n_context_get_value (result->context, context_key) :
        (NValue*) n_proplist_get (request->properties, key);

    /* if match value has a *, then any value for request will do. */

    str = n_value_get_string ((NValue*) value);
    if (str && g_str_equal (str, "*"))
        return;

    /* the moment we find a key and value that does not match, we're done
       here. */

    if (!match_value || !n_value_equals (value, match_value)) {
        result->has_match  = FALSE;
        result->skip_rest  = TRUE;
    }
}
Пример #6
0
static void
value_changed_cb (const char *profile,
                  const char *key,
                  const char *value,
                  const char *type,
                  void *userdata)
{
    (void) type;

    NCore      *core      = (NCore*) userdata;
    NContext   *context   = n_core_get_context (core);
    const char *current   = NULL;

    update_context_value (context, profile, key, value);

    /* update current profile value if necessary */

    current = n_value_get_string ((NValue*) n_context_get_value (context,
        CURRENT_PROFILE_KEY));
    if (current && g_str_equal (current, profile))
        update_context_value (context, NULL, key, value);
}
Пример #7
0
static void
query_current_values (NCore *core)
{
    NContext      *context     = n_core_get_context (core);
    char         **profiles    = NULL;
    char         **p           = NULL;
    const char    *current     = NULL;
    profileval_t  *values      = NULL;
    profileval_t  *v           = NULL;
    gboolean       is_current  = FALSE;

    profiles = profile_get_profiles ();
    current  = n_value_get_string ((NValue*) n_context_get_value (context,
        "profile.current_profile"));

    for (p = profiles; *p; ++p) {
        is_current = current && g_str_equal (current, *p);
        values = profile_get_values (*p);
        for (v = values; v->pv_key; ++v) {
            update_context_value (context, *p, v->pv_key, v->pv_val);
            if (is_current)
                update_context_value (context, NULL, v->pv_key, v->pv_val);
        }
        profile_free_values (values);
    }

    /* fallbacks */

    /* This is in a way a bug, since profiled doesn't expose fallback settings ever,
     * but, when requesting non-existing profile, profile_get_values() returns
     * fallback profile contents. */
    values = profile_get_values ("fallback");
    for (v = values; v->pv_key; ++v)
        update_context_value (context, "fallback", v->pv_key, v->pv_val);
    profile_free_values (values);

    profile_free_profiles (profiles);
}
Пример #8
0
static void
find_entries_within_event_cb (const char *key, const NValue *value,
                              gpointer userdata)
{
    (void) key;
    (void) value;
    (void) userdata;

    ProfileEntry *entry     = NULL;
    ProfileEntry *match     = NULL;
    const char   *value_str = NULL;

    if (g_strstr_len (key, 32, PROFILE_KEY_PATTERN) == NULL)
        return;

    N_DEBUG (LOG_CAT "possible profile key entry '%s'", key);

    value_str = n_value_get_string ((NValue*) value);
    entry = parse_profile_entry (value_str);

    if (!entry)
        return;

    match = (ProfileEntry*) g_hash_table_lookup (profile_entries, value_str);
    if (!match) {
        g_hash_table_insert (profile_entries, g_strdup (value_str), entry);
        N_DEBUG (LOG_CAT "new profile entry with key '%s', profile '%s' and target '%s'",
            entry->key, entry->profile, entry->target);

        if (g_str_has_suffix (key, PROFILE_KEY_PATTERN))
            request_keys = append_unique_key (request_keys, key);
    }
    else {
        free_entry (entry);
    }
}