static void flickr_credentials_mgr_goa_on_managed_objects(GObject* mgr_proxy, GAsyncResult* result, gpointer user_data) { /* UserCode on_managed_objects { */ FlickrCredentialsLoadClosure *closure = (FlickrCredentialsLoadClosure *) user_data; FlickrCredentialsManagerGOA *self = FLICKR_CREDENTIALS_MANAGER_GOA (closure->credentials); gboolean error_occurred = FALSE; GError *error = NULL; if (!result) { error_occurred = TRUE; goto exit; } GVariant *result_data = g_dbus_proxy_call_finish ((GDBusProxy *) mgr_proxy, result, NULL); if (!result_data) { error_occurred = TRUE; goto exit; } GVariant *content = g_variant_get_child_value (result_data, 0); g_variant_unref (result_data); GVariantIter iter; GVariant *child; GVariant *object_path; GVariant *interfaces; GVariant *account; GVariant *provider_type; gboolean done = FALSE; g_variant_iter_init (&iter, content); while ((child = g_variant_iter_next_value(&iter))) { /* Check whether child is an account: */ interfaces = g_variant_get_child_value (child, 1); account = g_variant_lookup_value ( interfaces, "org.gnome.OnlineAccounts.Account", NULL ); if (account) { /* Is account a flickr account? */ provider_type = g_variant_lookup_value (account, "ProviderType", NULL); if (provider_type) { if (g_strcmp0 (g_variant_get_string (provider_type, NULL), "flickr") == 0) { object_path = g_variant_get_child_value (child, 0); self->priv->object_path = g_strdup (g_variant_get_string (object_path, NULL)); g_variant_unref (object_path); flickr_credentials_mgr_goa_get_access_data ( self, interfaces, closure, &error ); error_occurred = error ? TRUE : FALSE; done = TRUE; } g_variant_unref (provider_type); } g_variant_unref (account); } g_variant_unref (interfaces); if (done) { break; } } g_variant_unref (content); exit: g_object_unref (mgr_proxy); if (error_occurred) { closure->callback (closure->credentials, FALSE, error, closure->user_data); flickr_credentials_load_closure_free (closure); } if (error) { g_error_free (error); } /* } UserCode */ }
static GSList *scan(GSList *options) { struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; struct sr_channel *ch; struct sr_config *src; const struct fx2lafw_profile *prof; GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; libusb_device **devlist; struct libusb_device_handle *hdl; int devcnt, num_logic_channels, ret, i, j; const char *conn; char manufacturer[64], product[64]; drvc = di->priv; conn = NULL; for (l = options; l; l = l->next) { src = l->data; switch (src->key) { case SR_CONF_CONN: conn = g_variant_get_string(src->data, NULL); break; } } if (conn) conn_devices = sr_usb_find(drvc->sr_ctx->libusb_ctx, conn); else conn_devices = NULL; /* Find all fx2lafw compatible devices and upload firmware to them. */ devices = NULL; libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist); for (i = 0; devlist[i]; i++) { if (conn) { usb = NULL; for (l = conn_devices; l; l = l->next) { usb = l->data; if (usb->bus == libusb_get_bus_number(devlist[i]) && usb->address == libusb_get_device_address(devlist[i])) break; } if (!l) /* This device matched none of the ones that * matched the conn specification. */ continue; } if ((ret = libusb_get_device_descriptor( devlist[i], &des)) != 0) { sr_warn("Failed to get device descriptor: %s.", libusb_error_name(ret)); continue; } if ((ret = libusb_open(devlist[i], &hdl)) < 0) continue; if (des.iManufacturer == 0) { manufacturer[0] = '\0'; } else if ((ret = libusb_get_string_descriptor_ascii(hdl, des.iManufacturer, (unsigned char *) manufacturer, sizeof(manufacturer))) < 0) { sr_warn("Failed to get manufacturer string descriptor: %s.", libusb_error_name(ret)); continue; } if (des.iProduct == 0) { product[0] = '\0'; } else if ((ret = libusb_get_string_descriptor_ascii(hdl, des.iProduct, (unsigned char *) product, sizeof(product))) < 0) { sr_warn("Failed to get product string descriptor: %s.", libusb_error_name(ret)); continue; } libusb_close(hdl); prof = NULL; for (j = 0; supported_fx2[j].vid; j++) { if (des.idVendor == supported_fx2[j].vid && des.idProduct == supported_fx2[j].pid && (!supported_fx2[j].usb_manufacturer || !strcmp(manufacturer, supported_fx2[j].usb_manufacturer)) && (!supported_fx2[j].usb_manufacturer || !strcmp(product, supported_fx2[j].usb_product))) { prof = &supported_fx2[j]; break; } } /* Skip if the device was not found. */ if (!prof) continue; devcnt = g_slist_length(drvc->instances); sdi = sr_dev_inst_new(devcnt, SR_ST_INITIALIZING, prof->vendor, prof->model, prof->model_version); if (!sdi) return NULL; sdi->driver = di; /* Fill in channellist according to this device's profile. */ num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8; for (j = 0; j < num_logic_channels; j++) { if (!(ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]))) return NULL; sdi->channels = g_slist_append(sdi->channels, ch); } devc = fx2lafw_dev_new(); devc->profile = prof; sdi->priv = devc; drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); if (fx2lafw_check_conf_profile(devlist[i])) { /* Already has the firmware, so fix the new address. */ sr_dbg("Found an fx2lafw device."); sdi->status = SR_ST_INACTIVE; sdi->inst_type = SR_INST_USB; sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); } else { if (ezusb_upload_firmware(devlist[i], USB_CONFIGURATION, prof->firmware) == SR_OK) /* Store when this device's FW was updated. */ devc->fw_updated = g_get_monotonic_time(); else sr_err("Firmware upload failed for " "device %d.", devcnt); sdi->inst_type = SR_INST_USB; sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), 0xff, NULL); } } libusb_free_device_list(devlist, 1); g_slist_free_full(conn_devices, (GDestroyNotify)sr_usb_dev_inst_free); return devices; }
static gchar * gvariant_simple_to_string (GVariant *variant) { GVariantClass class; gchar *str; class = g_variant_classify (variant); switch (class) { case G_VARIANT_CLASS_BOOLEAN: if (g_variant_get_boolean (variant)) str = g_strdup ("true"); else str = g_strdup ("false"); break; case G_VARIANT_CLASS_BYTE: str = g_strdup_printf ("%u", g_variant_get_byte (variant)); break; case G_VARIANT_CLASS_INT16: str = g_strdup_printf ("%d", g_variant_get_int16 (variant)); break; case G_VARIANT_CLASS_UINT16: str = g_strdup_printf ("%u", g_variant_get_uint16 (variant)); break; case G_VARIANT_CLASS_INT32: str = g_strdup_printf ("%d", g_variant_get_int32 (variant)); break; case G_VARIANT_CLASS_UINT32: str = g_strdup_printf ("%u", g_variant_get_uint32 (variant)); break; case G_VARIANT_CLASS_INT64: str = g_strdup_printf ("%" G_GINT64_FORMAT, g_variant_get_int64 (variant)); break; case G_VARIANT_CLASS_UINT64: str = g_strdup_printf ("%" G_GUINT64_FORMAT, g_variant_get_uint64 (variant)); break; case G_VARIANT_CLASS_HANDLE: str = g_strdup_printf ("%d", g_variant_get_handle (variant)); break; case G_VARIANT_CLASS_DOUBLE: { gchar buf[G_ASCII_DTOSTR_BUF_SIZE]; g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f", g_variant_get_double (variant)); str = g_strdup (buf); break; } case G_VARIANT_CLASS_STRING: case G_VARIANT_CLASS_OBJECT_PATH: case G_VARIANT_CLASS_SIGNATURE: str = g_strdup (g_variant_get_string (variant, NULL)); break; default: g_assert_not_reached (); break; } return str; }
static void flickr_credentials_mgr_goa_get_access_data(FlickrCredentialsManagerGOA* self, GVariant* interfaces, FlickrCredentialsLoadClosure* closure, GError** error) { /* UserCode get_access_data { */ GVariant *oauth = NULL; GVariant *consumer_key = NULL; GVariant *consumer_secret = NULL; GDBusProxy *proxy = NULL; gboolean called = FALSE; oauth = g_variant_lookup_value (interfaces, "org.gnome.OnlineAccounts.OAuthBased", NULL); if (!oauth) goto exit; consumer_key = g_variant_lookup_value (oauth, "ConsumerKey", NULL); if (!consumer_key) goto exit; consumer_secret = g_variant_lookup_value (oauth, "ConsumerSecret", NULL); if (!consumer_secret) goto exit; self->priv->consumer_key = g_strdup (g_variant_get_string (consumer_key, NULL)); self->priv->consumer_secret = g_strdup (g_variant_get_string (consumer_secret, NULL)); proxy = flickr_credentials_mgr_goa_create_proxy_sync ( self, "org.gnome.OnlineAccounts", self->priv->object_path, "org.gnome.OnlineAccounts.OAuthBased" ); if (proxy) { g_dbus_proxy_call ( proxy, "GetAccessToken", NULL, /* GVariant *parameters */ G_DBUS_CALL_FLAGS_NONE, /*GDBusCallFlags flags */ -1, /* gint timeout_msec */ NULL, /* GCancellable *cancellable */ (GAsyncReadyCallback) flickr_credentials_mgr_goa_on_access_token, closure ); called = TRUE; } exit: if (error && !called) { *error = g_error_new ( FLICKR_CREDENTIALS_ERROR, FLICKR_CREDENTIALS_ERROR_FAILURE, G_STRLOC ": access token cannot be read" ); } if (proxy && !called) { g_object_unref (proxy); } if (consumer_key) { g_variant_unref (consumer_key); } if (consumer_secret) { g_variant_unref (consumer_secret); } if (oauth) { g_variant_unref (oauth); } /* } UserCode */ }
static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; struct analog_gen *ag; struct sr_channel *ch; GSList *l; int logic_pattern, analog_pattern, ret; unsigned int i; const char *stropt; devc = sdi->priv; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; ret = SR_OK; switch (key) { case SR_CONF_SAMPLERATE: devc->cur_samplerate = g_variant_get_uint64(data); break; case SR_CONF_LIMIT_SAMPLES: devc->limit_msec = 0; devc->limit_samples = g_variant_get_uint64(data); break; case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); devc->limit_samples = 0; break; case SR_CONF_AVERAGING: devc->avg = g_variant_get_boolean(data); sr_dbg("%s averaging", devc->avg ? "Enabling" : "Disabling"); break; case SR_CONF_AVG_SAMPLES: devc->avg_samples = g_variant_get_uint64(data); sr_dbg("Setting averaging rate to %" PRIu64, devc->avg_samples); break; case SR_CONF_PATTERN_MODE: if (!cg) return SR_ERR_CHANNEL_GROUP; stropt = g_variant_get_string(data, NULL); logic_pattern = analog_pattern = -1; for (i = 0; i < ARRAY_SIZE(logic_pattern_str); i++) { if (!strcmp(stropt, logic_pattern_str[i])) { logic_pattern = i; break; } } for (i = 0; i < ARRAY_SIZE(analog_pattern_str); i++) { if (!strcmp(stropt, analog_pattern_str[i])) { analog_pattern = i; break; } } if (logic_pattern == -1 && analog_pattern == -1) return SR_ERR_ARG; for (l = cg->channels; l; l = l->next) { ch = l->data; if (ch->type == SR_CHANNEL_LOGIC) { if (logic_pattern == -1) return SR_ERR_ARG; sr_dbg("Setting logic pattern to %s", logic_pattern_str[logic_pattern]); devc->logic_pattern = logic_pattern; /* Might as well do this now, these are static. */ if (logic_pattern == PATTERN_ALL_LOW) memset(devc->logic_data, 0x00, LOGIC_BUFSIZE); else if (logic_pattern == PATTERN_ALL_HIGH) memset(devc->logic_data, 0xff, LOGIC_BUFSIZE); } else if (ch->type == SR_CHANNEL_ANALOG) { if (analog_pattern == -1) return SR_ERR_ARG; sr_dbg("Setting analog pattern for channel %s to %s", ch->name, analog_pattern_str[analog_pattern]); ag = g_hash_table_lookup(devc->ch_ag, ch); ag->pattern = analog_pattern; } else return SR_ERR_BUG; } break; case SR_CONF_AMPLITUDE: if (!cg) return SR_ERR_CHANNEL_GROUP; for (l = cg->channels; l; l = l->next) { ch = l->data; if (ch->type != SR_CHANNEL_ANALOG) return SR_ERR_ARG; ag = g_hash_table_lookup(devc->ch_ag, ch); ag->amplitude = g_variant_get_double(data); } break; default: ret = SR_ERR_NA; } return ret; }
gboolean flatpak_builtin_build_commit_from (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) dst_repofile = NULL; g_autoptr(OstreeRepo) dst_repo = NULL; g_autoptr(GFile) src_repofile = NULL; g_autoptr(OstreeRepo) src_repo = NULL; g_autofree char *src_repo_uri = NULL; const char *dst_repo_arg; const char **dst_refs; int n_dst_refs = 0; g_autoptr(FlatpakRepoTransaction) transaction = NULL; g_autoptr(GPtrArray) src_refs = NULL; g_autoptr(GPtrArray) resolved_src_refs = NULL; OstreeRepoCommitState src_commit_state; struct timespec ts; guint64 timestamp; int i; context = g_option_context_new (_("DST-REPO [DST-REF…] - Make a new commit from existing commits")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 2) return usage_error (context, _("DST-REPO must be specified"), error); dst_repo_arg = argv[1]; dst_refs = (const char **) argv + 2; n_dst_refs = argc - 2; if (opt_src_repo == NULL && n_dst_refs != 1) return usage_error (context, _("If --src-repo is not specified, exactly one destination ref must be specified"), error); if (opt_src_ref != NULL && n_dst_refs != 1) return usage_error (context, _("If --src-ref is specified, exactly one destination ref must be specified"), error); if (opt_src_repo == NULL && opt_src_ref == NULL) return flatpak_fail (error, _("Either --src-repo or --src-ref must be specified.")); if (opt_timestamp) { if (!parse_datetime (&ts, opt_timestamp, NULL)) return flatpak_fail (error, _("Could not parse '%s'"), opt_timestamp); } dst_repofile = g_file_new_for_commandline_arg (dst_repo_arg); if (!g_file_query_exists (dst_repofile, cancellable)) return flatpak_fail (error, _("'%s' is not a valid repository"), dst_repo_arg); dst_repo = ostree_repo_new (dst_repofile); if (!ostree_repo_open (dst_repo, cancellable, error)) return FALSE; if (opt_disable_fsync) ostree_repo_set_disable_fsync (dst_repo, TRUE); if (opt_src_repo) { src_repofile = g_file_new_for_commandline_arg (opt_src_repo); if (!g_file_query_exists (src_repofile, cancellable)) return flatpak_fail (error, _("'%s' is not a valid repository"), opt_src_repo); src_repo_uri = g_file_get_uri (src_repofile); src_repo = ostree_repo_new (src_repofile); if (!ostree_repo_open (src_repo, cancellable, error)) return FALSE; } else { src_repo = g_object_ref (dst_repo); } src_refs = g_ptr_array_new_with_free_func (g_free); if (opt_src_ref) { g_assert (n_dst_refs == 1); g_ptr_array_add (src_refs, g_strdup (opt_src_ref)); } else { g_assert (opt_src_repo != NULL); if (n_dst_refs == 0) { g_autofree const char **keys = NULL; g_autoptr(GHashTable) all_src_refs = NULL; if (!ostree_repo_list_refs (src_repo, NULL, &all_src_refs, cancellable, error)) return FALSE; keys = (const char **) g_hash_table_get_keys_as_array (all_src_refs, NULL); for (i = 0; keys[i] != NULL; i++) { if (g_str_has_prefix (keys[i], "runtime/") || g_str_has_prefix (keys[i], "app/")) g_ptr_array_add (src_refs, g_strdup (keys[i])); } n_dst_refs = src_refs->len; dst_refs = (const char **) src_refs->pdata; } else { for (i = 0; i < n_dst_refs; i++) g_ptr_array_add (src_refs, g_strdup (dst_refs[i])); } } resolved_src_refs = g_ptr_array_new_with_free_func (g_free); for (i = 0; i < src_refs->len; i++) { const char *src_ref = g_ptr_array_index (src_refs, i); char *resolved_ref; if (!ostree_repo_resolve_rev (src_repo, src_ref, FALSE, &resolved_ref, error)) return FALSE; g_ptr_array_add (resolved_src_refs, resolved_ref); } if (src_repo_uri != NULL) { OstreeRepoPullFlags pullflags = 0; GVariantBuilder builder; g_autoptr(OstreeAsyncProgress) progress = NULL; g_auto(GLnxConsoleRef) console = { 0, }; g_autoptr(GVariant) options = NULL; gboolean res; if (opt_untrusted) pullflags |= OSTREE_REPO_PULL_FLAGS_UNTRUSTED; glnx_console_lock (&console); if (console.is_tty) progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}")); g_variant_builder_add (&builder, "{s@v}", "flags", g_variant_new_variant (g_variant_new_int32 (pullflags))); g_variant_builder_add (&builder, "{s@v}", "refs", g_variant_new_variant (g_variant_new_strv ((const char * const *) resolved_src_refs->pdata, resolved_src_refs->len))); g_variant_builder_add (&builder, "{s@v}", "depth", g_variant_new_variant (g_variant_new_int32 (0))); options = g_variant_ref_sink (g_variant_builder_end (&builder)); res = ostree_repo_pull_with_options (dst_repo, src_repo_uri, options, progress, cancellable, error); if (progress) ostree_async_progress_finish (progress); if (!res) return FALSE; } /* By now we have the commit with commit_id==resolved_ref and dependencies in dst_repo. We now create a new * commit based on the toplevel tree ref from that commit. * This is equivalent to: * ostree commit --skip-if-unchanged --repo=${destrepo} --tree=ref=${resolved_ref} */ transaction = flatpak_repo_transaction_start (dst_repo, cancellable, error); if (transaction == NULL) return FALSE; for (i = 0; i < resolved_src_refs->len; i++) { const char *dst_ref = dst_refs[i]; const char *resolved_ref = g_ptr_array_index (resolved_src_refs, i); g_autofree char *dst_parent = NULL; g_autoptr(GFile) dst_parent_root = NULL; g_autoptr(GFile) src_ref_root = NULL; g_autoptr(GVariant) src_commitv = NULL; g_autoptr(GVariant) dst_commitv = NULL; g_autoptr(OstreeMutableTree) mtree = NULL; g_autoptr(GFile) dst_root = NULL; g_autoptr(GVariant) commitv_metadata = NULL; g_autoptr(GVariant) metadata = NULL; const char *subject; const char *body; g_autofree char *commit_checksum = NULL; GVariantBuilder metadata_builder; gint j; const char *dst_collection_id = NULL; const char *main_collection_id = NULL; g_autoptr(GPtrArray) collection_ids = NULL; if (!ostree_repo_resolve_rev (dst_repo, dst_ref, TRUE, &dst_parent, error)) return FALSE; if (dst_parent != NULL && !ostree_repo_read_commit (dst_repo, dst_parent, &dst_parent_root, NULL, cancellable, error)) return FALSE; if (!ostree_repo_read_commit (dst_repo, resolved_ref, &src_ref_root, NULL, cancellable, error)) return FALSE; if (!ostree_repo_load_commit (dst_repo, resolved_ref, &src_commitv, &src_commit_state, error)) return FALSE; if (src_commit_state & OSTREE_REPO_COMMIT_STATE_PARTIAL) return flatpak_fail (error, _("Can't commit from partial source commit.")); /* Don't create a new commit if this is the same tree */ if (!opt_force && dst_parent_root != NULL && g_file_equal (dst_parent_root, src_ref_root)) { g_print (_("%s: no change\n"), dst_ref); continue; } mtree = ostree_mutable_tree_new (); if (!ostree_repo_write_directory_to_mtree (dst_repo, src_ref_root, mtree, NULL, cancellable, error)) return FALSE; if (!ostree_repo_write_mtree (dst_repo, mtree, &dst_root, cancellable, error)) return FALSE; commitv_metadata = g_variant_get_child_value (src_commitv, 0); g_variant_get_child (src_commitv, 3, "&s", &subject); if (opt_subject) subject = (const char *) opt_subject; g_variant_get_child (src_commitv, 4, "&s", &body); if (opt_body) body = (const char *) opt_body; dst_collection_id = ostree_repo_get_collection_id (dst_repo); collection_ids = g_ptr_array_new_with_free_func (g_free); if (dst_collection_id) { main_collection_id = dst_collection_id; g_ptr_array_add (collection_ids, g_strdup (dst_collection_id)); } if (opt_extra_collection_ids != NULL) { for (j = 0; opt_extra_collection_ids[j] != NULL; j++) { const char *cid = opt_extra_collection_ids[j]; if (main_collection_id == NULL) main_collection_id = cid; /* Fall back to first arg */ if (g_strcmp0 (cid, dst_collection_id) != 0) g_ptr_array_add (collection_ids, g_strdup (cid)); } } g_ptr_array_sort (collection_ids, (GCompareFunc)flatpak_strcmp0_ptr); /* Copy old metadata */ g_variant_builder_init (&metadata_builder, G_VARIANT_TYPE ("a{sv}")); /* Bindings. xa.ref is deprecated but added anyway for backwards compatibility. */ g_variant_builder_add (&metadata_builder, "{sv}", "ostree.collection-binding", g_variant_new_string (main_collection_id ? main_collection_id : "")); if (collection_ids->len > 0) { g_autoptr(GVariantBuilder) cr_builder = g_variant_builder_new (G_VARIANT_TYPE ("a(ss)")); for (j = 0; j < collection_ids->len; j++) g_variant_builder_add (cr_builder, "(ss)", g_ptr_array_index (collection_ids, j), dst_ref); g_variant_builder_add (&metadata_builder, "{sv}", "ostree.collection-refs-binding", g_variant_builder_end (cr_builder)); } g_variant_builder_add (&metadata_builder, "{sv}", "ostree.ref-binding", g_variant_new_strv (&dst_ref, 1)); g_variant_builder_add (&metadata_builder, "{sv}", "xa.ref", g_variant_new_string (dst_ref)); /* Record the source commit. This is nice to have, but it also means the commit-from gets a different commit id, which avoids problems with e.g. sharing .commitmeta files (signatures) */ g_variant_builder_add (&metadata_builder, "{sv}", "xa.from_commit", g_variant_new_string (resolved_ref)); for (j = 0; j < g_variant_n_children (commitv_metadata); j++) { g_autoptr(GVariant) child = g_variant_get_child_value (commitv_metadata, j); g_autoptr(GVariant) keyv = g_variant_get_child_value (child, 0); const char *key = g_variant_get_string (keyv, NULL); if (strcmp (key, "xa.ref") == 0 || strcmp (key, "xa.from_commit") == 0 || strcmp (key, "ostree.collection-binding") == 0 || strcmp (key, "ostree.collection-refs-binding") == 0 || strcmp (key, "ostree.ref-binding") == 0) continue; if (opt_endoflife && strcmp (key, OSTREE_COMMIT_META_KEY_ENDOFLIFE) == 0) continue; g_variant_builder_add_value (&metadata_builder, child); } if (opt_endoflife && *opt_endoflife) g_variant_builder_add (&metadata_builder, "{sv}", OSTREE_COMMIT_META_KEY_ENDOFLIFE, g_variant_new_string (opt_endoflife)); timestamp = ostree_commit_get_timestamp (src_commitv); if (opt_timestamp) timestamp = ts.tv_sec; metadata = g_variant_ref_sink (g_variant_builder_end (&metadata_builder)); if (!ostree_repo_write_commit_with_time (dst_repo, dst_parent, subject, body, metadata, OSTREE_REPO_FILE (dst_root), timestamp, &commit_checksum, cancellable, error)) return FALSE; g_print ("%s: %s\n", dst_ref, commit_checksum); if (!ostree_repo_load_commit (dst_repo, commit_checksum, &dst_commitv, NULL, error)) return FALSE; /* This doesn't copy the detached metadata. I'm not sure if this is a problem. * The main thing there is commit signatures, and we can't copy those, as the commit hash changes. */ if (opt_gpg_key_ids) { char **iter; for (iter = opt_gpg_key_ids; iter && *iter; iter++) { const char *keyid = *iter; g_autoptr(GError) my_error = NULL; if (!ostree_repo_sign_commit (dst_repo, commit_checksum, keyid, opt_gpg_homedir, cancellable, &my_error) && !g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_EXISTS)) { g_propagate_error (error, g_steal_pointer (&my_error)); return FALSE; } } } if (dst_collection_id != NULL) { OstreeCollectionRef ref = { (char *) dst_collection_id, (char *) dst_ref }; ostree_repo_transaction_set_collection_ref (dst_repo, &ref, commit_checksum); } else { ostree_repo_transaction_set_ref (dst_repo, NULL, dst_ref, commit_checksum); } if (opt_extra_collection_ids) { for (j = 0; opt_extra_collection_ids[j] != NULL; j++) { OstreeCollectionRef ref = { (char *) opt_extra_collection_ids[j], (char *) dst_ref }; ostree_repo_transaction_set_collection_ref (dst_repo, &ref, commit_checksum); } } /* Copy + Rewrite any deltas */ { const char *from[2]; gsize j, n_from = 0; if (dst_parent != NULL) from[n_from++] = dst_parent; from[n_from++] = NULL; for (j = 0; j < n_from; j++) { g_autoptr(GError) local_error = NULL; if (!rewrite_delta (src_repo, resolved_ref, dst_repo, commit_checksum, dst_commitv, from[j], &local_error)) g_debug ("Failed to copy delta: %s", local_error->message); } } } if (!ostree_repo_commit_transaction (dst_repo, NULL, cancellable, error)) return FALSE; if (opt_update_appstream && !flatpak_repo_generate_appstream (dst_repo, (const char **) opt_gpg_key_ids, opt_gpg_homedir, 0, cancellable, error)) return FALSE; if (!opt_no_update_summary && !flatpak_repo_update (dst_repo, (const char **) opt_gpg_key_ids, opt_gpg_homedir, cancellable, error)) return FALSE; return TRUE; }
static GSList *scan(GSList *options) { struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; struct sr_probe *probe; struct sr_serial_dev_inst *serial; GSList *l, *devices; int len, cnt; const char *conn, *serialcomm; char *buf; char fmttype[10]; char req[10]; int auxtype; devices = NULL; drvc = di->priv; drvc->instances = NULL; conn = serialcomm = NULL; for (l = options; l; l = l->next) { src = l->data; switch (src->key) { case SR_CONF_CONN: conn = g_variant_get_string(src->data, NULL); break; case SR_CONF_SERIALCOMM: serialcomm = g_variant_get_string(src->data, NULL); break; } } if (!conn) return NULL; if (!serialcomm) serialcomm = SERIALCOMM; if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) return NULL; if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return NULL; serial_flush(serial); if (!(buf = g_try_malloc(BUF_MAX))) { sr_err("Serial buffer malloc failed."); return NULL; } snprintf(req, sizeof(req), "%s\r\n", nmadmm_requests[NMADMM_REQ_IDN].req_str); for (cnt = 0; cnt < 7; cnt++) { if (serial_write(serial, req, strlen(req)) == -1) { sr_err("Unable to send identification request: %d %s.", errno, strerror(errno)); return NULL; } len = BUF_MAX; serial_readline(serial, &buf, &len, 1500); if (!len) continue; buf[BUF_MAX - 1] = '\0'; /* Match ID string, e.g. "1834 065 V1.06,IF V1.02" (DM950) */ if (g_regex_match_simple("^1834 [^,]*,IF V*", (char *)buf, 0, 0)) { auxtype = xgittoint(buf[7]); // TODO: Will this work with non-DM950? snprintf(fmttype, sizeof(fmttype), "DM9%d0", auxtype); sr_spew("Norma %s DMM %s detected!", fmttype, &buf[9]); if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "Norma", fmttype, buf + 9))) return NULL; if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { sr_err("Device context malloc failed."); return NULL; } devc->type = auxtype; devc->version = g_strdup(&buf[9]); devc->elapsed_msec = g_timer_new(); sdi->conn = serial; sdi->priv = devc; sdi->driver = di; if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) return NULL; sdi->probes = g_slist_append(sdi->probes, probe); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; } /* * The interface of the DM9x0 contains a cap that needs to * charge for up to 10s before the interface works, if not * powered externally. Therefore wait a little to improve * chances. */ if (cnt == 3) { sr_info("Waiting 5s to allow interface to settle."); g_usleep(5 * 1000 * 1000); } } g_free(buf); serial_close(serial); if (!devices) sr_serial_dev_inst_free(serial); return devices; }
static void terminal_profile_gsettings_notify_cb (GSettings *settings, gchar *key, gpointer user_data) { TerminalProfile *profile = TERMINAL_PROFILE (user_data); TerminalProfilePrivate *priv = profile->priv; TerminalProfileClass *klass; GVariant *settings_value; GParamSpec *pspec; GValue value = { 0, }; gboolean equal; gboolean force_set = FALSE; if (!key) return; _terminal_debug_print (TERMINAL_DEBUG_PROFILE, "GSettings notification for key %s [%s]\n", key, g_settings_is_writable (settings, key) ? "writable" : "LOCKED"); klass = TERMINAL_PROFILE_GET_CLASS (profile); pspec = g_hash_table_lookup (klass->gsettings_keys, key); if (!pspec) return; /* ignore unknown keys, for future extensibility */ priv->locked[pspec->param_id] = !g_settings_is_writable (settings, key); settings_value = g_settings_get_value (settings, key); if (!settings_value) return; g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec)); if (G_IS_PARAM_SPEC_BOOLEAN (pspec)) { if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_BOOLEAN)) goto out; g_value_set_boolean (&value, g_variant_get_boolean (settings_value)); } else if (G_IS_PARAM_SPEC_STRING (pspec)) { if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_STRING)) goto out; g_value_set_string (&value, g_variant_get_string (settings_value, NULL)); } else if (G_IS_PARAM_SPEC_ENUM (pspec)) { if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_STRING)) goto out; g_value_set_enum (&value, g_settings_get_enum (settings, key)); } else if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_COLOR) { GdkColor color; if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_STRING)) goto out; if (!gdk_color_parse (g_variant_get_string (settings_value, NULL), &color)) goto out; g_value_set_boxed (&value, &color); } else if (G_PARAM_SPEC_VALUE_TYPE (pspec) == PANGO_TYPE_FONT_DESCRIPTION) { if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_STRING)) goto out; g_value_take_boxed (&value, pango_font_description_from_string (g_variant_get_string (settings_value, NULL))); } else if (G_IS_PARAM_SPEC_DOUBLE (pspec)) { if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_DOUBLE)) goto out; g_value_set_double (&value, g_variant_get_double (settings_value)); } else if (G_IS_PARAM_SPEC_INT (pspec)) { if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_INT16) && !g_variant_is_of_type (settings_value, G_VARIANT_TYPE_INT32) && !g_variant_is_of_type (settings_value, G_VARIANT_TYPE_INT64)) goto out; g_value_set_int (&value, g_settings_get_int(settings, key)); } else if (G_IS_PARAM_SPEC_VALUE_ARRAY (pspec) && G_PARAM_SPEC_VALUE_TYPE (G_PARAM_SPEC_VALUE_ARRAY (pspec)->element_spec) == GDK_TYPE_COLOR) { char **color_strings; GdkColor *colors; int n_colors, i; if (!g_variant_is_of_type (settings_value, G_VARIANT_TYPE_STRING)) goto out; color_strings = g_strsplit (g_variant_get_string (settings_value, NULL), ":", -1); if (!color_strings) goto out; n_colors = g_strv_length (color_strings); colors = g_new0 (GdkColor, n_colors); for (i = 0; i < n_colors; ++i) { if (!gdk_color_parse (color_strings[i], &colors[i])) continue; /* ignore errors */ } g_strfreev (color_strings); /* We continue even with a palette size != TERMINAL_PALETTE_SIZE, * so we can change the palette size in future versions without * causing too many issues. */ set_value_from_palette (&value, colors, n_colors); g_free (colors); } else { g_printerr ("Unhandled value type %s of pspec %s\n", g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)), pspec->name); goto out; } if (g_param_value_validate (pspec, &value)) { _terminal_debug_print (TERMINAL_DEBUG_PROFILE, "Invalid value in GSettings for key %s was changed to comply with pspec %s\n", key, pspec->name); force_set = TRUE; } /* Only set the property if the value is different than our current value, * so we don't go into an infinite loop. */ equal = values_equal (pspec, &value, g_value_array_get_nth (priv->properties, pspec->param_id)); #ifdef MATE_ENABLE_DEBUG _TERMINAL_DEBUG_IF (TERMINAL_DEBUG_PROFILE) { if (!equal) _terminal_debug_print (TERMINAL_DEBUG_PROFILE, "Setting property %s to a different value\n" " now: %s\n" " new: %s\n", pspec->name, g_strdup_value_contents (g_value_array_get_nth (priv->properties, pspec->param_id)), g_strdup_value_contents (&value)); } #endif if (!equal || force_set) { priv->gsettings_notification_pspec = pspec; g_object_set_property (G_OBJECT (profile), pspec->name, &value); priv->gsettings_notification_pspec = NULL; } out: /* FIXME: if we arrive here through goto in the error cases, * should we maybe reset the property to its default value? */ g_value_unset (&value); g_variant_unref (settings_value); }
JSValueRef dbus_to_js(JSContextRef ctx, GVariant *dbus) { JSValueRef jsvalue = NULL; GVariantClass type = g_variant_classify(dbus); switch (type) { case G_VARIANT_CLASS_STRING: case G_VARIANT_CLASS_OBJECT_PATH: case G_VARIANT_CLASS_SIGNATURE: { JSStringRef js_string = JSStringCreateWithUTF8CString( g_variant_get_string(dbus, NULL)); jsvalue = JSValueMakeString(ctx, js_string); JSStringRelease(js_string); return jsvalue; } case G_VARIANT_CLASS_BYTE: return JSValueMakeNumber(ctx, g_variant_get_byte(dbus)); case G_VARIANT_CLASS_DOUBLE: return JSValueMakeNumber(ctx, g_variant_get_double(dbus)); case G_VARIANT_CLASS_INT16: return JSValueMakeNumber(ctx, g_variant_get_int16(dbus)); case G_VARIANT_CLASS_UINT16: return JSValueMakeNumber(ctx, g_variant_get_uint16(dbus)); case G_VARIANT_CLASS_INT32: return JSValueMakeNumber(ctx, g_variant_get_int32(dbus)); case G_VARIANT_CLASS_UINT32: return JSValueMakeNumber(ctx, g_variant_get_uint32(dbus)); case G_VARIANT_CLASS_INT64: return JSValueMakeNumber(ctx, g_variant_get_int64(dbus)); case G_VARIANT_CLASS_UINT64: return JSValueMakeNumber(ctx, g_variant_get_uint64(dbus)); case G_VARIANT_CLASS_BOOLEAN: return JSValueMakeBoolean(ctx, g_variant_get_boolean(dbus)); case G_VARIANT_CLASS_HANDLE: g_warning("[%s] does not support FD type\n", __func__); return JSValueMakeNumber(ctx, g_variant_get_uint32(dbus)); case G_VARIANT_CLASS_VARIANT: { GVariant* v = g_variant_get_variant(dbus); jsvalue = dbus_to_js(ctx, v); g_variant_unref(v); return jsvalue; } case G_VARIANT_CLASS_DICT_ENTRY: /*g_assert_not_reached();*/ break; case G_VARIANT_CLASS_ARRAY: { if (g_variant_type_is_dict_entry( g_variant_type_element(g_variant_get_type(dbus)))) { jsvalue = JSObjectMake(ctx, NULL, NULL); for (size_t i=0; i<g_variant_n_children(dbus); i++) { GVariant *dic = g_variant_get_child_value(dbus, i); GVariant *key= g_variant_get_child_value (dic, 0); GVariant *value = g_variant_get_child_value (dic, 1); JSValueRef js_key = dbus_to_js(ctx, key); JSValueRef js_value = dbus_to_js(ctx, value); JSStringRef key_str = JSValueToStringCopy(ctx, js_key, NULL); JSObjectSetProperty(ctx, (JSObjectRef)jsvalue, key_str, js_value, 0, NULL); JSStringRelease(key_str); g_variant_unref(key); g_variant_unref(value); g_variant_unref(dic); } return jsvalue; } else { int n = g_variant_n_children(dbus); JSValueRef *args = g_new(JSValueRef, n); for (int i=0; i < n; i++) { GVariant* v = g_variant_get_child_value(dbus, i); args[i] = dbus_to_js(ctx, v); g_variant_unref(v); } jsvalue = JSObjectMakeArray(ctx, n, args, NULL); g_free(args); return jsvalue; } } case G_VARIANT_CLASS_TUPLE: { int n = g_variant_n_children(dbus); jsvalue = JSObjectMakeArray(ctx, 0, NULL, NULL); for (int i=0; i < n; i++) { GVariant* v = g_variant_get_child_value(dbus, i); JSObjectSetPropertyAtIndex(ctx, (JSObjectRef)jsvalue, i, dbus_to_js(ctx, v), NULL); g_variant_unref(v); } return jsvalue; } case G_VARIANT_CLASS_MAYBE: g_assert_not_reached(); } g_warning("[%s] does not support signature type:%c\n", __func__, type); return JSValueMakeUndefined(ctx); }