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 canberra_sink_stop (NSinkInterface *iface, NRequest *request) { N_DEBUG (LOG_CAT "sink stop"); (void) iface; CanberraData *data = (CanberraData*) n_request_get_data (request, CANBERRA_KEY); g_assert (data != NULL); if (data->complete_cb_id > 0) g_source_remove (data->complete_cb_id); g_slice_free (CanberraData, data); }
static void mce_sink_stop (NSinkInterface *iface, NRequest *request) { (void) iface; MceData *data = (MceData*) n_request_get_data (request, MCE_KEY); g_assert (data != NULL); if (data->pattern) { toggle_pattern (data->pattern, FALSE); g_free (data->pattern); data->pattern = NULL; } active_events = g_list_remove_all(active_events, data); g_slice_free (MceData, data); }
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; }