static void sensor_changes (GUdevClient *client, gchar *action, GUdevDevice *device, SensorData *data) { guint i; if (g_strcmp0 (action, "remove") == 0) { for (i = 0; i < NUM_SENSOR_TYPES; i++) { GUdevDevice *dev = DEVICE_FOR_TYPE(i); if (!dev) continue; if (g_strcmp0 (g_udev_device_get_sysfs_path (device), g_udev_device_get_sysfs_path (dev)) == 0) { g_debug ("Sensor type %s got removed (%s)", driver_type_to_str (i), g_udev_device_get_sysfs_path (dev)); g_clear_object (&DEVICE_FOR_TYPE(i)); DRIVER_FOR_TYPE(i) = NULL; g_clear_pointer (&data->clients[i], g_hash_table_unref); data->clients[i] = create_clients_hash_table (); send_driver_changed_dbus_event (data, i); } } if (!any_sensors_left (data)) g_main_loop_quit (data->loop); } else if (g_strcmp0 (action, "add") == 0) { guint i; for (i = 0; i < G_N_ELEMENTS(drivers); i++) { SensorDriver *driver = (SensorDriver *) drivers[i]; if (!driver_type_exists (data, driver->type) && driver_discover (driver, device)) { g_debug ("Found hotplugged device %s of type %s at %s", g_udev_device_get_sysfs_path (device), driver_type_to_str (driver->type), driver->name); if (driver_open (driver, device, driver_type_to_callback_func (driver->type), data)) { GHashTable *ht; DEVICE_FOR_TYPE(driver->type) = g_object_ref (device); DRIVER_FOR_TYPE(driver->type) = (SensorDriver *) driver; send_driver_changed_dbus_event (data, driver->type); ht = data->clients[driver->type]; if (g_hash_table_size (ht) > 0) driver_set_polling (DRIVER_FOR_TYPE(driver->type), TRUE); } break; } } } }
static GObject * hev_scgi_connection_manager_constructor(GType type, guint n, GObjectConstructParam * param) { g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); return G_OBJECT_CLASS(hev_scgi_connection_manager_parent_class)->constructor(type, n, param); }
static void hev_scgi_connection_manager_init(HevSCGIConnectionManager * self) { g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); }
void ghb_audio_list_refresh_selected(signal_user_data_t *ud) { GtkTreeView *treeview; GtkTreePath *treepath; GtkTreeSelection *selection; GtkTreeModel *store; GtkTreeIter iter; gint *indices; gint row; GValue *asettings = NULL; const GValue *audio_list; g_debug("ghb_audio_list_refresh_selected ()"); treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list")); selection = gtk_tree_view_get_selection (treeview); if (gtk_tree_selection_get_selected(selection, &store, &iter)) { const gchar *track, *codec, *br = NULL, *sr, *mix; gchar *s_drc, *s_gain, *s_quality = NULL; gdouble drc, gain; // Get the row number treepath = gtk_tree_model_get_path (store, &iter); indices = gtk_tree_path_get_indices (treepath); row = indices[0]; gtk_tree_path_free(treepath); // find audio settings if (row < 0) return; audio_list = ghb_settings_get_value(ud->settings, "audio_list"); if (row >= ghb_array_len(audio_list)) return; asettings = ghb_array_get_nth(audio_list, row); track = ghb_settings_combo_option(asettings, "AudioTrack"); codec = ghb_settings_combo_option(asettings, "AudioEncoderActual"); double quality = ghb_settings_get_double(asettings, "AudioTrackQuality"); if (ghb_settings_get_boolean(asettings, "AudioTrackQualityEnable") && quality != HB_INVALID_AUDIO_QUALITY) { int codec = ghb_settings_combo_int(asettings, "AudioEncoderActual"); s_quality = ghb_format_quality("Q/", codec, quality); } else { br = ghb_settings_combo_option(asettings, "AudioBitrate"); } sr = ghb_settings_combo_option(asettings, "AudioSamplerate"); mix = ghb_settings_combo_option(asettings, "AudioMixdown"); gain = ghb_settings_get_double(asettings, "AudioTrackGain"); s_gain = g_strdup_printf("%ddB", (int)gain); drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider"); if (drc < 1.0) s_drc = g_strdup("Off"); else s_drc = g_strdup_printf("%.1f", drc); gtk_list_store_set(GTK_LIST_STORE(store), &iter, // These are displayed in list 0, track, 1, codec, 2, s_quality ? s_quality : br, 3, sr, 4, mix, 5, s_gain, 6, s_drc, -1); g_free(s_drc); g_free(s_gain); g_free(s_quality); } }
G_MODULE_EXPORT void audio_codec_changed_cb(GtkWidget *widget, signal_user_data_t *ud) { static gint prev_acodec = 0; gint acodec_code; GValue *asettings, *gval; g_debug("audio_codec_changed_cb ()"); gval = ghb_widget_value(widget); acodec_code = ghb_lookup_combo_int("AudioEncoder", gval); ghb_value_free(gval); if (block_updates) { prev_acodec = acodec_code; ghb_grey_combo_options (ud); ghb_check_dependency(ud, widget, NULL); return; } asettings = get_selected_asettings(ud); if (ghb_audio_is_passthru (prev_acodec) && !ghb_audio_is_passthru (acodec_code)) { // Transition from passthru to not, put some audio settings back to // pref settings gint titleindex; gint track; gint br, sr, mix_code; if (asettings != NULL) { br = ghb_settings_get_int(asettings, "AudioBitrate"); sr = ghb_settings_combo_int(asettings, "AudioSamplerate"); mix_code = ghb_settings_combo_int(asettings, "AudioMixdown"); } else { br = 160; sr = 0; mix_code = 0; } titleindex = ghb_settings_combo_int(ud->settings, "title"); track = ghb_settings_combo_int(ud->settings, "AudioTrack"); if (sr) { sr = ghb_find_closest_audio_rate(sr); } ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(sr)); hb_audio_config_t *aconfig; aconfig = ghb_get_scan_audio_info(titleindex, track); if (sr == 0) { sr = aconfig ? aconfig->in.samplerate : 48000; } mix_code = ghb_get_best_mix( aconfig, acodec_code, mix_code); br = hb_get_best_audio_bitrate(acodec_code, br, sr, mix_code); ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(br)); ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix_code)); } ghb_adjust_audio_rate_combos(ud); ghb_grey_combo_options (ud); ghb_check_dependency(ud, widget, NULL); prev_acodec = acodec_code; if (asettings != NULL) { ghb_widget_to_setting(asettings, widget); ghb_settings_set_value(asettings, "AudioEncoderActual", ghb_settings_get_value(ud->settings, "AudioEncoderActual")); ghb_audio_list_refresh_selected(ud); } ghb_live_reset(ud); float low, high, gran, defval; int dir; hb_get_audio_quality_limits(acodec_code, &low, &high, &gran, &dir); defval = hb_get_default_audio_quality(acodec_code); GtkScaleButton *sb; GtkAdjustment *adj; sb = GTK_SCALE_BUTTON(GHB_WIDGET(ud->builder, "AudioTrackQuality")); adj = gtk_scale_button_get_adjustment(sb); if (dir) { // Quality values are inverted defval = high - defval + low; } gtk_adjustment_configure (adj, defval, low, high, gran, gran * 10, 0); }
/** * Responds to a vaccination by recording it. * * @param self the model. * @param event a vaccination event. */ void handle_vaccination_event (struct adsm_module_t_ *self, EVT_vaccination_event_t * event) { local_data_t *local_data; UNT_unit_t *unit; UNT_control_t update; ADSM_control_reason reason; UNT_production_type_t prodtype; double nanimals; #if DEBUG g_debug ("----- ENTER handle_vaccination_event (%s)", MODEL_NAME); #endif local_data = (local_data_t *) (self->model_data); unit = event->unit; update.unit_index = unit->index; update.day_commitment_made = event->day_commitment_made; update.reason = event->reason; #ifdef USE_SC_GUILIB sc_vaccinate_unit( event->day, unit, update ); #else if (NULL != adsm_vaccinate_unit) { adsm_vaccinate_unit (update); } #endif reason = event->reason; prodtype = unit->production_type; nanimals = (double)(unit->size); /* Initially vaccinated units do not count as the first vaccination. */ if (event->reason != ADSM_ControlInitialState) { if (local_data->first_vaccination->is_null) { RPT_reporting_set_integer (local_data->first_vaccination, event->day); RPT_reporting_set_integer (local_data->vaccination_occurred, 1); } if (local_data->first_vaccination_by_reason[reason]->is_null) RPT_reporting_set_integer (local_data->first_vaccination_by_reason[reason], event->day); if (local_data->first_vaccination_by_prodtype[prodtype]->is_null) RPT_reporting_set_integer (local_data->first_vaccination_by_prodtype[prodtype], event->day); if (local_data->first_vaccination_by_reason_and_prodtype[reason][prodtype]->is_null) RPT_reporting_set_integer (local_data->first_vaccination_by_reason_and_prodtype[reason][prodtype], event->day); /* Initially vaccinated units also are not included in many of the * counts. They will not be part of vacnU or vacnU broken down by * production type. They will be part of vacnUIni and vacnUIni broken * down by production type. */ RPT_reporting_add_integer (local_data->num_units_vaccinated, 1); RPT_reporting_add_integer (local_data->num_units_vaccinated_by_prodtype[prodtype], 1); RPT_reporting_add_real (local_data->num_animals_vaccinated, nanimals); RPT_reporting_add_real (local_data->num_animals_vaccinated_by_prodtype[prodtype], nanimals); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated, 1); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_prodtype[prodtype], 1); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated, nanimals); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_prodtype[prodtype], nanimals); } RPT_reporting_add_integer (local_data->num_units_vaccinated_by_reason[reason], 1); RPT_reporting_add_real (local_data->num_animals_vaccinated_by_reason[reason], nanimals); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_reason[reason], 1); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_reason[reason], nanimals); RPT_reporting_add_integer (local_data->num_units_vaccinated_by_reason_and_prodtype[reason][prodtype], 1); RPT_reporting_add_real (local_data->num_animals_vaccinated_by_reason_and_prodtype[reason][prodtype], nanimals); RPT_reporting_add_integer (local_data->cumul_num_units_vaccinated_by_reason_and_prodtype[reason][prodtype], 1); RPT_reporting_add_real (local_data->cumul_num_animals_vaccinated_by_reason_and_prodtype[reason][prodtype], nanimals); #if DEBUG g_debug ("----- EXIT handle_vaccination_event (%s)", MODEL_NAME); #endif }
void ghb_adjust_audio_rate_combos(signal_user_data_t *ud) { gint titleindex, track, acodec, select_acodec, mix; hb_audio_config_t *aconfig; GtkWidget *widget; GValue *gval; gint mux; gint bitrate; gint sr = 48000; g_debug("ghb_adjust_audio_rate_combos ()"); mux = ghb_settings_combo_int(ud->settings, "FileFormat"); titleindex = ghb_settings_combo_int(ud->settings, "title"); widget = GHB_WIDGET(ud->builder, "AudioTrack"); gval = ghb_widget_value(widget); track = ghb_lookup_combo_int("AudioTrack", gval); ghb_value_free(gval); widget = GHB_WIDGET(ud->builder, "AudioEncoder"); gval = ghb_widget_value(widget); acodec = ghb_lookup_combo_int("AudioEncoder", gval); ghb_value_free(gval); widget = GHB_WIDGET(ud->builder, "AudioMixdown"); gval = ghb_widget_value(widget); mix = ghb_lookup_combo_int("AudioMixdown", gval); ghb_value_free(gval); widget = GHB_WIDGET(ud->builder, "AudioBitrate"); gval = ghb_widget_value(widget); bitrate = ghb_lookup_combo_int("AudioBitrate", gval); widget = GHB_WIDGET(ud->builder, "AudioSamplerate"); gval = ghb_widget_value(widget); sr = ghb_lookup_combo_int("AudioSamplerate", gval); aconfig = ghb_get_scan_audio_info(titleindex, track); if (sr == 0) { sr = aconfig ? aconfig->in.samplerate : 48000; } gint fallback = ghb_select_fallback( ud->settings, mux, acodec ); gint copy_mask = ghb_get_copy_mask(ud->settings); select_acodec = ghb_select_audio_codec(mux, aconfig, acodec, fallback, copy_mask); gboolean codec_defined_bitrate = FALSE; if (ghb_audio_is_passthru (select_acodec)) { if (aconfig) { bitrate = aconfig->in.bitrate / 1000; // Set the values for bitrate and samplerate to the input rates ghb_set_bitrate_opts (ud->builder, bitrate, bitrate, bitrate); mix = 0; ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG; codec_defined_bitrate = TRUE; ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0)); } else { ghb_ui_update(ud, "AudioSamplerate", ghb_int64_value(0)); mix = 0; ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); bitrate = 448; } ghb_ui_update(ud, "AudioTrackDRCSlider", ghb_double_value(0)); } else { if (mix == 0) mix = ghb_get_best_mix( aconfig, select_acodec, 0); bitrate = hb_get_best_audio_bitrate(select_acodec, bitrate, sr, mix); ghb_ui_update(ud, "AudioMixdown", ghb_int64_value(mix)); } if (!codec_defined_bitrate) { int low, high; mix = ghb_get_best_mix( aconfig, select_acodec, mix); hb_get_audio_bitrate_limits(select_acodec, sr, mix, &low, &high); ghb_set_bitrate_opts (ud->builder, low, high, -1); } ghb_ui_update(ud, "AudioBitrate", ghb_int64_value(bitrate)); ghb_settings_take_value(ud->settings, "AudioEncoderActual", ghb_lookup_acodec_value(select_acodec)); GValue *asettings = get_selected_asettings(ud); if (asettings) { ghb_settings_take_value(asettings, "AudioEncoderActual", ghb_lookup_acodec_value(select_acodec)); } ghb_audio_list_refresh_selected(ud); ghb_check_dependency(ud, NULL, "AudioEncoderActual"); }
/** * pk_plugin_transaction_finished_end: */ void pk_plugin_transaction_finished_end (PkPlugin *plugin, PkTransaction *transaction) { gchar *error_msg = NULL; gchar *path; gchar *statement; gfloat step; gint rc; GPtrArray *array = NULL; guint i; PkRoleEnum role; /* skip simulate actions */ if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction), PK_TRANSACTION_FLAG_ENUM_SIMULATE)) { goto out; } /* skip only-download */ if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction), PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) { goto out; } /* load */ if (plugin->priv->db == NULL) pk_transaction_plugin_load_db (plugin, transaction); /* no database */ if (plugin->priv->db == NULL) goto out; /* check the role */ role = pk_transaction_get_role (transaction); if (role != PK_ROLE_ENUM_REFRESH_CACHE) goto out; /* connect to backend */ if (!pk_backend_is_implemented (plugin->backend, PK_ROLE_ENUM_SEARCH_FILE)) { g_debug ("cannot search files"); goto out; } /* use a local backend instance */ pk_backend_reset_job (plugin->backend, plugin->job); pk_backend_job_set_vfunc (plugin->job, PK_BACKEND_SIGNAL_FINISHED, (PkBackendJobVFunc) pk_plugin_finished_cb, plugin); pk_backend_job_set_vfunc (plugin->job, PK_BACKEND_SIGNAL_PACKAGE, (PkBackendJobVFunc) pk_plugin_package_cb, plugin); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_SCAN_APPLICATIONS); /* reset hash */ g_hash_table_remove_all (plugin->priv->hash); pk_backend_job_set_percentage (plugin->job, 101); /* first go through the existing data, and look for * modifications and removals */ statement = g_strdup ("SELECT filename, md5 FROM cache"); rc = sqlite3_exec (plugin->priv->db, statement, pk_plugin_sqlite_cache_rescan_cb, plugin, &error_msg); g_free (statement); if (rc != SQLITE_OK) { g_warning ("SQL error: %s\n", error_msg); sqlite3_free (error_msg); goto out; } array = g_ptr_array_new_with_free_func (g_free); pk_plugin_get_desktop_files (plugin, PK_DESKTOP_DEFAULT_APPLICATION_DIR, array); if (array->len) { step = 100.0f / array->len; pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_GENERATE_PACKAGE_LIST); /* process files in an array */ for (i=0; i<array->len; i++) { pk_backend_job_set_percentage (plugin->job, i * step); path = g_ptr_array_index (array, i); pk_plugin_sqlite_add_filename (plugin, path, NULL); } } pk_backend_job_set_percentage (plugin->job, 100); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_FINISHED); out: if (array != NULL) g_ptr_array_unref (array); }
/** * pk_plugin_transaction_finished_results: */ void pk_plugin_transaction_finished_results (PkPlugin *plugin, PkTransaction *transaction) { gchar **package_ids = NULL; gchar *package_id_tmp; GPtrArray *array = NULL; GPtrArray *list = NULL; guint i; PkInfoEnum info; PkPackage *item; PkResults *results; PkRoleEnum role; /* skip simulate actions */ if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction), PK_TRANSACTION_FLAG_ENUM_SIMULATE)) { goto out; } /* skip only-download */ if (pk_bitfield_contain (pk_transaction_get_transaction_flags (transaction), PK_TRANSACTION_FLAG_ENUM_ONLY_DOWNLOAD)) { goto out; } /* load */ if (plugin->priv->db == NULL) pk_transaction_plugin_load_db (plugin, transaction); /* no database */ if (plugin->priv->db == NULL) goto out; /* check the role */ role = pk_transaction_get_role (transaction); if (role != PK_ROLE_ENUM_INSTALL_PACKAGES) goto out; /* connect to backend */ if (!pk_backend_is_implemented (plugin->backend, PK_ROLE_ENUM_GET_FILES)) { g_debug ("cannot get files"); goto out; } /* get results */ results = pk_transaction_get_results (transaction); array = pk_results_get_package_array (results); /* filter on INSTALLING | UPDATING */ list = g_ptr_array_new_with_free_func (g_free); for (i=0; i<array->len; i++) { item = g_ptr_array_index (array, i); info = pk_package_get_info (item); if (info == PK_INFO_ENUM_INSTALLING || info == PK_INFO_ENUM_UPDATING) { /* we convert the package_id data to be 'installed' */ package_id_tmp = pk_package_id_build (pk_package_get_name (item), pk_package_get_version (item), pk_package_get_arch (item), "installed"); g_ptr_array_add (list, package_id_tmp); } } /* process file lists on these packages */ if (list->len == 0) goto out; g_debug ("processing %i packages for desktop files", list->len); /* get all the files touched in the packages we just installed */ pk_backend_reset_job (plugin->backend, plugin->job); pk_backend_job_set_vfunc (plugin->job, PK_BACKEND_SIGNAL_FINISHED, (PkBackendJobVFunc) pk_plugin_finished_cb, plugin); pk_backend_job_set_vfunc (plugin->job, PK_BACKEND_SIGNAL_FILES, (PkBackendJobVFunc) pk_plugin_files_cb, plugin); pk_backend_job_set_status (plugin->job, PK_STATUS_ENUM_SCAN_APPLICATIONS); pk_backend_job_set_percentage (plugin->job, 101); package_ids = pk_ptr_array_to_strv (list); pk_backend_get_files (plugin->backend, plugin->job, package_ids); /* wait for finished */ g_main_loop_run (plugin->priv->loop); pk_backend_job_set_percentage (plugin->job, 100); out: if (array != NULL) g_ptr_array_unref (array); if (list != NULL) g_ptr_array_unref (list); g_strfreev (package_ids); }
gpointer cockpit_polkit_agent_register (CockpitTransport *transport, GCancellable *cancellable) { PolkitAgentListener *listener = NULL; PolkitAuthority *authority = NULL; PolkitSubject *subject = NULL; GVariant *options; GError *error = NULL; gpointer handle = NULL; guint handler = 0; gchar *string; authority = polkit_authority_get_sync (cancellable, &error); if (authority == NULL) { g_message ("couldn't get polkit authority: %s", error->message); goto out; } subject = polkit_unix_session_new_for_process_sync (getpid (), cancellable, &error); if (subject == NULL) { g_warning ("couldn't create polkit session subject: %s", error->message); goto out; } listener = g_object_new (COCKPIT_TYPE_POLKIT_AGENT, "transport", transport, NULL); options = NULL; /* * HACK: Work around polkitagent warning: * * https://bugs.freedesktop.org/show_bug.cgi?id=78193 */ handler = g_log_set_handler (NULL, G_LOG_LEVEL_WARNING, cockpit_null_log_handler, NULL); handle = polkit_agent_listener_register_with_options (listener, POLKIT_AGENT_REGISTER_FLAGS_NONE, subject, NULL, options, cancellable, &error); g_log_remove_handler (NULL, handler); if (error != NULL) { if ((g_error_matches (error, POLKIT_ERROR, POLKIT_ERROR_FAILED) && error->message && strstr (error->message, "already exists")) || g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) { g_debug ("couldn't register polkit agent: %s", error->message); } else { g_dbus_error_strip_remote_error (error); g_message ("couldn't register polkit authentication agent: %s", error->message); } goto out; } string = polkit_subject_to_string (subject); g_debug ("registered polkit authentication agent for subject: %s", string); g_free (string); out: if (subject) g_object_unref (subject); if (authority) g_object_unref (authority); if (listener) g_object_unref (listener); g_clear_error (&error); return handle; }
static int hal_device_is_pda (LibHalContext *ctx, const char *udi, gchar **ret_ifname) { int result = 0; DBusError error; dbus_error_init (&error); /* Be sure it is a network interface */ gchar *ifname = libhal_device_get_property_string (ctx, udi, "net.interface", &error); if (ifname == NULL) goto DONE; if (ret_ifname != NULL) *ret_ifname = g_strdup(ifname); libhal_free_string (ifname); /* We'll then check some properties of its parent */ gchar *parentname = libhal_device_get_property_string (ctx, udi, "info.parent", &error); if (parentname == NULL) goto DONE; /* Check the parent's device driver name (for usb-rndis-lite) */ gchar *drvname = libhal_device_get_property_string (ctx, parentname, "info.linux.driver", &error); if (drvname != NULL) { if (strncmp ("rndis_host", drvname, 11) == 0) result = 1; libhal_free_string (drvname); } else { g_debug("%s: drvname not set", G_STRFUNC); if (dbus_error_is_set(&error)) { g_warning ("%s: failed with D-Bus error %s: %s\n", G_STRFUNC, error.name, error.message); dbus_error_free(&error); } } /* Check pda.platform property (for usb-rndis-ng) */ gchar *pdaplatform = libhal_device_get_property_string (ctx, parentname, "pda.platform", &error); if (pdaplatform != NULL) { if (strncmp ("pocketpc", pdaplatform, 8) == 0) result = 1; libhal_free_string (pdaplatform); } else { g_debug("%s: pdaplatform not set", G_STRFUNC); if (dbus_error_is_set(&error)) { g_warning ("%s: failed with D-Bus error %s: %s\n", G_STRFUNC, error.name, error.message); dbus_error_free(&error); } } libhal_free_string (parentname); DONE: if (dbus_error_is_set(&error)) dbus_error_free (&error); /*g_debug ("%s: udi='%s', result=%d", G_STRFUNC, udi, result);*/ return result; }
static void cockpit_polkit_agent_initiate_authentication (PolkitAgentListener *listener, const gchar *action_id, const gchar *message, const gchar *icon_name, PolkitDetails *details, const gchar *cookie, GList *identities, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { CockpitPolkitAgent *self = COCKPIT_POLKIT_AGENT (listener); PolkitIdentity *identity = NULL; GSimpleAsyncResult *result = NULL; GString *unsupported = NULL; ReauthorizeCaller *caller; gchar *string; uid_t uid; GList *l; const gchar *argv[] = { PACKAGE_LIBEXEC_DIR "/cockpit-polkit", cookie, NULL, }; g_debug ("polkit is requesting authentication"); result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, cockpit_polkit_agent_initiate_authentication); uid = getuid (); unsupported = g_string_new (""); for (l = identities; l != NULL; l = g_list_next (l)) { if (POLKIT_IS_UNIX_USER (l->data)) { if (polkit_unix_user_get_uid (l->data) == uid) { identity = g_object_ref (l->data); break; } } string = polkit_identity_to_string (l->data); g_string_append_printf (unsupported, "%s ", string); g_free (string); } if (!identity) { g_message ("cannot reauthorize identity(s): %s", unsupported->str); g_simple_async_result_set_error (result, POLKIT_ERROR, POLKIT_ERROR_FAILED, "Reauthorization not supported for identity"); g_simple_async_result_complete_in_idle (result); goto out; } string = polkit_identity_to_string (identity); g_message ("Reauthorizing %s", string); g_free (string); caller = g_new0 (ReauthorizeCaller, 1); caller->cookie = g_strdup (cookie); caller->helper = cockpit_pipe_spawn (argv, NULL, NULL); caller->read_sig = g_signal_connect (caller->helper, "read", G_CALLBACK (on_helper_read), caller); caller->close_sig = g_signal_connect (caller->helper, "close", G_CALLBACK (on_helper_close), caller); caller->cancellable = g_object_ref (cancellable); caller->cancel_sig = g_cancellable_connect (cancellable, G_CALLBACK (on_cancelled), caller, NULL); caller->result = g_object_ref (result); caller->self = self; g_hash_table_replace (self->callers, caller->cookie, caller); g_debug ("cockpit-polkit helper starting"); out: if (unsupported) g_string_free (unsupported, TRUE); g_object_unref (result); if (identity) g_object_unref (identity); }
static gboolean clutter_backend_wayland_post_parse (ClutterBackend *backend, GError **error) { ClutterBackendWayland *backend_wayland = CLUTTER_BACKEND_WAYLAND (backend); EGLBoolean status; g_atexit (clutter_backend_at_exit); /* TODO: expose environment variable/commandline option for this... */ backend_wayland->wayland_display = wl_display_connect (NULL); if (!backend_wayland->wayland_display) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Failed to open Wayland display socket"); return FALSE; } backend_wayland->wayland_source = _clutter_event_source_wayland_new (backend_wayland->wayland_display); g_source_attach (backend_wayland->wayland_source, NULL); /* Set up listener so we'll catch all events. */ wl_display_add_global_listener (backend_wayland->wayland_display, display_handle_global, backend_wayland); /* Process connection events. */ wl_display_iterate (backend_wayland->wayland_display, WL_DISPLAY_READABLE); if (!try_get_display(backend_wayland, error)) return FALSE; status = eglInitialize (backend_wayland->edpy, &backend_wayland->egl_version_major, &backend_wayland->egl_version_minor); if (status != EGL_TRUE) { g_set_error (error, CLUTTER_INIT_ERROR, CLUTTER_INIT_ERROR_BACKEND, "Unable to Initialize EGL"); return FALSE; } CLUTTER_NOTE (BACKEND, "EGL Reports version %i.%i", backend_wayland->egl_version_major, backend_wayland->egl_version_minor); backend_wayland->drm_enabled = try_enable_drm(backend_wayland, error); if (!backend_wayland->drm_enabled) { if (backend_wayland->wayland_shm == NULL) return FALSE; g_debug("Could not enable DRM buffers, falling back to SHM buffers"); g_clear_error(error); } return TRUE; }
static void foreach_cb(gpointer data, gpointer user_data) { FcitxLayoutItem* item = data; g_debug("%s %s %s %s", item->layout, item->variant, item->name, item->langcode); }
static int signal_update_order(LassiConnection *lc, DBusMessage *m) { gint32 generation; DBusError e; DBusMessageIter iter, sub; GList *new_order = NULL, *merged_order = NULL; int r = 0; int c = 0; dbus_error_init(&e); if (!(dbus_message_get_args( m, &e, DBUS_TYPE_INT32, &generation, DBUS_TYPE_INVALID))) { g_warning("Received invalid message: %s", e.message); dbus_error_free(&e); return -1; } dbus_message_iter_init(m, &iter); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING) { g_debug("Bad connection list fo the left"); return -1; } if (lc->server->order_generation > generation) { g_debug("Ignoring request for layout"); return 0; } dbus_message_iter_recurse(&iter, &sub); while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { const char *id; dbus_message_iter_get_basic(&sub, &id); new_order = g_list_prepend(new_order, g_strdup(id)); dbus_message_iter_next(&sub); } new_order = g_list_reverse(new_order); if (!lassi_list_nodups(new_order)) { g_warning("Received invalid list."); r = -1; goto finish; } c = lassi_list_compare(lc->server->order, new_order); if (c == 0) { g_debug("Requested order identical to ours."); goto finish; } if (lc->server->order_generation == generation && c > 0) { g_debug("Ignoring request for layout 2"); goto finish; } merged_order = lassi_list_merge(lassi_list_copy(new_order), lc->server->order); if (lassi_list_compare(lc->server->order, merged_order)) { lassi_server_set_order(lc->server, merged_order); merged_order = NULL; } lassi_server_send_update_order(lc->server, lassi_list_compare(lc->server->order, new_order) ? NULL : lc); lc->server->order_generation = generation; finish: lassi_list_free(new_order); lassi_list_free(merged_order); if (lc->delayed_welcome) { lc->delayed_welcome = FALSE; show_welcome(lc, TRUE); } return r; }
static void gs_screenshot_image_complete_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { g_autoptr(GsScreenshotImage) ssimg = GS_SCREENSHOT_IMAGE (user_data); gboolean ret; g_autoptr(GError) error = NULL; g_autoptr(GdkPixbuf) pixbuf = NULL; g_autoptr(GInputStream) stream = NULL; /* return immediately if the message was cancelled or if we're in destruction */ if (msg->status_code == SOUP_STATUS_CANCELLED || ssimg->session == NULL) return; if (msg->status_code == SOUP_STATUS_NOT_MODIFIED) { g_debug ("screenshot has not been modified"); as_screenshot_show_image (ssimg); return; } if (msg->status_code != SOUP_STATUS_OK) { g_warning ("Result of screenshot downloading attempt with " "status code '%u': %s", msg->status_code, msg->reason_phrase); /* if we're already showing an image, then don't set the error * as having an image (even if outdated) is better */ if (ssimg->showing_image) return; /* TRANSLATORS: this is when we try to download a screenshot and * we get back 404 */ gs_screenshot_image_set_error (ssimg, _("Screenshot not found")); return; } /* create a buffer with the data */ stream = g_memory_input_stream_new_from_data (msg->response_body->data, msg->response_body->length, NULL); if (stream == NULL) return; /* load the image */ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL); if (pixbuf == NULL) { /* TRANSLATORS: possibly image file corrupt or not an image */ gs_screenshot_image_set_error (ssimg, _("Failed to load image")); return; } /* is image size destination size unknown or exactly the correct size */ if (ssimg->width == G_MAXUINT || ssimg->height == G_MAXUINT || (ssimg->width * ssimg->scale == (guint) gdk_pixbuf_get_width (pixbuf) && ssimg->height * ssimg->scale == (guint) gdk_pixbuf_get_height (pixbuf))) { ret = g_file_set_contents (ssimg->filename, msg->response_body->data, msg->response_body->length, &error); if (!ret) { gs_screenshot_image_set_error (ssimg, error->message); return; } } else if (!gs_screenshot_image_save_downloaded_img (ssimg, pixbuf, &error)) { gs_screenshot_image_set_error (ssimg, error->message); return; } /* got image, so show */ as_screenshot_show_image (ssimg); }
void xi_driveable_point_to_g_debug(XIDriveablePoint *point) { g_debug("XIDriveablePoint {"); g_debug(" x = %g", point->x); g_debug(" y = %g", point->y); g_debug(" z = %g", point->z); g_debug(" input_x = %g", point->input_x); g_debug(" input_y = %g", point->input_y); g_debug(" input_z = %g", point->input_z); g_debug(" input_up = %g", point->input_up); g_debug(" input_down = %g", point->input_down); g_debug(" input_left = %g", point->input_left); g_debug(" input_right = %g", point->input_right); g_debug(" input_in = %g", point->input_in); g_debug(" input_out = %g", point->input_out); g_debug(" speed_x = %g", point->speed_x); g_debug(" speed_y = %g", point->speed_y); g_debug(" speed_z = %g", point->speed_z); g_debug(" max_speed = %g", point->max_speed); g_debug(" accel_rate = %g", point->accel_rate); g_debug(" decel_rate = %g", point->decel_rate); g_debug(" elapsed = %g", point->elapsed); g_debug(" prev_elapsed = %g", point->prev_elapsed); g_debug("}"); }
void gs_screenshot_image_load_async (GsScreenshotImage *ssimg, GCancellable *cancellable) { AsImage *im = NULL; const gchar *url; g_autofree gchar *basename = NULL; g_autofree gchar *cache_kind = NULL; g_autofree gchar *cachefn_thumb = NULL; g_autofree gchar *sizedir = NULL; g_autoptr(SoupURI) base_uri = NULL; g_return_if_fail (GS_IS_SCREENSHOT_IMAGE (ssimg)); g_return_if_fail (AS_IS_SCREENSHOT (ssimg->screenshot)); g_return_if_fail (ssimg->width != 0); g_return_if_fail (ssimg->height != 0); /* load an image according to the scale factor */ ssimg->scale = (guint) gtk_widget_get_scale_factor (GTK_WIDGET (ssimg)); im = as_screenshot_get_image (ssimg->screenshot, ssimg->width * ssimg->scale, ssimg->height * ssimg->scale); /* if we've failed to load a HiDPI image, fallback to LoDPI */ if (im == NULL && ssimg->scale > 1) { ssimg->scale = 1; im = as_screenshot_get_image (ssimg->screenshot, ssimg->width, ssimg->height); } if (im == NULL) { /* TRANSLATORS: this is when we request a screenshot size that * the generator did not create or the parser did not add */ gs_screenshot_image_set_error (ssimg, _("Screenshot size not found")); return; } /* check if the URL points to a local file */ url = as_image_get_url (im); if (g_str_has_prefix (url, "file://")) { g_free (ssimg->filename); ssimg->filename = g_strdup (url + 7); if (g_file_test (ssimg->filename, G_FILE_TEST_EXISTS)) { as_screenshot_show_image (ssimg); return; } } basename = gs_screenshot_get_cachefn_for_url (url); if (ssimg->width == G_MAXUINT || ssimg->height == G_MAXUINT) { sizedir = g_strdup ("unknown"); } else { sizedir = g_strdup_printf ("%ux%u", ssimg->width * ssimg->scale, ssimg->height * ssimg->scale); } cache_kind = g_build_filename ("screenshots", sizedir, NULL); g_free (ssimg->filename); ssimg->filename = gs_utils_get_cache_filename (cache_kind, basename, GS_UTILS_CACHE_FLAG_NONE, NULL); if (ssimg->filename == NULL) { /* TRANSLATORS: this is when we try create the cache directory * but we were out of space or permission was denied */ gs_screenshot_image_set_error (ssimg, _("Could not create cache")); return; } /* does local file already exist and has recently been downloaded */ if (g_file_test (ssimg->filename, G_FILE_TEST_EXISTS)) { guint64 age_max; g_autoptr(GFile) file = NULL; /* show the image we have in cache while we're checking for the * new screenshot (which probably won't have changed) */ as_screenshot_show_image (ssimg); /* verify the cache age against the maximum allowed */ age_max = g_settings_get_uint (ssimg->settings, "screenshot-cache-age-maximum"); file = g_file_new_for_path (ssimg->filename); /* image new enough, not re-requesting from server */ if (age_max > 0 && gs_utils_get_file_age (file) < age_max) return; } /* if we're not showing a full-size image, we try loading a blurred * smaller version of it straight away */ if (!ssimg->showing_image && ssimg->width > AS_IMAGE_THUMBNAIL_WIDTH && ssimg->height > AS_IMAGE_THUMBNAIL_HEIGHT) { const gchar *url_thumb; g_autofree gchar *basename_thumb = NULL; g_autofree gchar *cache_kind_thumb = NULL; im = as_screenshot_get_image (ssimg->screenshot, AS_IMAGE_THUMBNAIL_WIDTH * ssimg->scale, AS_IMAGE_THUMBNAIL_HEIGHT * ssimg->scale); url_thumb = as_image_get_url (im); basename_thumb = gs_screenshot_get_cachefn_for_url (url_thumb); cache_kind_thumb = g_build_filename ("screenshots", "112x63", NULL); cachefn_thumb = gs_utils_get_cache_filename (cache_kind_thumb, basename_thumb, GS_UTILS_CACHE_FLAG_NONE, NULL); if (cachefn_thumb == NULL) return; if (g_file_test (cachefn_thumb, G_FILE_TEST_EXISTS)) gs_screenshot_image_show_blurred (ssimg, cachefn_thumb); } /* re-request the cache filename, which might be different as it needs * to be writable this time */ g_free (ssimg->filename); ssimg->filename = gs_utils_get_cache_filename (cache_kind, basename, GS_UTILS_CACHE_FLAG_WRITEABLE, NULL); /* download file */ g_debug ("downloading %s to %s", url, ssimg->filename); base_uri = soup_uri_new (url); if (base_uri == NULL || !SOUP_URI_VALID_FOR_HTTP (base_uri)) { /* TRANSLATORS: this is when we try to download a screenshot * that was not a valid URL */ gs_screenshot_image_set_error (ssimg, _("Screenshot not valid")); return; } /* cancel any previous messages */ if (ssimg->message != NULL) { soup_session_cancel_message (ssimg->session, ssimg->message, SOUP_STATUS_CANCELLED); g_clear_object (&ssimg->message); } ssimg->message = soup_message_new_from_uri (SOUP_METHOD_GET, base_uri); if (ssimg->message == NULL) { /* TRANSLATORS: this is when networking is not available */ gs_screenshot_image_set_error (ssimg, _("Screenshot not available")); return; } /* not all servers support If-Modified-Since, but worst case we just * re-download the entire file again every 30 days */ if (g_file_test (ssimg->filename, G_FILE_TEST_EXISTS)) { g_autoptr(GFile) file = g_file_new_for_path (ssimg->filename); gs_screenshot_soup_msg_set_modified_request (ssimg->message, file); } /* send async */ soup_session_queue_message (ssimg->session, g_object_ref (ssimg->message) /* transfer full */, gs_screenshot_image_complete_cb, g_object_ref (ssimg)); }
void ghb_sanitize_audio(GValue *settings, GValue *asettings) { gint titleindex, track, acodec, select_acodec, mix; hb_audio_config_t *aconfig; gint mux; gint bitrate; gint sr; g_debug("ghb_santiize_audio ()"); mux = ghb_settings_combo_int(settings, "FileFormat"); titleindex = ghb_settings_get_int(settings, "title_no"); track = ghb_settings_combo_int(asettings, "AudioTrack"); acodec = ghb_settings_combo_int(asettings, "AudioEncoder"); mix = ghb_settings_combo_int(asettings, "AudioMixdown"); bitrate = ghb_settings_combo_int(asettings, "AudioBitrate"); sr = ghb_settings_combo_int(asettings, "AudioSamplerate"); aconfig = ghb_get_scan_audio_info(titleindex, track); if (sr == 0) { sr = aconfig ? aconfig->in.samplerate : 48000; } gint fallback = ghb_select_fallback(settings, mux, acodec); gint copy_mask = ghb_get_copy_mask(settings); select_acodec = ghb_select_audio_codec(mux, aconfig, acodec, fallback, copy_mask); if (ghb_audio_is_passthru (select_acodec)) { if (aconfig) { bitrate = aconfig->in.bitrate / 1000; // Set the values for bitrate and samplerate to the input rates mix = 0; ghb_settings_set_string(asettings, "AudioMixdown", ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG; ghb_settings_set_string(asettings, "AudioSamplerate", ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(0))); } else { mix = 0; ghb_settings_set_string(asettings, "AudioMixdown", ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); ghb_settings_set_string(asettings, "AudioSamplerate", ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(0))); bitrate = 448; } ghb_settings_set_double(asettings, "AudioTrackDRCSlider", 0.0); } else { if (mix == 0) mix = ghb_get_best_mix( aconfig, select_acodec, 0); bitrate = hb_get_best_audio_bitrate(select_acodec, bitrate, sr, mix); ghb_settings_set_string(asettings, "AudioMixdown", ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); } ghb_settings_set_string(asettings, "AudioBitrate", ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate))); ghb_settings_take_value(asettings, "AudioEncoderActual", ghb_lookup_acodec_value(select_acodec)); }
static int signal_acquire_clipboard(LassiConnection *lc, DBusMessage *m) { DBusError e; gint32 g; gboolean primary; DBusMessageIter iter, sub; char **targets; unsigned alloc_targets, j; dbus_error_init(&e); if (!(dbus_message_get_args(m, &e, DBUS_TYPE_INT32, &g, DBUS_TYPE_BOOLEAN, &primary, DBUS_TYPE_INVALID))) { g_warning("Received invalid message: %s", e.message); dbus_error_free(&e); return -1; } if ((primary ? lc->server->primary_generation : lc->server->clipboard_generation) > g) { g_debug("Ignoring request for clipboard."); return 0; } /* FIXME, tie break missing */ dbus_message_iter_init(m, &iter); dbus_message_iter_next(&iter); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRING) { g_debug("Bad target list"); return -1; } dbus_message_iter_recurse(&iter, &sub); targets = g_new(char*, alloc_targets = 20); j = 0; while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) { const char *t; dbus_message_iter_get_basic(&sub, &t); if (j >= alloc_targets) { alloc_targets *= 2; targets = g_realloc(targets, sizeof(char*) * (alloc_targets+1)); } g_assert(j < alloc_targets); targets[j++] = (char*) t; dbus_message_iter_next(&sub); g_debug("Received target %s on %s", t, lc->id); } targets[j] = NULL; lassi_clipboard_set(&lc->server->clipboard_info, primary, targets); g_free(targets); if (primary) { lc->server->primary_connection = lc; lc->server->primary_empty = FALSE; lc->server->primary_generation = g; } else { lc->server->clipboard_connection = lc; lc->server->clipboard_empty = FALSE; lc->server->clipboard_generation = g; } return 0; }
void ghb_set_pref_audio_settings(gint titleindex, GValue *settings) { gint track; gchar *source_lang; hb_audio_config_t *aconfig; GHashTable *track_indices; gint mux; const GValue *pref_audio; const GValue *audio, *drc, *gain, *enable_qual; gint acodec, bitrate, mix; gdouble rate, quality; gint count, ii, list_count; g_debug("set_pref_audio"); mux = ghb_settings_combo_int(settings, "FileFormat"); track_indices = g_hash_table_new_full(g_int_hash, g_int_equal, free_audio_hash_key_value, free_audio_hash_key_value); // Clear the audio list ghb_clear_audio_list_settings(settings); // Find "best" audio based on audio preferences if (!ghb_settings_get_boolean(settings, "AudioDUB")) { source_lang = g_strdup(ghb_get_source_audio_lang(titleindex, 0)); } else { source_lang = ghb_settings_get_string(settings, "PreferredLanguage"); } pref_audio = ghb_settings_get_value(settings, "AudioList"); list_count = 0; count = ghb_array_len(pref_audio); for (ii = 0; ii < count; ii++) { gint select_acodec; gint fallback; audio = ghb_array_get_nth(pref_audio, ii); acodec = ghb_settings_combo_int(audio, "AudioEncoder"); fallback = ghb_select_fallback(settings, mux, acodec); gint copy_mask = ghb_get_copy_mask(settings); select_acodec = ghb_select_audio_codec(mux, NULL, acodec, fallback, copy_mask); bitrate = ghb_settings_combo_int(audio, "AudioBitrate"); rate = ghb_settings_combo_double(audio, "AudioSamplerate"); mix = ghb_settings_combo_int(audio, "AudioMixdown"); drc = ghb_settings_get_value(audio, "AudioTrackDRCSlider"); gain = ghb_settings_get_value(audio, "AudioTrackGain"); enable_qual = ghb_settings_get_value(audio, "AudioTrackQualityEnable"); quality = ghb_settings_get_double(audio, "AudioTrackQuality"); // If there are multiple audios using the same codec, then // select sequential tracks for each. The hash keeps track // of the tracks used for each codec. track = ghb_find_audio_track(titleindex, source_lang, select_acodec, fallback, track_indices); // Check to see if: // 1. pref codec is passthru // 2. source codec is not passthru // 3. next pref is enabled aconfig = ghb_get_scan_audio_info(titleindex, track); if (aconfig && ghb_audio_is_passthru (acodec)) { // HB_ACODEC_* are bit fields. Treat acodec as mask if (!(aconfig->in.codec & select_acodec & HB_ACODEC_PASS_MASK)) { if (acodec != HB_ACODEC_AUTO_PASS) acodec = fallback; // If we can't substitute the passthru with a suitable // encoder and // If there's more audio to process, or we've already // placed one in the list, then we can skip this one if (!(select_acodec & fallback) && ((ii + 1 < count) || (list_count != 0))) { // Skip this audio acodec = 0; } } else { select_acodec &= aconfig->in.codec | HB_ACODEC_PASS_FLAG; } } if (titleindex >= 0 && track < 0) acodec = 0; if (acodec != 0) { GValue *asettings = ghb_dict_value_new(); ghb_settings_set_int(asettings, "AudioTrack", track); ghb_settings_set_string(asettings, "AudioEncoder", ghb_lookup_combo_string("AudioEncoder", ghb_int_value(acodec))); ghb_settings_set_value(asettings, "AudioEncoderActual", ghb_lookup_acodec_value(select_acodec)); ghb_settings_set_value(asettings, "AudioTrackQualityEnable", enable_qual); ghb_settings_set_double(asettings, "AudioTrackQuality", quality); // This gets set autimatically if the codec is passthru ghb_settings_set_string(asettings, "AudioBitrate", ghb_lookup_combo_string("AudioBitrate", ghb_int_value(bitrate))); ghb_settings_set_string(asettings, "AudioSamplerate", ghb_lookup_combo_string("AudioSamplerate", ghb_int_value(rate))); mix = ghb_get_best_mix( aconfig, select_acodec, mix); ghb_settings_set_string(asettings, "AudioMixdown", ghb_lookup_combo_string("AudioMixdown", ghb_int_value(mix))); ghb_settings_set_value(asettings, "AudioTrackDRCSlider", drc); ghb_settings_set_value(asettings, "AudioTrackGain", gain); ghb_sanitize_audio(settings, asettings); ghb_add_audio_to_settings(settings, asettings); } } g_free(source_lang); g_hash_table_destroy(track_indices); }
static int server_init(LassiServer *ls) { DBusError e; int r = -1; guint16 port; g_assert(ls); memset(ls, 0, sizeof(*ls)); dbus_error_init(&e); for (port = PORT_MIN; port < PORT_MAX; port++) { char *t; t = g_strdup_printf("tcp:port=%u,host=0.0.0.0", port); ls->dbus_server = dbus_server_listen(t, &e); g_free(t); if (ls->dbus_server) { ls->port = port; break; } if (!dbus_error_has_name(&e, DBUS_ERROR_ADDRESS_IN_USE)) { g_warning("Failed to create D-Bus server: %s %s", e.message, e.name); goto finish; } dbus_error_free(&e); } if (!ls->dbus_server) { g_warning("All ports blocked."); goto finish; } g_debug("Listening on port %u", port); dbus_server_setup_with_g_main(ls->dbus_server, NULL); dbus_server_set_new_connection_function(ls->dbus_server, new_connection, ls, NULL); ls->connections_by_id = g_hash_table_new(g_str_hash, g_str_equal); ls->id = g_strdup_printf(_("%s's desktop on %s"), g_get_user_name(), g_get_host_name()); if (lassi_avahi_init(&ls->avahi_info, ls) < 0) goto finish; /* The initialization of Avahi might have changed ls->id! */ ls->address = dbus_server_get_address(ls->dbus_server); ls->order = g_list_prepend(NULL, g_strdup(ls->id)); if (lassi_grab_init(&ls->grab_info, ls) < 0) goto finish; if (lassi_osd_init(&ls->osd_info) < 0) goto finish; if (lassi_tray_init(&ls->tray_info, ls) < 0) goto finish; if (lassi_clipboard_init(&ls->clipboard_info, ls) < 0) goto finish; if (lassi_prefs_init(&ls->prefs_info, ls) < 0) goto finish; r = 0; finish: dbus_error_free(&e); return r; }
void ghb_audio_list_refresh(signal_user_data_t *ud) { GtkTreeView *treeview; GtkTreeIter iter; GtkListStore *store; gboolean done; gint row = 0; const GValue *audio_list; g_debug("ghb_audio_list_refresh ()"); treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_list")); store = GTK_LIST_STORE(gtk_tree_view_get_model(treeview)); if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) { do { const gchar *track, *codec, *br = NULL, *sr, *mix; gchar *s_drc, *s_gain, *s_quality = NULL; gdouble drc, gain; GValue *asettings; audio_list = ghb_settings_get_value(ud->settings, "audio_list"); if (row >= ghb_array_len(audio_list)) return; asettings = ghb_array_get_nth(audio_list, row); track = ghb_settings_combo_option(asettings, "AudioTrack"); codec = ghb_settings_combo_option(asettings, "AudioEncoderActual"); double quality = ghb_settings_get_double(asettings, "AudioTrackQuality"); if (ghb_settings_get_boolean(asettings, "AudioTrackQualityEnable") && quality != HB_INVALID_AUDIO_QUALITY) { int codec = ghb_settings_combo_int(asettings, "AudioEncoderActual"); s_quality = ghb_format_quality("Q/", codec, quality); } else { br = ghb_settings_get_string(asettings, "AudioBitrate"); } sr = ghb_settings_combo_option(asettings, "AudioSamplerate"); mix = ghb_settings_combo_option(asettings, "AudioMixdown"); gain = ghb_settings_get_double(asettings, "AudioTrackGain"); s_gain = g_strdup_printf("%.fdB", gain); drc = ghb_settings_get_double(asettings, "AudioTrackDRCSlider"); if (drc < 1.0) s_drc = g_strdup("Off"); else s_drc = g_strdup_printf("%.1f", drc); gtk_list_store_set(GTK_LIST_STORE(store), &iter, // These are displayed in list 0, track, 1, codec, 2, s_quality ? s_quality : br, 3, sr, 4, mix, 5, s_gain, 6, s_drc, -1); g_free(s_drc); g_free(s_gain); done = !gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); row++; } while (!done); } }
static void connection_unlink(LassiConnection *lc, gboolean remove_from_order) { LassiServer *ls; g_assert(lc); g_debug("Unlinking %s (%s)", lc->id, lc->address); ls = lc->server; if (lc->id) { DBusMessage *n; dbus_bool_t b; /* Tell everyone */ n = dbus_message_new_signal("/", LASSI_INTERFACE, "NodeRemoved"); g_assert(n); b = dbus_message_append_args(n, DBUS_TYPE_STRING, &lc->id, DBUS_TYPE_STRING, &lc->address, DBUS_TYPE_BOOLEAN, &remove_from_order, DBUS_TYPE_INVALID); g_assert(b); server_broadcast(ls, n, NULL); dbus_message_unref(n); } ls->connections = g_list_remove(ls->connections, lc); ls->n_connections --; if (lc->id) { show_welcome(lc, FALSE); g_hash_table_remove(ls->connections_by_id, lc->id); ls->connections_left = g_list_remove(ls->connections_left, lc); ls->connections_right = g_list_remove(ls->connections_right, lc); if (ls->active_connection == lc) server_pick_active_connection(ls); if (ls->clipboard_connection == lc) { ls->clipboard_connection = NULL; ls->clipboard_empty = TRUE; lassi_clipboard_clear(&lc->server->clipboard_info, FALSE); } if (ls->primary_connection == lc) { ls->primary_connection = NULL; ls->primary_empty = TRUE; lassi_clipboard_clear(&lc->server->clipboard_info, TRUE); } if (remove_from_order) { GList *i = g_list_find_custom(ls->order, lc->id, (GCompareFunc) strcmp); if (i) ls->order = g_list_delete_link(ls->order, i); } server_layout_changed(ls, -1); lassi_prefs_update(&ls->prefs_info); server_dump(ls); } lassi_tray_update(&ls->tray_info, ls->n_connections); connection_destroy(lc); }
static gboolean find_max_width_and_height (const gchar *uri, guint *width, guint *height) { GError *error = NULL; GFile *file; GFileInputStream *stream; guint n_images; guint i; guint16 header [ICON_HEADER_SIZE_16]; *width = 0; *height = 0; file = g_file_new_for_uri (uri); stream = g_file_read (file, NULL, &error); if (error) { g_message ("Could not read file '%s': %s", uri, error->message); g_error_free (error); g_object_unref (file); return FALSE; } /* Header consists of: * - 2bytes, reserved, must be 0 * - 2bytes, image type (1:icon, 2:cursor, other values invalid) * - 2bytes, number of images in the file. * * Right now we just need the number of images in the file. */ if (!g_input_stream_read_all (G_INPUT_STREAM (stream), header, ICON_HEADER_SIZE_16 * 2, NULL, NULL, &error)) { g_message ("Error reading icon header from stream: '%s'", error->message); g_error_free (error); g_object_unref (stream); g_object_unref (file); return FALSE; } n_images = GUINT16_FROM_LE (header[2]); g_debug ("Found '%u' images in the icon file...", n_images); /* Loop images looking for the biggest one... */ for (i = 0; i < n_images; i++) { guint8 image_metadata [ICON_IMAGE_METADATA_SIZE_8]; /* Image metadata chunk consists of: * - 1 byte, width in pixels, 0 means 256 * - 1 byte, height in pixels, 0 means 256 * - Plus some other stuff we don't care about... */ if (!g_input_stream_read_all (G_INPUT_STREAM (stream), image_metadata, ICON_IMAGE_METADATA_SIZE_8, NULL, NULL, &error)) { g_message ("Error reading icon image metadata '%u' from stream: '%s'", i, error->message); g_error_free (error); break; } g_debug (" Image '%u'; width:%u height:%u", i, image_metadata[0], image_metadata[1]); /* Width... */ if (image_metadata[0] == 0) { *width = 256; } else if (image_metadata[0] > *width) { *width = image_metadata[0]; } /* Height... */ if (image_metadata[1] == 0) { *height = 256; } else if (image_metadata[1] > *width) { *height = image_metadata[0]; } } g_input_stream_close (G_INPUT_STREAM (stream), NULL, NULL); g_object_unref (stream); g_object_unref (file); return TRUE; }
int lassi_server_get_clipboard(LassiServer *ls, gboolean primary, const char *t, int *f, gpointer *p, int *l) { DBusMessage *n, *reply; DBusConnection *c; DBusError e; int ret = -1; DBusMessageIter iter, sub; gboolean b; g_assert(ls); dbus_error_init(&e); if (primary) { if (ls->primary_empty || !ls->primary_connection) return -1; c = ls->primary_connection->dbus_connection; } else { if (ls->clipboard_empty || !ls->clipboard_connection) return -1; c = ls->clipboard_connection->dbus_connection; } n = dbus_message_new_method_call(NULL, "/", LASSI_INTERFACE, "GetClipboard"); g_assert(n); b = dbus_message_append_args(n, DBUS_TYPE_BOOLEAN, &primary, DBUS_TYPE_STRING, &t, DBUS_TYPE_INVALID); g_assert(b); if (!(reply = dbus_connection_send_with_reply_and_block(c, n, -1, &e))) { g_debug("Getting clipboard failed: %s", e.message); goto finish; } dbus_message_iter_init(reply, &iter); dbus_message_iter_get_basic(&iter, f); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE) { g_debug("Invalid clipboard data"); goto finish; } dbus_message_iter_recurse(&iter, &sub); dbus_message_iter_get_fixed_array(&sub, p, l); *p = g_memdup(*p, *l); ret = 0; finish: dbus_message_unref(n); if (reply) dbus_message_unref(reply); dbus_error_free(&e); return ret; }
static void hev_scgi_connection_manager_constructed(GObject * obj) { g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); G_OBJECT_CLASS(hev_scgi_connection_manager_parent_class)->constructed(obj); }
static int signal_hello(LassiConnection *lc, DBusMessage *m) { const char *id, *address; DBusError e; GList *i; dbus_bool_t b; DBusMessage *n; gint32 active_generation, order_generation, clipboard_generation; dbus_error_init(&e); if (lc->id) { g_debug("Received duplicate HelloNode."); return -1; } if (!(dbus_message_get_args( m, &e, DBUS_TYPE_STRING, &id, DBUS_TYPE_STRING, &address, DBUS_TYPE_INT32, &active_generation, DBUS_TYPE_INT32, &order_generation, DBUS_TYPE_INT32, &clipboard_generation, DBUS_TYPE_INVALID))) { g_warning("Received invalid message: %s", e.message); dbus_error_free(&e); return -1; } if (strcmp(id, lc->server->id) == 0) { g_debug("Dropping looped back connection."); return -1; } if (g_hash_table_lookup(lc->server->connections_by_id, id)) { g_debug("Dropping duplicate connection."); return -1; } lc->server->active_generation = MAX(lc->server->active_generation, active_generation); lc->server->order_generation = MAX(lc->server->order_generation, order_generation); lc->server->clipboard_generation = MAX(lc->server->clipboard_generation, clipboard_generation); g_debug("Got welcome from %s (%s)", id, address); lc->id = g_strdup(id); lc->address = g_strdup(address); g_hash_table_insert(lc->server->connections_by_id, lc->id, lc); server_position_connection(lc->server, lc); /* Notify all old nodes of the new one */ n = dbus_message_new_signal("/", LASSI_INTERFACE, "NodeAdded"); g_assert(n); b = dbus_message_append_args(n, DBUS_TYPE_STRING, &id, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID); g_assert(b); server_broadcast(lc->server, n, lc); dbus_message_unref(n); /* Notify new node about old nodes */ for (i = lc->server->connections; i; i = i->next) { LassiConnection *k = i->data; if (k == lc || !k->id) continue; n = dbus_message_new_signal("/", LASSI_INTERFACE, "NodeAdded"); g_assert(n); b = dbus_message_append_args(n, DBUS_TYPE_STRING, &id, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID); g_assert(b); b = dbus_connection_send(lc->dbus_connection, n, NULL); g_assert(b); dbus_message_unref(n); } if (lc->we_are_client) { server_send_update_grab(lc->server, -1); lassi_server_send_update_order(lc->server, NULL); lc->delayed_welcome = FALSE; show_welcome(lc, TRUE); } else lc->delayed_welcome = TRUE; server_layout_changed(lc->server, -1); lassi_prefs_update(&lc->server->prefs_info); server_dump(lc->server); return 0; }
GObject * hev_scgi_connection_manager_new(void) { g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); return g_object_new(HEV_TYPE_SCGI_CONNECTION_MANAGER, NULL); }
static void * example_thread(void *data) { NiceAgent *agent; NiceCandidate *local, *remote; GIOChannel* io_stdin; guint stream_id; gchar *line = NULL; int rval; #ifdef G_OS_WIN32 io_stdin = g_io_channel_win32_new_fd(_fileno(stdin)); #else io_stdin = g_io_channel_unix_new(fileno(stdin)); #endif g_io_channel_set_flags (io_stdin, G_IO_FLAG_NONBLOCK, NULL); // Create the nice agent agent = nice_agent_new(g_main_loop_get_context (gloop), NICE_COMPATIBILITY_RFC5245); if (agent == NULL) g_error("Failed to create agent"); // Set the STUN settings and controlling mode if (stun_addr) { g_object_set(agent, "stun-server", stun_addr, NULL); g_object_set(agent, "stun-server-port", stun_port, NULL); } g_object_set(agent, "controlling-mode", controlling, NULL); // Connect to the signals g_signal_connect(agent, "candidate-gathering-done", G_CALLBACK(cb_candidate_gathering_done), NULL); g_signal_connect(agent, "new-selected-pair", G_CALLBACK(cb_new_selected_pair), NULL); g_signal_connect(agent, "component-state-changed", G_CALLBACK(cb_component_state_changed), NULL); // Create a new stream with one component stream_id = nice_agent_add_stream(agent, 1); if (stream_id == 0) g_error("Failed to add stream"); // Attach to the component to receive the data // Without this call, candidates cannot be gathered nice_agent_attach_recv(agent, stream_id, 1, g_main_loop_get_context (gloop), cb_nice_recv, NULL); // Start gathering local candidates if (!nice_agent_gather_candidates(agent, stream_id)) g_error("Failed to start candidate gathering"); g_debug("waiting for candidate-gathering-done signal..."); g_mutex_lock(&gather_mutex); while (!exit_thread && !candidate_gathering_done) g_cond_wait(&gather_cond, &gather_mutex); g_mutex_unlock(&gather_mutex); if (exit_thread) goto end; // Candidate gathering is done. Send our local candidates on stdout printf("Copy this line to remote client:\n"); printf("\n "); print_local_data(agent, stream_id, 1); printf("\n"); // Listen on stdin for the remote candidate list printf("Enter remote data (single line, no wrapping):\n"); printf("> "); fflush (stdout); while (!exit_thread) { GIOStatus s = g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL); if (s == G_IO_STATUS_NORMAL) { // Parse remote candidate list and set it on the agent rval = parse_remote_data(agent, stream_id, 1, line); if (rval == EXIT_SUCCESS) { g_free (line); break; } else { fprintf(stderr, "ERROR: failed to parse remote data\n"); printf("Enter remote data (single line, no wrapping):\n"); printf("> "); fflush (stdout); } g_free (line); } else if (s == G_IO_STATUS_AGAIN) { g_usleep (100000); } } g_debug("waiting for state READY or FAILED signal..."); g_mutex_lock(&negotiate_mutex); while (!exit_thread && !negotiation_done) g_cond_wait(&negotiate_cond, &negotiate_mutex); g_mutex_unlock(&negotiate_mutex); if (exit_thread) goto end; // Get current selected candidate pair and print IP address used if (nice_agent_get_selected_pair (agent, stream_id, 1, &local, &remote)) { gchar ipaddr[INET6_ADDRSTRLEN]; nice_address_to_string(&local->addr, ipaddr); printf("\nNegotiation complete: ([%s]:%d,", ipaddr, nice_address_get_port(&local->addr)); nice_address_to_string(&remote->addr, ipaddr); printf(" [%s]:%d)\n", ipaddr, nice_address_get_port(&remote->addr)); } // Listen to stdin and send data written to it printf("\nSend lines to remote (Ctrl-D to quit):\n"); printf("> "); fflush (stdout); while (!exit_thread) { GIOStatus s = g_io_channel_read_line (io_stdin, &line, NULL, NULL, NULL); if (s == G_IO_STATUS_NORMAL) { nice_agent_send(agent, stream_id, 1, strlen(line), line); g_free (line); printf("> "); fflush (stdout); } else if (s == G_IO_STATUS_AGAIN) { g_usleep (100000); } else { // Ctrl-D was pressed. nice_agent_send(agent, stream_id, 1, 1, "\0"); break; } } end: g_io_channel_unref (io_stdin); g_object_unref(agent); g_main_loop_quit (gloop); return NULL; }