/** * pk_backend_implement: **/ void pk_backend_implement (PkBackend *backend, PkRoleEnum role) { g_return_if_fail (PK_IS_BACKEND (backend)); g_return_if_fail (role != PK_ROLE_ENUM_UNKNOWN); pk_bitfield_add (backend->priv->roles, role); }
/** * pk_backend_get_roles: */ PkBitfield pk_backend_get_roles(PkBackend *backend) { PkBitfield roles; roles = pk_bitfield_from_enums( PK_ROLE_ENUM_CANCEL, PK_ROLE_ENUM_DEPENDS_ON, PK_ROLE_ENUM_GET_DETAILS, PK_ROLE_ENUM_GET_FILES, PK_ROLE_ENUM_REQUIRED_BY, PK_ROLE_ENUM_GET_PACKAGES, PK_ROLE_ENUM_WHAT_PROVIDES, PK_ROLE_ENUM_GET_UPDATES, PK_ROLE_ENUM_GET_UPDATE_DETAIL, PK_ROLE_ENUM_INSTALL_PACKAGES, PK_ROLE_ENUM_INSTALL_SIGNATURE, PK_ROLE_ENUM_REFRESH_CACHE, PK_ROLE_ENUM_REMOVE_PACKAGES, PK_ROLE_ENUM_DOWNLOAD_PACKAGES, PK_ROLE_ENUM_RESOLVE, PK_ROLE_ENUM_SEARCH_DETAILS, PK_ROLE_ENUM_SEARCH_FILE, PK_ROLE_ENUM_SEARCH_GROUP, PK_ROLE_ENUM_SEARCH_NAME, PK_ROLE_ENUM_UPDATE_PACKAGES, PK_ROLE_ENUM_GET_REPO_LIST, PK_ROLE_ENUM_REPO_ENABLE, PK_ROLE_ENUM_REPAIR_SYSTEM, PK_ROLE_ENUM_REPO_REMOVE, -1); // only add GetDistroUpgrades if the binary is present if (g_file_test(PREUPGRADE_BINARY, G_FILE_TEST_EXISTS)) { pk_bitfield_add(roles, PK_ROLE_ENUM_GET_DISTRO_UPGRADES); } // only add GetDistroUpgrades if the binary is present if (g_file_test(GDEBI_BINARY, G_FILE_TEST_EXISTS)) { pk_bitfield_add(roles, PK_ROLE_ENUM_INSTALL_FILES); } return roles; }
/** * pk_backend_get_filters: */ PkBitfield pk_backend_get_filters(PkBackend *backend) { PkBitfield filters; filters = pk_bitfield_from_enums( PK_FILTER_ENUM_GUI, PK_FILTER_ENUM_INSTALLED, PK_FILTER_ENUM_DEVELOPMENT, PK_FILTER_ENUM_SUPPORTED, PK_FILTER_ENUM_FREE, -1); // if we have multiArch support we add the native filter if (APT::Configuration::getArchitectures(false).size() > 1) { pk_bitfield_add(filters, PK_FILTER_ENUM_ARCH); } return filters; }
/** * gpk_dbus_set_interaction_from_text: **/ static void gpk_dbus_set_interaction_from_text (PkBitfield *interact, gint *timeout, const gchar *interaction) { guint i; guint len; gchar **interactions; interactions = g_strsplit (interaction, ",", -1); len = g_strv_length (interactions); /* do special keys first */ for (i=0; i<len; i++) { if (g_strcmp0 (interactions[i], "always") == 0) *interact = GPK_CLIENT_INTERACT_ALWAYS; else if (g_strcmp0 (interactions[i], "never") == 0) *interact = GPK_CLIENT_INTERACT_NEVER; } /* add or remove from defaults */ for (i=0; i<len; i++) { /* show */ if (g_strcmp0 (interactions[i], "show-confirm-search") == 0) pk_bitfield_add (*interact, GPK_CLIENT_INTERACT_CONFIRM_SEARCH); else if (g_strcmp0 (interactions[i], "show-confirm-deps") == 0) pk_bitfield_add (*interact, GPK_CLIENT_INTERACT_CONFIRM_DEPS); else if (g_strcmp0 (interactions[i], "show-confirm-install") == 0) pk_bitfield_add (*interact, GPK_CLIENT_INTERACT_CONFIRM_INSTALL); else if (g_strcmp0 (interactions[i], "show-progress") == 0) pk_bitfield_add (*interact, GPK_CLIENT_INTERACT_PROGRESS); else if (g_strcmp0 (interactions[i], "show-finished") == 0) pk_bitfield_add (*interact, GPK_CLIENT_INTERACT_FINISHED); else if (g_strcmp0 (interactions[i], "show-warning") == 0) pk_bitfield_add (*interact, GPK_CLIENT_INTERACT_WARNING); /* hide */ else if (g_strcmp0 (interactions[i], "hide-confirm-search") == 0) pk_bitfield_remove (*interact, GPK_CLIENT_INTERACT_CONFIRM_SEARCH); else if (g_strcmp0 (interactions[i], "hide-confirm-deps") == 0) pk_bitfield_remove (*interact, GPK_CLIENT_INTERACT_CONFIRM_DEPS); else if (g_strcmp0 (interactions[i], "hide-confirm-install") == 0) pk_bitfield_remove (*interact, GPK_CLIENT_INTERACT_CONFIRM_INSTALL); else if (g_strcmp0 (interactions[i], "hide-progress") == 0) pk_bitfield_remove (*interact, GPK_CLIENT_INTERACT_PROGRESS); else if (g_strcmp0 (interactions[i], "hide-finished") == 0) pk_bitfield_remove (*interact, GPK_CLIENT_INTERACT_FINISHED); else if (g_strcmp0 (interactions[i], "hide-warning") == 0) pk_bitfield_remove (*interact, GPK_CLIENT_INTERACT_WARNING); /* wait */ else if (g_str_has_prefix (interactions[i], "timeout=")) *timeout = atoi (&interactions[i][8]); } g_strfreev (interactions); }
/** * pk_backend_get_roles: **/ PkBitfield pk_backend_get_roles (PkBackend *backend) { PkBitfield roles = backend->priv->roles; PkBackendDesc *desc; g_return_val_if_fail (PK_IS_BACKEND (backend), PK_ROLE_ENUM_UNKNOWN); g_return_val_if_fail (backend->priv->loaded, PK_ROLE_ENUM_UNKNOWN); /* optimise - we only skip here if we already loaded backend settings, * so we don't override preexisting settings (e.g. by plugins) */ if (backend->priv->backend_roles_set) goto out; /* not compulsory, but use it if we've got it */ if (backend->priv->desc->get_roles != NULL) { backend->priv->roles = backend->priv->desc->get_roles (backend); pk_bitfield_add (backend->priv->roles, PK_ROLE_ENUM_GET_OLD_TRANSACTIONS); goto out; } /* lets reduce pointer dereferences... */ desc = backend->priv->desc; if (desc->cancel != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_CANCEL); if (desc->depends_on != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_DEPENDS_ON); if (desc->get_details != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_DETAILS); if (desc->get_details_local != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_DETAILS_LOCAL); if (desc->get_files_local != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_FILES_LOCAL); if (desc->get_files != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_FILES); if (desc->required_by != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_REQUIRED_BY); if (desc->get_packages != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_PACKAGES); if (desc->what_provides != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_WHAT_PROVIDES); if (desc->get_updates != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_UPDATES); if (desc->get_update_detail != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_UPDATE_DETAIL); if (desc->install_packages != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_INSTALL_PACKAGES); if (desc->install_signature != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_INSTALL_SIGNATURE); if (desc->install_files != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_INSTALL_FILES); if (desc->refresh_cache != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_REFRESH_CACHE); if (desc->remove_packages != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_REMOVE_PACKAGES); if (desc->download_packages != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_DOWNLOAD_PACKAGES); if (desc->resolve != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_RESOLVE); if (desc->search_details != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_SEARCH_DETAILS); if (desc->search_files != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_SEARCH_FILE); if (desc->search_groups != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_SEARCH_GROUP); if (desc->search_names != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_SEARCH_NAME); if (desc->update_packages != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_UPDATE_PACKAGES); if (desc->get_repo_list != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_REPO_LIST); if (desc->repo_enable != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_REPO_ENABLE); if (desc->repo_set_data != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_REPO_SET_DATA); if (desc->repo_remove != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_REPO_REMOVE); if (desc->get_distro_upgrades != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_DISTRO_UPGRADES); if (desc->get_categories != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_GET_CATEGORIES); if (desc->repair_system != NULL) pk_bitfield_add (roles, PK_ROLE_ENUM_REPAIR_SYSTEM); pk_bitfield_add (roles, PK_ROLE_ENUM_GET_OLD_TRANSACTIONS); backend->priv->roles = roles; backend->priv->backend_roles_set = TRUE; out: return backend->priv->roles; }
void pk_bitfield_test (gpointer user_data) { EggTest *test = (EggTest *) user_data; gchar *text; PkBitfield filter; gint value; PkBitfield values; if (!egg_test_start (test, "PkBitfield")) return; /************************************************************/ egg_test_title (test, "check we can convert filter bitfield to text (none)"); text = pk_filter_bitfield_to_text (pk_bitfield_value (PK_FILTER_ENUM_NONE)); if (g_strcmp0 (text, "none") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can invert a bit 1 -> 0"); values = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_NOT_NEWEST); pk_bitfield_invert (values, PK_FILTER_ENUM_NOT_DEVELOPMENT); if (values == pk_bitfield_value (PK_FILTER_ENUM_NOT_NEWEST)) egg_test_success (test, NULL); else egg_test_failed (test, "values were %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "check we can invert a bit 0 -> 1"); values = 0; pk_bitfield_invert (values, PK_FILTER_ENUM_NOT_DEVELOPMENT); if (values == pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT)) egg_test_success (test, NULL); else egg_test_failed (test, "values were %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "check we can convert filter bitfield to text (single)"); text = pk_filter_bitfield_to_text (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT)); if (g_strcmp0 (text, "~devel") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can convert filter bitfield to text (plural)"); text = pk_filter_bitfield_to_text (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST)); if (g_strcmp0 (text, "~devel;gui;newest") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can convert filter text to bitfield (none)"); filter = pk_filter_bitfield_from_text ("none"); if (filter == pk_bitfield_value (PK_FILTER_ENUM_NONE)) egg_test_success (test, NULL); else egg_test_failed (test, "filter was %" PK_BITFIELD_FORMAT, filter); /************************************************************/ egg_test_title (test, "check we can convert filter text to bitfield (single)"); filter = pk_filter_bitfield_from_text ("~devel"); if (filter == pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT)) egg_test_success (test, NULL); else egg_test_failed (test, "filter was %" PK_BITFIELD_FORMAT, filter); /************************************************************/ egg_test_title (test, "check we can convert filter text to bitfield (plural)"); filter = pk_filter_bitfield_from_text ("~devel;gui;newest"); if (filter == (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST))) egg_test_success (test, NULL); else egg_test_failed (test, "filter was %" PK_BITFIELD_FORMAT, filter); /************************************************************/ egg_test_title (test, "check we can add / remove bitfield"); filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST); pk_bitfield_add (filter, PK_FILTER_ENUM_NOT_FREE); pk_bitfield_remove (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT); text = pk_filter_bitfield_to_text (filter); if (g_strcmp0 (text, "gui;~free;newest") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "check we can test enum presence"); filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_GUI) | pk_bitfield_value (PK_FILTER_ENUM_NEWEST); if (pk_bitfield_contain (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT)) egg_test_success (test, NULL); else egg_test_failed (test, "wrong boolean"); /************************************************************/ egg_test_title (test, "check we can test enum false-presence"); if (!pk_bitfield_contain (filter, PK_FILTER_ENUM_FREE)) egg_test_success (test, NULL); else egg_test_failed (test, "wrong boolean"); /************************************************************/ egg_test_title (test, "check we can add / remove bitfield to nothing"); filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT); pk_bitfield_remove (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT); text = pk_filter_bitfield_to_text (filter); if (g_strcmp0 (text, "none") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "text was %s", text); g_free (text); /************************************************************/ egg_test_title (test, "role bitfield from enums (unknown)"); values = pk_bitfield_from_enums (PK_ROLE_ENUM_UNKNOWN, -1); if (values == pk_bitfield_value (PK_ROLE_ENUM_UNKNOWN)) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "role bitfield from enums (random)"); values = pk_bitfield_from_enums (PK_ROLE_ENUM_SEARCH_GROUP, PK_ROLE_ENUM_SEARCH_DETAILS, -1); if (values == (pk_bitfield_value (PK_ROLE_ENUM_SEARCH_DETAILS) | pk_bitfield_value (PK_ROLE_ENUM_SEARCH_GROUP))) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "group bitfield from enums (unknown)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, -1); if (values == pk_bitfield_value (PK_GROUP_ENUM_UNKNOWN)) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "group bitfield from enums (random)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_ACCESSIBILITY, -1); if (values == (pk_bitfield_value (PK_GROUP_ENUM_ACCESSIBILITY))) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield %" PK_BITFIELD_FORMAT, values); /************************************************************/ egg_test_title (test, "group bitfield to text (unknown)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, -1); text = pk_group_bitfield_to_text (values); if (g_strcmp0 (text, "unknown") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield text %s (%" PK_BITFIELD_FORMAT ")", text, values); g_free (text); /************************************************************/ egg_test_title (test, "group bitfield to text (first and last)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_ACCESSIBILITY, PK_GROUP_ENUM_UNKNOWN, -1); text = pk_group_bitfield_to_text (values); if (g_strcmp0 (text, "unknown;accessibility") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield text %s (%" PK_BITFIELD_FORMAT ")", text, values); g_free (text); /************************************************************/ egg_test_title (test, "group bitfield to text (random)"); values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, PK_GROUP_ENUM_REPOS, -1); text = pk_group_bitfield_to_text (values); if (g_strcmp0 (text, "unknown;repos") == 0) egg_test_success (test, NULL); else egg_test_failed (test, "returned bitfield text %s (%" PK_BITFIELD_FORMAT ")", text, values); g_free (text); /************************************************************/ egg_test_title (test, "priority check missing"); values = pk_bitfield_value (PK_ROLE_ENUM_SEARCH_DETAILS) | pk_bitfield_value (PK_ROLE_ENUM_SEARCH_GROUP); value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_FILE, -1); if (value == -1) egg_test_success (test, NULL); else egg_test_failed (test, "returned priority %i when should be missing", value); /************************************************************/ egg_test_title (test, "priority check first"); value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_GROUP, -1); if (value == PK_ROLE_ENUM_SEARCH_GROUP) egg_test_success (test, NULL); else egg_test_failed (test, "returned wrong value; %i", value); /************************************************************/ egg_test_title (test, "priority check second, correct"); value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_FILE, PK_ROLE_ENUM_SEARCH_GROUP, -1); if (value == PK_ROLE_ENUM_SEARCH_GROUP) egg_test_success (test, NULL); else egg_test_failed (test, "returned wrong value; %i", value); egg_test_end (test); }
static GHashTable * group_map_new (GError **error) { GHashTable *map; GFile *file; GFileInputStream *file_stream; GDataInputStream *data_stream; gchar *key, *value; GError *e = NULL; g_debug ("pacman: reading groups from %s", PACMAN_GROUP_LIST); file = g_file_new_for_path (PACMAN_GROUP_LIST); file_stream = g_file_read (file, NULL, &e); if (file_stream == NULL) { g_object_unref (file); g_propagate_error (error, e); return NULL; } map = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); data_stream = g_data_input_stream_new (G_INPUT_STREAM (file_stream)); /* read groups line by line, ignoring comments */ while ((value = g_data_input_stream_read_line (data_stream, NULL, NULL, &e)) != NULL) { PkGroupEnum group; g_strstrip (value); if (*value == '\0' || *value == '#') { g_free (value); continue; } /* line format: alpm-group (space|tab)+ packagekit-group */ key = strsep (&value, " "); g_strchomp (key); if (value == NULL) { /* safe to cast as it is never freed or modified */ value = (gchar *) "other"; group = PK_GROUP_ENUM_OTHER; } else { g_strchug (value); group = pk_group_enum_from_string (value); } if (group != PK_GROUP_ENUM_UNKNOWN) { /* use replace because key and value are allocated together */ g_hash_table_replace (map, key, value); pk_bitfield_add (groups, group); } } g_object_unref (data_stream); g_object_unref (file_stream); g_object_unref (file); if (e != NULL) { g_hash_table_unref (map); g_propagate_error (error, e); return NULL; } else { return map; } }