(file) Return to wql.h CVS log (file) (dir) Up to [OMI] / omi / wql

  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 krisbash 1.3     WQL_TYPE_LIKE,
 53                  WQL_TYPE_ISA,
 54 mike     1.1     WQL_TYPE_IDENTIFIER,
 55                  WQL_TYPE_BOOLEAN,
 56                  WQL_TYPE_INTEGER,
 57                  WQL_TYPE_REAL,
 58                  WQL_TYPE_STRING,
 59 krisbash 1.3     WQL_TYPE_NULL,
 60                  WQL_TYPE_ANY
 61 mike     1.1 }
 62              WQL_Type;
 63              
 64              /* Value of symbol (if any) appearing in the WHERE clause. We avoid the use
 65               * of unions here to permit static structure initialization (unions only 
 66               * support initialization of the first field).
 67               */
 68              typedef struct _WQL_Value
 69              {
 70                  unsigned char boolean;
 71                  long long integer;
 72                  double real;
 73 krisbash 1.3     /* property name or literal string */
 74                  ZChar* string;
 75                  /* Example: SourceInstance.CIM_StorageVolume::OperationStatus */
 76                  ZChar* embeddedClassName;
 77                  /* Example: SourceInstance.OperationStatus */
 78                  ZChar* embeddedPropertyName;
 79 mike     1.1 }
 80              WQL_Value;
 81              
 82 krisbash 1.3 #define WQL_VALUE_BOOLEAN(X) { X, 0, 0, NULL, NULL, NULL }
 83              #define WQL_VALUE_INTEGER(X) { 0, X, 0, NULL , NULL, NULL}
 84              #define WQL_VALUE_REAL(X) { 0, 0, X, NULL , NULL, NULL}
 85              #define WQL_VALUE_STRING(X) { 0, 0, 0, X , NULL, NULL}
 86 mike     1.1 
 87              /* Represents an operand or operator appearing in the WHERE clause */
 88              typedef struct _WQL_Symbol
 89              {
 90                  WQL_Type type;
 91                  WQL_Value value;
 92              }
 93              WQL_Symbol;
 94              
 95 krisbash 1.3 /* This parser supports WQL and CQL dialects */
 96              typedef enum _WQL_Dialect
 97              {
 98                  WQL_DIALECT_WQL,
 99                  WQL_DIALECT_CQL
100              }
101              WQL_Dialect;
102              
103 mike     1.1 /* Output structure from WQL parser */
104              typedef struct _WQL
105              {
106                  /* Properties given by SELECT list */
107 krisbash 1.3     const ZChar* properties[WQL_MAX_PROPERTIES];
108 mike     1.1     size_t nproperties;
109              
110                  /* Class name given by FROM clause */
111 krisbash 1.3     const ZChar* className;
112 mike     1.1 
113                  /* Condition symbols given by WHERE class (in postfix order) */
114                  WQL_Symbol symbols[WQL_MAX_SYMBOLS];
115                  size_t nsymbols;
116              
117                  /* Allocate blocks from this batch (if provided) */
118                  Batch* batch;
119              
120                  /* Whether batch object should be deleted in WQL_Delete() */
121                  int deleteBatch;
122              
123                  /* The query text */
124 krisbash 1.3     ZChar* text;
125              
126                  /* Dialect being parsed: WQL or CQL */
127                  WQL_Dialect dialect;
128 mike     1.1 }
129              WQL;
130              
131 krisbash 1.3 WQL* WQL_Parse(
132                  const ZChar* text, 
133                  Batch* batch, 
134                  WQL_Dialect dialect);
135 mike     1.1 
136              WQL* WQL_Clone(const WQL* self, Batch* batch);
137              
138              void WQL_Delete(WQL* self);
139              
140              /* Generate a static C definition of this WQL structure */
141              int WQL_Define(const WQL* self, Buf* out, size_t nindent);
142              
143              /* Dump WQL instance to standard output */
144              int WQL_Dump(const WQL* self, size_t nindent);
145              
146              /* Return non-zero if the two WQL instances are identical */
147              int WQL_Identical(const WQL* x, const WQL* y);
148              
149 krisbash 1.3 /* Signature of Lookup() function called by WQL_Eval().
150               *     name -
151               *         The property to be looked up.
152               *     embeddedClassName -
153               *         If non-null, the class type when 'name' is an embedded instance 
154               *         property (uses ISA relationship).
155               *     embeddedPropertyName -
156               *         If non-null, the name of a property of the embedded instances
157               *         given by 'name'.
158               *     symbol - 
159               *         Holds the result of the lookup operation (usually the value
160               *         of the property given by 'name'.
161               *     batch -
162               *         Batch allocator in case any memory must be allocated.
163               *     data -
164               *         The data argument passed to Lookup() function.
165               *
166               * More on these parameters:
167               *     name
168               *     embeddedClassName
169               *     embeddedPropertyName
170 krisbash 1.3  *
171               * There are 4 conditions involving these parameters to consider:
172               *
173               *     Case 1: (name && !embeddedClassName && !embeddedPropertyName)
174               *         Get the value of the property given by the 'name' parameter.
175               *
176               *     Case 2: (name && embeddedClassName && !embeddedPropertyName)
177               *         Perform an ISA operation where the instance is given by the 'name'
178               *         embedded instance property and the classname is given by the
179               *         'embeddedClassName' parameter.
180               *         WQL Example: SourceInstance ISA CIM_StorageVolume
181               *             name=SourceInstance
182               *             embeddedClassName=CIM_StorageVolume
183               *             embeddedPropertyName=NULL
184               *
185               *     Case 3: (name && !embeddedClassName && embeddedPropertyName)
186               *         Get the value of the property given by the 'embeddedPropertyName'
187               *         parameter from the instance given by the 'name' parameter.
188               *         WQL Example: SourceInstance.OperationalStatus
189               *             name=SourceInstance
190               *             embeddedClassName=NULL
191 krisbash 1.3  *             embeddedPropertyName=OperationalStatus
192               *
193               *     Case 4: (name && embeddedClassName && embeddedPropertyName)
194               *         Get the value of the property given by the 'embeddedPropertyName'
195               *         parameter from the instance given by the 'name' parameter and
196               *         require that the the class satisfy the ISA relationship with
197               *         the 'embeddedClassName' parameter.
198               *         WQL Example: SourceInstance.CIM_StorageVolume.OperationalStatus
199               *             name=SourceInstance
200               *             embeddedClassName=CIM_StorageVolume
201               *             embeddedPropertyName=OperationalStatus
202               *
203               */
204 mike     1.1 typedef int (*WQL_Lookup)(
205 krisbash 1.3     const ZChar* name, 
206                  const ZChar* embeddedClassName, 
207                  const ZChar* embeddedPropertyName, 
208 mike     1.1     WQL_Symbol* symbol, 
209                  Batch* batch,
210                  void* data);
211              
212              /* Evaluate WQL expression, obtaining property values with the lookup()
213               * callback function. Return value: 0=match, 1=mismatch, -1=error.
214               */
215              int WQL_Eval(
216                  const WQL* wql, 
217                  WQL_Lookup lookup,
218                  void* data);
219              
220              /* Lookup function that may be passed to WQL_Eval(). This function looks up
221               * property values from an MI_Instance( the data parameter is an MI_Instance).
222               */
223              int WQL_LookupInstanceProperty(
224 krisbash 1.3     const ZChar* name, 
225                  const ZChar* embeddedClassName, 
226                  const ZChar* embeddedPropertyName, 
227 mike     1.1     WQL_Symbol* symbol, 
228                  Batch* batch,
229                  void* data);
230              
231              /* Return non-zero if the WQL property list contains the given property */
232              MI_Boolean WQL_ContainsProperty(
233                  const WQL* self,
234 krisbash 1.3     const ZChar* propertyName);
235 mike     1.1 
236 krisbash 1.3 /* Validate the query against the given class declaration: returns 0 or -1 */
237 mike     1.1 int WQL_Validate(
238                  const WQL* self, 
239                  const MI_ClassDecl* cd);
240              
241              #ifdef __cplusplus
242              }
243              #endif
244              
245              #endif /* _wql_wql_h */

ViewCVS 0.9.2