[gnome-boxes] Add utility function to compare CPU architectures
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Add utility function to compare CPU architectures
- Date: Thu, 24 Jan 2013 14:00:13 +0000 (UTC)
commit fb018a674e7a30a891a65a6c92234d10d1723bc2
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Jan 16 17:03:03 2013 +0200
Add utility function to compare CPU architectures
https://bugzilla.gnome.org/show_bug.cgi?id=692246
src/installer-media.vala | 11 ++++---
src/util-app.vala | 69 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+), 5 deletions(-)
---
diff --git a/src/installer-media.vala b/src/installer-media.vala
index 7351505..278d4da 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -94,11 +94,12 @@ private class Boxes.InstallerMedia : GLib.Object {
}
public bool is_architecture_compatible (string architecture) {
- return os_media == null || // Unknown media
- os_media.architecture == architecture ||
- (os_media.architecture == "i386" && architecture == "i686") ||
- (os_media.architecture == "i386" && architecture == "x86_64") ||
- (os_media.architecture == "i686" && architecture == "x86_64");
+ if (os_media == null) // Unknown media
+ return true;
+
+ var compatibility = compare_cpu_architectures (architecture, os_media.architecture);
+
+ return compatibility != CPUArchCompatibity.INCOMPATIBLE;
}
protected void add_cd_config (Domain domain,
diff --git a/src/util-app.vala b/src/util-app.vala
index 674a137..d98f259 100644
--- a/src/util-app.vala
+++ b/src/util-app.vala
@@ -394,6 +394,75 @@ namespace Boxes {
} catch (IOError.EXISTS error) {}
}
+ // Warning: architecture compability is not computative. e.g "i386" is compatible with "i686" but "i686" is
+ // incompatible with "i386".
+ public enum CPUArchCompatibity {
+ INCOMPATIBLE = -1, // First architecture is incompatible to second one
+ IDENTICAL = 0, // First architecture is identical to second one
+ COMPATIBLE = 1, // First architecture is compatible with second one
+ COMPATIBLE_DIFF_WORDSIZE = 2, // First architecture is more modern than but compatible
+ // with second one but has different word-size
+ }
+
+ public CPUArchCompatibity compare_cpu_architectures (string arch1, string arch2) {
+ switch (arch2) {
+ case "i386":
+ switch (arch1) {
+ case "i386":
+ return CPUArchCompatibity.IDENTICAL;
+ case "i486":
+ case "i586":
+ case "i686":
+ return CPUArchCompatibity.COMPATIBLE;
+ case "x86_64":
+ return CPUArchCompatibity.COMPATIBLE_DIFF_WORDSIZE;
+ default:
+ return CPUArchCompatibity.INCOMPATIBLE;
+ }
+ case "i486":
+ switch (arch1) {
+ case "i486":
+ return CPUArchCompatibity.IDENTICAL;
+ case "i586":
+ case "i686":
+ return CPUArchCompatibity.COMPATIBLE;
+ case "x86_64":
+ return CPUArchCompatibity.COMPATIBLE_DIFF_WORDSIZE;
+ default:
+ return CPUArchCompatibity.INCOMPATIBLE;
+ }
+ case "i586":
+ switch (arch1) {
+ case "i586":
+ return CPUArchCompatibity.IDENTICAL;
+ case "i686":
+ return CPUArchCompatibity.COMPATIBLE;
+ case "x86_64":
+ return CPUArchCompatibity.COMPATIBLE_DIFF_WORDSIZE;
+ default:
+ return CPUArchCompatibity.INCOMPATIBLE;
+ }
+ case "i686":
+ switch (arch1) {
+ case "i686":
+ return CPUArchCompatibity.IDENTICAL;
+ case "x86_64":
+ return CPUArchCompatibity.COMPATIBLE_DIFF_WORDSIZE;
+ default:
+ return CPUArchCompatibity.INCOMPATIBLE;
+ }
+ case "x86_64":
+ switch (arch1) {
+ case "x86_64":
+ return CPUArchCompatibity.IDENTICAL;
+ default:
+ return CPUArchCompatibity.INCOMPATIBLE;
+ }
+ default:
+ return CPUArchCompatibity.INCOMPATIBLE;
+ }
+ }
+
namespace UUID {
[CCode (cname = "uuid_generate", cheader_filename = "uuid/uuid.h")]
internal extern static void generate ([CCode (array_length = false)] uchar[] uuid);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]