1 mike 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 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _wql_wql_h
26 #define _wql_wql_h
27
28 #include <common.h>
29 #include <stddef.h>
30 #include <base/batch.h>
31 #include <base/buf.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #define WQL_MAX_PROPERTIES 128
38 #define WQL_MAX_SYMBOLS 64
39
40 /* Type of symbol appearing in the WHERE clause */
41 typedef enum _WQL_Type
42 {
43 mike 1.1 WQL_TYPE_OR,
44 WQL_TYPE_AND,
45 WQL_TYPE_NOT,
46 WQL_TYPE_EQ,
47 WQL_TYPE_NE,
48 WQL_TYPE_LT,
49 WQL_TYPE_LE,
50 WQL_TYPE_GT,
51 WQL_TYPE_GE,
52 WQL_TYPE_IDENTIFIER,
53 WQL_TYPE_BOOLEAN,
54 WQL_TYPE_INTEGER,
55 WQL_TYPE_REAL,
56 WQL_TYPE_STRING,
57 WQL_TYPE_NULL
58 }
59 WQL_Type;
60
61 /* Value of symbol (if any) appearing in the WHERE clause. We avoid the use
62 * of unions here to permit static structure initialization (unions only
63 * support initialization of the first field).
64 mike 1.1 */
65 typedef struct _WQL_Value
66 {
67 unsigned char boolean;
68 long long integer;
69 double real;
70 MI_Char* string;
71 }
72 WQL_Value;
73
74 #define WQL_VALUE_BOOLEAN(X) { X, 0, 0, NULL }
75 #define WQL_VALUE_INTEGER(X) { 0, X, 0, NULL }
76 #define WQL_VALUE_REAL(X) { 0, 0, X, NULL }
77 #define WQL_VALUE_STRING(X) { 0, 0, 0, X }
78
79 /* Represents an operand or operator appearing in the WHERE clause */
80 typedef struct _WQL_Symbol
81 {
82 WQL_Type type;
83 WQL_Value value;
84 }
85 mike 1.1 WQL_Symbol;
86
87 /* Output structure from WQL parser */
88 typedef struct _WQL
89 {
90 /* Properties given by SELECT list */
91 const MI_Char* properties[WQL_MAX_PROPERTIES];
92 size_t nproperties;
93
94 /* Class name given by FROM clause */
95 const MI_Char* className;
96
97 /* Condition symbols given by WHERE class (in postfix order) */
98 WQL_Symbol symbols[WQL_MAX_SYMBOLS];
99 size_t nsymbols;
100
101 /* Allocate blocks from this batch (if provided) */
102 Batch* batch;
103
104 /* Whether batch object should be deleted in WQL_Delete() */
105 int deleteBatch;
106 mike 1.1
107 /* The query text */
108 MI_Char* text;
109 }
110 WQL;
111
112 WQL* WQL_Parse(const MI_Char* text, Batch* batch);
113
114 WQL* WQL_Clone(const WQL* self, Batch* batch);
115
116 void WQL_Delete(WQL* self);
117
118 /* Generate a static C definition of this WQL structure */
119 int WQL_Define(const WQL* self, Buf* out, size_t nindent);
120
121 /* Dump WQL instance to standard output */
122 int WQL_Dump(const WQL* self, size_t nindent);
123
124 /* Return non-zero if the two WQL instances are identical */
125 int WQL_Identical(const WQL* x, const WQL* y);
126
127 mike 1.1 /* Lookup function passed to WQL_Eval() */
128 typedef int (*WQL_Lookup)(
129 const MI_Char* name,
130 WQL_Symbol* symbol,
131 Batch* batch,
132 void* data);
133
134 /* Evaluate WQL expression, obtaining property values with the lookup()
135 * callback function. Return value: 0=match, 1=mismatch, -1=error.
136 */
137 int WQL_Eval(
138 const WQL* wql,
139 WQL_Lookup lookup,
140 void* data);
141
142 /* Lookup function that may be passed to WQL_Eval(). This function looks up
143 * property values from an MI_Instance( the data parameter is an MI_Instance).
144 */
145 int WQL_LookupInstanceProperty(
146 const MI_Char* name_,
147 WQL_Symbol* symbol,
148 mike 1.1 Batch* batch,
149 void* data);
150
151 /* Return non-zero if the WQL property list contains the given property */
152 MI_Boolean WQL_ContainsProperty(
153 const WQL* self,
154 const MI_Char* propertyName);
155
156 /* Validate the query against the given class declaration */
157 int WQL_Validate(
158 const WQL* self,
159 const MI_ClassDecl* cd);
160
161 #ifdef __cplusplus
162 }
163 #endif
164
165 #endif /* _wql_wql_h */
|