Use the invokeMethod interface to call a method in a class supported by a provider. To retrieve the signature of a method, an application must first get the definition of the class to which the method belongs. The invokeMethod interface takes four arguments described in the following table:
Table 4–11 Parameters to the invokeMethodMethod
Parameter |
Data Type |
Description |
---|---|---|
name |
CIMObjectPath |
The name of the instance on which the method must be invoked. |
methodName |
String |
The name of the method to call. |
inParams |
Vector |
Input parameters to pass to the method. |
outParams |
Vector |
Output parameters to get from the method. |
The invokeMethod method returns a CIMValue. The return value is null when the method you invoke does not define a return value.
The code segment in Example 4–17 gets the instances of the CIM_Service class (services that manage device or software features) and uses the invokeMethod method to stop each service.
{ ... /* Pass the CIM Object Path of the CIM_Service class to the CIM Object Manager. We want to invoke a method defined in this class. */ CIMObjectPath op = new CIMObjectPath("CIM_Service"); /* The CIM Object Manager returns an enumeration of instance object paths, the names of instances of the CIM_Service class. */ Enumeration e = cc.enumInstances(op, cc.DEEP); /* Iterate through the enumeration of instance object paths. Use the CIM Client getInstance class to get the instances referred to by each object path. */ while(e.hasMoreElements()) { // Get the instance CIMInstance ci = cc.getInstance(e.nextElement(), true); //Invoke the Stop Service method to stop the CIM services. cc.invokeMethod(ci, "StopService", null, null); } }