Adding Instrumentation to the Code

[This is preliminary documentation and subject to change.]

    To add instrumentation to the code

There are two ways that a provider can be called: either it is asked to enumerate all instances (which calls AddDynamicInstances, or it can be asked for one specific instance through the GetObject call, which calls RefreshInstance.

In real code, you could use this fact to implement "expensive" properties. When the enumerate function is called, you could return only the "cheap" values. When the GetObject function is called, you can get all information.

In the following sample, different values are returned to show that both methods are being called.

  1. Add the following code to CMyClass::AddDynamicInstances just before the return statement:
    BuildNewInstance();
        MyName = "Fred";
        Age = 15;
        dwInstanceCount++;
        CommitNewInstance();
     
        BuildNewInstance();
        MyName = "Mary";
        Age = 16;
        dwInstanceCount++;
        CommitNewInstance();
     

    This means we will be returning two instances. You can also structure this as:

    {
       BuildNewInstance();
       .
       .
       .
       CommitNewInstance();
       dwInstanceCount++;
    }
     
  2. Add the following code to CMyClass::RefreshInstance just before the return statement:
    char szTemp[255];
        CHString sTemp;
        sTemp=MyName;
    
        strcpy(szTemp, sTemp.GetBuffer(255));
    
        if (stricmp(szTemp, "Fred") == 0) {
            Age = 15;
        } else if (stricmp(szTemp, "Mary") == 0) {
            Age = 16;
        } else {
            return FALSE;
        }
    
  3. Stop CIMOM.
  4. Recompile the code.