[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [libosinfo 1/7] Add setters for Resources' attributes



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

---
 docs/reference/Libosinfo-sections.txt |    4 ++
 osinfo/libosinfo.syms                 |    4 ++
 osinfo/osinfo_resources.c             |   58 +++++++++++++++++++++++++++++++++
 osinfo/osinfo_resources.h             |    5 +++
 4 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/docs/reference/Libosinfo-sections.txt b/docs/reference/Libosinfo-sections.txt
index 8d5f274..70423c9 100644
--- a/docs/reference/Libosinfo-sections.txt
+++ b/docs/reference/Libosinfo-sections.txt
@@ -459,6 +459,10 @@ osinfo_resources_get_cpu
 osinfo_resources_get_n_cpus
 osinfo_resources_get_ram
 osinfo_resources_get_storage
+osinfo_resources_set_n_cpus
+osinfo_resources_set_cpu
+osinfo_resources_set_ram
+osinfo_resources_set_storage
 OSINFO_RESOURCES
 OSINFO_IS_RESOURCES
 OSINFO_TYPE_RESOURCES
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index c35a0f6..dfed3ff 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -168,6 +168,10 @@ LIBOSINFO_0.0.1 {
 	osinfo_resources_get_n_cpus;
 	osinfo_resources_get_ram;
 	osinfo_resources_get_storage;
+	osinfo_resources_set_n_cpus;
+	osinfo_resources_set_cpu;
+	osinfo_resources_set_ram;
+	osinfo_resources_set_storage;
 	osinfo_resourceslist_get_type;
 	osinfo_resourceslist_new;
 	osinfo_resourceslist_new_copy;
diff --git a/osinfo/osinfo_resources.c b/osinfo/osinfo_resources.c
index e635572..d2b83d2 100644
--- a/osinfo/osinfo_resources.c
+++ b/osinfo/osinfo_resources.c
@@ -62,6 +62,16 @@ static gint64 get_param_as_int64(OsinfoResources *resources,
     return (gint64) g_ascii_strtod(str, NULL);
 }
 
+static void set_param_from_int64(OsinfoResources *resources,
+                                 const gchar *key,
+                                 gint64 value)
+{
+    gchar *str;
+
+    str = g_strdup_printf("%"G_GUINT64_FORMAT, value);
+    osinfo_entity_set_param(OSINFO_ENTITY(resources), key, str);
+}
+
 static void
 osinfo_resources_finalize (GObject *object)
 {
@@ -175,6 +185,54 @@ gint64 osinfo_resources_get_storage(OsinfoResources *resources)
     return get_param_as_int64(resources, OSINFO_RESOURCES_PROP_STORAGE);
 }
 
+/**
+ * osinfo_resources_set_n_cpus:
+ * @resources: a #OsinfoResources instance
+ * @n_cpus: the number of CPUs
+ *
+ * Sets the number of CPUs.
+ */
+void osinfo_resources_set_n_cpus(OsinfoResources *resources, gint n_cpus)
+{
+    set_param_from_int64 (resources, OSINFO_RESOURCES_PROP_N_CPUS, n_cpus);
+}
+
+/**
+ * osinfo_resources_set_cpu:
+ * @resources: a #OsinfoResources instance
+ * @cpu: the CPU frequency in hertz (Hz)
+ *
+ * Sets the CPU frequency.
+ */
+void osinfo_resources_set_cpu(OsinfoResources *resources, gint64 cpu)
+{
+    set_param_from_int64 (resources, OSINFO_RESOURCES_PROP_CPU, cpu);
+}
+
+/**
+ * osinfo_resources_set_ram:
+ * @resources: a #OsinfoResources instance
+ * @ram: the amount of ram in bytes
+ *
+ * Sets the amount of RAM in bytes.
+ */
+void osinfo_resources_set_ram(OsinfoResources *resources, gint64 ram)
+{
+    set_param_from_int64 (resources, OSINFO_RESOURCES_PROP_RAM, ram);
+}
+
+/**
+ * osinfo_resources_set_storage:
+ * @resources: a #OsinfoResources instance
+ * @storage: the amount of storage in bytes
+ *
+ * Sets the amount of storage space.
+ */
+void osinfo_resources_set_storage(OsinfoResources *resources, gint64 storage)
+{
+    set_param_from_int64 (resources, OSINFO_RESOURCES_PROP_STORAGE, storage);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_resources.h b/osinfo/osinfo_resources.h
index 7f8767e..dd3f8ae 100644
--- a/osinfo/osinfo_resources.h
+++ b/osinfo/osinfo_resources.h
@@ -92,6 +92,11 @@ gint64 osinfo_resources_get_cpu(OsinfoResources *resources);
 gint64 osinfo_resources_get_ram(OsinfoResources *resources);
 gint64 osinfo_resources_get_storage(OsinfoResources *resources);
 
+void osinfo_resources_set_n_cpus(OsinfoResources *resources, gint n_cpus);
+void osinfo_resources_set_cpu(OsinfoResources *resources, gint64 cpu);
+void osinfo_resources_set_ram(OsinfoResources *resources, gint64 ram);
+void osinfo_resources_set_storage(OsinfoResources *resources, gint64 storage);
+
 #endif /* __OSINFO_RESOURCES_H__ */
 /*
  * Local variables:
-- 
1.7.6.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]