static int mce_sink_play (NSinkInterface *iface, NRequest *request) { const NProplist *props = n_request_get_properties (request); (void) iface; const gchar *pattern = NULL; MceData *data = (MceData*) n_request_get_data (request, MCE_KEY); g_assert (data != NULL); if (n_proplist_get_bool (props, "mce.backlight_on")) backlight_on (); pattern = n_proplist_get_string (props, "mce.led_pattern"); if (pattern != NULL) { data->pattern = g_strdup (pattern); if (toggle_pattern (pattern, TRUE)) { active_events = g_list_append(active_events, data); } else { g_free (data->pattern); data->pattern = NULL; } } return TRUE; }
static void transform_properties_cb (NHook *hook, void *data, void *userdata) { (void) hook; (void) data; (void) userdata; NCore *core = (NCore*) userdata; NContext *context = n_core_get_context (core); NProplist *new_props = NULL; NProplist *props = NULL; GList *iter = NULL; const char *match_str = NULL; ProfileEntry *entry = NULL; NValue *value = NULL; gchar *context_key = NULL; NCoreHookTransformPropertiesData *transform = (NCoreHookTransformPropertiesData*) data; N_DEBUG (LOG_CAT "transforming profile values for request '%s'", n_request_get_name (transform->request)); new_props = n_proplist_new (); props = (NProplist*) n_request_get_properties (transform->request); for (iter = g_list_first (request_keys); iter; iter = g_list_next (iter)) { match_str = n_proplist_get_string (props, (gchar*) iter->data); if (!match_str) continue; entry = g_hash_table_lookup (profile_entries, match_str); if (!entry) continue; /* if this a fallback request, we don't care if there is existing target. otherwise check if the target exists. */ if (!n_request_is_fallback (transform->request) && n_proplist_has_key (props, entry->target)) continue; context_key = construct_context_key (entry->profile, entry->key); value = (NValue*) n_context_get_value (context, context_key); if (value) { N_DEBUG (LOG_CAT "+ transforming profile key '%s' to target '%s'", entry->key, entry->target); n_proplist_set (new_props, entry->target, n_value_copy (value)); } g_free (context_key); } n_proplist_merge (props, new_props); n_proplist_free (new_props); N_DEBUG (LOG_CAT "new properties:") n_proplist_dump (props); }
static int mce_sink_can_handle (NSinkInterface *iface, NRequest *request) { (void) iface; const NProplist *props = n_request_get_properties (request); if (n_proplist_has_key (props, "mce.backlight_on") || n_proplist_has_key (props, "mce.led_pattern")) { return TRUE; } return FALSE; }
static int tonegen_sink_can_handle (NSinkInterface *iface, NRequest *request) { (void) iface; NProplist *props = (NProplist*) n_request_get_properties (request); if (n_proplist_has_key (props, "tonegen.pattern")) return TRUE; return FALSE; }
static int canberra_sink_can_handle (NSinkInterface *iface, NRequest *request) { (void) iface; NProplist *props = NULL; props = (NProplist*) n_request_get_properties (request); if (n_proplist_has_key (props, SOUND_FILENAME_KEY)) { N_DEBUG (LOG_CAT "request has a sound.filename, we can handle this."); return TRUE; } return FALSE; }
static int tonegen_sink_play (NSinkInterface *iface, NRequest *request) { (void) iface; NProplist *props = (NProplist*) n_request_get_properties (request); guint pattern = 0; gint volume = 0; pattern = (guint) n_proplist_get_int (props, "tonegen.pattern"); volume = n_proplist_get_int (props, "tonegen.volume"); tone_generator_toggle (system_bus, pattern, volume, TRUE); return TRUE; }
static int canberra_sink_prepare (NSinkInterface *iface, NRequest *request) { N_DEBUG (LOG_CAT "sink prepare"); CanberraData *data = g_slice_new0 (CanberraData); NProplist *props = props = (NProplist*) n_request_get_properties (request); data->request = request; data->iface = iface; data->filename = n_proplist_get_string (props, SOUND_FILENAME_KEY); data->sound_enabled = TRUE; data->complete_cb_id = 0; n_request_store_data (request, CANBERRA_KEY, data); n_sink_interface_synchronize (iface, request); if (n_proplist_has_key (props, SOUND_VOLUME_KEY)) data->sound_enabled = n_proplist_get_int (props, SOUND_VOLUME_KEY) > 0; return TRUE; }
static const char *get_type(NRequest *request) { return n_proplist_get_string(n_request_get_properties(request), "tonegen.type"); }
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; }