/** * D-Bus callback for the ALS disabling method call * * @param msg The D-Bus message * @return TRUE */ static gboolean als_disable_req_dbus_cb(DBusMessage *const msg) { const char *sender; gssize retval; if( !(sender = dbus_message_get_sender(msg)) ) goto EXIT; mce_log(LL_DEBUG, "Received ALS disable request from %s", sender); retval = mce_dbus_owner_monitor_remove(sender, &ext_als_enablers); if (retval == -1) { mce_log(LL_INFO, "Failed to remove name owner monitoring" " for `%s'",sender); goto EXIT; } rethink_als_status(); EXIT: if( !dbus_message_get_no_reply(msg) ) { DBusMessage *reply = dbus_new_method_reply(msg); dbus_send_message(reply), reply = 0; } return TRUE; }
/** * GConf callback for ALS settings * * @param gcc Unused * @param id Connection ID from gconf_client_notify_add() * @param entry The modified GConf entry * @param data Unused */ static void use_als_gconf_cb(GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data) { const GConfValue *gcv = gconf_entry_get_value(entry); (void)gcc; (void)data; /* Key is unset */ if (gcv == NULL) { mce_log(LL_DEBUG, "GConf Key `%s' has been unset", gconf_entry_get_key(entry)); goto EXIT; } if (id == use_als_gconf_id) { use_als_flag = gconf_value_get_bool(gcv); rethink_als_status(); } else { mce_log(LL_WARN, "Spurious GConf value received; confused!"); } EXIT: return; }
/** GConf callback for powerkey related settings * * @param gcc (not used) * @param id Connection ID from gconf_client_notify_add() * @param entry The modified GConf entry * @param data (not used) */ static void fba_gconf_cb(GConfClient *const gcc, const guint id, GConfEntry *const entry, gpointer const data) { (void)gcc; (void)data; (void)id; const GConfValue *gcv = gconf_entry_get_value(entry); if( !gcv ) { mce_log(LL_DEBUG, "GConf Key `%s' has been unset", gconf_entry_get_key(entry)); goto EXIT; } if( id == use_als_gconf_id ) { gboolean old = use_als_flag; use_als_flag = gconf_value_get_bool(gcv); if( use_als_flag != old ) { rethink_als_status(); } } else if( id == als_input_filter_gconf_id ) { const char *val = gconf_value_get_string(gcv); if( !eq(als_input_filter, val) ) { g_free(als_input_filter); als_input_filter = g_strdup(val); inputflt_select(als_input_filter); } } else if( id == als_sample_time_gconf_id ) { gint old = als_sample_time; als_sample_time = gconf_value_get_int(gcv); if( als_sample_time != old ) { mce_log(LL_NOTICE, "als_sample_time: %d -> %d", old, als_sample_time); // NB: takes effect on the next sample timer restart } } else if (id == color_profile_gconf_id) { const gchar *val = gconf_value_get_string(gcv); if( !eq(color_profile_name, val) ) { if( !set_color_profile(val) ) save_color_profile(color_profile_name); } } else { mce_log(LL_WARN, "Spurious GConf value received; confused!"); } EXIT: return; }
/** * Handle display state change * * @param data The display stated stored in a pointer */ static void display_state_trigger(gconstpointer data) { display_state_t prev = display_state; display_state = GPOINTER_TO_INT(data); if( prev == display_state ) goto EXIT; mce_log(LL_DEBUG, "display_state: %s -> %s", display_state_repr(prev), display_state_repr(display_state)); rethink_als_status(); EXIT: return; }
const gchar *g_module_check_init(GModule *module) { (void)module; fba_config_init(); fba_datapipe_init(); fba_init_dbus(); fba_gconf_init(); inputflt_init(); rethink_als_status(); return NULL; }
/** * Handle display state change * * @param data The display stated stored in a pointer */ static void display_state_trigger(gconstpointer data) { static display_state_t old_display_state = MCE_DISPLAY_UNDEF; display_state = GPOINTER_TO_INT(data); if( old_display_state == display_state ) goto EXIT; mce_log(LL_DEBUG, "display: %d -> %d", old_display_state, display_state); old_display_state = display_state; rethink_als_status(); EXIT: return; }
/** * D-Bus callback used for reference counting ALS enabling; * if the requesting process exits, immediately decrease the refcount * * @param msg The D-Bus message * @return TRUE */ static gboolean als_owner_monitor_dbus_cb(DBusMessage *const msg) { const gchar *old_name = 0; const gchar *new_name = 0; const gchar *service = 0; DBusError error = DBUS_ERROR_INIT; gssize retval; if( !dbus_message_get_args(msg, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_STRING, &old_name, DBUS_TYPE_STRING, &new_name, DBUS_TYPE_INVALID) ) { mce_log(LL_ERR, "Failed to get argument from %s.%s; %s: %s", "org.freedesktop.DBus", "NameOwnerChanged", error.name, error.message); goto EXIT; } /* Remove the name monitor for the ALS owner */ retval = mce_dbus_owner_monitor_remove(service, &ext_als_enablers); if (retval == -1) { mce_log(LL_WARN, "Failed to remove name owner monitoring" " for `%s'", service); goto EXIT; } rethink_als_status(); EXIT: dbus_error_free(&error); return TRUE; }
const gchar *g_module_check_init(GModule *module) { (void)module; /* Read lux ramps from configuration */ als_filter_load_config(&lut_display); als_filter_load_config(&lut_led); als_filter_load_config(&lut_key); /* Get intial display state */ display_state = datapipe_get_gint(display_state_pipe); /* Append triggers/filters to datapipes */ append_filter_to_datapipe(&display_brightness_pipe, display_brightness_filter); append_filter_to_datapipe(&led_brightness_pipe, led_brightness_filter); append_filter_to_datapipe(&key_backlight_pipe, key_backlight_filter); append_output_trigger_to_datapipe(&display_state_pipe, display_state_trigger); /* Add dbus method call handlers */ mce_dbus_handler_add(MCE_REQUEST_IF, MCE_REQ_ALS_ENABLE, NULL, DBUS_MESSAGE_TYPE_METHOD_CALL, als_enable_req_dbus_cb); mce_dbus_handler_add(MCE_REQUEST_IF, MCE_REQ_ALS_DISABLE, NULL, DBUS_MESSAGE_TYPE_METHOD_CALL, als_disable_req_dbus_cb); mce_dbus_handler_add(MCE_REQUEST_IF, MCE_COLOR_PROFILE_GET, NULL, DBUS_MESSAGE_TYPE_METHOD_CALL, color_profile_get_req_dbus_cb); mce_dbus_handler_add(MCE_REQUEST_IF, MCE_COLOR_PROFILE_IDS_GET, NULL, DBUS_MESSAGE_TYPE_METHOD_CALL, color_profile_ids_get_req_dbus_cb); mce_dbus_handler_add(MCE_REQUEST_IF, MCE_COLOR_PROFILE_CHANGE_REQ, NULL, DBUS_MESSAGE_TYPE_METHOD_CALL, color_profile_change_req_dbus_cb); /* ALS enabled setting */ mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH, MCE_GCONF_DISPLAY_ALS_ENABLED_PATH, use_als_gconf_cb, &use_als_gconf_id); mce_gconf_get_bool(MCE_GCONF_DISPLAY_ALS_ENABLED_PATH, &use_als_flag); /* Color profile setting */ mce_gconf_notifier_add(MCE_GCONF_DISPLAY_PATH, MCE_GCONF_DISPLAY_COLOR_PROFILE_PATH, color_profile_gconf_cb, &color_profile_gconf_id); if( init_color_profiles() ) init_current_color_profile(); rethink_als_status(); return NULL; }