]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
esx: add esxVI_GetInt
authorDawid Zamirski <dzamirski@datto.com>
Mon, 9 Mar 2015 15:54:04 +0000 (11:54 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 3 Apr 2015 09:30:13 +0000 (11:30 +0200)
Modeled after the already existing esxVI_GetLong.

src/esx/esx_vi.c
src/esx/esx_vi.h
src/esx/esx_vi_types.c
src/esx/esx_vi_types.h

index bbec912479dec1064af1f28b149c2b0183b73c6f..af822b14cfc5ba93c9c2ab4dfa2cb72a23a74a1a 100644 (file)
@@ -2412,6 +2412,38 @@ esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyName,
 
 
 
+int
+esxVI_GetInt(esxVI_ObjectContent *objectContent, const char *propertyName,
+             esxVI_Int **value, esxVI_Occurrence occurence)
+{
+    esxVI_DynamicProperty *dynamicProperty;
+
+    if (!value || *value) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+        return -1;
+    }
+
+    for (dynamicProperty = objectContent->propSet; dynamicProperty;
+         dynamicProperty = dynamicProperty->_next) {
+        if (STREQ(dynamicProperty->name, propertyName)) {
+            if (esxVI_Int_CastFromAnyType(dynamicProperty->val, value) < 0)
+                return -1;
+
+            break;
+        }
+    }
+
+    if (!(*value) && occurence == esxVI_Occurrence_RequiredItem) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Missing '%s' property"), propertyName);
+        return -1;
+    }
+
+    return 0;
+}
+
+
+
 int
 esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName,
               esxVI_Long **value, esxVI_Occurrence occurrence)
index b7f0160936850d052037817e1a17272ecd945a95..c41541e9aed056f69028535bf0446f93d74be2fc 100644 (file)
@@ -338,6 +338,9 @@ int esxVI_GetBoolean(esxVI_ObjectContent *objectContent,
                      const char *propertyName,
                      esxVI_Boolean *value, esxVI_Occurrence occurrence);
 
+int esxVI_GetInt(esxVI_ObjectContent *objectContent, const char *propertyName,
+                 esxVI_Int **value, esxVI_Occurrence occurrence);
+
 int esxVI_GetLong(esxVI_ObjectContent *objectContent, const char *propertyName,
                   esxVI_Long **value, esxVI_Occurrence occurrence);
 
index 15024678cfd2992067ef77991af58d3ba567b337..6b558e59fb8a64004890d3fd91c1f86ecdcc0d72 100644 (file)
@@ -1376,6 +1376,9 @@ ESX_VI__TEMPLATE__DEEP_COPY(Int,
     (*dest)->value = src->value;
 })
 
+/* esxVI_Int_CastFromAnyType */
+ESX_VI__TEMPLATE__CAST_FROM_ANY_TYPE(Int)
+
 /* esxVI_Int_Serialize */
 ESX_VI__TEMPLATE__SERIALIZE(Int,
 {
index 34901d7e9d07cc7d302026ac0d8d4e74bf3ad967..66a5705c8701516762a9a494b21ae42c8cb34799 100644 (file)
@@ -241,6 +241,7 @@ void esxVI_Int_Free(esxVI_Int **numberList);
 int esxVI_Int_Validate(esxVI_Int *number);
 int esxVI_Int_AppendToList(esxVI_Int **numberList, esxVI_Int *number);
 int esxVI_Int_DeepCopy(esxVI_Int **dest, esxVI_Int *src);
+int esxVI_Int_CastFromAnyType(esxVI_AnyType *anyType, esxVI_Int **number);
 int esxVI_Int_Serialize(esxVI_Int *number, const char *element,
                         virBufferPtr output);
 int esxVI_Int_SerializeList(esxVI_Int *numberList, const char *element,