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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2