(file) Return to CIMConfigCommand.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Clients / cimconfig

   1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
   2           //
   3 kumpf 1.15 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
   4 mike  1.2  // The Open Group, Tivoli Systems
   5            //
   6            // Permission is hereby granted, free of charge, to any person obtaining a copy
   7            // of this software and associated documentation files (the "Software"), to
   8            // deal in the Software without restriction, including without limitation the
   9            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10            // sell copies of the Software, and to permit persons to whom the Software is
  11            // furnished to do so, subject to the following conditions:
  12 kumpf 1.15 // 
  13 mike  1.2  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  14            // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  15            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  16            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  17            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21            //
  22            //==============================================================================
  23            //
  24            // Author: Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
  25            //
  26            // Modified By: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
  27            //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
  28 kumpf 1.14 //              Carol Ann Krug Graves, Hewlett-Packard Company
  29            //                  (carolann_graves@hp.com)
  30 mike  1.2  //
  31            //%/////////////////////////////////////////////////////////////////////////////
  32            
  33            
  34            #include <Pegasus/Common/Config.h>
  35            #include <Pegasus/getoopt/getoopt.h>
  36 kumpf 1.16 #include <Pegasus/Common/Constants.h>
  37 mike  1.2  #include <Pegasus/Common/System.h>
  38            #include <Pegasus/Common/FileSystem.h>
  39            #include <Pegasus/Common/CIMProperty.h>
  40 kumpf 1.13 #include <Pegasus/Common/CIMObjectPath.h>
  41 mike  1.2  #include <Pegasus/Common/CIMStatusCode.h>
  42            #include <Pegasus/Common/Exception.h>
  43 kumpf 1.9  #include <Pegasus/Common/PegasusVersion.h>
  44 kumpf 1.22 #include <Pegasus/Common/XmlWriter.h>
  45 kumpf 1.9  
  46 mike  1.2  #include <Pegasus/Client/CIMClient.h>
  47            #include <Pegasus/Config/ConfigFileHandler.h>
  48            #include "CIMConfigCommand.h"
  49            
  50 chuck 1.24 #ifdef PEGASUS_OS_OS400
  51            #include "qycmutiltyUtility.H"
  52 chuck 1.26 #include "vfyptrs.cinc"
  53            #include <stdio.h>
  54 chuck 1.24 #endif
  55            
  56 mike  1.2  PEGASUS_NAMESPACE_BEGIN
  57            
  58            /**
  59                The command name.
  60            */
  61            static const char COMMAND_NAME []              = "cimconfig";
  62            
  63            /**
  64                The usage string for this command.  This string is displayed
  65                when an error occurs in parsing or validating the command line.
  66            */
  67            static const char USAGE []                     = "usage: ";
  68            
  69            /**
  70                This constant represents the getoopt argument designator
  71            */
  72            static const char GETOPT_ARGUMENT_DESIGNATOR   = ':';
  73            
  74            /*
  75                These constants represent the operation modes supported by the CLI.
  76                Any new operation should be added here.
  77 mike  1.2  */
  78            
  79            /**
  80                This constant signifies that an operation option has not been recorded
  81            */
  82            static const Uint32 OPERATION_TYPE_UNINITIALIZED  = 0;
  83            
  84            /**
  85                This constant represents a property get operation
  86            */
  87            static const Uint32 OPERATION_TYPE_GET            = 1;
  88            
  89            /**
  90                This constant represents a property set operation
  91            */
  92            static const Uint32 OPERATION_TYPE_SET            = 2;
  93            
  94            /**
  95                This constant represents a property unset operation
  96            */
  97            static const Uint32 OPERATION_TYPE_UNSET          = 3;
  98 mike  1.2  
  99            /**
 100                This constant represents a property list operation
 101            */
 102            static const Uint32 OPERATION_TYPE_LIST           = 4;
 103            
 104            
 105            /**
 106                The constants representing the string literals.
 107            */
 108 kumpf 1.22 static const CIMName PROPERTY_NAME              = CIMName ("PropertyName");
 109 mike  1.2  
 110 kumpf 1.22 static const CIMName DEFAULT_VALUE              = CIMName ("DefaultValue");
 111 mike  1.2  
 112 kumpf 1.22 static const CIMName CURRENT_VALUE              = CIMName ("CurrentValue");
 113 mike  1.2  
 114 kumpf 1.22 static const CIMName PLANNED_VALUE              = CIMName ("PlannedValue");
 115 mike  1.2  
 116 kumpf 1.22 static const CIMName DYNAMIC_PROPERTY           = CIMName ("DynamicProperty");
 117 mike  1.2  
 118            /**
 119                The constants representing the messages.
 120            */
 121            static const char CIMOM_NOT_RUNNING []         = 
 122 kumpf 1.10                         "CIM server may not be running.";
 123 mike  1.2  
 124            static const char FILE_NOT_EXIST []            = 
 125 kumpf 1.23                         "Configuration files does not exist.";
 126 mike  1.2  
 127            static const char FILE_NOT_READABLE []         = 
 128                                    "Configuration file not readable.";
 129            
 130            static const char FAILED_TO_GET_PROPERTY []    = 
 131                                    "Failed to get the config property.";
 132            
 133            static const char FAILED_TO_SET_PROPERTY []    = 
 134                                    "Failed to set the config property.";
 135            
 136            static const char FAILED_TO_UNSET_PROPERTY []  = 
 137                                    "Failed to unset the config property.";
 138            
 139            static const char FAILED_TO_LIST_PROPERTIES [] = 
 140                                    "Failed to list the config properties. ";
 141            
 142            static const char CURRENT_VALUE_OF_PROPERTY [] =
 143                                    "Current value for the property '";
 144            
 145            static const char PLANNED_VALUE_OF_PROPERTY [] =
 146                                    "Planned value for the property '";
 147 mike  1.2  
 148            static const char DEFAULT_VALUE_OF_PROPERTY [] =
 149                                    "Default value for the property '";
 150            
 151            static const char IS_SET_TO []                 = "' is set to ";
 152            
 153            static const char IS_NOT_SET []                = "' is not set." ;
 154            
 155            static const char IN_CIMSERVER []              = " in CIMServer.";
 156            
 157            static const char IN_CONFIG_FILE []            = " in configuration file.";
 158            
 159            static const char IS_UNSET_IN_FILE []          =
 160                                    "' is unset in the configuration file.";
 161            
 162            static const char UPDATED_IN_FILE []           =
 163                                    "' updated in configuration file.";
 164            
 165            static const char CONFIG_SCHEMA_NOT_LOADED []  =
 166 kumpf 1.23     "Please restore the internal repository on the CIM Server.";
 167 mike  1.2  
 168            static const char PROPERTY_NOT_FOUND []        =
 169                                    "Specified property name was not found.";
 170            
 171            static const char INVALID_PROPERTY_VALUE []    =
 172                                    "Specified property value is not valid.";
 173            
 174            static const char PROPERTY_NOT_MODIFIED []     =
 175                                    "Specified property can not be modified.";
 176            
 177            /**
 178                The option character used to specify get config property.
 179            */
 180            static const char   OPTION_GET                 = 'g';
 181            
 182            /**
 183                The option character used to specify set config property.
 184            */
 185            static const char   OPTION_SET                 = 's';
 186            
 187 chuck 1.26 #ifdef PEGASUS_OS_OS400
 188            /**
 189                The option character used to specify no output to stdout or stderr.
 190            */
 191 humberto 1.27      static const char OPTION_QUIET_VALUE      = 'q';
 192 chuck    1.26 #endif
 193               
 194 mike     1.2  /**
 195                   The option character used to specify unset config property.
 196               */
 197               static const char   OPTION_UNSET               = 'u';
 198               
 199               /**
 200                   The option character used to specify listing of config properties.
 201               */
 202               static const char   OPTION_LIST                = 'l';
 203               
 204               /**
 205                   The option character used to specify the current config value.
 206               */
 207               static const char   OPTION_CURRENT_VALUE       = 'c';
 208               
 209               /**
 210                   The option character used to specify the planned config value.
 211               */
 212               static const char   OPTION_PLANNED_VALUE       = 'p';
 213               
 214               /**
 215 mike     1.2      The option character used to specify the default config value.
 216               */
 217               static const char   OPTION_DEFAULT_VALUE       = 'd';
 218               
 219               
 220               
 221               /**
 222                   Constructs a CIMConfigCommand and initializes instance variables.
 223               */
 224               CIMConfigCommand::CIMConfigCommand ()
 225               {
 226                   /**
 227                       Initialize the instance variables.
 228                   */
 229                   _operationType       = OPERATION_TYPE_UNINITIALIZED;
 230 kumpf    1.22     _propertyName        = CIMName ();
 231 mike     1.2      _propertyValue       = String::EMPTY;
 232                   _currentValueSet     = false;
 233                   _plannedValueSet     = false;
 234                   _defaultValueSet     = false;
 235 humberto 1.27 #ifdef PEGASUS_OS_OS400
 236                    _defaultQuietSet     = false;
 237               #endif
 238 mike     1.2      _hostName            = String::EMPTY;
 239               
 240                   /**
 241                       Build the usage string for the config command.  
 242                   */
 243 kumpf    1.11     String usage;
 244 kumpf    1.18     usage.reserveCapacity(200);
 245 kumpf    1.11     usage.append(USAGE);
 246                   usage.append(COMMAND_NAME);
 247 humberto 1.27 #ifdef PEGASUS_OS_OS400
 248                   usage.append(" -").append(OPTION_GET).append(" name");
 249                   usage.append(" [ -").append(OPTION_CURRENT_VALUE); 
 250                   usage.append(" ] [ -").append(OPTION_DEFAULT_VALUE);
 251                   usage.append(" ] [ -").append(OPTION_PLANNED_VALUE);
 252                   usage.append(" ] [ -").append(OPTION_QUIET_VALUE).append(" ]\n");
 253               
 254                   usage.append("                 -").append(OPTION_SET).append(" name=value");
 255                   usage.append(" [ -").append(OPTION_CURRENT_VALUE);
 256                   usage.append(" ] [ -").append(OPTION_PLANNED_VALUE);
 257                   usage.append(" ] [ -").append(OPTION_QUIET_VALUE).append(" ]\n");
 258 kumpf    1.11 
 259 humberto 1.27     usage.append("                 -").append(OPTION_UNSET).append(" name");
 260                   usage.append(" [ -").append(OPTION_CURRENT_VALUE);
 261                   usage.append(" ] [ -").append(OPTION_PLANNED_VALUE);
 262                   usage.append(" ] [ -").append(OPTION_QUIET_VALUE).append(" ]\n");
 263               
 264                   usage.append("                 -").append(OPTION_LIST);
 265                   usage.append(" [ -").append(OPTION_CURRENT_VALUE);
 266                   usage.append(" | -").append(OPTION_PLANNED_VALUE).append(" ]\n");
 267               #else  
 268 kumpf    1.11     usage.append(" -").append(OPTION_GET).append(" name");
 269                   usage.append(" [ -").append(OPTION_CURRENT_VALUE); 
 270                   usage.append(" ] [ -").append(OPTION_DEFAULT_VALUE);
 271                   usage.append(" ] [ -").append(OPTION_PLANNED_VALUE).append(" ]\n");
 272               
 273                   usage.append("                 -").append(OPTION_SET).append(" name=value");
 274                   usage.append(" [ -").append(OPTION_CURRENT_VALUE);
 275                   usage.append(" ] [ -").append(OPTION_PLANNED_VALUE).append(" ]\n");
 276               
 277                   usage.append("                 -").append(OPTION_UNSET).append(" name");
 278                   usage.append(" [ -").append(OPTION_CURRENT_VALUE);
 279                   usage.append(" ] [ -").append(OPTION_PLANNED_VALUE).append(" ]\n");
 280               
 281                   usage.append("                 -").append(OPTION_LIST);
 282                   usage.append(" [ -").append(OPTION_CURRENT_VALUE);
 283                   usage.append(" | -").append(OPTION_PLANNED_VALUE).append(" ]\n");
 284 chuck    1.26 #endif
 285 mike     1.2  
 286                   setUsage (usage);
 287               }
 288               
 289               
 290               /**
 291                   Parses the command line, validates the options, and sets instance 
 292                   variables based on the option arguments.
 293               */
 294               void CIMConfigCommand::setCommand (Uint32 argc, char* argv []) 
 295                   throw (CommandFormatException)
 296               {
 297                   unsigned int      i                = 0;
 298                   Uint32            c                = 0;
 299                   String            property         = String ();
 300                   String            badOptionString  = String ();
 301                   String            optString        = String ();
 302                   Uint32            equalsIndex      = 0;
 303               
 304                   //
 305                   //  Construct optString
 306 mike     1.2      //
 307 kumpf    1.11     optString.append(OPTION_GET);
 308                   optString.append(GETOPT_ARGUMENT_DESIGNATOR);
 309 mike     1.2  
 310 kumpf    1.11     optString.append(OPTION_SET);
 311                   optString.append(GETOPT_ARGUMENT_DESIGNATOR);
 312 mike     1.2  
 313 kumpf    1.11     optString.append(OPTION_UNSET);
 314                   optString.append(GETOPT_ARGUMENT_DESIGNATOR);
 315 mike     1.2  
 316 humberto 1.27 
 317 chuck    1.26 
 318 kumpf    1.11     optString.append(OPTION_LIST);
 319                   optString.append(OPTION_CURRENT_VALUE);
 320                   optString.append(OPTION_PLANNED_VALUE);
 321                   optString.append(OPTION_DEFAULT_VALUE);
 322 humberto 1.27 #ifdef PEGASUS_OS_OS400
 323                   optString.append(OPTION_QUIET_VALUE);
 324               #endif
 325 mike     1.2  
 326                   //
 327                   //  Initialize and parse options
 328                   //
 329                   getoopt options ("");
 330                   options.addFlagspec(optString);
 331               
 332                   options.parse (argc, argv);
 333               
 334                   if (options.hasErrors ())
 335                   {
 336                       CommandFormatException e (options.getErrorStrings () [0]);
 337                       throw e;
 338                   }
 339                   
 340                   _operationType = OPERATION_TYPE_UNINITIALIZED;
 341               
 342 chuck    1.26 
 343 mike     1.2      //
 344                   //  Get options and arguments from the command line
 345                   //
 346                   for (i =  options.first (); i <  options.last (); i++)
 347                   {
 348                       if (options [i].getType () == Optarg::LONGFLAG)
 349                       {
 350                           //
 351                           //  This path should not be hit
 352                           //  The cimconfig command has no LONGFLAG options
 353                           //
 354                           c = options [i].getopt () [0];
 355               
 356                           UnexpectedOptionException e (c);
 357                           throw e;
 358                       } 
 359                       else if (options [i].getType () == Optarg::REGULAR)
 360                       {
 361                           //
 362                           //  The cimconfig command has no non-option argument options
 363                           //
 364 mike     1.2              UnexpectedArgumentException e (options [i].Value ()); 
 365                           throw e;
 366                       } 
 367                       else /* if (options [i].getType () == Optarg::FLAG) */
 368                       {
 369               
 370                           c = options [i].getopt () [0];
 371               
 372                           switch (c) 
 373 chuck    1.26 	    {
 374 mike     1.2                  case OPTION_GET: 
 375                               {
 376                                   if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 377                                   {
 378                                       //
 379                                       // More than one operation option was found
 380                                       //
 381                                       UnexpectedOptionException e (OPTION_GET);
 382                                       throw e;
 383                                   }
 384               
 385                                   if (options.isSet (OPTION_GET) > 1)
 386                                   {
 387                                       //
 388                                       // More than one get option was found
 389                                       //
 390                                       DuplicateOptionException e (OPTION_GET); 
 391                                       throw e;
 392                                   }
 393               
 394 kumpf    1.25                     try
 395                                   {
 396                                       _propertyName = options [i].Value ();
 397                                   }
 398                                   catch (InvalidNameException& e)
 399                                   {
 400                                       throw InvalidOptionArgumentException(
 401                                           options[i].Value(), OPTION_GET);
 402                                   }
 403 mike     1.2  
 404                                   _operationType = OPERATION_TYPE_GET;
 405               
 406                                   break;
 407                               }
 408               
 409                               case OPTION_SET: 
 410                               {
 411                                   if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 412                                   {
 413                                       //
 414                                       // More than one operation option was found
 415                                       //
 416                                       UnexpectedOptionException e (OPTION_SET);
 417                                       throw e;
 418                                   }
 419               
 420                                   if (options.isSet (OPTION_SET) > 1)
 421                                   {
 422                                       //
 423                                       // More than one set option was found
 424 mike     1.2                          //
 425                                       DuplicateOptionException e (OPTION_SET); 
 426                                       throw e;
 427                                   }
 428               
 429                                   _operationType = OPERATION_TYPE_SET;
 430               
 431                                   property = options [i].Value ();
 432               
 433                                   equalsIndex = property.find ('=');
 434               
 435                                   if ( equalsIndex == PEG_NOT_FOUND )
 436                                   {
 437                                       //
 438                                       // The property value was not specified
 439                                       //
 440                                       InvalidOptionArgumentException e (property,
 441                                           OPTION_SET);
 442                                       throw e;
 443                                   }
 444               
 445 kumpf    1.25                     try
 446                                   {
 447                                       _propertyName = CIMName (property.subString
 448                                           (0, equalsIndex));
 449                                   }
 450                                   catch (InvalidNameException& e)
 451                                   {
 452                                       throw InvalidOptionArgumentException(
 453                                           property, OPTION_SET);
 454                                   }
 455 mike     1.2  
 456                                   _propertyValue = property.subString( equalsIndex + 1 );
 457               
 458                                   break;
 459                               }
 460               
 461                               case OPTION_UNSET: 
 462                               {
 463                                   if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 464                                   {
 465                                       //
 466                                       // More than one operation option was found
 467                                       //
 468                                       UnexpectedOptionException e (OPTION_UNSET);
 469                                       throw e;
 470                                   }
 471               
 472                                   if (options.isSet (OPTION_UNSET) > 1)
 473                                   {
 474                                       //
 475                                       // More than one unset option was found
 476 mike     1.2                          //
 477                                       DuplicateOptionException e (OPTION_UNSET); 
 478                                       throw e;
 479                                   }
 480               
 481 kumpf    1.25                     try
 482                                   {
 483                                       _propertyName = options [i].Value ();
 484                                   }
 485                                   catch (InvalidNameException& e)
 486                                   {
 487                                       throw InvalidOptionArgumentException(
 488                                           options[i].Value(), OPTION_UNSET);
 489                                   }
 490 mike     1.2  
 491                                   _operationType = OPERATION_TYPE_UNSET;
 492               
 493                                   break;
 494                               }
 495               
 496                               case OPTION_LIST: 
 497                               {
 498                                   if (_operationType != OPERATION_TYPE_UNINITIALIZED)
 499                                   {
 500                                       //
 501                                       // More than one operation option was found
 502                                       //
 503                                       UnexpectedOptionException e (OPTION_LIST);
 504                                       throw e;
 505                                   }
 506               
 507                                   if (options.isSet (OPTION_LIST) > 1)
 508                                   {
 509                                       //
 510                                       // More than one list option was found
 511 mike     1.2                          //
 512                                       DuplicateOptionException e (OPTION_LIST); 
 513                                       throw e;
 514                                   }
 515                                   _operationType = OPERATION_TYPE_LIST;
 516                                   break;
 517                               }
 518               
 519                               case OPTION_CURRENT_VALUE: 
 520                               {
 521                                   if (options.isSet (OPTION_CURRENT_VALUE) > 1)
 522                                   {
 523                                       //
 524                                       // More than one current value option was found
 525                                       //
 526                                       DuplicateOptionException e (OPTION_CURRENT_VALUE); 
 527                                       throw e;
 528                                   }
 529               
 530                                   _currentValueSet = true;
 531                                   break;
 532 mike     1.2                  }
 533               
 534                               case OPTION_PLANNED_VALUE: 
 535                               {
 536                                   if (options.isSet (OPTION_PLANNED_VALUE) > 1)
 537                                   {
 538                                       //
 539                                       // More than one planned value option was found
 540                                       //
 541                                       DuplicateOptionException e (OPTION_PLANNED_VALUE); 
 542                                       throw e;
 543                                   }
 544               
 545                                   _plannedValueSet = true;
 546                                   break;
 547                               }
 548               
 549                               case OPTION_DEFAULT_VALUE: 
 550                               {
 551                                   if (options.isSet (OPTION_DEFAULT_VALUE) > 1)
 552                                   {
 553 mike     1.2                          //
 554                                       // More than one default value option was found
 555                                       //
 556                                       DuplicateOptionException e (OPTION_DEFAULT_VALUE); 
 557                                       throw e;
 558                                   }
 559               
 560                                   _defaultValueSet = true;
 561                                   break;
 562                               }
 563               
 564 humberto 1.27 #ifdef PEGASUS_OS_OS400
 565                                // check for quiet option before processing the rest of the options
 566               		case OPTION_QUIET_VALUE:
 567               		{
 568               			_defaultQuietSet = true;
 569               			break;
 570               	        }     
 571               #endif
 572               
 573 mike     1.2                  default:
 574                                   //
 575                                   // Should never get here
 576                                   //
 577                                   break;
 578                           }
 579                       }
 580                   }
 581               
 582                   if ( _operationType == OPERATION_TYPE_UNINITIALIZED )
 583                   {
 584                       //
 585                       // No operation type was specified; throw exception
 586                       // so that usage can be displayed.
 587                       //
 588                       CommandFormatException e ("");
 589                       throw e;
 590                   }
 591               
 592                   if ( ( _operationType != OPERATION_TYPE_GET ) && ( _defaultValueSet ) )
 593                   {
 594 mike     1.2          //
 595                       // An invalid option was encountered
 596                       //
 597                       InvalidOptionException e (OPTION_DEFAULT_VALUE);
 598                       throw e;
 599                   }
 600               
 601                   if (_operationType == OPERATION_TYPE_LIST)
 602                   {
 603                       if ( _currentValueSet && _plannedValueSet )
 604                       {
 605                           //
 606                           // An invalid option was encountered
 607                           //
 608                           InvalidOptionException e (OPTION_CURRENT_VALUE);
 609                           throw e;
 610                       }
 611 humberto 1.27 #ifdef PEGASUS_OS_OS400
 612               	if( _defaultQuietSet ){
 613               	    //
 614                           // An invalid option was encountered
 615                           //
 616                           InvalidOptionException e (OPTION_QUIET_VALUE);
 617                           throw e;
 618               	}
 619               #endif
 620 mike     1.2      }
 621                   else
 622                   {
 623                       //
 624                       // if no options specified for get, set or unset operations
 625                       // then set option as _currentValueSet
 626                       //
 627                       if ( !_currentValueSet && !_plannedValueSet && !_defaultValueSet )
 628                       {
 629                           _currentValueSet = true;
 630                       }
 631                   }
 632               
 633               }
 634               
 635               /** 
 636                   Print message to the given stream
 637               */
 638               
 639               //void CIMConfigCommand::_printErrorMessage(
 640               //    CIMStatusCode code, 
 641 mike     1.2  //    const String&,
 642               //    ostream& errPrintWriter)
 643               //{
 644               //
 645               //}
 646               
 647               /**
 648                   Executes the command and writes the results to the PrintWriters.
 649               */
 650               Uint32 CIMConfigCommand::execute (
 651                   ostream& outPrintWriter, 
 652                   ostream& errPrintWriter)
 653               {
 654                   Boolean   connected     = false;
 655                   String    defaultValue  = String::EMPTY;
 656                   String    currentValue  = String::EMPTY;
 657                   String    plannedValue  = String::EMPTY;
 658                   String    pegasusHome   = String::EMPTY;
 659 kumpf    1.10     Boolean   gotCurrentValue = false;
 660                   Boolean   gotPlannedValue = false;
 661 mike     1.2  
 662 humberto 1.27 
 663               #ifdef PEGASUS_OS_OS400
 664                   // disable standard output and standard error
 665                   if( _defaultQuietSet && (_operationType != OPERATION_TYPE_LIST) ){
 666                       freopen("/dev/null","w",stdout);
 667               	freopen("/dev/null","w",stderr);
 668                   }
 669               #endif
 670 mike     1.2  
 671                   if ( _operationType == OPERATION_TYPE_UNINITIALIZED )
 672                   {
 673                       //
 674                       // The command was not initialized
 675                       //
 676                       return ( RC_ERROR );
 677                   }
 678               
 679                   //
 680                   // Get environment variables
 681                   //
 682               
 683                   const char* env = getenv("PEGASUS_HOME");
 684 chuck    1.24 
 685               #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
 686                   // Set pegasusHome to the env var,if it is set.  Otherwise,
 687                   // use the OS/400 default path.
 688                   if (env != NULL)
 689               	pegasusHome = env;
 690                   else
 691                       pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 692               
 693                   String currentFile = FileSystem::getAbsolutePath(pegasusHome.getCString(), CURRENT_CONFIG_FILE);
 694                   String plannedFile = FileSystem::getAbsolutePath(pegasusHome.getCString(), PLANNED_CONFIG_FILE);
 695               #else
 696 kumpf    1.17     String currentFile = FileSystem::getAbsolutePath(env, CURRENT_CONFIG_FILE);
 697                   String plannedFile = FileSystem::getAbsolutePath(env, PLANNED_CONFIG_FILE);
 698 chuck    1.24 #endif
 699 mike     1.2  
 700                   try
 701                   {
 702                       //
 703                       // Open default config files and load current config properties
 704                       //
 705                       _configFileHandler = new ConfigFileHandler(currentFile, plannedFile, true);
 706                   }
 707                   catch (NoSuchFile& nsf)
 708                   {
 709                   }
 710                   catch (FileNotReadable& fnr)
 711                   {
 712                       errPrintWriter << FILE_NOT_READABLE << fnr.getMessage() << endl;
 713                       return ( RC_ERROR );
 714                   }
 715                   catch (ConfigFileSyntaxError& cfse)
 716                   {
 717                       errPrintWriter << cfse.getMessage() << endl;
 718                       return ( RC_ERROR );
 719                   }
 720 mike     1.2  
 721 kumpf    1.3      //
 722 mike     1.2      // Get local host name
 723                   //
 724                   _hostName.assign(System::getHostName());
 725               
 726                   try
 727                   {
 728                       //
 729                       // Open connection with CIMSever
 730                       //
 731 kumpf    1.5          _client = new CIMClient;
 732 mike     1.2  
 733 kumpf    1.4          _client->connectLocal();
 734 mike     1.2  
 735                       connected = true;
 736                   }
 737 kumpf    1.20     catch(Exception& e)
 738 mike     1.2      {
 739                       //
 740                       // Failed to connect, so process the request offline.
 741                       // When CIMOM is running the config command updates changes to 
 742                       // config properties in the planned config file, so load only
 743                       // planned config properties. 
 744                       //
 745                       _configFileHandler->loadPlannedConfigProperties();
 746                       connected = false;
 747                   }
 748               
 749                   //
 750                   // Perform the requested operation
 751                   //
 752                   switch ( _operationType )
 753                   {
 754                       case OPERATION_TYPE_GET:
 755                           try
 756                           {
 757                               if (connected)
 758                               {
 759 mike     1.2                      Array<String> propertyValues;
 760               
 761                                   _getPropertiesFromCIMServer( outPrintWriter, 
 762                                       errPrintWriter, _propertyName, propertyValues);
 763               
 764                                   defaultValue = propertyValues[1];
 765                                   currentValue = propertyValues[2];
 766 kumpf    1.10                     gotCurrentValue = true;
 767 mike     1.2                      plannedValue = propertyValues[3];
 768 kumpf    1.10                     gotPlannedValue = true;
 769 mike     1.2                  }
 770                               else
 771                               {
 772                                   if (_defaultValueSet)
 773                                   {
 774                                       errPrintWriter << "Option -" << OPTION_DEFAULT_VALUE <<
 775                                          " is not valid for this command when" <<
 776 kumpf    1.10                            " CIM server is not running." << endl;
 777 mike     1.2                          return ( RC_ERROR );
 778                                   }
 779                                   else 
 780                                   {
 781 kumpf    1.10                         gotCurrentValue = _configFileHandler->getCurrentValue ( 
 782                                           _propertyName, currentValue );
 783                                       gotPlannedValue = _configFileHandler->getPlannedValue ( 
 784                                           _propertyName, plannedValue );
 785 mike     1.2                      }
 786                               }
 787                           }
 788 kumpf    1.20             catch (CIMException& e)
 789 mike     1.2              {
 790                               CIMStatusCode code = e.getCode();
 791               
 792 kumpf    1.8                  if (code == CIM_ERR_NOT_FOUND || 
 793 mike     1.2                      code == CIM_ERR_FAILED)
 794                               {
 795                                   outPrintWriter << PROPERTY_NOT_FOUND << endl;
 796               
 797                                   errPrintWriter << e.getMessage() << endl;
 798                               }
 799                               else if (code == CIM_ERR_INVALID_CLASS)
 800                               {
 801                                   outPrintWriter << FAILED_TO_GET_PROPERTY << endl <<
 802                                       CONFIG_SCHEMA_NOT_LOADED << endl;
 803                               }
 804                               else
 805                               {
 806                                   errPrintWriter << FAILED_TO_GET_PROPERTY <<
 807                                       e.getMessage() << endl;
 808                               }
 809                               return ( RC_ERROR );
 810                           }
 811 kumpf    1.20             catch (Exception& e)
 812 kumpf    1.3              {
 813                               outPrintWriter << FAILED_TO_GET_PROPERTY << endl <<
 814 kumpf    1.7                      e.getMessage() << endl;
 815 kumpf    1.3                  return ( RC_ERROR );
 816                           }
 817 mike     1.2  
 818                           if( _currentValueSet || ( !_plannedValueSet && !_defaultValueSet ) )
 819                           {
 820 kumpf    1.10                 if (gotCurrentValue)
 821                               {
 822                                   outPrintWriter << "Current value: " << currentValue << endl;
 823                               }
 824                               else
 825                               {
 826 kumpf    1.12                     outPrintWriter << "Current value can not be determined " <<
 827 kumpf    1.10                         "because the CIM server is not running." << endl;
 828                               }
 829 mike     1.2              }
 830               
 831                           if( _plannedValueSet )
 832                           {
 833 kumpf    1.10                 if (gotPlannedValue)
 834                               {
 835                                   outPrintWriter << "Planned value: " << plannedValue << endl;
 836                               }
 837                               else
 838                               {
 839                                   outPrintWriter << "Planned value can not be determined "
 840                                       "because the CIM server is not running." << endl;
 841                               }
 842 mike     1.2              }
 843               
 844                           if( _defaultValueSet )
 845                           {
 846                               outPrintWriter << "Default value: " << defaultValue << endl;
 847                           }
 848                           break; 
 849               
 850                       case OPERATION_TYPE_SET:
 851                           //
 852                           // send changes to CIMOM if running, else send to config file
 853                           //
 854                           try
 855                           {
 856                               if (connected)
 857                               {
 858                                   _updatePropertyInCIMServer( outPrintWriter, 
 859 kumpf    1.10                         errPrintWriter, _propertyName, _propertyValue, false);
 860 mike     1.2  
 861                                   if ( _currentValueSet )
 862                                   {
 863                                       outPrintWriter << CURRENT_VALUE_OF_PROPERTY
 864                                           << _propertyName << IS_SET_TO << "\"" 
 865                                           << _propertyValue << "\"" << IN_CIMSERVER << endl;
 866                                   }
 867               
 868                                   if ( _plannedValueSet )
 869                                   {
 870                                       outPrintWriter << PLANNED_VALUE_OF_PROPERTY
 871                                           << _propertyName << IS_SET_TO << "\"" <<_propertyValue
 872                                           << "\"" << IN_CIMSERVER << endl;
 873                                   }
 874                               }
 875                               else
 876                               {
 877                                   if (_currentValueSet)
 878                                   {
 879 kumpf    1.12                         outPrintWriter << CURRENT_VALUE_OF_PROPERTY <<
 880                                           _propertyName <<"' can not be set " <<
 881                                           "because the CIM server is not running." << endl;
 882               
 883 mike     1.2                          return ( RC_ERROR );
 884                                   }
 885                                   else if (_plannedValueSet)
 886                                   {
 887                                       if ( !_configFileHandler->updatePlannedValue( 
 888 kumpf    1.10                             _propertyName, _propertyValue, false ) )
 889 mike     1.2                          {
 890 kumpf    1.12                             outPrintWriter << "Failed to update the planned" 
 891 mike     1.2                                  << " value of the Property '" << _propertyName 
 892                                               << "'" << IN_CONFIG_FILE << endl;
 893                                           return ( RC_ERROR );
 894                                       }
 895                                   }
 896               
 897                                   outPrintWriter << "Property '" << _propertyName <<
 898                                       UPDATED_IN_FILE << endl;
 899                               }
 900                           }
 901 kumpf    1.20             catch (CIMException& e)
 902 mike     1.2              {
 903                               CIMStatusCode code = e.getCode();
 904               
 905                               if (code == CIM_ERR_TYPE_MISMATCH)
 906                               { 
 907                                   outPrintWriter << INVALID_PROPERTY_VALUE << endl;
 908               
 909                                   errPrintWriter << e.getMessage() << endl;
 910                               }
 911 kumpf    1.8                  else if (code == CIM_ERR_NOT_FOUND)
 912 mike     1.2                  {
 913                                   outPrintWriter << PROPERTY_NOT_FOUND << endl;
 914               
 915                                   errPrintWriter << e.getMessage() << endl;
 916                               }
 917                               else if (code == CIM_ERR_NOT_SUPPORTED)
 918                               {
 919                                   outPrintWriter << PROPERTY_NOT_MODIFIED << endl;
 920               
 921                                   errPrintWriter << e.getMessage() << endl;
 922                               }
 923                               else if (code == CIM_ERR_FAILED)
 924                               {
 925                                   outPrintWriter << FAILED_TO_SET_PROPERTY << 
 926                                       e.getMessage() << endl;
 927                               }
 928                               else if (code == CIM_ERR_ALREADY_EXISTS)
 929                               {
 930                                   outPrintWriter << "The property '" << _propertyName <<
 931                                       "' value is already set to '" << _propertyValue <<
 932                                       "'." << endl;
 933 mike     1.2  
 934                                   errPrintWriter << e.getMessage() << endl;
 935                               }
 936                               else if (code == CIM_ERR_INVALID_CLASS)
 937                               {
 938                                   outPrintWriter << FAILED_TO_SET_PROPERTY << endl << 
 939                                       CONFIG_SCHEMA_NOT_LOADED << endl;
 940                               }
 941                               else
 942                               {
 943                                   errPrintWriter << e.getMessage() << endl;
 944                               }
 945                               return ( RC_ERROR );
 946                           }
 947 kumpf    1.20             catch (Exception& e)
 948 kumpf    1.3              {
 949                               outPrintWriter << FAILED_TO_SET_PROPERTY << endl << 
 950 kumpf    1.7                      e.getMessage() << endl;
 951 kumpf    1.3                  return ( RC_ERROR );
 952                           }
 953 mike     1.2              break;
 954               
 955                       case OPERATION_TYPE_UNSET:
 956                           //
 957                           // send changes to CIMOM if running, else send to config file
 958                           //
 959                           try
 960                           {
 961                               if (connected)
 962                               {
 963 kumpf    1.10                     _propertyValue = String::EMPTY;
 964 mike     1.2  
 965                                   _updatePropertyInCIMServer( outPrintWriter, 
 966 kumpf    1.10                         errPrintWriter, _propertyName, _propertyValue, true);
 967 mike     1.2  
 968                                   if ( _currentValueSet )
 969                                   {
 970                                       outPrintWriter << CURRENT_VALUE_OF_PROPERTY
 971                                           << _propertyName <<"' is set to default value"
 972                                           << IN_CIMSERVER << endl;
 973                                   }
 974               
 975                                   if ( _plannedValueSet )
 976                                   {
 977                                       outPrintWriter << "Property '" << _propertyName <<
 978                                      	    IS_UNSET_IN_FILE << endl;
 979                                   }
 980                               }
 981                               else
 982                               {
 983                                   if (_currentValueSet)
 984                                   {
 985                                       outPrintWriter << CURRENT_VALUE_OF_PROPERTY <<
 986 kumpf    1.12                             _propertyName <<"' can not be unset " <<
 987                                           "because the CIM server is not running." << endl;
 988 mike     1.2  
 989                                       return ( RC_ERROR );
 990                                   }
 991               
 992                                   if ( !_configFileHandler->updatePlannedValue( 
 993 kumpf    1.10                         _propertyName, _propertyValue, true ) )
 994 mike     1.2                      {
 995                                       return ( RC_ERROR );
 996                                   }
 997               
 998                                   outPrintWriter << "Property '" << _propertyName <<
 999                                       IS_UNSET_IN_FILE << endl;
1000                               }
1001               
1002                           }
1003 kumpf    1.20             catch (CIMException& e)
1004 mike     1.2              {
1005                               CIMStatusCode code = e.getCode();
1006               
1007                               if (code == CIM_ERR_TYPE_MISMATCH)
1008                               {
1009                                   outPrintWriter << INVALID_PROPERTY_VALUE << endl;
1010               
1011                                   errPrintWriter << e.getMessage() << endl;
1012                               }
1013 kumpf    1.8                  else if (code == CIM_ERR_NOT_FOUND)
1014 mike     1.2                  {
1015                                   outPrintWriter << PROPERTY_NOT_FOUND << endl;
1016               
1017                                   errPrintWriter << e.getMessage() << endl;
1018                               }
1019                               else if (code == CIM_ERR_NOT_SUPPORTED)
1020                               {
1021                                   outPrintWriter << PROPERTY_NOT_MODIFIED << endl;
1022               
1023                                   errPrintWriter << e.getMessage() << endl;
1024                               }
1025                               else if (code == CIM_ERR_FAILED)
1026                               {
1027                                   outPrintWriter << FAILED_TO_UNSET_PROPERTY <<
1028                                       e.getMessage() << endl;
1029                               }
1030                               else if (code == CIM_ERR_ALREADY_EXISTS)
1031                               {
1032                                   outPrintWriter << "The property '" << _propertyName <<
1033                                       "' value is already unset." << endl;
1034               
1035 mike     1.2                      errPrintWriter << e.getMessage() << endl;
1036                               }
1037                               else if (code == CIM_ERR_INVALID_CLASS)
1038                               {
1039                                   outPrintWriter << FAILED_TO_UNSET_PROPERTY << endl <<
1040                                       CONFIG_SCHEMA_NOT_LOADED << endl;
1041                               }
1042                               else
1043                               {
1044                                   errPrintWriter << e.getMessage() << endl;
1045                               }
1046                               return ( RC_ERROR );
1047                           }
1048 kumpf    1.20             catch (Exception& e)
1049 kumpf    1.3              {
1050                               outPrintWriter << FAILED_TO_UNSET_PROPERTY << endl <<
1051 kumpf    1.7                      e.getMessage() << endl;
1052 kumpf    1.3                  return ( RC_ERROR );
1053                           }
1054 mike     1.2              break;
1055               
1056                       case OPERATION_TYPE_LIST:
1057                           //
1058                           // send request to CIMOM if running, else send to config file
1059                           //
1060                           try
1061                           {
1062 kumpf    1.22                 Array<CIMName> propertyNames;
1063 mike     1.2                  Array<String> propertyValues;
1064               
1065                               if (connected)
1066                               {
1067                                   _listAllPropertiesInCIMServer(outPrintWriter, 
1068                                        errPrintWriter, propertyNames, propertyValues);
1069               
1070                               }
1071                               else
1072                               {
1073 kumpf    1.12                     if (_plannedValueSet)
1074 mike     1.2                      {
1075                                       _configFileHandler->getAllPlannedProperties(
1076                                           propertyNames, propertyValues);
1077                                   }
1078                                   else
1079                                   {
1080 kumpf    1.12                         outPrintWriter << "Current value of properties can not be " <<
1081                                           "listed because the CIM server is not running." << endl;
1082                                       break;
1083 mike     1.2                      }
1084                               }
1085               
1086                               Uint32 valuesSize = propertyValues.size();
1087                               Uint32 namesSize  = propertyNames.size();
1088               
1089                               if (namesSize == 0)
1090                               {
1091                                   outPrintWriter << "No configuration properties found"
1092                                       << " in the configuration file." << endl;
1093                                   break;
1094                               }
1095               
1096                               for ( Uint32 i = 0; i < namesSize; i++ )
1097                               {
1098                                   outPrintWriter << propertyNames[i];
1099                                   if ( ( _currentValueSet || _plannedValueSet ) &&
1100                                        ( valuesSize == namesSize) )
1101                                   {
1102                                       outPrintWriter << "=" << propertyValues[i];
1103                                   }
1104 mike     1.2                      outPrintWriter << endl;
1105                               }
1106                               break;
1107                           }
1108 kumpf    1.20             catch (CIMException& e)
1109 mike     1.2              {
1110                               CIMStatusCode code = e.getCode();
1111               
1112                               if (code == CIM_ERR_NOT_FOUND || code == CIM_ERR_INVALID_CLASS)
1113                               {
1114                                   outPrintWriter << FAILED_TO_LIST_PROPERTIES << endl <<
1115                                       CONFIG_SCHEMA_NOT_LOADED << endl;
1116                               }
1117                               else if (code == CIM_ERR_FAILED)
1118                               {
1119                                   outPrintWriter << FAILED_TO_LIST_PROPERTIES <<
1120                                       e.getMessage() << endl;
1121                               }
1122                               else
1123                               {
1124                                   errPrintWriter << e.getMessage() << endl;
1125                               }
1126               
1127                               return ( RC_ERROR );
1128                           }
1129 kumpf    1.20             catch (Exception& e)
1130 mike     1.2              {
1131 kumpf    1.3                  outPrintWriter << FAILED_TO_LIST_PROPERTIES <<  endl <<
1132 kumpf    1.7                      e.getMessage() << endl;
1133 mike     1.2                  return ( RC_ERROR );
1134                           }
1135               
1136                       default:
1137                           //
1138                           // Should never get here
1139                           //
1140                           break;
1141                   }
1142               
1143                   return (RC_SUCCESS);
1144               }
1145               
1146               /**
1147                   Get property values for the specified property from the CIM Server.
1148               */
1149               void CIMConfigCommand::_getPropertiesFromCIMServer
1150                   (
1151                   ostream&    outPrintWriter, 
1152                   ostream&    errPrintWriter,
1153 kumpf    1.22     const CIMName&    propName,
1154 mike     1.2      Array <String>&    propValues
1155                   ) 
1156               {
1157                   CIMProperty prop;
1158               
1159                   try
1160                   {
1161 kumpf    1.21         Array<CIMKeyBinding> kbArray;
1162                       CIMKeyBinding        kb;
1163 mike     1.2  
1164                       kb.setName(PROPERTY_NAME);
1165 kumpf    1.22         kb.setValue(propName.getString());
1166 kumpf    1.21         kb.setType(CIMKeyBinding::STRING);
1167 mike     1.2  
1168                       kbArray.append(kb);
1169               
1170 kumpf    1.13         CIMObjectPath reference(
1171 kumpf    1.16             _hostName, PEGASUS_NAMESPACENAME_CONFIG,
1172                           PEGASUS_CLASSNAME_CONFIGSETTING, kbArray);
1173 mike     1.2  
1174 kumpf    1.6          CIMInstance cimInstance =
1175 kumpf    1.16             _client->getInstance(PEGASUS_NAMESPACENAME_CONFIG, reference);
1176 mike     1.2  
1177                       Uint32 pos = cimInstance.findProperty(PROPERTY_NAME);
1178                       prop = (CIMProperty)cimInstance.getProperty(pos);
1179                       propValues.append(prop.getValue().toString());
1180               
1181                       pos = cimInstance.findProperty(DEFAULT_VALUE);
1182                       prop = (CIMProperty)cimInstance.getProperty(pos);
1183                       propValues.append(prop.getValue().toString());
1184               
1185                       pos = cimInstance.findProperty(CURRENT_VALUE);
1186                       prop = (CIMProperty)cimInstance.getProperty(pos);
1187                       propValues.append(prop.getValue().toString());
1188               
1189                       pos = cimInstance.findProperty(PLANNED_VALUE);
1190                       prop = (CIMProperty)cimInstance.getProperty(pos);
1191                       propValues.append(prop.getValue().toString());
1192               
1193                       pos = cimInstance.findProperty(DYNAMIC_PROPERTY);
1194                       prop = (CIMProperty)cimInstance.getProperty(pos);
1195                       propValues.append(prop.getValue().toString());
1196                   }
1197 kumpf    1.20     catch (Exception& e)
1198 mike     1.2      {
1199                       throw e;
1200                   }
1201               }
1202               
1203               /**
1204                   Send an updated property value to the CIM Server.
1205                */
1206               void CIMConfigCommand::_updatePropertyInCIMServer
1207                   (
1208                   ostream&    outPrintWriter, 
1209                   ostream&    errPrintWriter,
1210 kumpf    1.22     const CIMName&   propName,
1211 kumpf    1.10     const String&   propValue,
1212                   Boolean     isUnsetOperation
1213 mike     1.2      ) 
1214               {
1215               
1216                   try
1217                   {
1218 kumpf    1.21         Array<CIMKeyBinding> kbArray;
1219                       CIMKeyBinding        kb;
1220 mike     1.2  
1221                       kb.setName(PROPERTY_NAME);
1222 kumpf    1.22         kb.setValue(propName.getString());
1223 kumpf    1.21         kb.setType(CIMKeyBinding::STRING);
1224 mike     1.2  
1225                       kbArray.append(kb);
1226               
1227 kumpf    1.13         CIMObjectPath reference(
1228 kumpf    1.16             _hostName, PEGASUS_NAMESPACENAME_CONFIG,
1229                           PEGASUS_CLASSNAME_CONFIGSETTING, kbArray);
1230 mike     1.2  
1231 kumpf    1.16         CIMInstance modifiedInst = CIMInstance(PEGASUS_CLASSNAME_CONFIGSETTING);
1232 kumpf    1.19         Array<CIMName> propertyList;
1233 mike     1.2  
1234                       if ( _currentValueSet )
1235                       {
1236 kumpf    1.10             if (!isUnsetOperation)
1237                           {
1238                               CIMProperty prop =
1239                                   CIMProperty(CURRENT_VALUE, CIMValue(propValue));
1240                               modifiedInst.addProperty(prop);
1241                           }
1242                           propertyList.append(CURRENT_VALUE);
1243 mike     1.2          }
1244               
1245                       if ( _plannedValueSet )
1246                       {
1247 kumpf    1.10             if (!isUnsetOperation)
1248                           {
1249                               CIMProperty prop =
1250                                   CIMProperty(PLANNED_VALUE, CIMValue(propValue));
1251                               modifiedInst.addProperty(prop);
1252                           }
1253                           propertyList.append(PLANNED_VALUE);
1254 mike     1.2          }
1255               
1256 kumpf    1.14         CIMInstance namedInstance (modifiedInst);
1257                       namedInstance.setPath (reference);
1258 kumpf    1.10         _client->modifyInstance(
1259 kumpf    1.16             PEGASUS_NAMESPACENAME_CONFIG,
1260 kumpf    1.10             namedInstance,
1261                           false,
1262                           CIMPropertyList(propertyList));
1263 mike     1.2      }
1264 kumpf    1.20     catch (Exception& e)
1265 mike     1.2      {
1266                       throw e;
1267                   }
1268               }
1269               
1270               
1271               /**
1272                   get a list of all property names and value from the CIM Server.
1273                */
1274               void CIMConfigCommand::_listAllPropertiesInCIMServer
1275                   ( 
1276                   ostream&    outPrintWriter,
1277                   ostream&    errPrintWriter,
1278 kumpf    1.22     Array <CIMName>&   propNames,
1279 mike     1.2      Array <String>&   propValues
1280                   )
1281               {
1282 kumpf    1.14     Array<CIMInstance> configNamedInstances;
1283 mike     1.2  
1284                   try
1285                   {
1286                       if ( _currentValueSet ||  _plannedValueSet )
1287                       {
1288                           //
1289                           // get all the instances of class PG_ConfigSetting
1290                           //
1291                           configNamedInstances =
1292 kumpf    1.16                 _client->enumerateInstances(
1293                                   PEGASUS_NAMESPACENAME_CONFIG,
1294                                   PEGASUS_CLASSNAME_CONFIGSETTING);
1295 mike     1.2  
1296                           //
1297                           // copy all the property names and values
1298                           //
1299                           for (Uint32 i = 0; i < configNamedInstances.size(); i++)
1300                           {
1301                               CIMInstance& configInstance =
1302 kumpf    1.14                     configNamedInstances[i];
1303 mike     1.2  
1304 kumpf    1.22                 Uint32 pos = configInstance.findProperty
1305                                   (CIMName ("PropertyName"));
1306 mike     1.2                  CIMProperty prop = (CIMProperty)configInstance.getProperty(pos);
1307                               propNames.append(prop.getValue().toString());
1308               
1309                               if (_currentValueSet)
1310                               {
1311                                   //
1312                                   // get current value
1313                                   //
1314 kumpf    1.22                     pos = configInstance.findProperty(CIMName ("CurrentValue"));
1315 mike     1.2                      prop = (CIMProperty)configInstance.getProperty(pos);
1316                                   propValues.append(prop.getValue().toString());
1317                               }
1318                               else if (_plannedValueSet)
1319                               {
1320                                   //
1321                                   // get planned value
1322                                   //
1323 kumpf    1.22                     pos = configInstance.findProperty(CIMName ("PlannedValue"));
1324 mike     1.2                      prop = (CIMProperty)configInstance.getProperty(pos);
1325                                   propValues.append(prop.getValue().toString());
1326                               }
1327                           }
1328                       }
1329                       else 
1330                       {
1331                           //
1332                           // call enumerateInstanceNames
1333                           //
1334 kumpf    1.13             Array<CIMObjectPath> instanceNames =
1335 kumpf    1.16                 _client->enumerateInstanceNames(
1336                                   PEGASUS_NAMESPACENAME_CONFIG,
1337                                   PEGASUS_CLASSNAME_CONFIGSETTING);
1338 mike     1.2  
1339                           //
1340                           // copy all the property names
1341                           //
1342                           for (Uint32 i = 0; i < instanceNames.size(); i++)
1343                           {
1344 kumpf    1.21                 Array<CIMKeyBinding> kbArray = instanceNames[i].getKeyBindings();
1345 mike     1.2    
1346                               if (kbArray.size() > 0)
1347                               {
1348                                   propNames.append(kbArray[0].getValue());
1349                               }
1350                           }
1351                
1352                       }
1353                   }
1354 kumpf    1.20     catch (Exception& e)
1355 mike     1.2      {
1356                       throw e;
1357                   }
1358               }
1359               
1360               PEGASUS_NAMESPACE_END
1361               
1362               //
1363               // exclude main from the Pegasus Namespace
1364               //
1365               PEGASUS_USING_PEGASUS;
1366               
1367               PEGASUS_USING_STD;
1368               
1369               ///////////////////////////////////////////////////////////////////////////////
1370               /**
1371                   Parses the command line, and execute the command.
1372               
1373                   @param   args  the string array containing the command line arguments
1374               */
1375               ///////////////////////////////////////////////////////////////////////////////
1376 mike     1.2  
1377               int main (int argc, char* argv []) 
1378               {
1379                   CIMConfigCommand*    command;
1380                   Uint32               returnCode;
1381 chuck    1.26     
1382 chuck    1.24 
1383               #ifdef PEGASUS_OS_OS400
1384 chuck    1.26 
1385                 VFYPTRS_INCDCL;               // VFYPTRS local variables 
1386               
1387                 // verify pointers
1388                 #pragma exception_handler (qsyvp_excp_hndlr,qsyvp_excp_comm_area,\
1389                   0,_C2_MH_ESCAPE)
1390                     for( int arg_index = 1; arg_index < argc; arg_index++ ){
1391               	  VFYPTRS(VERIFY_SPP_NULL(argv[arg_index]));
1392                     }
1393                 #pragma disable_handler 
1394               
1395 chuck    1.24     if(FALSE == ycmCheckCmdAuthorities())
1396                   { 
1397                     return -9;
1398                   }
1399 chuck    1.26       
1400 chuck    1.24 #endif
1401 mike     1.2  
1402                   command  = new CIMConfigCommand ();
1403               
1404               
1405                   try 
1406                   {
1407                       command->setCommand (argc, argv);
1408                   } 
1409                   catch (CommandFormatException& cfe) 
1410                   {
1411                       if (!String::equal(cfe.getMessage (), ""))
1412                       {
1413                           cerr << COMMAND_NAME << ": " << cfe.getMessage () << endl;
1414                       }
1415                       cerr << command->getUsage () << endl;
1416                       exit (-1);
1417                   }
1418               
1419                   returnCode = command->execute (cout, cerr);
1420               
1421                   exit (returnCode);
1422 mike     1.2      return 0;
1423               }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2