-
Notifications
You must be signed in to change notification settings - Fork 0
/
predicate.c
158 lines (137 loc) · 3.9 KB
/
predicate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* $Id: predicate.c,v 1.7 2007/10/02 09:02:11 mihajlov Exp $
*
* © Copyright IBM Corp. 2005, 2007
*
* THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
* ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
* CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
*
* You can obtain a current copy of the Eclipse Public License from
* http://www.opensource.org/licenses/eclipse-1.0.php
*
* Author: Adrian Schuur <schuur@de.ibm.com>
*
* Description:
*
* CMPIPredicate implementation.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "native.h"
#include "queryOperation.h"
typedef struct native_predicate {
CMPIPredicate pred;
int mem_state;
QLOperation *op;
} NativePredicate;
static NativePredicate *__new_predicate(int mode, QLOperation * ptr,
CMPIStatus *rc);
/*****************************************************************************/
static CMPIStatus
__eft_release(CMPIPredicate *pred)
{
NativePredicate *p = (NativePredicate *) pred;
if (p->mem_state && p->mem_state != MEM_RELEASED) {
memUnlinkEncObj(p->mem_state);
p->mem_state = MEM_RELEASED;
free(p);
CMReturn(CMPI_RC_OK);
}
CMReturn(CMPI_RC_ERR_FAILED);
}
static CMPIPredicate *
__eft_clone(const CMPIPredicate *pred, CMPIStatus *rc)
{
NativePredicate *p = (NativePredicate *) pred;
return (CMPIPredicate *) __new_predicate(MEM_NOT_TRACKED, p->op, rc);
}
static CMPIStatus
__eft_getData(const CMPIPredicate *pred, CMPIType *type,
CMPIPredOp * opc, CMPIString **lhs, CMPIString **rhs)
{
NativePredicate *p = (NativePredicate *) pred;
QLOperation *op = p->op,
*o;
CMPIStatus irc = { CMPI_RC_OK, NULL };
if (op) {
if (op->opr == QL_bin) {
if (op->lhon)
o = op->lhon;
else
o = op->rhon;
if (o->lhod && o->lhod->type != QL_PropertyName)
*type = (o->lhod->type < 0) ? CMPI_null : (CMPIType)o->lhod->type;
else if (o->rhod && o->rhod->type != QL_PropertyName)
*type = (o->rhod->type < 0) ? CMPI_null : (CMPIType)o->rhod->type;
if (opc)
*opc = o->opr;
if (lhs) {
char* lstr = o->lhod->ft->toString(o->lhod);
*lhs = sfcb_native_new_CMPIString(lstr, NULL, 0);
}
if (rhs) {
char* rstr = o->rhod->ft->toString(o->rhod);
*rhs = sfcb_native_new_CMPIString(rstr, NULL, 0);
}
} else {
printf("--- NOT QL_bin\n");
CMSetStatusWithString(&irc, CMPI_RC_ERR_FAILED,
sfcb_native_new_CMPIString
("Predicate has no a binary operator.", NULL,
0));
}
}
return irc;
}
static CMPIBoolean
__eft_evaluate(const CMPIPredicate *pred,
CMPIAccessor * acc, void *v, CMPIStatus *rc)
{
if (rc)
CMSetStatus(rc, CMPI_RC_ERR_NOT_SUPPORTED);
return 0;
}
static NativePredicate *
__new_predicate(int mode, QLOperation * op, CMPIStatus *rc)
{
static CMPIPredicateFT eft = {
NATIVE_FT_VERSION,
__eft_release,
__eft_clone,
__eft_getData,
__eft_evaluate
};
static CMPIPredicate p = {
"CMPIPredicate",
&eft
};
int state;
NativePredicate pred,
*tPred;
memset(&pred, 0, sizeof(pred));
pred.pred = p;
pred.op = op;
tPred = memAddEncObj(mode, &pred, sizeof(pred), &state);
tPred->mem_state = state;
if (rc)
CMSetStatus(rc, CMPI_RC_OK);
return tPred;
}
CMPIPredicate *
TrackedCMPIPredicate(QLOperation * op, CMPIStatus *rc)
{
return (CMPIPredicate *) __new_predicate(MEM_TRACKED, op, rc);
}
CMPIPredicate *
NewCMPIPredicate(QLOperation * op, CMPIStatus *rc)
{
return (CMPIPredicate *) __new_predicate(MEM_NOT_TRACKED, op, rc);
}
/* MODELINES */
/* DO NOT EDIT BELOW THIS COMMENT */
/* Modelines are added by 'make pretty' */
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil; -*- */
/* vi:set ts=2 sts=2 sw=2 expandtab: */