(file) Return to MetaRepository.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Repository

  1 mike  1.1.2.1 //%2006////////////////////////////////////////////////////////////////////////
  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               // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8               // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9               // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10               // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11               // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12               // EMC Corporation; Symantec Corporation; The Open Group.
 13               //
 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               //
 21               // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 mike  1.1.2.1 // 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               #include <cstdarg>
 35               #include <cassert>
 36               #include "MetaRepository.h"
 37               #include <Pegasus/Common/System.h>
 38 mike  1.1.2.7 #include "MetaTypes.h"
 39 mike  1.1.2.1 
 40               PEGASUS_NAMESPACE_BEGIN
 41               
 42               static const size_t _MAX_NAMESPACES = 32;
 43               static const MetaNameSpace* _nameSpaces[_MAX_NAMESPACES];
 44               static size_t _nameSpacesSize = 0;
 45               
 46               static const size_t _MAX_FEATURES = 1024;
 47               static const size_t _MAX_QUALIFIERS = 1024;
 48               
 49               //==============================================================================
 50               //
 51               // Local definitions:
 52               //
 53               //==============================================================================
 54               
 55 mike  1.1.2.5 PEGASUS_FORMAT(2, 3)
 56               static void _throw(CIMStatusCode code, const char* format, ...)
 57               {
 58                   char buffer[4096];
 59               
 60                   va_list ap;
 61                   va_start(ap, format);
 62                   vsprintf(buffer, format, ap);
 63                   va_end(ap);
 64                   throw CIMException(code, buffer);
 65               }
 66               
 67               static bool _eqi(const char* s1, const char* s2)
 68               {
 69                   return System::strcasecmp(s1, s2) == 0;
 70               }
 71               
 72 mike  1.1.2.1 class Str
 73               {
 74               public:
 75                   Str(const String& s) : _cstr(s.getCString()) { }
 76                   Str(const CIMName& n) : _cstr(n.getString().getCString()) { }
 77                   Str(const CIMNamespaceName& n) : _cstr(n.getString().getCString()) { }
 78                   Str(const Exception& e) : _cstr(e.getMessage().getCString()) { }
 79                   Str(const CIMDateTime& x) : _cstr(x.toString().getCString()) { }
 80                   Str(const CIMObjectPath& x) : _cstr(x.toString().getCString()) { }
 81                   const char* operator*() const { return (const char*)_cstr; }
 82                   operator const char*() const { return (const char*)_cstr; }
 83               private:
 84                   CString _cstr;
 85               };
 86               
 87               static const MetaNameSpace* _findNameSpace(const char* name)
 88               {
 89                   for (size_t i = 0; i < _nameSpacesSize; i++)
 90                   {
 91                       if (_eqi(_nameSpaces[i]->name, name))
 92                           return _nameSpaces[i];
 93 mike  1.1.2.1     }
 94               
 95                   // Not found!
 96                   return 0;
 97               }
 98               
 99               static bool _isSubClass(const MetaClass* super, const MetaClass* sub)
