[Libvirt-cim] [PATCH 1 of 2] RegisteredProfile: adopt common look and feel of interfaces

Heidi Eckhart heidieck at linux.vnet.ibm.com
Thu Mar 13 12:55:13 UTC 2008


# HG changeset patch
# User Heidi Eckhart <heidieck at linux.vnet.ibm.com>
# Date 1205412087 -3600
# Node ID c54f01516458be69a914427668857951fb94e278
# Parent  b739fc9b13320e07a39f3932396c8411c2d4ad75
RegisteredProfile: adopt common look and feel of interfaces
Signed-off-by: Heidi Eckhart <heidieck at linux.vnet.ibm.com>

diff -r b739fc9b1332 -r c54f01516458 src/Virt_RegisteredProfile.c
--- a/src/Virt_RegisteredProfile.c	Tue Mar 11 13:28:04 2008 -0700
+++ b/src/Virt_RegisteredProfile.c	Thu Mar 13 13:41:27 2008 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright IBM Corp. 2007
+ * Copyright IBM Corp. 2007, 2008
  *
  * Authors:
  *  Dan Smith <danms at us.ibm.com>
@@ -40,19 +40,21 @@
 
 const static CMPIBroker *_BROKER;
 
-CMPIInstance *reg_prof_instance(const CMPIBroker *broker,
-                                const char *namespace,
-                                const char **properties,
-                                virConnectPtr conn,
-				struct reg_prof *profile)
+CMPIStatus get_profile(const CMPIBroker *broker,
+                       const CMPIObjectPath *reference,
+                       const char **properties,
+                       const char* interop_namespace,
+                       const char* pfx,
+                       struct reg_prof *profile,
+                       CMPIInstance **_inst)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
         CMPIInstance *instance = NULL;
