-
Notifications
You must be signed in to change notification settings - Fork 17
Fixing some TODOs #20
base: master
Are you sure you want to change the base?
Changes from all commits
69ac7f5
685e470
d1720c3
43d6017
602a3f7
56b3c73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,6 +346,52 @@ private static string PutEscapeCharacterBack(string propValue) | |
} | ||
*/ | ||
|
||
internal static object ConvertFromNativeLayer( | ||
MI_Type type, | ||
MI_Value value, | ||
CimInstance parent = null, | ||
bool clone = false) | ||
{ | ||
if (type == MI_Type.MI_INSTANCE) | ||
{ | ||
CimInstance instance = new CimInstance( | ||
clone ? value.Instance.Clone() : value.Instance); | ||
if (parent != null) | ||
{ | ||
instance.SetCimSessionComputerName(parent.GetCimSessionComputerName()); | ||
instance.SetCimSessionInstanceId(parent.GetCimSessionInstanceId()); | ||
} | ||
return instance; | ||
} | ||
|
||
if (type == MI_Type.MI_INSTANCEA) | ||
{ | ||
CimInstance[] arrayOfInstances = new CimInstance[value.InstanceA.Length]; | ||
for (int i = 0; i < value.InstanceA.Length; i++) | ||
{ | ||
MI_Instance h = value.InstanceA[i]; | ||
if (h == null) | ||
{ | ||
arrayOfInstances[i] = null; | ||
} | ||
else | ||
{ | ||
arrayOfInstances[i] = new CimInstance( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CimInstance had better clone the memory, otherwise my memory management pattern of having the underlying native memory be deleted on Dispose won't work |
||
clone ? h.Clone() : h); | ||
if (parent != null) | ||
{ | ||
arrayOfInstances[i].SetCimSessionComputerName(parent.GetCimSessionComputerName()); | ||
arrayOfInstances[i].SetCimSessionInstanceId(parent.GetCimSessionInstanceId()); | ||
} | ||
} | ||
} | ||
return arrayOfInstances; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
|
||
#endregion Helpers | ||
|
||
#region IDisposable Members | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,11 @@ public override CimQualifier this[string qualifierName] | |
|
||
MI_QualifierSet qualifierSet; | ||
MI_Result result = this.classHandle.GetClassQualifierSet(out qualifierSet); | ||
CimException.ThrowIfMiResultFailure(result); | ||
// TODO: there aren't many comments for the above pattern throughout the MMI sources, but if the above fails we shouldn't throw exception, just return MI_RESULT_NOT_FOUND like below. Make sure all of these cases are accounted for in MMI | ||
|
||
if (result != MI_Result.MI_RESULT_OK) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like a breaking change to the client. Why are you doing this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I actually need to add a few more conditions than I have it after reviewing the MMIN code for this. Previously, these MI calls (GetClassQualifierSet and GetQualifier below) were done in a single native C++ function called GetMethodQualifierElementAt_GetFlags. If the GetClassQualifierSet function call returned non-MI_RESULT_OK, then it wouldn't try to call GetQualifier, but it also wouldn't necessarily throw an exception either like the previous version of this file had. It would drop right down into the switch block below. I think a possible solution, if we want to preserve algorithmic equivalency, is to return null if result is MI_RESULT_NOT_FOUND, else if result is not MI_RESULT_OK then call ThrowIfMiResultFailure if it is, and if it is MI_RESULT_OK then just continue on with the function to call GetQualifier. |
||
{ | ||
return null; | ||
} | ||
|
||
MI_Type qualifierType; | ||
MI_Flags qualifierFlags; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeated code for initialization. Consider helper (e.g. ConvertInstanceFromNativeLayer)