100               {
101                   if (!super)
102                       return true;
103               
104                   for (MetaClass* p = sub->super; p; p = p->super)
105                   {
106                       if (p == super)
107                           return true;
108                   }
109               
110                   return false;
111               }
112               
113               static inline bool _isDirectSubClass(
114 mike  1.1.2.1     const MetaClass* super, 
115                   const MetaClass* sub)
116               {
117                   return sub->super == super;
118               }
119               
120               static const MetaClass* _findClass(
121                   const MetaNameSpace* ns, 
122                   const char* name)
123               {
124                   for (size_t i = 0; ns->classes[i]; i++)
125                   {
126 mike  1.1.2.3         const MetaClass* mc = ns->classes[i];
127 mike  1.1.2.1 
128 mike  1.1.2.3         if (_eqi(mc->name, name))
129                           return mc;
130 mike  1.1.2.1     }
131               
132                   // Not found!
133                   return 0;
134               }
135               
136 mike  1.1.2.4 static const MetaQualifierDecl* _findQualifierDecl(
137                   const MetaNameSpace* ns, 
138                   const char* name)
139               {
140                   for (size_t i = 0; ns->classes[i]; i++)
141                   {
142                       const MetaQualifierDecl* mqd = ns->qualifiers[i];
143               
144                       if (_eqi(mqd->name, name))
145                           return mqd;
146                   }
147               
148                   // Not found!
149                   return 0;
150               }
151               
152 mike  1.1.2.3 static char** _makePropertyList(const CIMPropertyList& propertyList)
153               {
154                   if (propertyList.isNull())
155                       return 0;
156               
157                   size_t size = propertyList.size();
158                   char** pl = (char**)malloc(sizeof(char*) * (size + 1));
159               
160                   for (size_t i = 0; i < size; i++)
161                       pl[i] = strdup(*Str(propertyList[i]));
162               
163                   pl[size] = 0;
164               
165                   return pl;
166               }
167               
168               static void _freePropertyList(char** pl)
169               {
170                   if (!pl)
171                       return;
172               
173 mike  1.1.2.3     for (size_t i = 0; pl[i]; i++)
174                   {
175                       free(pl[i]);
176                   }
177               
178                   free(pl);
179               }
180               
181               static void _printPropertyList(const char* const* pl)
182               {
183                   if (!pl)
184                       return;
185               
186                   for (size_t i = 0; pl[i]; i++)
187                       printf("pl[%s]\n", pl[i]);
188               }
189               
190 mike  1.1.2.1 //==============================================================================
191               //
192               // class MetaRepository
193               //
194               //==============================================================================
195               
196               MetaRepository::MetaRepository()
197               {
198               }
199               
200               MetaRepository::~MetaRepository()
201               {
202               }
203               
204               bool MetaRepository::addNameSpace(const MetaNameSpace* nameSpace)
205               {
206                   if (_nameSpacesSize == _MAX_NAMESPACES || !nameSpace)
207                       return false;
208               
209                   for (size_t i = 0; i < _nameSpacesSize; i++)
210                   {
211 mike  1.1.2.1         if (_eqi(_nameSpaces[i]->name, nameSpace->name))
212                           return false;
213                   }
214               
215                   _nameSpaces[_nameSpacesSize++] = nameSpace;
216                   return true;
217               }
218               
219               CIMClass MetaRepository::getClass(
220                   const CIMNamespaceName& nameSpace,
221                   const CIMName& className,
222                   Boolean localOnly,
223                   Boolean includeQualifiers,
224                   Boolean includeClassOrigin,
225                   const CIMPropertyList& propertyList)
226               {
227 mike  1.1.2.3     printf("===== MetaRepository::getClass()\n");
228               
229                   // Lookup namespace:
230               
231                   const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace));
232               
233                   if (!ns)
234                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
235               
236                   // Lookup class:
237               
238                   const MetaClass* mc = _findClass(ns, *Str(className));
239               
240                   if (!mc)
241                       _throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className));
242               
243                   // Build property list:
244               
245                   char** pl = _makePropertyList(propertyList);
246               
247                   // Make class:
248 mike  1.1.2.3 
249                   CIMClass cc;
250               
251 mike  1.1.2.5     if (MakeClass(ns, mc, localOnly, includeQualifiers, 
252 mike  1.1.2.3         includeQualifiers, pl, cc) != 0)
253                   {
254                       _freePropertyList(pl);
255                       _throw(CIM_ERR_FAILED, "conversion failed: %s", mc->name);
256                   }
257               
258                   _freePropertyList(pl);
259                   return cc;
260 mike  1.1.2.1 }
261               
262               Array<CIMClass> MetaRepository::enumerateClasses(
263                   const CIMNamespaceName& nameSpace,
264                   const CIMName& className,
265                   Boolean deepInheritance,
266                   Boolean localOnly,
267                   Boolean includeQualifiers,
268                   Boolean includeClassOrigin)
269               {
270 mike  1.1.2.3     printf("===== MetaRepository::enumerateClasses()\n");
271 mike  1.1.2.1 
272                   // Lookup namespace:
273               
274                   const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace));
275               
276                   if (!ns)
277                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
278               
279                   // Lookup class:
280               
281                   const MetaClass* super = 0;
282                   
283                   if (!className.isNull())
284                   {
285                       super = _findClass(ns, *Str(className));
286               
287                       if (!super)
288                           _throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className));
289                   }
290               
291                   // Iterate all classes looking for matches:
292 mike  1.1.2.1 
293                   Array<CIMClass> result;
294               
295                   for (size_t i = 0; ns->classes[i]; i++)
296                   {
297 mike  1.1.2.3         MetaClass* mc = ns->classes[i];
298 mike  1.1.2.1 
299 mike  1.1.2.3         bool flag = false;
300 mike  1.1.2.1 
301                       if (deepInheritance)
302                       {
303 mike  1.1.2.3             if (_isSubClass(super, mc))
304                               flag = true;
305 mike  1.1.2.1         }
306                       else
307                       {
308 mike  1.1.2.3             if (_isDirectSubClass(super, mc))
309                               flag = true;
310                       }
311               
312                       if (flag)
313                       {
314                           CIMClass cc;
315 mike  1.1.2.1 
316 mike  1.1.2.5             if (MakeClass(ns, mc, localOnly, includeQualifiers, 
317 mike  1.1.2.3                 includeQualifiers, 0, cc) != 0)
318                           {
319                               _throw(CIM_ERR_FAILED, "conversion failed: %s", mc->name);
320 mike  1.1.2.1             }
321 mike  1.1.2.3             else
322                               result.append(cc);
323 mike  1.1.2.1         }
324                   }
325               
326                   return result;
327               }
328               
329               Array<CIMName> MetaRepository::enumerateClassNames(
330                   const CIMNamespaceName& nameSpace,
331                   const CIMName& className,
332                   Boolean deepInheritance)
333               {
334 mike  1.1.2.3     printf("===== MetaRepository::enumerateClassNames()\n");
335               
336 mike  1.1.2.1     // Lookup namespace:
337               
338                   const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace));
339               
340                   if (!ns)
341                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
342               
343                   // Lookup class:
344               
345                   const MetaClass* super = 0;
346                   
347                   if (!className.isNull())
348                   {
349                       super = _findClass(ns, *Str(className));
350               
351                       if (!super)
352                           _throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className));
353                   }
354               
355                   // Iterate all classes looking for matches:
356               
357 mike  1.1.2.1     Array<CIMName> result;
358               
359                   for (size_t i = 0; ns->classes[i]; i++)
360                   {
361 mike  1.1.2.3         MetaClass* mc = ns->classes[i];
362 mike  1.1.2.1 
363                       if (deepInheritance)
364                       {
365 mike  1.1.2.3             if (_isSubClass(super, mc))
366                               result.append(mc->name);
367 mike  1.1.2.1         }
368                       else
369                       {
370 mike  1.1.2.3             if (_isDirectSubClass(super, mc))
371                               result.append(mc->name);
372 mike  1.1.2.1         }
373                   }
374               
375                   return result;
376               }
377               
378               void MetaRepository::deleteClass(
379                   const CIMNamespaceName& nameSpace,
380                   const CIMName& className)
381               {
382                   _throw(CIM_ERR_NOT_SUPPORTED, "deleteClass()");
383               }
384               
385               void MetaRepository::createClass(
386                   const CIMNamespaceName& nameSpace,
387                   const CIMClass& newClass)
388               {
389                   _throw(CIM_ERR_NOT_SUPPORTED, "createClass()");
390               }
391               
392               void MetaRepository::modifyClass(
393 mike  1.1.2.1     const CIMNamespaceName& nameSpace,
394                   const CIMClass& newClass)
395               {
396                   _throw(CIM_ERR_NOT_SUPPORTED, "modifyClass()");
397               }
398               
399 mike  1.1.2.4 void MetaRepository::getSubClassNames(
400                   const CIMNamespaceName& nameSpace,
401                   const CIMName& className,
402                   Boolean deepInheritance,
403                   Array<CIMName>& subClassNames)
404               {
405                   printf("===== MetaRepository::getSubClassNames()\n");
406               
407                   subClassNames = MetaRepository::enumerateClassNames(
408                       nameSpace, className, deepInheritance);
409               }
410               
411               void MetaRepository::getSuperClassNames(
412                   const CIMNamespaceName& nameSpace,
413                   const CIMName& className,
414                   Array<CIMName>& superClassNames)
415               {
416                   printf("===== MetaRepository::getSuperClassNames()\n");
417               
418                   superClassNames.clear();
419               
420 mike  1.1.2.4     // Lookup namespace:
421               
422                   const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace));
423               
424                   if (!ns)
425                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
426               
427                   // Lookup class:
428               
429                   const MetaClass* mc = _findClass(ns, *Str(className));
430                   
431                   if (!mc)
432                       _throw(CIM_ERR_NOT_FOUND, "unknown class: %s", *Str(className));
433               
434                   // Append superclass names:
435               
436                   for (const MetaClass* p = mc->super; p; p = p->super)
437                       superClassNames.append(p->name);
438               }
439               
440               void MetaRepository::createNameSpace(
441 mike  1.1.2.4     const CIMNamespaceName& nameSpace,
442                   const NameSpaceAttributes& attributes)
443               {
444                   printf("===== MetaRepository::createNameSpace()\n");
445               
446                   _throw(CIM_ERR_NOT_SUPPORTED, "createNameSpace()");
447               }
448               
449               void MetaRepository::modifyNameSpace(
450                   const CIMNamespaceName& nameSpace,
451                   const NameSpaceAttributes& attributes)
452               {
453                   printf("===== MetaRepository::modifyNameSpace()\n");
454               
455                   _throw(CIM_ERR_NOT_SUPPORTED, "modifyNameSpace()");
456               }
457               
458               Array<CIMNamespaceName> MetaRepository::enumerateNameSpaces()
459               {
460                   printf("===== MetaRepository::enumerateNameSpaces()\n");
461               
462 mike  1.1.2.4     Array<CIMNamespaceName> nameSpaces;
463               
464                   for (size_t i = 0; i < _nameSpacesSize; i++)
465                       nameSpaces.append(_nameSpaces[i]->name);
466               
467                   return Array<CIMNamespaceName>();
468               }
469               
470               void MetaRepository::deleteNameSpace(
471                   const CIMNamespaceName& nameSpace)
472               {
473                   printf("===== MetaRepository::deleteNameSpace()\n");
474               
475                   _throw(CIM_ERR_NOT_SUPPORTED, "deleteNameSpace()");
476               }
477               
478               Boolean MetaRepository::getNameSpaceAttributes(
479                   const CIMNamespaceName& nameSpace,
480                   NameSpaceAttributes& attributes)
481               {
482                   printf("===== MetaRepository::getNameSpaceAttributes()\n");
483 mike  1.1.2.4 
484                   _throw(CIM_ERR_NOT_SUPPORTED, "getNameSpaceAttributes()");
485               
486                   return false;
487               }
488               
489               Boolean MetaRepository::isRemoteNameSpace(
490                   const CIMNamespaceName& nameSpace,
491                   String& remoteInfo)
492               {
493                   printf("===== MetaRepository::isRemoteNameSpace()\n");
494               
495                   return false;
496               }
497               
498               CIMQualifierDecl MetaRepository::getQualifier(
499                   const CIMNamespaceName& nameSpace,
500                   const CIMName& qualifierName)
501               {
502                   printf("===== MetaRepository::getQualifier()\n");
503               
504 mike  1.1.2.4     // Lookup namespace:
505               
506                   const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace));
507               
508                   if (!ns)
509                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
510               
511                   // Lookup qualifier:
512               
513                   const MetaQualifierDecl* mqd = _findQualifierDecl(ns, *Str(qualifierName));
514                   
515                   if (!mqd)
516                       _throw(CIM_ERR_NOT_FOUND, "unknown qualifier: %s", *Str(qualifierName));
517               
518                   // Make the qualifier declaration:
519               
520                   CIMQualifierDecl cqd;
521               
522 mike  1.1.2.5     if (MakeQualifierDecl(ns, mqd, cqd) != 0)
523 mike  1.1.2.4     {
524                       _throw(CIM_ERR_FAILED, "conversion failed: %s", mqd->name);
525                   }
526               
527                   return cqd;
528               }
529               
530               void MetaRepository::setQualifier(
531                   const CIMNamespaceName& nameSpace,
532                   const CIMQualifierDecl& qualifierDecl)
533               {
534                   printf("===== MetaRepository::setQualifier()\n");
535               
536                   _throw(CIM_ERR_NOT_SUPPORTED, "setQualifier()");
537               
538               }
539               
540               void MetaRepository::deleteQualifier(
541                   const CIMNamespaceName& nameSpace,
542                   const CIMName& qualifierName)
543               {
544 mike  1.1.2.4     printf("===== MetaRepository::deleteQualifier()\n");
545               
546                   _throw(CIM_ERR_NOT_SUPPORTED, "deleteQualifier()");
547               }
548               
549               Array<CIMQualifierDecl> MetaRepository::enumerateQualifiers(
550                   const CIMNamespaceName& nameSpace)
551               {
552                   printf("===== MetaRepository::enumerateQualifiers()\n");
553               
554                   // Lookup namespace:
555               
556                   const MetaNameSpace* ns = _findNameSpace(*Str(nameSpace));
557               
558                   if (!ns)
559                       _throw(CIM_ERR_INVALID_NAMESPACE, "%s", *Str(nameSpace));
560               
561                   // Build the array of qualifier declarations:
562               
563                   Array<CIMQualifierDecl> result;
564               
565 mike  1.1.2.4     for (size_t i = 0; ns->qualifiers[i]; i++)
566                   {
567                       const MetaQualifierDecl* mqd = ns->qualifiers[i];
568                       CIMQualifierDecl cqd;
569               
570 mike  1.1.2.5         if (MakeQualifierDecl(ns, mqd, cqd) != 0)
571 mike  1.1.2.4         {
572                           _throw(CIM_ERR_FAILED, "conversion failed: %s", mqd->name);
573                       }
574               
575                       result.append(cqd);
576                   }
577               
578                   return result;
579               }
580               
581 mike  1.1.2.1 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2