(file) Return to CMPI_ContextArgs.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / ProviderManager2 / CMPI

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2