1 krisbash 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 krisbash 1.1 **==============================================================================
23 */
24
25 #include <ctype.h>
26 #include "instance.h"
27 #include "indent.h"
28 #include "field.h"
29 #include <pal/format.h>
30
31
32 MI_Result MI_CALL Instance_Print(
33 const MI_Instance* self_,
34 FILE* os,
35 MI_Uint32 level,
36 MI_Boolean showNulls,
37 MI_Boolean isClass)
38 {
39 Instance* self = Instance_GetSelf( self_ );
40 const MI_ClassDecl* cd;
41 MI_Uint32 i;
42 const MI_Char *objectType;
43 krisbash 1.1
44 /* Check for null arguments */
45 if (!self)
46 MI_RETURN(MI_RESULT_INVALID_PARAMETER);
47
48 cd = self->classDecl;
49
50 if (isClass)
51 objectType = PAL_T("class");
52 else
53 objectType = PAL_T("instance");
54
55 /* Print nameSpace and className */
56 if (self->nameSpace)
57 {
58 Indent(os, level);
59 Ftprintf(os, PAL_T("%T of %T:%T\n"), objectType, tcs(self->nameSpace),
60 tcs(cd->name));
61 }
62 else
63 {
64 krisbash 1.1 Indent(os, level);
65 Ftprintf(os, PAL_T("%T of %T\n"), objectType, tcs(cd->name));
66 }
67
68 Indent(os, level);
69 Ftprintf(os, PAL_T("{\n"));
70 level++;
71
72 /* Print the properties */
73 for (i = 0; i < cd->numProperties; i++)
74 {
75 const MI_PropertyDecl* pd = cd->properties[i];
76 const Field* field = (Field*)((char*)self + pd->offset);
77
78 if (showNulls || Field_GetExists(field, pd->type))
79 {
80 Indent(os, level);
81
82 if (isClass)
83 {
84 const MI_Char *typeName = Type_NameOf(pd->type);
85 krisbash 1.1 if (typeName == NULL)
86 typeName = PAL_T("unknown");
87 Ftprintf(os, PAL_T("[MI_%T] "), typeName);
88 }
89
90 if (pd->flags & MI_FLAG_KEY)
91 Ftprintf(os, PAL_T("[Key] "));
92
93 Ftprintf(os, PAL_T("%T="), tcs(pd->name));
94
95 Field_Print(field, os, pd->type, level, MI_TRUE, isClass);
96
97 if (pd->type == MI_INSTANCE || pd->type == MI_REFERENCE)
98 {
99 if (!field->instance.value)
100 Ftprintf(os, PAL_T("\n"));
101 }
102 else
103 Ftprintf(os, PAL_T("\n"));
104 }
105 }
106 krisbash 1.1
107 level--;
108 Indent(os, level);
109
110 Ftprintf(os, PAL_T("}\n"));
111
112 MI_RETURN(MI_RESULT_OK);
113 }
|