Sun WBEM SDK Developer's Guide

Using the Provider Examples

The example provider is a Java program that returns system properties and prints the string, “Hello World.” The provider calls native C methods to execute the code and return the values to the provider.

Provider Example Files

The following table describes the files that make up the example Provider program.

Table 7–2 Provider Example Files

File 

Purpose 

NativeProvider

Top level provider program that fulfills requests from the CIM Object Manager and routes them to the Native_Example provider. The NativeProvider program implements the instanceProvider and methodProvider APIs, and declares methods that enumerate instances and get an instance of the Native_Example class. It also declares a method that invokes a method to print the string "Hello World."

Native_Example.mof

Creates a class that registers the NativeProvider provider with the CIM Object Manager. The Native_Example.mof file identifies NativeProvider as the provider to service requests for dynamic data in the Native_Example class. This MOF file also declares the properties and methods to be implemented by the NativeProvider.

Native_Example.java

The NativeProvider program calls this provider to implement methods that enumerate instances and get an instance of the Native_Example class. The Native_Example provider uses the APIs to enumerate objects and create instances of objects. The Native_Example class declares native methods, which call C functions in the native.c file to get system-specific values, such as host name, serial number, release, machine, architecture, and manufacturer.

native.c

C program that implements calls from the Native_Example Java provider in native C code.

Native_Example.h

Machine-generated header file for Native_Example class. Defines the correspondence between the Java native method names and the native C functions that execute those methods.

libnative.so

Binary native C code compiled from the native.c file.

Writing a Native Provider

For detailed information on writing and integrating Java programs with native methods, visit the Java Web page at http://www.javasoft.com/docs/books/tutorial/native1.1/TOC.html.

Setting Up the Provider Example

The example provider program, NativeProvider, enumerates instances and gets properties for instances of the Native_Example class. You can use the CIM WorkShop to view this class and its instances.

How to Set Up the Provider Example
  1. Specify the location of shared library files in one of the following ways:

    • Set the LD_LIBRARY_PATH environment variable to the location of the shared library files. For example, using the C shell:


      Note –

      If you set the LD_LIBRARY_PATH environment variable in a shell, you must stop and restart the CIM Object Manager in the same shell for this new value to be recognized.



      % setenv LD_LIBRARY_PATH /wbem/provider/
      

      For example, using the Bourne shell:


      % LD_LIBRARY_PATH = /wbem/provider/
      

    • Copy the shared library files to the directory specified by the LD_LIBRARY_PATH environment variable. Installation sets this environment variable to /usr/sadm/lib/wbem. For example:


    % cp libnative.so /usr/sadm/lib/wbem 
    % cp native.c /usr/sadm/lib/wbem 
    % cp Native_Example.h /usr/sadm/lib/wbem
    

  2. Move the provider class files to /usr/sadm/lib/wbem.

    Move the provider class files to the same path as the package in which they are defined. For example, if the provider is packaged as com.sun.providers.myprovider.*, move the provider class files to /usr/sadm/lib/wbem/com/sun/wbem/myprovider/.class.

  3. Set the Solaris Provider CLASSPATH variable to the directory that contains the provider class files as described in To Set the Provider CLASSPATH.

  4. Stop the CIM Object Manager by typing the following command:


    # /etc/init.d/init.wbem -stop
    

  5. Restart the CIM Object Manager by typing the following command:


    # /etc/init.d/init.wbem -start
    

  6. Compile the Native_Example.mof file. For example:


    % mofcomp Native_Example.mof
    

    Compiling this MOF file loads the Native_Example class in the CIM Object Manager and identifies NativeProvider as its provider.

  7. Run CIM WorkShop and view the Native_Example class. For example:


    % /usr/sadm/bin/cimworkshop &
    

  8. In the Toolbar, click the Find Class icon.

  9. In the Input dialog box, type Native_Example and click OK.