* perform different operations or subscribe for event notifications.
*/
public final class SimulatorRemoteResource {
-
private long mNativeHandle;
private String mUri;
private int mConnType;
private Vector<String> mResInterfaces;
private boolean mIsObservable;
- private native void dispose();
-
- private SimulatorRemoteResource(long nativeHandle) {
- mNativeHandle = nativeHandle;
- }
-
@Override
protected void finalize() throws Throwable {
try {
- dispose();
+ nativeDispose();
} catch (Throwable t) {
throw t;
} finally {
* Enum to represent the verification types which can be used by the client
* to verify the resource model of the remote resource.
*/
- public enum VerificationType {
- GET, PUT, POST, DELETE;
+ public enum RequestType {
+ UKNOWN, GET, PUT, POST, DELETE;
}
/**
}
/**
+ * API to get the address detail of the resource.
+ *
+ * @return Host address.
+ */
+ public String getHost() {
+ return mHost;
+ }
+
+ /**
+ * API to get a unique Id of the resource.
+ *
+ * @return Unique ID.
+ */
+ public String getId() {
+ return mId;
+ }
+
+ /**
* API to get the connectivity type for this resource.
*
* @return Connectivity type.
}
/**
- * API to get the address detail of the resource.
- *
- * @return Host address.
- */
- public String getHost() {
- return mHost;
- }
-
- /**
- * API to get a unique Id of the resource.
- *
- * @return Unique ID.
- */
- public String getId() {
- return mId;
- }
-
- /**
* API to get the observe policy of this resource.
*
* @return True if the resource is observable, otherwise false.
/**
* API to start observing the resource.
*
+ * @param onObserveListener
+ * The handler method which will be invoked with a map of
+ * attribute names and values whenever there is a change in
+ * resource model of the remote resource.
+ *
+ * @throws InvalidArgsException
+ * This exception will be thrown if any parameter has invalid
+ * values.
+ * @throws SimulatorException
+ * This exception will be thrown for other errors.
+ */
+ public void observe(ObserveNotificationListener onObserveListener)
+ throws InvalidArgsException, SimulatorException {
+ nativeStartObserve(null, onObserveListener);
+ }
+
+ /**
+ * API to start observing the resource.
+ *
* @param queryParams
* Map which can have the query parameter names and values.
* @param onObserveListener
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
- public native void startObserve(Map<String, String> queryParams,
+ public void observe(Map<String, String> queryParams,
ObserveNotificationListener onObserveListener)
- throws InvalidArgsException, SimulatorException;
+ throws InvalidArgsException, SimulatorException {
+ if (null == queryParams)
+ throw new InvalidArgsException(
+ SimulatorResult.SIMULATOR_INVALID_PARAM,
+ "Invalid Query Parameters!");
+ nativeStartObserve(queryParams, onObserveListener);
+ }
/**
* API to stop observing the resource.
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
- public native void stopObserve() throws InvalidArgsException,
- SimulatorException;
+ public void stopObserve() throws InvalidArgsException, SimulatorException {
+ nativeStopObserve();
+ }
/**
* API to provide remote resource configure information, which is required
* @throws SimulatorException
* Thrown for other errors.
*/
- public native SimulatorResourceModel setConfigInfo(String path)
- throws InvalidArgsException, SimulatorException;
+ public Map<RequestType, SimulatorRequestModel> setConfigInfo(String path)
+ throws InvalidArgsException, SimulatorException {
+ return nativeSetConfigInfo(path);
+ }
/**
* API to send multiple requests for the resource, based on the configure
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
- public int startVerification(VerificationType type,
+ public int startVerification(RequestType type,
VerificationListener onVerifyListener) throws InvalidArgsException,
NoSupportException, OperationInProgressException,
SimulatorException {
- return startVerification(type.ordinal(), onVerifyListener);
+ return nativeStartAutoRequesting(type, onVerifyListener);
}
/**
* @throws SimulatorException
* Thrown for other errors.
*/
- public native void stopVerification(int id) throws InvalidArgsException,
- SimulatorException;
+ public void stopVerification(int id) throws InvalidArgsException,
+ SimulatorException {
+ nativeStopAutoRequesting(id);
+ }
/**
* Listener for receiving asynchronous response for GET request.
public void onVerificationCompleted(String uid, int id);
}
+ private SimulatorRemoteResource(long nativeHandle) {
+ mNativeHandle = nativeHandle;
+ }
+
private native void nativeGet(String resourceInterface,
Map<String, String> queryParamsMap,
GetResponseListener onGetListener);
SimulatorResourceModel representation,
PostResponseListener onPostListener);
- private native int startVerification(int type,
+ private native void nativeStartObserve(Map<String, String> queryParams,
+ ObserveNotificationListener onObserveListener);
+
+ private native void nativeStopObserve();
+
+ private native Map<RequestType, SimulatorRequestModel> nativeSetConfigInfo(
+ String path);
+
+ private native int nativeStartAutoRequesting(RequestType type,
VerificationListener onVerifyListener);
+
+ private native void nativeStopAutoRequesting(int id);
+
+ private native void nativeDispose();
}