-
+        
         instance = get_typed_instance(broker,
-                                      pfx_from_conn(conn),
+                                      pfx,
                                       "RegisteredProfile",
-                                      namespace);
+                                      interop_namespace);
 
         if (instance == NULL) {
                 cu_statusf(broker, &s, 
@@ -63,10 +65,7 @@ CMPIInstance *reg_prof_instance(const CM
 
         if (properties) {
                 const char *keys[] = {"InstanceID", NULL};
-                s = CMSetPropertyFilter(instance, properties, keys);
-                if (s.rc != CMPI_RC_OK) {
-                        goto out;
-                }
+                CMSetPropertyFilter(instance, properties, keys);
         }
         
         CMSetProperty(instance, "InstanceID",
@@ -81,41 +80,122 @@ CMPIInstance *reg_prof_instance(const CM
         CMSetProperty(instance, "RegisteredVersion", 
                       (CMPIValue *)profile->reg_version, CMPI_chars);
 
+        *_inst = instance;
+
  out:
-        return instance;
+
+        return s;
 }
 
-static CMPIStatus enum_profs(const CMPIObjectPath *ref,
-                             const CMPIResult *results,
-                             const char **properties,
-                             bool names_only)
+CMPIStatus get_profile_by_name(const CMPIBroker *broker,
+                               const CMPIObjectPath *reference,
+                               const char *name,
+                               const char **properties,
+                               CMPIInstance **_inst)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
-        CMPIInstance *instance;
+        virConnectPtr conn = NULL;
+        int i;
+        bool found = false;
+
+        conn = connect_by_classname(broker, CLASSNAME(reference), &s);
+        if (conn == NULL) {
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_NOT_FOUND,
+                           "No such instance");
+                goto out;
+        }
+
+        for (i = 0; profiles[i] != NULL; i++) {
+                if(STREQ(name, profiles[i]->reg_id)) {
+                        CMPIInstance *inst = NULL;
+
+                        s = get_profile(broker,
+                                        reference, 
+                                        properties,
+                                        CIM_INTEROP_NS,
+                                        pfx_from_conn(conn),
+                                        profiles[i],
+                                        &inst);
+                        if (s.rc != CMPI_RC_OK)
+                                goto out;
+
+                        *_inst = inst;
+                        found = true;
+                        break;
+                }
+        }
+
+        if (found == false)
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_NOT_FOUND,
+                           "No such instance (%s)",
+                           name);
+
+ out:
+        virConnectClose(conn);
+
+        return s;
+}
+
+CMPIStatus get_profile_by_ref(const CMPIBroker *broker,
+                              const CMPIObjectPath *reference,
+                              const char **properties,
+                              CMPIInstance **_inst)
+{
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        CMPIInstance *inst = NULL;
+        const char *name = NULL;
+
+        if (cu_get_str_path(reference, "InstanceID", &name) != CMPI_RC_OK) {
+                cu_statusf(broker, &s,
+                           CMPI_RC_ERR_FAILED,
+                           "No InstanceID specified");
+                goto out;
+        }
+
+        s = get_profile_by_name(broker, reference, name, properties, &inst);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+        
+        s = cu_validate_ref(broker, reference, inst);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
+        *_inst = inst;
+
+ out:
+        return s;
+}
+
+CMPIStatus enum_profiles(const CMPIBroker *broker,
+                         const CMPIObjectPath *reference,
+                         const char **properties,
+                         struct inst_list *list)
+{
+        CMPIStatus s = {CMPI_RC_OK, NULL};
         virConnectPtr conn = NULL;
         int i;
 
-        conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
+        conn = connect_by_classname(broker, CLASSNAME(reference), &s);
         if (conn == NULL)
-                return s;
+                goto out;
 
         for (i = 0; profiles[i] != NULL; i++) {
-                instance = reg_prof_instance(_BROKER, 
-                                             NAMESPACE(ref), 
-                                             properties,
-                                             conn,
-                                             profiles[i]);
-                if (instance == NULL) {
-                        cu_statusf(_BROKER, &s, 
-                                   CMPI_RC_ERR_FAILED,
-                                   "Can't create profile instance");
-                        goto out;
-                }
+                CMPIInstance *inst = NULL;
 
-                if (names_only)
-                        cu_return_instance_name(results, instance);
-                else
-                        CMReturnInstance(results, instance);
+                s = get_profile(broker,
+                                reference, 
+                                properties,
+                                CIM_INTEROP_NS,
+                                pfx_from_conn(conn),
+                                profiles[i],
+                                &inst);
+
+                if (s.rc != CMPI_RC_OK)
+                        continue;
+
+                inst_list_add(list, inst);
         }
 
  out:
@@ -124,50 +204,27 @@ static CMPIStatus enum_profs(const CMPIO
         return s;
 }
 
-static CMPIStatus get_prof(const CMPIObjectPath *ref,
-                           const CMPIResult *results,
-                           const char **properties)
-{       
-        CMPIStatus s = {CMPI_RC_OK, NULL};
-        CMPIInstance *instance = NULL;
-        virConnectPtr conn = NULL;
-        const char* id;
-        int i;
+static CMPIStatus return_enum_profiles(const CMPIObjectPath *reference,
+                                       const CMPIResult *results,
+                                       const char **properties,
+                                       const bool names_only)
+{
+        struct inst_list list;
+        CMPIStatus s;
 
-        conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
-        if (conn == NULL) {
-                cu_statusf(_BROKER, &s,
-                           CMPI_RC_ERR_NOT_FOUND,
-                           "No such instance");
+        inst_list_init(&list);
+
+        s = enum_profiles(_BROKER, reference, properties, &list);
+        if (s.rc != CMPI_RC_OK)
                 goto out;
-        }
 
-        if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) {
-                cu_statusf(_BROKER, &s,
-                           CMPI_RC_ERR_FAILED,
-                           "No InstanceID specified");
-                goto out;
-        }
+        if (names_only)
+                cu_return_instance_names(results, &list);
+        else
+                cu_return_instances(results, &list);
 
-        for (i = 0; profiles[i] != NULL; i++) {
-                if(STREQ(id, profiles[i]->reg_id)) {
-                        instance = reg_prof_instance(_BROKER, 
-                                                     NAMESPACE(ref), 
-                                                     properties,
-                                                     conn,
-                                                     profiles[i]);
-                        break;
-                }
-        }
-
-        if(instance)
-                CMReturnInstance(results, instance);
-        else
-                cu_statusf(_BROKER, &s,
-                           CMPI_RC_ERR_NOT_FOUND,
-                           "Profile instance not found");
  out:
-        virConnectClose(conn);
+        inst_list_free(&list);
 
         return s;
 }
@@ -177,7 +234,7 @@ static CMPIStatus EnumInstanceNames(CMPI
                                     const CMPIResult *results,
                                     const CMPIObjectPath *reference)
 {
-        return enum_profs(reference, results, NULL, true);
+        return return_enum_profiles(reference, results, NULL, true);
 }
 
 static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -186,7 +243,7 @@ static CMPIStatus EnumInstances(CMPIInst
                                 const CMPIObjectPath *reference,
                                 const char **properties)
 {
-        return enum_profs(reference, results, properties, false);
+        return return_enum_profiles(reference, results, properties, false);
 }
 
 static CMPIStatus GetInstance(CMPIInstanceMI *self,
@@ -195,7 +252,17 @@ static CMPIStatus GetInstance(CMPIInstan
                               const CMPIObjectPath *reference,
                               const char **properties)
 {
-        return get_prof(reference, results, properties);
+        CMPIStatus s = {CMPI_RC_OK, NULL};
+        CMPIInstance *inst = NULL;
+
+        s = get_profile_by_ref(_BROKER, reference, properties, &inst);
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
+        CMReturnInstance(results, inst);
+
+ out:
+        return s;
 }
 
 DEFAULT_CI();
diff -r b739fc9b1332 -r c54f01516458 src/Virt_RegisteredProfile.h
--- a/src/Virt_RegisteredProfile.h	Tue Mar 11 13:28:04 2008 -0700
+++ b/src/Virt_RegisteredProfile.h	Thu Mar 13 13:41:27 2008 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright IBM Corp. 2007
+ * Copyright IBM Corp. 2007, 2008
  *
  * Authors:
  *  Heidi Eckhart <heidieck at linux.vnet.ibm.com>
@@ -21,11 +21,29 @@
 #ifndef __VIRT_REGISTERED_PROFILE_H
 #define __VIRT_REGISTERED_PROFILE_H
 
-CMPIInstance *reg_prof_instance(const CMPIBroker *broker,
-                                const char *namespace,
-                                const char **properties,
-                                virConnectPtr conn,
-                                struct reg_prof *profile);
+CMPIStatus enum_profiles(const CMPIBroker *broker,
+                         const CMPIObjectPath *reference,
+                         const char **properties,
+                         struct inst_list *list);
+
+CMPIStatus get_profile(const CMPIBroker *broker,
+                       const CMPIObjectPath *reference,
+                       const char **properties,
+                       const char* interop_namespace,
+                       const char* pfx,
+                       struct reg_prof *profile,
+                       CMPIInstance **_inst);
+
+CMPIStatus get_profile_by_name(const CMPIBroker *broker,
+                               const CMPIObjectPath *reference,
+                               const char *name,
+                               const char **properties,
+                               CMPIInstance **_inst);
+
+CMPIStatus get_profile_by_ref(const CMPIBroker *broker,
+                              const CMPIObjectPath *reference,
+                              const char **properties,
+                              CMPIInstance **_inst);
 
 #endif
 
diff -r b739fc9b1332 -r c54f01516458 src/profiles.h
--- a/src/profiles.h	Tue Mar 11 13:28:04 2008 -0700
+++ b/src/profiles.h	Thu Mar 13 13:41:27 2008 +0100
@@ -1,8 +1,9 @@
 /*
- * Copyright IBM Corp. 2007
+ * Copyright IBM Corp. 2007, 2008
  *
  * Authors:
  *  Jay Gagnon <grendel at linux.vnet.ibm.com>
+ *  Heidi Eckhart <heidieck at linux.vnet.ibm.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,6 +19,10 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
  */
+
+/* Interop Namespace */
+#define CIM_INTEROP_NS "root/interop"
+
 struct reg_prof {
         uint16_t reg_org; // Valid: 1 = Other, 2 = DMTF
         char *reg_id;
@@ -26,7 +31,7 @@ struct reg_prof {
         int ad_types;
         char *other_reg_org;
         char *ad_type_descriptions;
-        char *provider_name;
+        char *scoping_class;
 };
 
 struct reg_prof SystemVirtualization = {
@@ -34,7 +39,7 @@ struct reg_prof SystemVirtualization = {
         .reg_id = "CIM:DSP1042-SystemVirtualization-1.0.0",
         .reg_name = "System Virtualization",
         .reg_version = "1.0.0",
-        .provider_name = "HostSystem"
+        .scoping_class = "HostSystem"
 };
 
 struct reg_prof VirtualSystem = {
@@ -42,7 +47,7 @@ struct reg_prof VirtualSystem = {
         .reg_id = "CIM:DSP1057-VirtualSystem-1.0.0a",
         .reg_name = "Virtual System Profile",
         .reg_version = "1.0.0a",
-        .provider_name = "ComputerSystem"
+        .scoping_class = "ComputerSystem"
 };
 
 




More information about the Libvirt-cim mailing list