private static volatile boolean sIsPlatformInitialized = false;
private static QualityOfService sPlatformQualityOfService = QualityOfService.NA;
+ private static volatile boolean sIsStopPlatform = false;
+
private OcPlatform() {
}
* @param platformConfig platform configuration
*/
public synchronized static void Configure(PlatformConfig platformConfig) {
+ if (sIsStopPlatform)
+ {
+ OcPlatform.start();
+ sIsStopPlatform = false;
+ }
+
if (!sIsPlatformInitialized) {
CaInterface.initialize(platformConfig.getActivity(), platformConfig.getContext());
platformConfig.getIpAddress(),
platformConfig.getPort(),
platformConfig.getQualityOfService().getValue(),
- platformConfig.getSvrDbPath()
+ platformConfig.getSvrDbPath(),
+ platformConfig.getDBDefaultPath(),
+ platformConfig.getDBRescuePath(),
+ platformConfig.getKeySize(),
+ platformConfig.getKey(),
+ platformConfig.getAvailableTransportType()
);
sIsPlatformInitialized = true;
String ipAddress,
int port,
int qualityOfService,
- String dbPath);
+ String dbPath,
+ String dbPathDefault,
+ String dbRescuePath,
+ int keySize,
+ byte[] key,
+ int transport);
+
+ /**
+ * API for stop all process of the OcPlatform.
+ * All of threads and memory will be terminated by this API.
+ * Iotivity Core can be started again through Configure(PlatformConfig platformConfig) API.
+ * Both Configure and Shutdown API is filtering for duplicated calling even while processing.
+ * <p>
+ * Note: This API is for both server and client side.
+ * </p>
+ */
+ public synchronized static void Shutdown() {
+ if (!sIsStopPlatform)
+ {
+ OcPlatform.stop();
+ sIsStopPlatform = true;
+ sIsPlatformInitialized = false;
+ }
+ }
+
+ private static native void stop();
+ private static native void start();
/**
* API for notifying base that resource's attributes have changed.
public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest);
}
+ /**
+ * Listner to get result of findKeepAliveResource and sendKeepAliveRequest.
+ * An PingListener can be registered via the OcPlatform.KeepAliveListener and
+ * OcPlatform.sendKeepAliveRequest call.
+ * Event listeners are notified asynchronously
+ */
+ public interface KeepAliveListener {
+ public void onKeepAliveListener(OcRepresentation ocRepresentation, int result);
+ }
+
private static void initCheck() {
if (!sIsPlatformInitialized) {
throw new IllegalStateException("OcPlatform must be configured by making a call to " +
* Method to set DeviceId.
*/
public static native void setDeviceId(byte[] deviceId) throws OcException;
+
+ /**
+ * gets OCRepresentation of KeepAlive resource from given host.
+ *
+ * @param host Host IP Address of pingResource
+ * @param onKeepAliveFoundListener Function to callback with result code and OCRepresentation.
+ * @throws OcException if failure
+ */
+ public static void findKeepAliveResource(String host,
+ KeepAliveListener onKeepAliveFoundListener)
+ throws OcException {
+ OcPlatform.initCheck();
+ OcPlatform.findKeepAliveResourceImpl(host, onKeepAliveFoundListener);
+ }
+
+ private static native void findKeepAliveResourceImpl(String host,
+ KeepAliveListener onKeepAliveFoundListener)
+ throws OcException;
+
+ /**
+ * send KeepAlive request to given host.
+ *
+ * @param interval interval time of expected pong response
+ * @param keepAliveResponseListener handles callback
+ * @throws OcException if failure
+ *
+ */
+ public static void sendKeepAliveRequest(String host, OcRepresentation ocRepresentation,
+ KeepAliveListener keepAliveResponseListener)
+ throws OcException {
+ OcPlatform.initCheck();
+ OcPlatform.sendKeepAliveRequestImpl(host, ocRepresentation, keepAliveResponseListener);
+ }
+
+ private static native void sendKeepAliveRequestImpl(String host,
+ OcRepresentation ocRepresentation,
+ KeepAliveListener keepAliveResponseListener)
+ throws OcException;
}