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

  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.2.6.1 #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.2.6.1 #include <string.h>
 40                
 41 schuur 1.1     PEGASUS_USING_STD;
 42                PEGASUS_NAMESPACE_BEGIN
 43                
 44                // CMPIArgs section
 45                
 46                static CMPIStatus argsRelease(CMPIArgs* eArg) {
 47 schuur 1.2.6.3    Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
 48                   if (arg) {
 49                      delete arg;
 50                      (reinterpret_cast<CMPI_Object*>(eArg))->unlinkAndDelete();
 51                   }
 52 schuur 1.1        CMReturn(CMPI_RC_OK);
 53                }
 54                
 55                static CMPIStatus argsReleaseNop(CMPIArgs* eArg) {
 56                   CMReturn(CMPI_RC_OK);
 57                }
 58                
 59                static CMPIArgs* argsClone(CMPIArgs* eArg, CMPIStatus* rc) {
 60                   Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
 61                   Array<CIMParamValue>* cArg=new Array<CIMParamValue>();
 62                   for (long i=0,s=arg->size(); i<s; i++) {
 63                      const CIMParamValue &v=(*arg)[i];
 64                      cArg->append(v.clone());
 65                   }
 66 schuur 1.2.6.3    CMPI_Object* obj=new CMPI_Object(cArg);
 67 schuur 1.2.6.2    obj->unlink();
 68                   CMPIArgs* neArg=(CMPIArgs*)obj;
 69 schuur 1.1        if (rc) CMSetStatus(rc,CMPI_RC_OK);
 70                   return neArg;
 71                }
 72                
 73                static long locateArg(const Array<CIMParamValue> &a, const CIMName &eName) {
 74                   for (long i=0,s=a.size(); i<s; i++) {
 75                      const String &n=a[i].getParameterName();
 76 schuur 1.2           if (String::equalNoCase(n,eName.getString())) return i;
 77 schuur 1.1        }
 78                   return -1;
 79                }
 80                
 81 schuur 1.2.6.1 static CMPIStatus argsAddArg(CMPIArgs* eArg, const char *name, CMPIValue* data, CMPIType type) {
 82 schuur 1.1        Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
 83                   CMPIrc rc;
 84                   CIMValue v=value2CIMValue(data,type,&rc);
 85                   CIMName sName(name);
 86                
 87                   long i=locateArg(*arg,sName);
 88                   if (i>=0) arg->remove(i);
 89                
 90 schuur 1.2        arg->append(CIMParamValue(sName.getString(),v));
 91 schuur 1.1        CMReturn(CMPI_RC_OK);
 92                }
 93                
 94                static CMPIData argsGetArgAt(CMPIArgs* eArg, CMPICount pos, CMPIString** name,
 95                               CMPIStatus* rc) {
 96                   Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
 97                   CMPIData data={0,0,{0}};
 98                
 99                   if (pos>arg->size()) {
100                      if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
101                      return data;
102                   }
103                
104                   CIMValue v=(*arg)[pos].getValue();
105                   CIMType pType=v.getType();
106                   CMPIType t=type2CMPIType(pType,v.isArray());
107                
108                   value2CMPIData(v,t,&data);
109                
110                   if (name) {
111                      String n=(*arg)[pos].getParameterName();
112 schuur 1.1           *name=(CMPIString*)string2CMPIString(n);
113                   }
114                
115                   if (rc) CMSetStatus(rc,CMPI_RC_OK);
116                   return data;
117                }
118                
119 schuur 1.2.6.1 static CMPIData argsGetArg(CMPIArgs* eArg, const char *name, CMPIStatus* rc) {
120 schuur 1.1        Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
121                   CIMName eName(name);
122                
123                   long i=locateArg(*arg,eName);
124                   if (i>=0) return argsGetArgAt(eArg,i,NULL,rc);
125                
126                   CMPIData data={0,0,{0}};
127                   if (rc) CMSetStatus(rc,CMPI_RC_ERR_NOT_FOUND);
128                   return data;
129                }
130                
131                static CMPICount argsGetArgCount(CMPIArgs* eArg, CMPIStatus* rc) {
132                   Array<CIMParamValue>* arg=(Array<CIMParamValue>*)eArg->hdl;
133                   if (rc) CMSetStatus(rc,CMPI_RC_OK);
134                   return arg->size();
135                }
136                
137                
138                static CMPIArgsFT args_FT={
139                     CMPICurrentVersion,
140                     argsRelease,
141 schuur 1.1          argsClone,
142                     argsAddArg,
143                     argsGetArg,
144                     argsGetArgAt,
145                     argsGetArgCount,
146                };
147                
148                CMPIArgsFT *CMPI_Args_Ftab=&args_FT;
149                
150                static CMPIArgsFT argsOnStack_FT={
151                     CMPICurrentVersion,
152                     argsReleaseNop,
153                     argsClone,
154                     argsAddArg,
155                     argsGetArg,
156                     argsGetArgAt,
157                     argsGetArgCount,
158                };
159                
160                CMPIArgsFT *CMPI_ArgsOnStack_Ftab=&argsOnStack_FT;
161                
162 schuur 1.1     
163                
164                // CMPIContext Session
165                
166                static CMPIStatus contextReleaseNop(CMPIContext* eCtx) {
167                   CMReturn(CMPI_RC_OK);
168                }
169                
170 schuur 1.2.6.1 static CMPIData contextGetEntry(CMPIContext* eCtx, const char *name, CMPIStatus* rc) {
171 schuur 1.1        return argsGetArg((CMPIArgs*)eCtx,name,rc);
172                }
173                
174                CMPIData contextGetEntryAt(CMPIContext* eCtx, CMPICount pos,
175                            CMPIString** name, CMPIStatus* rc) {
176                   return argsGetArgAt((CMPIArgs*)eCtx,pos,name,rc);
177                }
178                
179                static CMPICount contextGetEntryCount(CMPIContext* eCtx, CMPIStatus* rc) {
180                   return argsGetArgCount((CMPIArgs*)eCtx,rc);
181                }
182                
183 schuur 1.2.6.1 static CMPIStatus contextAddEntry(CMPIContext* eCtx, const char *name,
184 schuur 1.1                 CMPIValue* data, CMPIType type) {
185 schuur 1.2.6.1    if (strcmp(name,SnmpTrapOidContainer::NAME.getCString())==0) {
186                      OperationContext *ctx=((CMPI_Context*)eCtx)->ctx;
187                      if (type==CMPI_chars) {
188                         ctx->insert(SnmpTrapOidContainer((char*)data));
189                         CMReturn(CMPI_RC_OK);
190                      }
191                      else if (type==CMPI_string) {
192                         ctx->insert(SnmpTrapOidContainer((char*)data->string->hdl));
193                         CMReturn(CMPI_RC_OK);
194                      }
195                   }
196 schuur 1.1        return argsAddArg((CMPIArgs*)eCtx,name,data,type);
197                }
198                
199                
200                static CMPIContextFT context_FT={
201                     CMPICurrentVersion,
202                     contextReleaseNop,
203                     NULL,
204                     contextGetEntry,
205                     contextGetEntryAt,
206                     contextGetEntryCount,
207                     contextAddEntry,
208                };
209                
210                CMPIContextFT *CMPI_Context_Ftab=&context_FT;
211                
212                static CMPIContextFT contextOnStack_FT={
213                     CMPICurrentVersion,
214                     contextReleaseNop,
215                     NULL,
216                     contextGetEntry,
217 schuur 1.1          contextGetEntryAt,
218                     contextGetEntryCount,
219                     contextAddEntry,
220                };
221                
222                CMPIContextFT *CMPI_ContextOnStack_Ftab=&contextOnStack_FT;
223                
224                
225                CMPI_Context::CMPI_Context(const OperationContext& ct) {
226                      ctx=(OperationContext*)&ct;
227                      thr=NULL;
228                      hdl=(void*)new Array<CIMParamValue>();
229                      ft=CMPI_Context_Ftab;
230                   }
231                
232                CMPI_ContextOnStack::CMPI_ContextOnStack(const OperationContext& ct) {
233                      ctx=(OperationContext*)&ct;
234                      hdl=(void*)new Array<CIMParamValue>();
235                      ft=CMPI_ContextOnStack_Ftab;
236                   }
237                
238 schuur 1.1     CMPI_ContextOnStack::~CMPI_ContextOnStack() {
239                      delete (Array<CIMParamValue>*)hdl;
240                   }
241                
242                CMPI_ArgsOnStack::CMPI_ArgsOnStack(const Array<CIMParamValue>& args) {
243                      hdl=(void*)&args;
244                      ft=CMPI_ArgsOnStack_Ftab;
245                   }
246                
247                PEGASUS_NAMESPACE_END
248                
249                
250                
251                
252                
253                
254                

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2