# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1196935598 -3600
# Node ID 618509ea5c6089678975cde7f4b5a687aa1e68f0
# Parent d9af4651f76314647dbda82f5ccf3d926ce9dc05
Introduce generic LIBVIRT_CIM_DEFAULT_MAKEREF macro
Moved the content of association's make_ref() to
make_reference() in libxkutil to generalize it. The
make_reference can be used via
LIBVIRT_CIM_DEFAULT_MAKEREF macro by each association.
Reduces lines of code per provider.
Updated all association providers to make use of
make_reference() and LIBVIRT_CIM_DEFAULT_MAKEREF.
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r d9af4651f763 -r 618509ea5c60 libxkutil/misc_util.c
--- a/libxkutil/misc_util.c Wed Dec 05 09:42:26 2007 +0100
+++ b/libxkutil/misc_util.c Thu Dec 06 11:06:38 2007 +0100
@@ -342,7 +342,35 @@ bool match_hypervisor_prefix(const CMPIO
return rc;
}
-
+CMPIInstance *make_reference(const CMPIBroker *broker,
+ const CMPIObjectPath *source_ref,
+ const CMPIInstance *target_inst,
+ struct std_assoc_info *info,
+ struct std_assoc *assoc)
+{
+ CMPIInstance *ref_inst = NULL;
+ char* assoc_classname;
+
+ assoc_classname = class_base_name(assoc->assoc_class[0]);
+
+ ref_inst = get_typed_instance(broker,
+ CLASSNAME(source_ref),
+ assoc_classname,
+ NAMESPACE(source_ref));
+
+ if (ref_inst != NULL) {
+ CMPIObjectPath *target_ref;
+
+ target_ref = CMGetObjectPath(target_inst, NULL);
+
+ set_reference(assoc, ref_inst,
+ source_ref, target_ref);
+ }
+
+ free(assoc_classname);
+
+ return ref_inst;
+}
bool domain_online(virDomainPtr dom)
{
diff -r d9af4651f763 -r 618509ea5c60 libxkutil/misc_util.h
--- a/libxkutil/misc_util.h Wed Dec 05 09:42:26 2007 +0100
+++ b/libxkutil/misc_util.h Thu Dec 06 11:06:38 2007 +0100
@@ -109,6 +109,26 @@ bool match_hypervisor_prefix(const CMPIO
bool match_hypervisor_prefix(const CMPIObjectPath *reference,
struct std_assoc_info *info);
+CMPIInstance *make_reference(const CMPIBroker *broker,
+ const CMPIObjectPath *source_ref,
+ const CMPIInstance *target_inst,
+ struct std_assoc_info *info,
+ struct std_assoc *assoc);
+
+
+#define LIBVIRT_CIM_DEFAULT_MAKEREF() \
+ static CMPIInstance* make_ref(const CMPIObjectPath *source_ref, \
+ const CMPIInstance *target_inst, \
+ struct std_assoc_info *info, \
+ struct std_assoc *assoc) \
+ { \
+ return make_reference(_BROKER, \
+ source_ref, \
+ target_inst, \
+ info, \
+ assoc); \
+ }
+
/*
* Local Variables:
* mode: C
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_ElementAllocatedFromPool.c
--- a/src/Virt_ElementAllocatedFromPool.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_ElementAllocatedFromPool.c Thu Dec 06 11:06:38 2007 +0100
@@ -247,28 +247,7 @@ static CMPIStatus pool_to_vdev(const CMP
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIInstance *refinst = NULL;
-
- refinst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- "ElementAllocatedFromPool",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* antecedent[] = {
"Xen_ProcessorPool",
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_ElementCapabilities.c
--- a/src/Virt_ElementCapabilities.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_ElementCapabilities.c Thu Dec 06 11:06:38 2007 +0100
@@ -210,39 +210,7 @@ static CMPIStatus pool_to_alloc(const CM
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIStatus s = {CMPI_RC_OK, NULL};
- CMPIInstance *refinst = NULL;
- virConnectPtr conn = NULL;
-
- conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
- if (conn == NULL)
- return NULL;
-
- refinst = get_typed_instance(_BROKER,
- pfx_from_conn(conn),
- "ElementCapabilities",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- CMSetProperty(refinst, assoc->source_prop,
- (CMPIValue *)&ref, CMPI_ref);
- CMSetProperty(refinst, assoc->target_prop,
- (CMPIValue *)&instop, CMPI_ref);
- }
-
- virConnectClose(conn);
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* assoc_classname[] = {
"Xen_ElementCapabilities",
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_ElementConformsToProfile.c
--- a/src/Virt_ElementConformsToProfile.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_ElementConformsToProfile.c Thu Dec 06 11:06:38 2007 +0100
@@ -190,38 +190,7 @@ static CMPIStatus elem_to_prof(const CMP
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *source_op,
- const CMPIInstance *target_inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIStatus s = {CMPI_RC_OK, NULL};
- CMPIInstance *assoc_inst = NULL;
- virConnectPtr conn = NULL;
-
- conn = connect_by_classname(_BROKER, CLASSNAME(source_op), &s);
- if (conn == NULL)
- return NULL;
-
- assoc_inst = get_typed_instance(_BROKER,
- pfx_from_conn(conn),
- "ElementConformsToProfile",
- NAMESPACE(source_op));
-
- if (!CMIsNullObject(assoc_inst)) {
- CMPIObjectPath *target_op;
- target_op = CMGetObjectPath(target_inst, NULL);
-
- CMSetProperty(assoc_inst, assoc->source_prop,
- (CMPIValue *)&(source_op), CMPI_ref);
- CMSetProperty(assoc_inst, assoc->target_prop,
- (CMPIValue *)&(target_op), CMPI_ref);
- }
-
- virConnectClose(conn);
-
- return assoc_inst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* conformant_standard[] = {
"Xen_RegisteredProfile",
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_ElementSettingData.c
--- a/src/Virt_ElementSettingData.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_ElementSettingData.c Thu Dec 06 11:06:38 2007 +0100
@@ -126,50 +126,37 @@ static CMPIStatus rasd_to_rasd(const CMP
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
+static CMPIInstance *make_ref(const CMPIObjectPath *source_ref,
+ const CMPIInstance *target_inst,
struct std_assoc_info *info,
struct std_assoc *assoc)
{
- CMPIStatus s = {CMPI_RC_OK, NULL};
CMPIInstance *refinst = NULL;
- virConnectPtr conn = NULL;
uint16_t prop_value = 1;
- conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
- if (conn == NULL)
- return NULL;
-
- refinst = get_typed_instance(_BROKER,
- pfx_from_conn(conn),
- "ElementSettingData",
- NAMESPACE(ref));
+ refinst = make_reference(_BROKER,
+ source_ref,
+ target_inst,
+ info,
+ assoc);
if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
-
/* Set additional properties with values
* defined in the "Virtual System Profile."
*/
CMSetProperty(refinst, "IsDefault",
- (CMPIValue *)&prop_value, CMPI_uint16);
-
+ (CMPIValue *)&prop_value, CMPI_uint16);
+
CMSetProperty(refinst, "IsNext",
- (CMPIValue *)&prop_value, CMPI_uint16);
+ (CMPIValue *)&prop_value, CMPI_uint16);
CMSetProperty(refinst, "IsMinimum",
- (CMPIValue *)&prop_value, CMPI_uint16);
-
+ (CMPIValue *)&prop_value, CMPI_uint16);
+
CMSetProperty(refinst, "IsMaximum",
- (CMPIValue *)&prop_value, CMPI_uint16);
- }
-
- virConnectClose(conn);
-
+ (CMPIValue *)&prop_value, CMPI_uint16);
+ }
+
return refinst;
}
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_HostedDependency.c
--- a/src/Virt_HostedDependency.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_HostedDependency.c Thu Dec 06 11:06:38 2007 +0100
@@ -82,28 +82,7 @@ static CMPIStatus host_to_vs(const CMPIO
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIInstance *refinst = NULL;
-
- refinst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- "HostedDependency",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* antecedent[] = {
"Xen_ComputerSystem",
@@ -149,7 +128,6 @@ static struct std_assoc _host_to_vs = {
.make_ref = make_ref
};
-
static struct std_assoc *handlers[] = {
&_vs_to_host,
&_host_to_vs,
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_HostedResourcePool.c
--- a/src/Virt_HostedResourcePool.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_HostedResourcePool.c Thu Dec 06 11:06:38 2007 +0100
@@ -97,32 +97,7 @@ static CMPIStatus sys_to_pool(const CMPI
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIInstance *refinst;
- char *base;
-
- base = class_base_name(info->assoc_class);
-
- refinst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- base,
- NAMESPACE(ref));
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- free(base);
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* group_component[] = {
"Xen_HostSystem",
@@ -180,7 +155,6 @@ struct std_assoc *assoc_handlers[] = {
NULL
};
-
STDA_AssocMIStub(, Virt_HostedResourcePoolProvider, _BROKER, libvirt_cim_init(),
assoc_handlers);
/*
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_HostedService.c
--- a/src/Virt_HostedService.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_HostedService.c Thu Dec 06 11:06:38 2007 +0100
@@ -85,36 +85,7 @@ static CMPIStatus host_to_service(const
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIStatus s = {CMPI_RC_OK, NULL};
- CMPIInstance *refinst = NULL;
- virConnectPtr conn = NULL;
-
- conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
- if (conn == NULL)
- return NULL;
-
- refinst = get_typed_instance(_BROKER,
- pfx_from_conn(conn),
- "HostedService",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- virConnectClose(conn);
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* antecedent[] = {
"Xen_HostSystem",
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_ResourceAllocationFromPool.c
--- a/src/Virt_ResourceAllocationFromPool.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_ResourceAllocationFromPool.c Thu Dec 06 11:06:38 2007 +0100
@@ -226,28 +226,7 @@ static CMPIStatus pool_to_rasd(const CMP
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIInstance *refinst = NULL;
-
- refinst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- "ResourceAllocationFromPool",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* antecedent[] = {
"Xen_ProcessorPool",
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_SettingsDefineCapabilities.c
--- a/src/Virt_SettingsDefineCapabilities.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_SettingsDefineCapabilities.c Thu Dec 06 11:06:38 2007 +0100
@@ -812,39 +812,8 @@ static CMPIStatus rasd_to_alloc_cap(cons
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIStatus s = {CMPI_RC_OK, NULL};
- CMPIInstance *refinst = NULL;
- virConnectPtr conn = NULL;
-
- conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
- if (conn == NULL)
- return NULL;
-
- refinst = get_typed_instance(_BROKER,
- pfx_from_conn(conn),
- "SettingsDefineCapabilities",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- CMSetProperty(refinst, assoc->source_prop,
- (CMPIValue *)&ref, CMPI_ref);
- CMSetProperty(refinst, assoc->target_prop,
- (CMPIValue *)&instop, CMPI_ref);
- }
-
- virConnectClose(conn);
-
- return refinst;
-}
+
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* group_component[] = {
"Xen_AllocationCapabilities",
@@ -902,7 +871,6 @@ struct std_assoc *assoc_handlers[] = {
NULL
};
-
STDA_AssocMIStub(, Virt_SettingsDefineCapabilitiesProvider, _BROKER, libvirt_cim_init(),
assoc_handlers);
/*
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_SettingsDefineState.c
--- a/src/Virt_SettingsDefineState.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_SettingsDefineState.c Thu Dec 06 11:06:38 2007 +0100
@@ -288,28 +288,7 @@ static CMPIStatus vssd_to_vs(const CMPIO
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIInstance *refinst = NULL;
-
- refinst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- "SettingsDefineState",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* logical_device[] = {
"Xen_Processor",
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_SystemDevice.c
--- a/src/Virt_SystemDevice.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_SystemDevice.c Thu Dec 06 11:06:38 2007 +0100
@@ -130,30 +130,6 @@ static CMPIInstance *host_instance(char
return inst;
}
-
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIInstance *refinst = NULL;
-
- refinst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- "SystemDevice",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- return refinst;
-}
-
static CMPIStatus sys_to_dev(const CMPIObjectPath *ref,
struct std_assoc_info *info,
struct inst_list *list)
@@ -233,6 +209,8 @@ static CMPIStatus dev_to_sys(const CMPIO
return s;
}
+
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* group_component[] = {
"Xen_ComputerSystem",
diff -r d9af4651f763 -r 618509ea5c60 src/Virt_VSSDComponent.c
--- a/src/Virt_VSSDComponent.c Wed Dec 05 09:42:26 2007 +0100
+++ b/src/Virt_VSSDComponent.c Thu Dec 06 11:06:38 2007 +0100
@@ -152,28 +152,7 @@ static CMPIStatus rasd_to_vssd(const CMP
return s;
}
-static CMPIInstance *make_ref(const CMPIObjectPath *ref,
- const CMPIInstance *inst,
- struct std_assoc_info *info,
- struct std_assoc *assoc)
-{
- CMPIInstance *refinst = NULL;
-
- refinst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- "VirtualSystemSettingDataComponent",
- NAMESPACE(ref));
-
- if (refinst != NULL) {
- CMPIObjectPath *instop;
-
- instop = CMGetObjectPath(inst, NULL);
-
- set_reference(assoc, refinst, ref, instop);
- }
-
- return refinst;
-}
+LIBVIRT_CIM_DEFAULT_MAKEREF()
char* group_component[] = {
"Xen_VirtualSystemSettingData",
@@ -199,7 +178,6 @@ char* assoc_classname[] = {
NULL
};
-
static struct std_assoc forward = {
.source_class = (char**)&group_component,
.source_prop = "GroupComponent",