1 schuur 1.1 //%2003////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 schuur 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Adrian Schuur, schuur@de.ibm.com
27 //
28 // Modified By:
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
|
32 schuur 1.5 #include "CMPI_Version.h"
|
33 schuur 1.2
|
34 schuur 1.1 #include "CMPI_ContextArgs.h"
35 #include "CMPI_Ftabs.h"
36 #include "CMPI_Value.h"
37 #include "CMPI_String.h"
38
|
39 schuur 1.6 #include <string.h>
40
|
41 schuur 1.1 PEGASUS_USING_STD;
42 PEGASUS_NAMESPACE_BEGIN
43
44 // CMPIArgs section
45
|
46 schuur 1.10 extern "C" {
47
48 static CMPIStatus argsRelease(CMPIArgs* eArg) {
49 Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
50 if (arg) {
51 delete arg;
52 (reinterpret_cast<CMPI_Object*>(eArg))->unlinkAndDelete();
53 }
54 CMReturn(CMPI_RC_OK);
|
55 schuur 1.8 }
|
56 schuur 1.1
|
57 schuur 1.10 static CMPIStatus argsReleaseNop(CMPIArgs* eArg) {
58 CMReturn(CMPI_RC_OK);
59 }
|
60 schuur 1.1
|
61 schuur 1.10 static CMPIArgs* argsClone(CMPIArgs* eArg, CMPIStatus* rc) {
62 Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
63 Array<CIMParamValue>* cArg=new Array<CIMParamValue>();
64 for (long i=0,s=arg->size(); i<s; i++) {
65 const CIMParamValue &v=(*arg)[i];
66 cArg->append(v.clone());
67 }
68 CMPI_Object* obj=new CMPI_Object(cArg);
69 obj->unlink();
70 CMPIArgs* neArg=(CMPIArgs*)obj;
71 if (rc) CMSetStatus(rc,CMPI_RC_OK);
72 return neArg;
73 }
|
74 schuur 1.1
|
75 schuur 1.10 static long locateArg(const Array<CIMParamValue> &a, const CIMName &eName) {
76 for (long i=0,s=a.size(); i<s; i++) {
77 const String &n=a[i].getParameterName();
78 if (String::equalNoCase(n,eName.getString())) return i;
79 }
80 return -1;
|
81 schuur 1.1 }
82
|
83 schuur 1.10 static CMPIStatus argsAddArg(CMPIArgs* eArg, const char *name, CMPIValue* data, CMPIType type) {
84 Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
85 CMPIrc rc;
86 CIMValue v=value2CIMValue(data,type,&rc);
87 CIMName sName(name);
88
89 long i=locateArg(*arg,sName);
90 if (i>=0) arg->remove(i);
|
91 schuur 1.1
|
92 schuur 1.10 arg->append(CIMParamValue(sName.getString(),v));
93 CMReturn(CMPI_RC_OK);
94 }
|
95 schuur 1.1
|
96 schuur 1.10 static CMPIData argsGetArgAt(CMPIArgs* eArg, CMPICount pos, CMPIString** name,
97 CMPIStatus* rc) {
98 Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
99 CMPIData data={0,CMPI_nullValue | CMPI_notFound,{0}};
100
101 if (pos>arg->size()) {
102 if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
103 return data;
104 }
|
105 schuur 1.1
|
106 schuur 1.10 CIMValue v=(*arg)[pos].getValue();
107 CIMType pType=v.getType();
108 CMPIType t=type2CMPIType(pType,v.isArray());
109
110 value2CMPIData(v,t,&data);
111
112 if (name) {
113 String n=(*arg)[pos].getParameterName();
114 *name=(CMPIString*)string2CMPIString(n);
115 }
|
116 schuur 1.1
|
117 schuur 1.10 if (rc) CMSetStatus(rc,CMPI_RC_OK);
|
118 schuur 1.1 return data;
119 }
120
|
121 schuur 1.10 static CMPIData argsGetArg(CMPIArgs* eArg, const char *name, CMPIStatus* rc) {
122 Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
123 CIMName eName(name);
|
124 schuur 1.1
|
125 schuur 1.10 long i=locateArg(*arg,eName);
126 if (i>=0) return argsGetArgAt(eArg,i,NULL,rc);
|
127 schuur 1.1
|
128 schuur 1.10 CMPIData data={0,CMPI_nullValue | CMPI_notFound,{0}};
129 if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
130 return data;
|
131 schuur 1.1 }
132
|
133 schuur 1.10 static CMPICount argsGetArgCount(CMPIArgs* eArg, CMPIStatus* rc) {
134 Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
135 if (rc) CMSetStatus(rc,CMPI_RC_OK);
136 return arg->size();
137 }
|
138 schuur 1.1
139 }
140
141 static CMPIArgsFT args_FT={
142 CMPICurrentVersion,
143 argsRelease,
144 argsClone,
145 argsAddArg,
146 argsGetArg,
147 argsGetArgAt,
148 argsGetArgCount,
149 };
150
151 CMPIArgsFT *CMPI_Args_Ftab=&args_FT;
152
153 static CMPIArgsFT argsOnStack_FT={
154 CMPICurrentVersion,
155 argsReleaseNop,
156 argsClone,
157 argsAddArg,
158 argsGetArg,
159 schuur 1.1 argsGetArgAt,
160 argsGetArgCount,
161 };
162
163 CMPIArgsFT *CMPI_ArgsOnStack_Ftab=&argsOnStack_FT;
164
165
166
167 // CMPIContext Session
168
|
169 schuur 1.10 extern "C" {
170
|
171 schuur 1.1 static CMPIStatus contextReleaseNop(CMPIContext* eCtx) {
172 CMReturn(CMPI_RC_OK);
173 }
174
|
175 schuur 1.10 static CMPIData contextGetEntry(CMPIContext* eCtx, const char *name, CMPIStatus* rc) {
176 return argsGetArg((CMPIArgs*)eCtx,name,rc);
177 }
|
178 schuur 1.1
|
179 schuur 1.10 CMPIData contextGetEntryAt(CMPIContext* eCtx, CMPICount pos,
180 CMPIString** name, CMPIStatus* rc) {
181 return argsGetArgAt((CMPIArgs*)eCtx,pos,name,rc);
182 }
183
184 static CMPICount contextGetEntryCount(CMPIContext* eCtx, CMPIStatus* rc) {
185 return argsGetArgCount((CMPIArgs*)eCtx,rc);
186 }
187
188 static CMPIStatus contextAddEntry(CMPIContext* eCtx, const char *name,
189 CMPIValue* data, CMPIType type) {
190 if (strcmp(name,SnmpTrapOidContainer::NAME.getCString())==0) {
191 OperationContext *ctx=((CMPI_Context*)eCtx)->ctx;
192 if (type==CMPI_chars) {
193 ctx->insert(SnmpTrapOidContainer((char*)data));
194 CMReturn(CMPI_RC_OK);
195 }
196 else if (type==CMPI_string) {
197 ctx->insert(SnmpTrapOidContainer((char*)data->string->hdl));
198 CMReturn(CMPI_RC_OK);
199 }
|
200 schuur 1.4 }
|
201 schuur 1.10 return argsAddArg((CMPIArgs*)eCtx,name,data,type);
|
202 schuur 1.4 }
|
203 schuur 1.10
|
204 schuur 1.1 }
205
206 static CMPIContextFT context_FT={
207 CMPICurrentVersion,
208 contextReleaseNop,
209 NULL,
210 contextGetEntry,
211 contextGetEntryAt,
212 contextGetEntryCount,
213 contextAddEntry,
214 };
215
216 CMPIContextFT *CMPI_Context_Ftab=&context_FT;
217
218 static CMPIContextFT contextOnStack_FT={
219 CMPICurrentVersion,
220 contextReleaseNop,
221 NULL,
222 contextGetEntry,
223 contextGetEntryAt,
224 contextGetEntryCount,
225 schuur 1.1 contextAddEntry,
226 };
227
228 CMPIContextFT *CMPI_ContextOnStack_Ftab=&contextOnStack_FT;
229
230
231 CMPI_Context::CMPI_Context(const OperationContext& ct) {
232 ctx=(OperationContext*)&ct;
233 thr=NULL;
234 hdl=(void*)new Array<CIMParamValue>();
235 ft=CMPI_Context_Ftab;
236 }
237
238 CMPI_ContextOnStack::CMPI_ContextOnStack(const OperationContext& ct) {
239 ctx=(OperationContext*)&ct;
240 hdl=(void*)new Array<CIMParamValue>();
241 ft=CMPI_ContextOnStack_Ftab;
242 }
243
244 CMPI_ContextOnStack::~CMPI_ContextOnStack() {
245 delete (Array<CIMParamValue>*)hdl;
246 schuur 1.1 }
247
248 CMPI_ArgsOnStack::CMPI_ArgsOnStack(const Array<CIMParamValue>& args) {
249 hdl=(void*)&args;
250 ft=CMPI_ArgsOnStack_Ftab;
251 }
252
253 PEGASUS_NAMESPACE_END
254
255
256
257
258
259
260
|