Solaris WBEM SDK Developer's Guide

Writing a Method Provider

The method invokeMethod is the only way that a client program can call the methods of Solaris WBEM providers, whether those providers are:

The following sample code creates the Solaris_ComputerSystem provider class that routes requests from the CIM Object Manager to one or more specialized providers. These providers service requests for dynamic data for a particular type of managed object. For example, the Solaris_Package provider services requests to execute methods in the Solaris_Package class.

The method provider implements a single method, invokeMethod, that calls the appropriate provider to either reboot a system, shut down a system, or delete a serial port.


Example 4-2 Method Provider

...
public class Solaris_ComputerSystem implements MethodProvider {
	ProviderCIMOMHandle pch = null;
	public void initialize(CIMOMHandle ch) throws CIMExcepiton {
		pch = (ProviderCIMOMHandle)ch;
	}

	public void cleanup() throws CIMException {
	}

	public CIMValue invokeMethod(CIMObjectPath op, String methodName,
			Vector inParams, Vector outParams)  throws CIMException {
		if (op.getObjectName().equalsIgnoreCase("solaris_computersystem")) {
			if (methodName.equalsIgnoreCase("reboot")) {
				// call helper function, not shown here
				return new CIMValue(rebootSystem());
			}
			if (methodName.equalsIgnoreCase("shutdown")) {
				// call helper function, not shown here
				return new CIMValue(shutdownSystem());
			}
		}
		if (op.getObjectName().equalsIgnoreCase("solaris_serialport")) {
			if (methodName.equalsIgnoreCase("disableportservice")) {
				// call helper function, not shown here
				return new CIMValue(deletePort(op));
			}
		}
		// error if we get here
		throw new CIMException(CIMException.CIM_ERR_NOT_SUPPORTED,
			"The requested function does not exist");
	}
	// helper functions would be defined below
	...
}