X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=android%2Fandroid_api%2Fbase%2Fsrc%2Fmain%2Fjava%2Forg%2Fiotivity%2Fbase%2FOcPlatform.java;h=954eab26dd8e257f8e5e529c1f760a62d2f6ffe9;hb=refs%2Ftags%2Fsubmit%2Ftizen_4.0%2F20171010.021147;hp=f699e1697ff2efb8c902241c990491bc05c5e7ec;hpb=8f51e668ae78cb8ea4e57576160ab99ddcd40a81;p=platform%2Fupstream%2Fiotivity.git diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java index f699e16..954eab2 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatform.java @@ -77,6 +77,8 @@ public final class OcPlatform { private static volatile boolean sIsPlatformInitialized = false; private static QualityOfService sPlatformQualityOfService = QualityOfService.NA; + private static volatile boolean sIsStopPlatform = false; + private OcPlatform() { } @@ -89,6 +91,12 @@ public final class 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()); @@ -100,7 +108,12 @@ public final class OcPlatform { platformConfig.getIpAddress(), platformConfig.getPort(), platformConfig.getQualityOfService().getValue(), - platformConfig.getSvrDbPath() + platformConfig.getSvrDbPath(), + platformConfig.getDBDefaultPath(), + platformConfig.getDBRescuePath(), + platformConfig.getKeySize(), + platformConfig.getKey(), + platformConfig.getAvailableTransportType() ); sIsPlatformInitialized = true; @@ -112,7 +125,33 @@ public final class OcPlatform { 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. + *

+ * Note: This API is for both server and client side. + *

+ */ + 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. @@ -172,6 +211,10 @@ public final class OcPlatform { OcResourceResponse ocResourceResponse) throws OcException { OcPlatform.initCheck(); + if (ocObservationIdList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null"); + } + byte[] idArr = new byte[ocObservationIdList.size()]; Iterator it = ocObservationIdList.iterator(); int i = 0; @@ -211,6 +254,10 @@ public final class OcPlatform { QualityOfService qualityOfService) throws OcException { OcPlatform.initCheck(); + if (ocObservationIdList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocObservationIdList cannot be null"); + } + byte[] idArr = new byte[ocObservationIdList.size()]; Iterator it = ocObservationIdList.iterator(); int i = 0; @@ -554,6 +601,49 @@ public final class OcPlatform { ) throws OcException; /** + * Set param Info + * + * @param ocDeviceInfo object containing all the device specific information + * @throws OcException if failure + */ + public static void setPropertyValue( + int path, String propName, String propValue) throws OcException { + OcPlatform.initCheck(); + OcPlatform.setPropertyValue1(path, propName, propValue); + } + + public static void setPropertyValue( + int path, String propName, List propValue) throws OcException { + OcPlatform.initCheck(); + OcPlatform.setPropertyValue0(path, propName, propValue.toArray(new String[propValue.size()])); + } + + public static void getPropertyValue( + int path, String propName, String propValue) throws OcException { + OcPlatform.initCheck(); + OcPlatform.getPropertyValue0(path, propName, propValue); + } + + private static native void setPropertyValue1( + int path, + String propName, + String propValue + ) throws OcException; + + + private static native void setPropertyValue0( + int path, + String propName, + String[] propValue + ) throws OcException; + + private static native void getPropertyValue0( + int path, + String propName, + String propValue + ) throws OcException; + + /** * Register Platform Info * * @param ocPlatformInfo object containing all the platform specific information @@ -631,6 +721,11 @@ public final class OcPlatform { OcResourceHandle ocResourceCollectionHandle, List ocResourceHandleList) throws OcException { OcPlatform.initCheck(); + + if (ocResourceHandleList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null"); + } + OcPlatform.bindResources0( ocResourceCollectionHandle, ocResourceHandleList.toArray( @@ -672,6 +767,11 @@ public final class OcPlatform { OcResourceHandle ocResourceCollectionHandle, List ocResourceHandleList) throws OcException { OcPlatform.initCheck(); + + if (ocResourceHandleList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "ocResourceHandleList cannot be null"); + } + OcPlatform.unbindResources0( ocResourceCollectionHandle, ocResourceHandleList.toArray( @@ -987,313 +1087,6 @@ public final class OcPlatform { throws OcException; /** - * API to publish resource to remote resource-directory. - * - * @param host Host Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param onPublishResourceListener Handles events, success states and failure states. - * @throws OcException if failure - */ - public static void publishResourceToRD( - String host, - EnumSet connectivityTypeSet, - OnPublishResourceListener onPublishResourceListener) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.publishResourceToRD0( - host, - connTypeInt, - onPublishResourceListener, - sPlatformQualityOfService.getValue() - ); - } - - /** - * API to publish resource to remote resource-directory. - * - * @param host Host Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param onPublishResourceListener Handles events, success states and failure states. - * @param qualityOfService the quality of communication. - * @throws OcException if failure - */ - public static void publishResourceToRD( - String host, - EnumSet connectivityTypeSet, - OnPublishResourceListener onPublishResourceListener, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.publishResourceToRD0( - host, - connTypeInt, - onPublishResourceListener, - qualityOfService.getValue() - ); - } - - private static native void publishResourceToRD0( - String host, - int connectivityType, - OnPublishResourceListener onPublishResourceListener, - int qualityOfService) throws OcException; - - /** - * API to publish resource to remote resource-directory. - * - * @param host Host Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param ocResourceHandleList reference to list of resource handles to be published. - * @param onPublishResourceListener Handles events, success states and failure states. - * @throws OcException if failure - */ - public static void publishResourceToRD( - String host, - EnumSet connectivityTypeSet, - List ocResourceHandleList, - OnPublishResourceListener onPublishResourceListener) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.publishResourceToRD1( - host, - connTypeInt, - ocResourceHandleList.toArray( - new OcResourceHandle[ocResourceHandleList.size()]), - onPublishResourceListener, - sPlatformQualityOfService.getValue() - ); - } - - /** - * API to publish resource to remote resource-directory. - * - * @param host Host IP Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param ocResourceHandleList reference to list of resource handles to be published. - * @param onPublishResourceListener Handles events, success states and failure states. - * @param qualityOfService the quality of communication - * @throws OcException if failure - */ - public static void publishResourceToRD( - String host, - EnumSet connectivityTypeSet, - List ocResourceHandleList, - OnPublishResourceListener onPublishResourceListener, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.publishResourceToRD1( - host, - connTypeInt, - ocResourceHandleList.toArray( - new OcResourceHandle[ocResourceHandleList.size()]), - onPublishResourceListener, - qualityOfService.getValue() - ); - } - - private static native void publishResourceToRD1( - String host, - int connectivityType, - OcResourceHandle[] ocResourceHandleArray, - OnPublishResourceListener onPublishResourceListener, - int qualityOfService) throws OcException; - - /** - * API to delete resource from remote resource-directory. - * - * @param host Host Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param onDeleteResourceListener Handles events, success states and failure states. - * @throws OcException if failure - */ - public static void deleteResourceFromRD( - String host, - EnumSet connectivityTypeSet, - OnDeleteResourceListener onDeleteResourceListener) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.deleteResourceFromRD0( - host, - connTypeInt, - onDeleteResourceListener, - sPlatformQualityOfService.getValue() - ); - } - - /** - * API to delete resource from remote resource-directory. - * - * @param host Host Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param onDeleteResourceListener Handles events, success states and failure states. - * @param qualityOfService the quality of communication. - * @throws OcException if failure - */ - public static void deleteResourceFromRD( - String host, - EnumSet connectivityTypeSet, - OnDeleteResourceListener onDeleteResourceListener, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.deleteResourceFromRD0( - host, - connTypeInt, - onDeleteResourceListener, - qualityOfService.getValue() - ); - } - - private static native void deleteResourceFromRD0( - String host, - int connectivityType, - OnDeleteResourceListener onDeleteResourceListener, - int qualityOfService) throws OcException; - - /** - * API to delete resource from remote resource-directory. - * - * @param host Host Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param ocResourceHandleList reference to list of resource handles to be published. - * @param onDeleteResourceListener Handles events, success states and failure states. - * @throws OcException if failure - */ - public static void deleteResourceFromRD( - String host, - EnumSet connectivityTypeSet, - List ocResourceHandleList, - OnDeleteResourceListener onDeleteResourceListener) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.deleteResourceFromRD1( - host, - connTypeInt, - ocResourceHandleList.toArray( - new OcResourceHandle[ocResourceHandleList.size()]), - onDeleteResourceListener, - sPlatformQualityOfService.getValue() - ); - } - - /** - * API to delete resource from remote resource-directory. - * - * @param host Host IP Address of a service to publish resource. - * @param connectivityTypeSet Set of types of connectivity. Example: IP - * @param ocResourceHandleList reference to list of resource handles to be published. - * @param onDeleteResourceListener Handles events, success states and failure states. - * @param qualityOfService the quality of communication - * @throws OcException if failure - */ - public static void deleteResourceFromRD( - String host, - EnumSet connectivityTypeSet, - List ocResourceHandleList, - OnDeleteResourceListener onDeleteResourceListener, - QualityOfService qualityOfService) throws OcException { - OcPlatform.initCheck(); - - int connTypeInt = 0; - - for (OcConnectivityType connType : OcConnectivityType.values()) { - if (connectivityTypeSet.contains(connType)) { - connTypeInt |= connType.getValue(); - } - } - - OcPlatform.deleteResourceFromRD1( - host, - connTypeInt, - ocResourceHandleList.toArray( - new OcResourceHandle[ocResourceHandleList.size()]), - onDeleteResourceListener, - qualityOfService.getValue() - ); - } - - private static native void deleteResourceFromRD1( - String host, - int connectivityType, - OcResourceHandle[] ocResourceHandleArray, - OnDeleteResourceListener onDeleteResourceListener, - int qualityOfService) throws OcException; - - /** - * An OnPublishResourceListener can be registered via the OcPlatform.publishResourceToRD call. - * Event listeners are notified asynchronously - */ - public interface OnPublishResourceListener { - public void onPublishResourceCompleted(OcRepresentation ocRepresentation); - public void onPublishResourceFailed(Throwable ex); - } - - /** - * An OnDeleteResourceListener can be registered via the OcPlatform.deleteResourceFromRD call. - * Event listeners are notified asynchronously - */ - public interface OnDeleteResourceListener { - public void onDeleteResourceCompleted(int result); - } - - /** * An FindDirectPairingListener can be registered via the OcPlatform.findDirectPairingDevices call. * Event listeners are notified asynchronously */ @@ -1368,6 +1161,16 @@ public final class OcPlatform { 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 " + @@ -1419,4 +1222,52 @@ public final class OcPlatform { private static native OcAccountManager constructAccountManagerObject0( String host, int connectivityType) throws OcException; + /** + * Method to get device Id in byte array. + * @return My DeviceId. + */ + public static native byte[] getDeviceId(); + + /** + * 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; }