From 94651923bf67705c1b4bd61ab251e8c598d2a807 Mon Sep 17 00:00:00 2001 From: Youngjae Shin Date: Tue, 1 Nov 2016 16:39:53 +0900 Subject: [PATCH] Imported Upstream version 1.2.0 --- .gbs.conf | 4 + .gitignore | 27 +- Readme.scons.txt | 2 + SConstruct | 4 +- android/android_api/SConscript | 45 +- android/android_api/base/build.gradle | 69 +- android/android_api/base/jni/Android.mk | 62 +- android/android_api/base/jni/JniCaInterface.c | 128 +- android/android_api/base/jni/JniCaInterface.h | 19 +- .../android_api/base/jni/JniDisplayPinListener.cpp | 9 +- android/android_api/base/jni/JniEntityHandler.cpp | 9 +- .../base/jni/JniGetAclIdByDeviceListener.cpp | 128 ++ .../base/jni/JniGetAclIdByDeviceListener.h | 46 + android/android_api/base/jni/JniListenerManager.h | 56 +- .../android_api/base/jni/JniOcAccountManager.cpp | 1540 ++++++++++++++ android/android_api/base/jni/JniOcAccountManager.h | 308 +++ .../base/jni/JniOcCloudProvisioning.cpp | 576 +++++ .../android_api/base/jni/JniOcCloudProvisioning.h | 110 + .../base/jni/JniOcCloudResultListener.cpp | 155 ++ .../base/jni/JniOcCloudResultListener.h | 52 + .../android_api/base/jni/JniOcDirectPairDevice.cpp | 23 +- android/android_api/base/jni/JniOcPlatform.cpp | 836 +++++++- android/android_api/base/jni/JniOcPlatform.h | 84 + .../android_api/base/jni/JniOcPresenceHandle.cpp | 17 +- android/android_api/base/jni/JniOcPresenceHandle.h | 4 + android/android_api/base/jni/JniOcProvisioning.cpp | 40 +- android/android_api/base/jni/JniOcProvisioning.h | 8 +- .../android_api/base/jni/JniOcRepresentation.cpp | 265 ++- android/android_api/base/jni/JniOcRepresentation.h | 434 +++- .../android_api/base/jni/JniOcRequestHandle.cpp | 5 +- android/android_api/base/jni/JniOcResource.cpp | 654 +++++- android/android_api/base/jni/JniOcResource.h | 91 +- .../android_api/base/jni/JniOcResourceHandle.cpp | 5 +- .../base/jni/JniOcResourceIdentifier.cpp | 15 +- .../android_api/base/jni/JniOcResourceRequest.cpp | 68 +- .../android_api/base/jni/JniOcResourceResponse.cpp | 81 +- .../android_api/base/jni/JniOcSecureResource.cpp | 147 +- android/android_api/base/jni/JniOcSecureResource.h | 14 +- android/android_api/base/jni/JniOcStack.cpp | 148 +- android/android_api/base/jni/JniOcStack.h | 18 + .../base/jni/JniOnDPDevicesFoundListener.cpp | 45 +- .../android_api/base/jni/JniOnDeleteListener.cpp | 94 +- android/android_api/base/jni/JniOnDeleteListener.h | 11 +- .../base/jni/JniOnDeleteResourceListener.cpp | 112 + .../base/jni/JniOnDeleteResourceListener.h | 40 + .../base/jni/JniOnDeviceInfoListener.cpp | 46 +- .../base/jni/JniOnDirectPairingListener.cpp | 60 +- android/android_api/base/jni/JniOnGetListener.cpp | 98 +- android/android_api/base/jni/JniOnGetListener.h | 12 +- .../base/jni/JniOnMQSubscribeListener.cpp | 208 ++ .../base/jni/JniOnMQSubscribeListener.h | 45 + .../base/jni/JniOnMQTopicFoundListener.cpp | 265 +++ .../base/jni/JniOnMQTopicFoundListener.h | 46 + .../android_api/base/jni/JniOnObserveListener.cpp | 151 +- .../android_api/base/jni/JniOnObserveListener.h | 12 +- .../base/jni/JniOnPlatformInfoListener.cpp | 44 +- android/android_api/base/jni/JniOnPostListener.cpp | 101 +- android/android_api/base/jni/JniOnPostListener.h | 11 +- .../android_api/base/jni/JniOnPresenceListener.cpp | 62 +- .../base/jni/JniOnPublishResourceListener.cpp | 158 ++ .../base/jni/JniOnPublishResourceListener.h | 40 + android/android_api/base/jni/JniOnPutListener.cpp | 63 +- .../base/jni/JniOnResourceFoundListener.cpp | 133 +- .../base/jni/JniOnResourceFoundListener.h | 1 + .../android_api/base/jni/JniPinCheckListener.cpp | 40 +- .../base/jni/JniProvisionResultListner.cpp | 55 +- .../base/jni/JniProvisionResultListner.h | 1 + android/android_api/base/jni/JniSecureUtils.cpp | 104 - android/android_api/base/jni/JniSecureUtils.h | 1 - android/android_api/base/jni/JniUtils.cpp | 128 +- android/android_api/base/jni/JniUtils.h | 333 +-- .../org/iotivity/base/OcRepresentationTest.java | 52 +- .../java/org/iotivity/base/SmokeTest.java | 125 +- .../main/java/org/iotivity/base/AclGroupType.java | 38 + .../src/main/java/org/iotivity/base/CredType.java | 38 +- .../main/java/org/iotivity/base/DeviceStatus.java | 38 +- .../main/java/org/iotivity/base/EncodingType.java | 42 + .../org/iotivity/base/EntityHandlerResult.java | 38 +- .../src/main/java/org/iotivity/base/ErrorCode.java | 39 +- .../src/main/java/org/iotivity/base/KeySize.java | 38 +- .../src/main/java/org/iotivity/base/ModeType.java | 38 +- .../java/org/iotivity/base/ObservationInfo.java | 38 +- .../main/java/org/iotivity/base/ObserveAction.java | 38 +- .../main/java/org/iotivity/base/ObserveType.java | 38 +- .../java/org/iotivity/base/OcAccountManager.java | 509 +++++ .../org/iotivity/base/OcCloudProvisioning.java | 138 ++ .../java/org/iotivity/base/OcConnectivityType.java | 40 +- .../main/java/org/iotivity/base/OcDeviceInfo.java | 38 +- .../main/java/org/iotivity/base/OcException.java | 38 +- .../java/org/iotivity/base/OcHeaderOption.java | 38 +- .../main/java/org/iotivity/base/OcPlatform.java | 454 +++- .../java/org/iotivity/base/OcPlatformInfo.java | 38 +- .../java/org/iotivity/base/OcPlatformStatus.java | 38 +- .../java/org/iotivity/base/OcPresenceHandle.java | 38 +- .../java/org/iotivity/base/OcPresenceStatus.java | 38 +- .../java/org/iotivity/base/OcProvisioning.java | 51 +- .../java/org/iotivity/base/OcRepresentation.java | 49 +- .../java/org/iotivity/base/OcRequestHandle.java | 38 +- .../main/java/org/iotivity/base/OcResource.java | 301 ++- .../java/org/iotivity/base/OcResourceHandle.java | 38 +- .../org/iotivity/base/OcResourceIdentifier.java | 38 +- .../java/org/iotivity/base/OcResourceRequest.java | 38 +- .../java/org/iotivity/base/OcResourceResponse.java | 38 +- .../java/org/iotivity/base/OcSecureResource.java | 72 +- .../main/java/org/iotivity/base/OwnedStatus.java | 38 +- .../src/main/java/org/iotivity/base/OxmType.java | 38 +- .../java/org/iotivity/base/PlatformConfig.java | 38 +- .../java/org/iotivity/base/QualityOfService.java | 38 +- .../java/org/iotivity/base/RequestHandlerFlag.java | 38 +- .../main/java/org/iotivity/base/RequestType.java | 38 +- .../java/org/iotivity/base/ResourceProperty.java | 38 +- .../main/java/org/iotivity/base/ServiceType.java | 38 +- .../java/org/iotivity/ca/CaBtPairingInterface.java | 4 +- .../main/java/org/iotivity/ca/CaEdrInterface.java | 17 +- .../src/main/java/org/iotivity/ca/CaInterface.java | 62 +- .../main/java/org/iotivity/ca/CaIpInterface.java | 4 +- .../java/org/iotivity/ca/CaLeClientInterface.java | 13 +- .../main/java/org/iotivity/ca/CaNfcInterface.java | 4 +- .../src/main/java/org/iotivity/ca/OicCipher.java | 38 + android/android_api/build.gradle | 38 +- android/android_api/gradlew | 328 +-- android/android_api/settings.gradle | 38 +- .../assets/oic_svr_db_client_directpairing.dat | Bin 778 -> 996 bytes .../examples/cloudprovisioningclient/build.gradle | 37 + .../cloudprovisioningclient.iml | 96 + .../cloudprovisioningclient/proguard-rules.pro | 17 + .../src/main/AndroidManifest.xml | 22 + .../src/main/assets/oic_svr_db_client.dat | Bin 0 -> 1046 bytes .../src/main/assets/oic_svr_db_client.json | 59 +- .../CloudProvisioningClient.java | 666 ++++++ .../cloudprovisioningclient/LoginActivity.java | 86 + .../cloudprovisioningclient/StringConstants.java | 35 + .../src/main/res/drawable/dash_nil_border.xml | 30 + .../src/main/res/drawable/round_button.xml | 8 + .../src/main/res/layout/activity_login.xml | 16 + .../src/main/res/layout/main_activity.xml | 207 ++ .../src/main/res/layout/setting_layout.xml | 69 + .../src/main/res/menu/menu_cloud_provision.xml | 8 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../src/main/res/values-v21/styles.xml | 5 + .../src/main/res/values-w820dp/dimens.xml | 6 + .../src/main/res/values/dimens.xml | 5 + .../src/main/res/values/strings.xml | 6 + .../src/main/res/values/styles.xml | 8 + .../base/examples/DeviceDiscoveryClient.java | 38 +- .../base/examples/DeviceDiscoveryServer.java | 60 +- .../org/iotivity/base/examples/FridgeClient.java | 53 +- .../iotivity/base/examples/FridgeGroupClient.java | 46 +- .../org/iotivity/base/examples/DoorResource.java | 40 +- .../iotivity/base/examples/FridgeGroupServer.java | 38 +- .../org/iotivity/base/examples/FridgeResource.java | 38 +- .../org/iotivity/base/examples/LightResource.java | 38 +- .../org/iotivity/base/examples/Refrigerator.java | 40 +- .../java/org/iotivity/base/examples/Resource.java | 40 +- .../base/examples/fridgeserver/DeviceResource.java | 38 +- .../base/examples/fridgeserver/DoorResource.java | 40 +- .../base/examples/fridgeserver/FridgeServer.java | 38 +- .../base/examples/fridgeserver/LightResource.java | 38 +- .../base/examples/fridgeserver/Refrigerator.java | 38 +- .../base/examples/fridgeserver/Resource.java | 40 +- .../org/iotivity/base/examples/GroupClient.java | 44 +- .../org/iotivity/base/examples/GroupServer.java | 46 +- .../org/iotivity/base/examples/PresenceClient.java | 46 +- .../org/iotivity/base/examples/PresenceServer.java | 40 +- .../src/main/assets/oic_svr_db_client.dat | Bin 1046 -> 879 bytes .../src/main/assets/oic_svr_db_client.json | 30 +- .../provisioningclient/src/main/assets/rootca.crt | 19 + .../provisioningclient/ProvisioningClient.java | 97 +- .../provisioningclient/StringConstants.java | 1 + android/examples/settings.gradle | 8 + android/examples/simplebase/.gitignore | 1 + android/examples/simplebase/build.gradle | 38 + .../simplebase/libs/android-support-v4.jar | Bin 0 -> 1422188 bytes android/examples/simplebase/proguard-rules.pro | 17 + android/examples/simplebase/simplebase.iml | 96 + .../simplebase/src/main/AndroidManifest.xml | 41 + .../iotivity/base/examples/BluetoothFragment.java | 388 ++++ .../org/iotivity/base/examples/CloudFragment.java | 1403 ++++++++++++ .../java/org/iotivity/base/examples/Common.java | 86 + .../org/iotivity/base/examples/DrawerFragment.java | 203 ++ .../org/iotivity/base/examples/LoginActivity.java | 84 + .../iotivity/base/examples/MessageFragment.java | 587 +++++ .../org/iotivity/base/examples/SimpleBase.java | 101 + .../iotivity/base/examples/TemplateFragment.java | 100 + .../src/main/res/drawable-hdpi/drawer_shadow.9.png | Bin 0 -> 161 bytes .../src/main/res/drawable-hdpi/ic_drawer.png | Bin 0 -> 2829 bytes .../src/main/res/drawable-mdpi/drawer_shadow.9.png | Bin 0 -> 142 bytes .../src/main/res/drawable-mdpi/ic_drawer.png | Bin 0 -> 2820 bytes .../main/res/drawable-xhdpi/drawer_shadow.9.png | Bin 0 -> 174 bytes .../src/main/res/drawable-xhdpi/ic_drawer.png | Bin 0 -> 2836 bytes .../main/res/drawable-xxhdpi/drawer_shadow.9.png | Bin 0 -> 208 bytes .../src/main/res/drawable-xxhdpi/ic_drawer.png | Bin 0 -> 202 bytes .../src/main/res/drawable/iotivityicon.png | Bin 0 -> 2300 bytes .../src/main/res/drawable/iotivitylogo.png | Bin 0 -> 123110 bytes .../src/main/res/layout/activity_login.xml | 16 + .../src/main/res/layout/activity_simplebase.xml | 22 + .../src/main/res/layout/fragment_bluetooth.xml | 52 + .../src/main/res/layout/fragment_cloud.xml | 310 +++ .../src/main/res/layout/fragment_drawer.xml | 10 + .../src/main/res/layout/fragment_message.xml | 220 ++ .../src/main/res/layout/fragment_template.xml | 42 + .../simplebase/src/main/res/layout/input.xml | 28 + .../src/main/res/mipmap-hdpi/iotivityicon.png | Bin 0 -> 2300 bytes .../src/main/res/mipmap-mdpi/iotivityicon.png | Bin 0 -> 1300 bytes .../src/main/res/mipmap-xhdpi/iotivityicon.png | Bin 0 -> 2862 bytes .../src/main/res/mipmap-xxhdpi/iotivityicon.png | Bin 0 -> 2651 bytes .../simplebase/src/main/res/values-v21/styles.xml | 5 + .../src/main/res/values-w820dp/dimens.xml | 6 + .../simplebase/src/main/res/values/dimens.xml | 7 + .../simplebase/src/main/res/values/strings.xml | 34 + .../simplebase/src/main/res/values/styles.xml | 8 + .../src/main/assets/oic_svr_db_client.dat | Bin 1226 -> 1112 bytes .../src/main/assets/oic_svr_db_client.json | 16 +- .../java/org/iotivity/base/examples/Light.java | 38 +- .../org/iotivity/base/examples/SimpleClient.java | 148 +- .../src/main/assets/oic_svr_db_server.dat | Bin 1421 -> 1369 bytes .../src/main/assets/oic_svr_db_server.json | 10 +- .../java/org/iotivity/base/examples/Light.java | 41 +- .../org/iotivity/base/examples/SimpleServer.java | 38 +- auto_build.py | 521 +++++ auto_build.sh | 299 +-- build_common/SConscript | 96 +- build_common/android/SConscript | 4 +- build_common/arduino/SConscript | 3 + build_common/darwin/SConscript | 3 +- build_common/external_libs.scons | 12 +- build_common/linux/SConscript | 6 +- build_common/msys_nt/SConscript | 33 + build_common/thread.scons | 17 + build_common/tizen/SConscript | 2 +- build_common/tools/UnpackAll.py | 23 +- build_common/windows/SConscript | 45 +- build_docs.sh | 52 - cloud/.gitignore | 10 +- cloud/README | 8 +- cloud/SConscript | 2 +- cloud/account/.classpath | 26 - cloud/account/.gitignore | 1 - cloud/account/.project | 23 - cloud/account/Github.jar | Bin 0 -> 2768 bytes cloud/account/Google.jar | Bin 0 -> 3220 bytes cloud/account/README | 15 +- cloud/account/pom.xml | 124 +- cloud/account/properties/config.properties | 18 + .../cloud/accountserver/AccountServer.java | 56 +- .../cloud/accountserver/AccountServerManager.java | 197 -- .../iotivity/cloud/accountserver/Constants.java | 264 ++- .../cloud/accountserver/db/AccountDBManager.java | 289 ++- .../iotivity/cloud/accountserver/db/AclTable.java | 88 + .../iotivity/cloud/accountserver/db/CRLTable.java | 65 + .../cloud/accountserver/db/CertificateTable.java | 100 + .../cloud/accountserver/db/GroupTable.java | 175 ++ .../cloud/accountserver/db/InviteTable.java | 101 + .../iotivity/cloud/accountserver/db/MongoDB.java | 334 +-- .../cloud/accountserver/db/TokenTable.java | 179 ++ .../iotivity/cloud/accountserver/db/UserTable.java | 115 + .../oauth/{GitHub.java => Github.java} | 69 +- .../iotivity/cloud/accountserver/oauth/Google.java | 195 ++ .../cloud/accountserver/oauth/OAuthProvider.java | 67 + .../accountserver/oauth/OAuthProviderFactory.java | 173 ++ .../accountserver/resources/AccountResource.java | 253 --- .../accountserver/resources/AuthResource.java | 273 --- .../resources/account/AccountManager.java | 575 +++++ .../resources/account/AccountResource.java | 166 ++ .../resources/account/session/SessionResource.java | 121 ++ .../account/tokenrefresh/TokenRefreshResource.java | 112 + .../accountserver/resources/acl/group/Group.java | 342 +++ .../resources/acl/group/GroupManager.java | 341 +++ .../resources/acl/group/GroupResource.java | 210 ++ .../cloud/accountserver/resources/acl/id/Ace.java | 104 + .../resources/acl/id/AceResource.java | 71 + .../cloud/accountserver/resources/acl/id/Acl.java | 365 ++++ .../accountserver/resources/acl/id/AclManager.java | 136 ++ .../resources/acl/id/AclResource.java | 200 ++ .../resources/acl/invite/InviteManager.java | 307 +++ .../resources/acl/invite/InviteResource.java | 192 ++ .../resources/acl/verify/AclVerifyResource.java | 153 ++ .../resources/acl/verify/Permission.java | 19 + .../credprov/cert/CertificateConstants.java | 175 ++ .../credprov/cert/CertificateManager.java | 136 ++ .../credprov/cert/CertificateResource.java | 253 +++ .../credprov/cert/CertificateStorage.java | 138 ++ .../resources/credprov/crl/CrlManager.java | 173 ++ .../resources/credprov/crl/CrlResource.java | 185 ++ .../accountserver/util/CoapMessageBuilder.java | 136 -- .../accountserver/util/TypeCastingManager.java | 72 + .../cloud/accountserver/x509/cert/CSRParser.java | 112 + .../x509/cert/CertificateBuilder.java | 123 ++ .../x509/cert/CertificateExtension.java | 76 + .../cloud/accountserver/x509/cert/Utility.java | 77 + .../cloud/accountserver/x509/crl/CrlIssuer.java | 73 + .../resources/account/AccountResourceTest.java | 454 ++++ .../credprov/cert/CertificateResourceTest.java | 343 +++ .../account/credprov/cert/GenerateCSR.java | 63 + .../account/credprov/crl/CrlResourceTest.java | 592 ++++++ .../account/session/SessionResourceTest.java | 371 ++++ .../tokenrefresh/TokenRefreshResourceTest.java | 173 ++ .../resources/acl/group/GroupResourceTest.java | 467 ++++ .../resources/acl/invite/InviteResourceTest.java | 421 ++++ .../cloud/testaccountserver/TestAccountServer.java | 168 -- cloud/certificate/iotivitycloud.crt | 19 + cloud/certificate/iotivitycloud.key | 28 + cloud/certificate/rootca.crt | 19 + cloud/interface/.classpath | 26 - cloud/interface/.gitignore | 1 - cloud/interface/.project | 23 - cloud/interface/README | 7 +- cloud/interface/pom.xml | 50 +- .../cloud/ciserver/CloudInterfaceServer.java | 116 +- .../org/iotivity/cloud/ciserver/Constants.java | 40 +- .../cloud/ciserver/DeviceServerSystem.java | 406 ++++ .../cloud/ciserver/protocols/CoapAuthHandler.java | 153 -- .../cloud/ciserver/protocols/CoapRelayHandler.java | 341 --- .../cloud/ciserver/resources/DiResource.java | 217 ++ .../ciserver/resources/KeepAliveResource.java | 199 +- .../ciserver/resources/proxy/account/Account.java | 106 + .../resources/proxy/account/AccountSession.java | 73 + .../ciserver/resources/proxy/account/Acl.java | 55 + .../ciserver/resources/proxy/account/AclGroup.java | 116 + .../resources/proxy/account/AclInvite.java | 95 + .../resources/proxy/account/Certificate.java | 55 + .../ciserver/resources/proxy/account/Crl.java | 30 + .../ciserver/resources/proxy/mq/MessageQueue.java | 57 + .../resources/proxy/rd/DevicePresence.java | 172 ++ .../resources/proxy/rd/ResourceDirectory.java | 254 +++ .../ciserver/resources/proxy/rd/ResourceFind.java | 176 ++ .../resources/proxy/rd/ResourcePresence.java | 171 ++ .../cloud/ciserver/DeviceServerSystemTest.java | 452 ++++ .../cloud/ciserver/resources/DiResourceTest.java | 231 ++ .../ciserver/resources/KeepAliveResourceTest.java | 139 ++ .../proxy/account/AccountSessionTest.java | 160 ++ .../resources/proxy/account/AccountTest.java | 175 ++ .../resources/proxy/account/AclGroupTest.java | 231 ++ .../resources/proxy/account/AclInviteTest.java | 154 ++ .../ciserver/resources/proxy/account/AclTest.java | 101 + .../resources/proxy/account/CertificateTest.java | 104 + .../resources/proxy/mq/MessageQueueTest.java | 103 + .../resources/proxy/rd/DevicePresenceTest.java | 232 ++ .../resources/proxy/rd/ResourceDirectoryTest.java | 275 +++ .../resources/proxy/rd/ResourceFindTest.java | 249 +++ .../resources/proxy/rd/ResourcePresenceTest.java | 187 ++ .../cloud/ciserver/testci/TestCloudInterface.java | 275 --- cloud/messagequeue/README | 39 + cloud/messagequeue/pom.xml | 101 + cloud/messagequeue/server.properties | 138 ++ .../org/iotivity/cloud/mqserver/Constants.java | 39 + .../cloud/mqserver/MessageQueueServer.java | 78 + .../iotivity/cloud/mqserver/MessageQueueUtils.java | 85 + .../cloud/mqserver/kafka/KafkaCommonWrapper.java | 106 + .../cloud/mqserver/kafka/KafkaConsumerWrapper.java | 310 +++ .../cloud/mqserver/kafka/KafkaProducerWrapper.java | 102 + .../cloud/mqserver/resources/MQBrokerResource.java | 307 +++ .../org/iotivity/cloud/mqserver/topic/Topic.java | 346 +++ .../cloud/mqserver/topic/TopicManager.java | 197 ++ .../mqserver/resources/MQBrokerResourceTest.java | 697 ++++++ cloud/resourcedirectory/.classpath | 26 - cloud/resourcedirectory/.gitignore | 1 - cloud/resourcedirectory/.project | 23 - cloud/resourcedirectory/README | 5 +- cloud/resourcedirectory/pom.xml | 16 +- .../org/iotivity/cloud/rdserver/Constants.java | 79 +- .../java/org/iotivity/cloud/rdserver/MongoDB.java | 359 ---- .../cloud/rdserver/ResourceDirectoryServer.java | 46 +- .../org/iotivity/cloud/rdserver/db/DBManager.java | 248 +++ .../org/iotivity/cloud/rdserver/db/MongoDB.java | 337 +++ .../rdserver/resources/LinksPayloadFormat.java | 147 -- .../rdserver/resources/PublishPayloadFormat.java | 139 -- .../resources/ResourceDirectoryResource.java | 530 ----- .../resources/directory/PayloadManager.java | 103 + .../rdserver/resources/directory/RDManager.java | 293 +++ .../resources/directory/rd/InsManager.java | 84 + .../directory/rd/ResourceDirectoryResource.java | 154 ++ .../resources/directory/res/DiscoveryResource.java | 96 + .../resources/presence/PresenceManager.java | 348 +++ .../presence/device/DevicePresenceResource.java | 129 ++ .../presence/resource/ResPresenceResource.java | 83 + .../testrdserver/DevicePresenceResourceTest.java | 248 +++ .../cloud/testrdserver/DiscoveryResourceTest.java | 151 ++ .../iotivity/cloud/testrdserver/RDServerTest.java | 281 --- .../cloud/testrdserver/RDServerTestUtils.java | 56 + .../ResourceDirectoryResourceTest.java | 180 ++ .../testrdserver/ResourcePresenceResourceTest.java | 139 ++ cloud/samples/client/README | 21 +- cloud/samples/client/SConscript | 78 +- .../client/airconditioner/aircon_controlee.cpp | 690 ++++++ .../client/airconditioner/aircon_controller.cpp | 369 ++++ cloud/samples/client/cloud_connector.c | 292 --- cloud/samples/client/group_invite/group_invite.cpp | 393 ++++ .../client/group_invite/group_light_share.cpp | 432 ++++ cloud/samples/client/messagequeue/mq_publisher.cpp | 307 +++ .../samples/client/messagequeue/mq_subscriber.cpp | 309 +++ cloud/samples/client/sample_device.cpp | 853 -------- .../samples/client/thin_light/thin_room_light.cpp | 716 +++++++ cloud/stack/.classpath | 21 - cloud/stack/.gitignore | 1 - cloud/stack/.project | 23 - cloud/stack/pom.xml | 38 +- cloud/stack/src/main/java/log4j.properties | 11 + .../java/org/iotivity/cloud/base/CoapClient.java | 123 -- .../java/org/iotivity/cloud/base/HttpServer.java | 139 -- .../java/org/iotivity/cloud/base/OICConstants.java | 126 ++ .../org/iotivity/cloud/base/ResourceManager.java | 77 - .../java/org/iotivity/cloud/base/ServerSystem.java | 158 ++ .../org/iotivity/cloud/base/SessionManager.java | 86 - .../iotivity/cloud/base/connector/CoapClient.java | 164 ++ .../cloud/base/connector/CoapConnector.java | 168 ++ .../cloud/base/connector/ConnectorPool.java | 52 + .../cloud/base/{ => connector}/HttpClient.java | 30 +- .../org/iotivity/cloud/base/device/CoapDevice.java | 210 ++ .../base/{Resource.java => device/Device.java} | 46 +- .../iotivity/cloud/base/device/HttpDevice.java} | 56 +- .../cloud/base/device/IRequestChannel.java | 29 + .../cloud/base/device/IRequestEventHandler.java | 30 + .../cloud/base/device/IResponseEventHandler.java | 29 + .../cloud/base/exception/ClientException.java | 25 + .../cloud/base/exception/ServerException.java | 106 + .../iotivity/cloud/base/protocols/IRequest.java} | 52 +- .../iotivity/cloud/base/protocols/IResponse.java} | 32 +- .../org/iotivity/cloud/base/protocols/Message.java | 126 ++ .../cloud/base/protocols/MessageBuilder.java | 139 ++ .../cloud/base/protocols/coap/CoapDecoder.java | 8 +- .../cloud/base/protocols/coap/CoapEncoder.java | 10 +- .../cloud/base/protocols/coap/CoapLogHandler.java | 247 +++ .../cloud/base/protocols/coap/CoapMessage.java | 292 ++- .../protocols/coap/{enums => }/CoapOption.java | 23 +- .../cloud/base/protocols/coap/CoapRequest.java | 123 +- .../cloud/base/protocols/coap/CoapResponse.java | 142 +- .../base/protocols/coap/enums/CoapMethod.java | 33 - .../base/protocols/coap/enums/CoapStatus.java | 97 - .../cloud/base/protocols/enums/ContentFormat.java | 26 + .../cloud/base/protocols/enums/Observe.java | 26 + .../cloud/base/protocols/enums/RequestMethod.java | 26 + .../cloud/base/protocols/enums/ResponseStatus.java | 39 + .../cloud/base/protocols/http/HttpMessage.java | 26 + .../base/protocols/proxy/CoapHttpProxyHandler.java | 204 -- .../org/iotivity/cloud/base/resource/Resource.java | 131 ++ .../cloud/base/resource/ResourceManager.java | 54 + .../iotivity/cloud/base/resource/URIPathNode.java | 64 + .../iotivity/cloud/base/server/CoapServer.java} | 31 +- .../iotivity/cloud/base/server/HttpServer.java} | 33 +- .../base/{CoapServer.java => server/Server.java} | 94 +- .../main/java/org/iotivity/cloud/util/Bytes.java | 78 + .../main/java/org/iotivity/cloud/util/Cbor.java | 11 +- .../org/iotivity/cloud/util/CoapLogHandler.java | 179 -- .../java/org/iotivity/cloud/util/JSONUtil.java | 62 +- .../iotivity/cloud/util/{Logger.java => Log.java} | 73 +- .../org/iotivity/cloud/base/CoapClientTest.java | 104 - .../iotivity/cloud/base/ResourceManagerTest.java | 66 - .../java/org/iotivity/cloud/base/ResourceTest.java | 54 - .../iotivity/cloud/base/SessionManagerTest.java | 99 - .../cloud/base/protocols/coap/CoapRequestTest.java | 91 - .../base/protocols/coap/CoapResponseTest.java | 21 - .../java/org/iotivity/cloud/util/UtilTest.java | 55 - examples/OICMiddle/SConscript | 7 +- examples/OICMiddle/WrapResource.h | 3 +- examples/OICSensorBoard/Makefile | 23 +- extlibs/asn1cert/SConscript | 57 - extlibs/asn1cert/certificate.asn | 61 - extlibs/asn1cert/crl.asn | 45 - extlibs/asn1cert/csr.asn | 42 - extlibs/boost/SConscript | 62 +- extlibs/cjson/cJSON.h | 6 +- extlibs/gtest/SConscript | 92 +- extlibs/hippomocks.scons | 4 +- extlibs/libcoap/SConscript | 170 ++ extlibs/libstrophe/SConscript | 57 +- extlibs/mbedtls/SConscript | 148 ++ extlibs/mbedtls/ocf.patch | 640 ++++++ extlibs/sqlite3/SConscript | 47 +- extlibs/timer/SConscript | 7 +- extlibs/timer/timer.c | 22 +- extlibs/timer/timer.h | 6 +- extlibs/tinycbor/SConscript | 4 +- extlibs/tinydtls/SConscript | 36 +- extlibs/tinydtls/alert.h | 4 +- extlibs/tinydtls/ccm.c | 6 +- extlibs/tinydtls/crypto.c | 12 +- extlibs/tinydtls/crypto.h | 4 +- extlibs/tinydtls/debug.c | 10 +- extlibs/tinydtls/debug.h | 24 +- extlibs/tinydtls/dtls.c | 73 +- extlibs/tinydtls/dtls.h | 22 +- extlibs/tinydtls/dtls_config.h | 19 + extlibs/tinydtls/dtls_time.c | 13 + extlibs/tinydtls/dtls_time.h | 2 + extlibs/tinydtls/ecc/ecc.c | 8 +- extlibs/tinydtls/global.h | 6 +- extlibs/tinydtls/hmac.c | 8 +- extlibs/tinydtls/hmac.h | 8 +- extlibs/tinydtls/netq.c | 8 +- extlibs/tinydtls/netq.h | 2 +- extlibs/tinydtls/numeric.h | 24 +- extlibs/tinydtls/peer.c | 4 +- extlibs/tinydtls/peer.h | 14 +- extlibs/tinydtls/prng.h | 10 +- extlibs/tinydtls/session.c | 7 +- extlibs/tinydtls/session.h | 17 + extlibs/tinydtls/t_list.h | 14 +- extlibs/tinydtls/tests/dtls-client.c | 24 +- extlibs/tinydtls/tests/dtls-server.c | 19 +- extlibs/tinydtls/tinydtls.h | 12 + extlibs/tinydtls/utlist.h | 8 +- extlibs/wksxmppxep/SConscript | 37 +- gbsbuild.sh | 65 +- iotivity.pc.in | 3 +- plugins/SConscript | 2 +- plugins/samples/linux/IotivityandZigbeeClient.c | 3 +- plugins/samples/linux/IotivityandZigbeeServer.c | 1 - plugins/samples/linux/SConscript | 2 +- plugins/src/SConscript | 16 +- plugins/src/pluginlist.c | 2 +- plugins/unittests/SConscript | 7 +- plugins/zigbee_wrapper/src/SConscript | 2 +- plugins/zigbee_wrapper/src/zigbee_wrapper.c | 2 +- .../telegesis_wrapper/include/twsocketlist.h | 3 +- .../telegesis_wrapper/src/SConscript | 2 +- .../telegesis_wrapper/src/telegesis_wrapper.c | 72 +- resource/SConscript | 28 +- resource/c_common/SConscript | 132 +- .../inc/pkix => c_common}/byte_array.h | 8 +- resource/c_common/ocrandom/include/ocrandom.h | 4 +- resource/c_common/ocrandom/src/ocrandom.c | 41 +- resource/c_common/ocrandom/test/SConscript | 12 +- resource/c_common/oic_malloc/test/SConscript | 5 +- resource/c_common/oic_string/include/oic_string.h | 8 + resource/c_common/oic_string/src/oic_string.c | 11 + resource/c_common/oic_string/test/SConscript | 9 +- resource/c_common/oic_time/include/oic_time.h | 3 + resource/c_common/oic_time/src/oic_time.c | 21 +- resource/c_common/oic_time/test/SConscript | 3 - resource/c_common/platform_features.h | 54 +- resource/c_common/windows/SConscript | 29 + resource/c_common/windows/include/getopt.h | 20 + resource/c_common/windows/include/pthread_create.h | 26 + resource/c_common/windows/include/vs12_snprintf.h | 40 + resource/c_common/windows/include/win_sleep.h | 45 + resource/c_common/windows/src/getopt.c | 52 + resource/c_common/windows/src/pthread_create.c | 23 + resource/c_common/windows/src/snprintf.c | 41 + resource/c_common/windows/src/win_sleep.c | 62 + resource/csdk/SConscript | 123 +- resource/csdk/connectivity/SConscript | 34 +- resource/csdk/connectivity/api/cacommon.h | 242 ++- resource/csdk/connectivity/api/cainterface.h | 11 +- .../csdk/connectivity/api/casecurityinterface.h | 140 +- resource/csdk/connectivity/api/cautilinterface.h | 35 +- resource/csdk/connectivity/build/SConscript | 10 +- .../csdk/connectivity/build/android/SConscript | 2 +- resource/csdk/connectivity/build/linux/SConscript | 3 +- resource/csdk/connectivity/build/tizen/gbsbuild.sh | 13 +- .../build/tizen/packaging/com.oic.ca.spec | 7 +- .../csdk/connectivity/build/tizen/scons/SConscript | 3 +- resource/csdk/connectivity/common/SConscript | 2 +- .../csdk/connectivity/common/inc/cacommonutil.h | 3 +- resource/csdk/connectivity/common/inc/camutex.h | 10 - .../csdk/connectivity/common/src/camutex_noop.c | 15 +- .../connectivity/common/src/camutex_pthreads.c | 157 +- .../csdk/connectivity/common/src/caremotehandler.c | 18 +- .../common/src/cathreadpool_pthreads.c | 34 +- resource/csdk/connectivity/common/src/uqueue.c | 4 +- .../csdk/connectivity/inc/ca_adapter_net_ssl.h | 192 ++ .../csdk/connectivity/inc/caadapterinterface.h | 9 +- resource/csdk/connectivity/inc/caadapternetdtls.h | 21 +- resource/csdk/connectivity/inc/caadapterutils.h | 26 +- .../csdk/connectivity/inc/cablockwisetransfer.h | 31 +- resource/csdk/connectivity/inc/caedradapter.h | 6 +- resource/csdk/connectivity/inc/cafragmentation.h | 297 +++ resource/csdk/connectivity/inc/cagattservice.h | 4 +- .../csdk/connectivity/inc/cainterfacecontroller.h | 13 +- resource/csdk/connectivity/inc/caipadapter.h | 7 +- resource/csdk/connectivity/inc/caipinterface.h | 20 +- resource/csdk/connectivity/inc/camessagehandler.h | 9 +- resource/csdk/connectivity/inc/canfcadapter.h | 7 +- resource/csdk/connectivity/inc/caprotocolmessage.h | 13 +- resource/csdk/connectivity/inc/caraadapter.h | 5 +- resource/csdk/connectivity/inc/caretransmission.h | 11 +- resource/csdk/connectivity/inc/catcpadapter.h | 24 +- resource/csdk/connectivity/inc/catcpinterface.h | 37 + resource/csdk/connectivity/inc/pkix/cert.h | 78 - resource/csdk/connectivity/inc/pkix/crl.h | 89 - .../csdk/connectivity/inc/pkix/crypto_adapter.h | 83 - resource/csdk/connectivity/inc/pkix/der_dec.h | 144 -- resource/csdk/connectivity/inc/pkix/pki.h | 107 - resource/csdk/connectivity/inc/pkix/pki_errors.h | 320 --- resource/csdk/connectivity/inc/pkix/sn_store.h | 67 - .../lib/arduino/arduino_libraries.patch | 46 + .../csdk/connectivity/lib/libcoap-4.1.1/README | 2 +- .../csdk/connectivity/lib/libcoap-4.1.1/SConscript | 79 - .../csdk/connectivity/lib/libcoap-4.1.1/async.c | 47 +- .../csdk/connectivity/lib/libcoap-4.1.1/block.c | 67 +- .../connectivity/lib/libcoap-4.1.1/coap_list.c | 8 +- .../csdk/connectivity/lib/libcoap-4.1.1/debug.c | 145 +- .../csdk/connectivity/lib/libcoap-4.1.1/encode.c | 7 +- .../csdk/connectivity/lib/libcoap-4.1.1/hashkey.c | 2 +- .../lib/libcoap-4.1.1/{ => include/coap}/address.h | 24 +- .../lib/libcoap-4.1.1/{ => include/coap}/async.h | 2 +- .../lib/libcoap-4.1.1/{ => include/coap}/bits.h | 6 +- .../lib/libcoap-4.1.1/{ => include/coap}/block.h | 4 +- .../lib/libcoap-4.1.1/{ => include/coap}/coap.h | 0 .../libcoap-4.1.1/{ => include/coap}/coap_list.h | 0 .../libcoap-4.1.1/{ => include/coap}/coap_time.h | 28 +- .../lib/libcoap-4.1.1/{ => include/coap}/config.h | 55 +- .../lib/libcoap-4.1.1/{ => include/coap}/debug.h | 0 .../lib/libcoap-4.1.1/{ => include/coap}/encode.h | 2 +- .../lib/libcoap-4.1.1/{ => include/coap}/hashkey.h | 0 .../lib/libcoap-4.1.1/{ => include/coap}/mem.h | 0 .../lib/libcoap-4.1.1/{ => include/coap}/net.h | 12 +- .../lib/libcoap-4.1.1/{ => include/coap}/option.h | 34 +- .../lib/libcoap-4.1.1/{ => include/coap}/pdu.h | 423 ++-- .../lib/libcoap-4.1.1/{ => include/coap}/prng.h | 4 +- .../libcoap-4.1.1/{ => include/coap}/resource.h | 2 +- .../lib/libcoap-4.1.1/{ => include/coap}/str.h | 0 .../libcoap-4.1.1/{ => include/coap}/subscribe.h | 0 .../lib/libcoap-4.1.1/{ => include/coap}/t_list.h | 14 +- .../lib/libcoap-4.1.1/{ => include/coap}/uri.h | 0 .../lib/libcoap-4.1.1/{ => include/coap}/uthash.h | 0 .../lib/libcoap-4.1.1/{ => include/coap}/utlist.h | 10 +- resource/csdk/connectivity/lib/libcoap-4.1.1/net.c | 224 +- .../csdk/connectivity/lib/libcoap-4.1.1/option.c | 67 +- resource/csdk/connectivity/lib/libcoap-4.1.1/pdu.c | 444 ++-- .../csdk/connectivity/lib/libcoap-4.1.1/resource.c | 52 +- resource/csdk/connectivity/lib/libcoap-4.1.1/str.c | 8 +- .../connectivity/lib/libcoap-4.1.1/subscribe.c | 16 +- resource/csdk/connectivity/lib/libcoap-4.1.1/uri.c | 16 +- resource/csdk/connectivity/src/SConscript | 162 +- .../src/adapter_util/ca_adapter_net_ssl.c | 2047 ++++++++++++++++++ .../src/adapter_util/caadapternetdtls.c | 1260 ----------- .../connectivity/src/adapter_util/caadapterutils.c | 60 +- .../src/adapter_util/cafragmentation.c | 255 +++ .../csdk/connectivity/src/adapter_util/pkix/cert.c | 171 -- .../csdk/connectivity/src/adapter_util/pkix/crl.c | 170 -- .../connectivity/src/adapter_util/pkix/der_dec.c | 57 - .../csdk/connectivity/src/adapter_util/pkix/pki.c | 225 -- .../connectivity/src/adapter_util/pkix/sn_store.c | 119 -- .../connectivity/src/bt_edr_adapter/SConscript | 2 +- .../src/bt_edr_adapter/android/caedrclient.c | 129 +- .../src/bt_edr_adapter/android/caedrnwmonitor.c | 54 +- .../src/bt_edr_adapter/android/caedrserver.c | 442 ++-- .../src/bt_edr_adapter/android/caedrserver.h | 28 +- .../src/bt_edr_adapter/android/caedrutils.c | 366 ++-- .../src/bt_edr_adapter/android/caedrutils.h | 20 +- .../android/org_iotivity_ca_CaEdrInterface.h | 11 +- .../connectivity/src/bt_edr_adapter/caedradapter.c | 173 +- .../src/bt_edr_adapter/tizen/caedrclient.c | 8 +- .../src/bt_edr_adapter/tizen/caedrnwmonitor.c | 7 +- .../src/bt_edr_adapter/tizen/caedrserver.c | 6 + .../src/bt_le_adapter/android/caleclient.c | 869 ++++---- .../src/bt_le_adapter/android/caleclient.h | 41 +- .../src/bt_le_adapter/android/calenwmonitor.c | 161 +- .../src/bt_le_adapter/android/caleserver.c | 181 +- .../src/bt_le_adapter/android/caleutils.c | 81 +- .../src/bt_le_adapter/android/caleutils.h | 21 +- .../android/org_iotivity_ca_CaLeClientInterface.h | 16 +- .../android/org_iotivity_ca_CaLeServerInterface.h | 7 +- .../src/bt_le_adapter/arduino/cableserver.cpp | 61 +- .../connectivity/src/bt_le_adapter/caleadapter.c | 1058 +++++++-- .../src/bt_le_adapter/linux/descriptor.c | 4 +- .../src/bt_le_adapter/tizen/caleclient.c | 21 + .../src/bt_le_adapter/tizen/calenwmonitor.c | 19 +- .../src/bt_le_adapter/tizen/caleserver.c | 100 +- .../src/bt_le_adapter/tizen/caleutil.c | 9 + .../csdk/connectivity/src/cablockwisetransfer.c | 170 +- .../csdk/connectivity/src/caconnectivitymanager.c | 161 +- .../csdk/connectivity/src/cainterfacecontroller.c | 167 +- resource/csdk/connectivity/src/camessagehandler.c | 242 ++- resource/csdk/connectivity/src/caprotocolmessage.c | 151 +- resource/csdk/connectivity/src/caqueueingthread.c | 22 +- resource/csdk/connectivity/src/caretransmission.c | 71 +- .../csdk/connectivity/src/ip_adapter/SConscript | 3 + .../src/ip_adapter/android/caipnwmonitor.c | 61 +- .../src/ip_adapter/arduino/caipnwmonitor_eth.cpp | 10 +- .../src/ip_adapter/arduino/caipnwmonitor_wifi.cpp | 8 +- .../src/ip_adapter/arduino/caipserver_eth.cpp | 13 +- .../src/ip_adapter/arduino/caipserver_wifi.cpp | 13 +- .../csdk/connectivity/src/ip_adapter/caipadapter.c | 42 +- .../csdk/connectivity/src/ip_adapter/caipserver.c | 845 ++++++-- .../src/ip_adapter/linux/caipnwmonitor.c | 44 +- .../src/ip_adapter/tizen/caipnwmonitor.c | 24 +- .../connectivity/src/ip_adapter/windows/SConscript | 12 + .../src/ip_adapter/windows/caipnwmonitor.c | 289 +++ .../src/nfc_adapter/android/canfcserver.c | 41 +- .../connectivity/src/nfc_adapter/canfcadapter.c | 8 +- .../csdk/connectivity/src/ra_adapter/caraadapter.c | 20 +- .../csdk/connectivity/src/tcp_adapter/SConscript | 4 +- .../src/tcp_adapter/arduino/SConscript | 17 + .../tcp_adapter/arduino/catcpadapterutils_eth.cpp | 82 + .../tcp_adapter/arduino/catcpadapterutils_eth.h | 66 + .../src/tcp_adapter/arduino/catcpserver_eth.cpp | 329 +++ .../connectivity/src/tcp_adapter/catcpadapter.c | 148 +- .../connectivity/src/tcp_adapter/catcpserver.c | 436 +++- resource/csdk/connectivity/test/SConscript | 53 +- .../csdk/connectivity/test/ca_api_unittest.cpp | 195 +- .../csdk/connectivity/test/cablocktransfertest.cpp | 752 +++++++ resource/csdk/connectivity/test/camutex_tests.cpp | 67 +- .../connectivity/test/caprotocolmessagetest.cpp | 43 +- resource/csdk/connectivity/test/catests.cpp | 8 + .../csdk/connectivity/test/ssladapter_test.cpp | 2239 ++++++++++++++++++++ resource/csdk/connectivity/test/ulinklist_test.cpp | 179 ++ resource/csdk/connectivity/test/uqueue_test.cpp | 192 ++ .../connectivity/util/inc/camanagerleinterface.h | 8 + .../util/src/btpairing/android/cabtpairing.c | 2 +- .../util/src/btpairing/android/cabtpairing.h | 2 +- .../util/src/camanager/android/caleautoconnector.c | 18 +- .../src/camanager/android/caleconnectionmanager.c | 294 +-- .../util/src/camanager/android/camanagerdevice.c | 122 +- .../util/src/camanager/android/camanagerdevice.h | 38 +- .../util/src/camanager/android/camanagerleutil.c | 42 +- .../util/src/camanager/android/camanagerleutil.h | 8 - .../src/camanager/tizen/caleconnectionmanager.c | 144 ++ .../csdk/connectivity/util/src/cautilinterface.c | 174 +- resource/csdk/logger/SConscript | 7 +- resource/csdk/logger/include/logger.h | 19 +- resource/csdk/logger/src/logger.c | 53 +- resource/csdk/octbstack_product.def | 104 + resource/csdk/octbstack_product_secured.def | 36 + resource/csdk/octbstack_test.def | 6 + .../csdk}/resource-directory/SConscript | 75 +- .../csdk/resource-directory/include/rd_client.h | 131 ++ .../csdk/resource-directory/include/rd_database.h | 93 + .../csdk}/resource-directory/include/rd_server.h | 3 +- .../csdk}/resource-directory/samples/SConscript | 29 +- .../samples/oic_svr_db_server.dat | Bin 0 -> 1260 bytes .../csdk}/resource-directory/samples/rd_main.c | 4 +- .../samples/rd_publishingClient.cpp | 57 +- .../resource-directory/samples/rd_queryClient.cpp | 14 +- .../csdk/resource-directory/samples/rdclient.cpp | 287 +++ .../resource-directory/src/internal/rd_database.c | 584 +++++ resource/csdk/resource-directory/src/rd_client.c | 265 +++ .../csdk}/resource-directory/src/rd_server.c | 118 +- .../csdk/resource-directory}/unittests/SConscript | 57 +- .../resource-directory/unittests/rddatabase.cpp | 172 ++ .../csdk/resource-directory/unittests/rdtests.cpp | 294 +++ resource/csdk/routing/SConscript | 3 + resource/csdk/routing/src/routingmanager.c | 5 +- resource/csdk/routing/src/routingutility.c | 3 +- ...-building-and-running-secure-IoTivity-stack.txt | 11 +- resource/csdk/security/SConscript | 150 +- .../csdk/security/include/internal/aclresource.h | 47 + resource/csdk/security/include/internal/amsmgr.h | 1 - .../csdk/security/include/internal/credresource.h | 79 +- .../csdk/security/include/internal/crlresource.h | 35 +- .../csdk/security/include/internal/doxmresource.h | 40 + .../security/include/internal/dpairingresource.h | 4 +- .../csdk/security/include/internal/policyengine.h | 5 + .../security/include/internal/srmresourcestrings.h | 18 + resource/csdk/security/include/pinoxmcommon.h | 115 +- .../include/pkix_interface.h} | 27 +- .../security/include/securevirtualresourcetypes.h | 122 +- resource/csdk/security/include/srmutility.h | 2 +- resource/csdk/security/provisioning/README.txt | 2 +- resource/csdk/security/provisioning/SConscript | 100 +- .../security/provisioning/ck_manager/SConscript | 50 - .../ck_manager/include/cert_generator.h | 60 - .../provisioning/ck_manager/include/ck_manager.h | 208 -- .../provisioning/ck_manager/include/ckm_info.h | 328 --- .../ck_manager/include/crl_generator.h | 75 - .../ck_manager/include/csr_generator.h | 74 - .../provisioning/ck_manager/sample/Door_sample.cpp | 580 ----- .../ck_manager/sample/Light_sample.cpp | 334 --- .../provisioning/ck_manager/sample/README.txt | 132 -- .../provisioning/ck_manager/sample/SConscript | 13 +- .../ck_manager/sample/oic_svr_db_door.dat | Bin 1054 -> 0 bytes .../ck_manager/sample/oic_svr_db_light.dat | Bin 1054 -> 0 bytes .../ck_manager/sample/provisioningclient.c | 794 ------- .../provisioning/ck_manager/src/cert_generator.c | 246 --- .../provisioning/ck_manager/src/ck_manager.c | 702 ------ .../provisioning/ck_manager/src/ckm_info.c | 565 ----- .../provisioning/ck_manager/src/crl_generator.c | 241 --- .../provisioning/ck_manager/src/csr_generator.c | 278 --- .../provisioning/ck_manager/tools/SConscript | 59 - .../provisioning/ck_manager/unittest/SConscript | 102 - .../ck_manager/unittest/ckm_info_test.cpp | 272 --- .../ck_manager/unittest/crl_generator_test.cpp | 98 - .../ck_manager/unittest/csr_generator_test.cpp | 110 - .../provisioning/ck_manager/unittest/pki_test.cpp | 1059 --------- .../ck_manager/unittest/test_data/01.der | Bin 624 -> 0 bytes .../ck_manager/unittest/test_data/CKMInfo.dat | Bin 996 -> 0 bytes .../ck_manager/unittest/test_data/cacert.der | Bin 590 -> 0 bytes .../ck_manager/unittest/test_data/capub.der | Bin 91 -> 0 bytes .../ck_manager/unittest/test_data/cert_chain.dat | Bin 2887 -> 0 bytes .../ck_manager/unittest/test_data/chain.der | Bin 1760 -> 0 bytes .../include/cloud/occloudprovisioning.h | 440 ++++ .../security/provisioning/include/cloud/utils.h | 69 + .../internal/multipleownershiptransfermanager.h | 117 + .../include/internal/secureresourceprovider.h | 51 +- .../provisioning/include/ocprovisioningmanager.h | 222 +- .../provisioning/include/oxm/oxmpreconfpin.h | 82 + .../csdk/security/provisioning/include/pmtypes.h | 4 + .../csdk/security/provisioning/include/pmutility.h | 34 +- .../security/provisioning/sample/README-cloud.txt | 32 + .../csdk/security/provisioning/sample/SConscript | 95 +- .../sample/oic_svr_db_pt.dat => sample/cloud.dat} | Bin 878 -> 879 bytes .../oic_svr_db_pt.json => sample/cloud.json} | 136 +- .../security/provisioning/sample/cloud/cloudAuth.c | 327 +++ .../security/provisioning/sample/cloud/cloudAuth.h | 54 + .../provisioning/sample/cloud/cloudCommon.c | 681 ++++++ .../provisioning/sample/cloud/cloudCommon.h | 77 + .../provisioning/sample/cloud/cloudDiscovery.c | 230 ++ .../provisioning/sample/cloud/cloudDiscovery.h | 38 + .../provisioning/sample/cloud/cloudResource.c | 244 +++ .../provisioning/sample/cloud/cloudResource.h | 38 + .../provisioning/sample/cloud/cloudWrapper.c | 739 +++++++ .../provisioning/sample/cloud/cloudWrapper.h | 291 +++ .../security/provisioning/sample/cloudClient.c | 35 + .../security/provisioning/sample/cloudServer.c | 49 + .../provisioning/sample/oic_svr_db_client.dat | Bin 1046 -> 879 bytes .../provisioning/sample/oic_svr_db_client.json | 22 +- .../oic_svr_db_randompin_with_empty_deviceid.dat | Bin 1261 -> 998 bytes .../oic_svr_db_randompin_with_empty_deviceid.json | 34 +- .../sample/oic_svr_db_server_justworks.dat | Bin 1260 -> 997 bytes .../sample/oic_svr_db_server_justworks.json | 34 +- .../sample/oic_svr_db_server_randompin.dat | Bin 1261 -> 998 bytes .../sample/oic_svr_db_server_randompin.json | 34 +- .../sample/oic_svr_db_subowner_client.dat | Bin 0 -> 1046 bytes .../oic_svr_db_subowner_client.json} | 49 +- .../provisioning/sample/provisioningclient.c | 417 +++- .../csdk/security/provisioning/sample/rootca.crt | 19 + .../provisioning/sample/sampleserver_justworks.cpp | 20 +- .../provisioning/sample/sampleserver_randompin.cpp | 89 +- .../security/provisioning/sample/subownerclient.c | 1043 +++++++++ .../security/provisioning/src/cloud/aclgroup.c | 314 +++ .../csdk/security/provisioning/src/cloud/aclid.c | 529 +++++ .../security/provisioning/src/cloud/aclinvite.c | 361 ++++ .../csdk/security/provisioning/src/cloud/crl.c | 173 ++ .../csdk/security/provisioning/src/cloud/csr.c | 492 +++++ .../csdk/security/provisioning/src/cloud/utils.c | 163 ++ .../provisioning/src/credentialgenerator.c | 154 +- .../src/multipleownershiptransfermanager.c | 1127 ++++++++++ .../provisioning/src/ocprovisioningmanager.c | 406 +++- .../provisioning/src/ownershiptransfermanager.c | 403 +++- .../csdk/security/provisioning/src/oxmjustworks.c | 25 +- .../csdk/security/provisioning/src/oxmpreconfpin.c | 215 ++ .../csdk/security/provisioning/src/oxmrandompin.c | 47 +- .../csdk/security/provisioning/src/pmutility.c | 558 ++++- .../provisioning/src/secureresourceprovider.c | 459 ++-- .../csdk/security/provisioning/unittest/SConscript | 61 +- .../unittest/credentialgeneratortest.cpp | 47 - .../unittest/ocprovisioningmanager.cpp | 2 - .../security/provisioning/unittest/otmunittest.cpp | 293 ++- .../unittest/provisioningdatabasemanager.cpp | 3 +- .../provisioning/unittest/sampleserver1.cpp | 131 +- .../provisioning/unittest/sampleserver2.cpp | 131 +- resource/csdk/security/src/aclresource.c | 646 +++++- resource/csdk/security/src/amaclresource.c | 2 +- resource/csdk/security/src/amsmgr.c | 21 +- resource/csdk/security/src/credresource.c | 1180 +++++++++-- resource/csdk/security/src/crlresource.c | 535 +++-- resource/csdk/security/src/directpairing.c | 2085 +++++++++--------- resource/csdk/security/src/doxmresource.c | 596 +++++- resource/csdk/security/src/dpairingresource.c | 40 +- resource/csdk/security/src/iotvticalendar.c | 7 +- resource/csdk/security/src/oxmpincommon.c | 370 +++- resource/csdk/security/src/pbkdf2.c | 1 + resource/csdk/security/src/pconfresource.c | 12 +- .../csdk/security/src/pkix_interface.c | 30 +- resource/csdk/security/src/policyengine.c | 143 +- resource/csdk/security/src/psinterface.c | 35 +- resource/csdk/security/src/pstatresource.c | 30 +- resource/csdk/security/src/resourcemanager.c | 12 +- resource/csdk/security/src/secureresourcemanager.c | 82 +- resource/csdk/security/src/srmresourcestrings.c | 20 +- resource/csdk/security/src/srmutility.c | 6 +- resource/csdk/security/src/strptime.c | 141 ++ resource/csdk/security/src/svcresource.c | 5 +- resource/csdk/security/src/verresource.c | 3 +- resource/csdk/security/tool/SConscript | 17 +- resource/csdk/security/tool/json2cbor.c | 25 +- resource/csdk/security/unittest/SConscript | 43 +- .../csdk/security/unittest/aclresourcetest.cpp | 9 +- .../csdk/security/unittest/credentialresource.cpp | 57 +- .../csdk/security/unittest/crlresourcetest.cpp | 28 +- .../csdk/security/unittest/iotvticalendartest.cpp | 25 + resource/csdk/security/unittest/oic_svr_db.dat | Bin 1104 -> 1105 bytes resource/csdk/security/unittest/oic_svr_db.json | 4 +- .../csdk/security/unittest/oic_svr_db_prov.dat | Bin 1311 -> 1312 bytes .../csdk/security/unittest/oic_svr_db_prov.json | 4 +- resource/csdk/security/unittest/policyengine.cpp | 3 - resource/csdk/security/unittest/pstatresource.cpp | 3 + .../security/unittest/securityresourcemanager.cpp | 15 + resource/csdk/security/unittest/srmtestcommon.cpp | 2 +- resource/csdk/security/unittest/srmtestcommon.h | 2 +- resource/csdk/stack/include/internal/occlientcb.h | 56 +- resource/csdk/stack/include/internal/ocobserve.h | 3 - resource/csdk/stack/include/internal/ocresource.h | 11 + .../stack/include/internal/ocresourcehandler.h | 22 +- .../csdk/stack/include/internal/ocstackinternal.h | 42 +- resource/csdk/stack/include/internal/oicgroup.h | 3 + .../csdk/stack/include/internal/oickeepalive.h | 8 +- resource/csdk/stack/include/ocpayload.h | 32 +- resource/csdk/stack/include/ocstack.h | 137 +- resource/csdk/stack/include/ocstackconfig.h | 16 + resource/csdk/stack/include/octypes.h | 501 +++-- resource/csdk/stack/include/payload_logging.h | 387 ++-- resource/csdk/stack/include/rdpayload.h | 182 -- .../samples/linux/SimpleClientServer/SConscript | 41 +- .../samples/linux/SimpleClientServer/common.cpp | 3 + .../samples/linux/SimpleClientServer/common.h | 7 + .../samples/linux/SimpleClientServer/occlient.cpp | 109 +- .../samples/linux/SimpleClientServer/occlient.h | 8 - .../linux/SimpleClientServer/occlientbasicops.cpp | 8 + .../linux/SimpleClientServer/occlientcoll.cpp | 13 +- .../linux/SimpleClientServer/occlientslow.cpp | 17 +- .../SimpleClientServer/ocremoteaccessclient.cpp | 2 +- .../samples/linux/SimpleClientServer/ocserver.cpp | 88 +- .../linux/SimpleClientServer/ocserverbasicops.cpp | 8 + .../linux/SimpleClientServer/ocservercoll.cpp | 14 +- .../linux/SimpleClientServer/ocserverslow.cpp | 34 +- .../csdk/stack/samples/linux/secure/SConscript | 20 +- .../stack/samples/linux/secure/ocamsservice.cpp | 9 +- .../samples/linux/secure/occlientbasicops.cpp | 55 +- .../samples/linux/secure/occlientdirectpairing.cpp | 46 +- .../samples/linux/secure/ocserverbasicops.cpp | 8 + .../stack/samples/linux/secure/oic_amss_db.dat | Bin 1284 -> 1170 bytes .../stack/samples/linux/secure/oic_amss_db.json | 16 +- .../samples/linux/secure/oic_svr_db_client.dat | Bin 1284 -> 0 bytes .../samples/linux/secure/oic_svr_db_client.json | 102 - .../linux/secure/oic_svr_db_client_devowner.dat | Bin 1284 -> 1170 bytes .../linux/secure/oic_svr_db_client_devowner.json | 16 +- .../linux/secure/oic_svr_db_client_nondevowner.dat | Bin 1284 -> 1170 bytes .../secure/oic_svr_db_client_nondevowner.json | 16 +- .../samples/linux/secure/oic_svr_db_server.dat | Bin 1941 -> 1827 bytes .../samples/linux/secure/oic_svr_db_server.json | 16 +- .../linux/secure/oic_svr_db_server_justworks.dat | Bin 1260 -> 997 bytes .../linux/secure/oic_svr_db_server_justworks.json | 34 +- .../samples/tizen/SimpleClientServer/SConscript | 7 +- .../samples/tizen/SimpleClientServer/common.cpp | 2 + .../samples/tizen/SimpleClientServer/occlient.cpp | 53 +- .../samples/tizen/SimpleClientServer/ocserver.cpp | 18 +- .../packaging/com.oic.ri.sample.spec | 5 +- .../tizen/SimpleClientServer/scons/SConscript | 27 +- resource/csdk/stack/samples/tizen/build/SConscript | 20 +- .../csdk/stack/samples/tizen/build/gbsbuild.sh | 25 +- .../samples/tizen/build/packaging/com.oic.ri.spec | 21 +- .../stack/samples/tizen/build/scons/SConscript | 21 +- resource/csdk/stack/src/occlientcb.c | 71 +- resource/csdk/stack/src/occollection.c | 11 +- resource/csdk/stack/src/ocobserve.c | 12 +- resource/csdk/stack/src/ocpayload.c | 299 ++- resource/csdk/stack/src/ocpayloadconvert.c | 118 +- resource/csdk/stack/src/ocpayloadparse.c | 310 +-- resource/csdk/stack/src/ocresource.c | 338 ++- resource/csdk/stack/src/ocserverrequest.c | 24 +- resource/csdk/stack/src/ocstack.c | 913 +++++--- resource/csdk/stack/src/oicgroup.c | 176 +- resource/csdk/stack/src/oickeepalive.c | 162 +- resource/csdk/stack/src/rdpayload.c | 888 -------- resource/csdk/stack/test/SConscript | 23 +- resource/csdk/stack/test/cbortests.cpp | 2 + resource/csdk/stack/test/linux/SConscript | 46 + resource/csdk/stack/test/linux/occlient.c | 16 +- resource/csdk/stack/test/linux/ocserver.c | 8 +- resource/csdk/stack/test/stacktests.cpp | 213 +- resource/docs/c-doc/Doxyfile | 56 +- resource/docs/cpp-doc/Doxyfile | 9 +- resource/docs/javadocGen.sh | 12 +- resource/examples/SConscript | 133 +- resource/examples/devicediscoveryserver.cpp | 51 +- resource/examples/directpairingclient.cpp | 4 +- resource/examples/fridgeclient.cpp | 31 + resource/examples/fridgeserver.cpp | 117 + resource/examples/garageclient.cpp | 36 +- resource/examples/garageserver.cpp | 116 + resource/examples/groupclient.cpp | 1 - resource/examples/lightserver.cpp | 122 ++ resource/examples/mediaserver.cpp | 638 ++++++ resource/examples/oic_svr_db_client.dat | Bin 1222 -> 1170 bytes resource/examples/oic_svr_db_client.json | 10 +- resource/examples/oic_svr_db_server.dat | Bin 1313 -> 1261 bytes resource/examples/oic_svr_db_server.json | 10 +- resource/examples/presenceclient.cpp | 59 +- resource/examples/presenceserver.cpp | 129 +- resource/examples/roomclient.cpp | 29 + resource/examples/roomserver.cpp | 118 ++ resource/examples/simpleclient.cpp | 143 +- resource/examples/simpleclientHQ.cpp | 95 +- resource/examples/simpleserver.cpp | 142 +- resource/examples/simpleserverHQ.cpp | 130 +- resource/examples/threadingsample.cpp | 6 + resource/examples/winuiclient.cpp | 519 +++++ resource/examples/winuiclient.h | 89 + resource/examples/winuiclientgui.cpp | 370 ++++ resource/include/AttributeValue.h | 38 +- resource/include/CAManager.h | 36 +- resource/include/IClientWrapper.h | 45 +- resource/include/IServerWrapper.h | 13 + resource/include/InProcClientWrapper.h | 69 +- resource/include/InProcServerWrapper.h | 29 + resource/include/OCAccountManager.h | 352 +++ resource/include/OCApi.h | 41 +- resource/include/OCCloudProvisioning.h | 139 ++ resource/include/OCHeaderOption.h | 14 + resource/include/OCPlatform.h | 234 +- resource/include/OCPlatform_impl.h | 54 +- resource/include/OCProvisioningManager.h | 75 +- resource/include/OCRepresentation.h | 58 +- resource/include/OCResource.h | 147 +- resource/include/OCResourceRequest.h | 52 +- resource/include/OCResourceResponse.h | 33 +- resource/include/OCSerialization.h | 64 +- resource/include/OCUtilities.h | 8 +- resource/include/OutOfProcClientWrapper.h | 46 + resource/include/ResourceInitException.h | 2 +- resource/include/StringConstants.h | 14 + resource/oc_logger/SConscript | 27 +- resource/oc_logger/examples/SConscript | 11 +- resource/oc_logger/include/oc_log_stream.hpp | 6 +- resource/provisioning/SConscript | 27 +- resource/provisioning/examples/SConscript | 64 +- resource/provisioning/examples/cloud.dat | Bin 0 -> 879 bytes .../examples/cloud.json} | 151 +- resource/provisioning/examples/cloudAuth.cpp | 460 ++++ resource/provisioning/examples/cloudAuth.h | 90 + resource/provisioning/examples/cloudClient.cpp | 528 +++++ resource/provisioning/examples/cloudWrapper.cpp | 621 ++++++ resource/provisioning/examples/cloudWrapper.h | 245 +++ .../provisioning/examples/oic_svr_db_client.dat | Bin 993 -> 879 bytes .../provisioning/examples/oic_svr_db_client.json | 16 +- .../provisioning/examples/provisioningclient.cpp | 98 +- resource/provisioning/examples/rootca.crt | 19 + resource/provisioning/src/OCCloudProvisioning.cpp | 210 ++ .../provisioning/src/OCProvisioningManager.cpp | 185 +- .../unittests/OCCloudProvisioningTest.cpp | 82 + .../provisioning/unittests/OCProvisioningTest.cpp | 19 + resource/provisioning/unittests/SConscript | 29 +- resource/src/CAManager.cpp | 78 +- resource/src/InProcClientWrapper.cpp | 690 +++++- resource/src/InProcServerWrapper.cpp | 158 +- resource/src/OCAccountManager.cpp | 514 +++++ resource/src/OCApi.cpp | 12 +- resource/src/OCException.cpp | 4 + resource/src/OCPlatform.cpp | 140 ++ resource/src/OCPlatform_impl.cpp | 114 +- resource/src/OCRepresentation.cpp | 112 +- resource/src/OCResource.cpp | 178 +- resource/src/SConscript | 101 +- resource/third_party_libs.scons | 4 + resource/unit_tests.scons | 24 +- resource/unittests/OCAccountManagerTest.cpp | 529 +++++ resource/unittests/OCExceptionTest.cpp | 4 + resource/unittests/OCMQResourceTest.cpp | 127 ++ resource/unittests/OCPlatformTest.cpp | 49 + .../unittests/OCRepresentationEncodingTest.cpp | 297 ++- resource/unittests/OCRepresentationTest.cpp | 134 ++ resource/unittests/OCResourceResponseTest.cpp | 6 +- resource/unittests/OCResourceTest.cpp | 23 +- resource/unittests/SConscript | 40 +- run.bat | 159 ++ scons_script_how_to.txt | 26 +- service/SConscript | 15 +- service/coap-http-proxy/SConscript | 89 + service/coap-http-proxy/include/CoapHttpHandler.h | 59 + service/coap-http-proxy/include/CoapHttpMap.h | 94 + service/coap-http-proxy/include/CoapHttpParser.h | 195 ++ service/coap-http-proxy/samples/SConscript | 54 + service/coap-http-proxy/samples/proxy_client.c | 391 ++++ service/coap-http-proxy/samples/proxy_main.c | 123 ++ service/coap-http-proxy/src/CoapHttpHandler.c | 519 +++++ service/coap-http-proxy/src/CoapHttpMap.c | 520 +++++ service/coap-http-proxy/src/CoapHttpParser.c | 869 ++++++++ .../coap-http-proxy/unittests/CoAPHttpUnitTest.cpp | 129 ++ service/coap-http-proxy/unittests/SConscript | 94 + .../Build_Instructions_Android_Arduino.txt | 5 +- service/easy-setup/SConscript | 29 +- service/easy-setup/enrollee/SConscript | 94 +- service/easy-setup/enrollee/arduino/easysetup.cpp | 207 -- service/easy-setup/enrollee/arduino/onboarding.cpp | 86 - .../enrollee/arduino/resourcehandler.cpp | 396 ---- service/easy-setup/enrollee/arduino/softap.cpp | 89 - .../enrollee/arduino/wifi/networkhandler.cpp | 249 --- .../enrollee/arduino/wifi/networkhandler.h | 68 - service/easy-setup/enrollee/inc/ESEnrolleeCommon.h | 107 + service/easy-setup/enrollee/inc/easysetup.h | 88 +- .../enrollee/linux/wifi/networkhandler.c | 80 - .../enrollee/linux/wifi/networkhandler.h | 63 - service/easy-setup/enrollee/src/easysetup.c | 264 ++- .../easy-setup/enrollee/src/easysetupcallbacks.h | 69 - service/easy-setup/enrollee/src/onboarding.c | 94 - service/easy-setup/enrollee/src/onboarding.h | 70 - service/easy-setup/enrollee/src/resourcehandler.c | 1309 ++++++++++-- service/easy-setup/enrollee/src/resourcehandler.h | 68 +- service/easy-setup/enrollee/src/softap.c | 89 - service/easy-setup/enrollee/src/softap.h | 85 - .../enrollee/tizen/wifi/networkhandler.c | 184 -- .../enrollee/tizen/wifi/networkhandler.h | 63 - .../easy-setup/enrollee/tizen/wifi/softapnative.c | 42 - .../easy-setup/enrollee/tizen/wifi/softapnative.h | 66 - .../enrollee/unittests/ESEnrolleeTest.cpp | 543 +++++ .../enrollee/unittests/ESMediatorSimulator.h | 503 +++++ service/easy-setup/enrollee/unittests/SConscript | 125 +- .../enrollee/unittests/enrolleetests.cpp | 303 --- .../easy-setup/enrollee/unittests/gtesthelper.h | 151 -- service/easy-setup/inc/escommon.h | 363 ++-- service/easy-setup/mediator/SConscript | 3 - service/easy-setup/mediator/csdk/SConscript | 148 -- .../easy-setup/mediator/csdk/inc/provisioning.h | 119 -- .../easy-setup/mediator/csdk/src/provisioning.cpp | 577 ----- .../mediator/csdk/src/provisioningapi.cpp | 127 -- .../mediator/csdk/src/wifiprovisioning.cpp | 274 --- .../mediator/csdk/unittests/MediatorCSDKTest.cpp | 124 -- service/easy-setup/mediator/richsdk/SConscript | 69 +- .../android/EasySetupCore/EasySetupCore.iml | 103 + .../richsdk/android/EasySetupCore/build.gradle | 89 +- .../android/EasySetupCore/proguard-rules.pro | 17 + .../EasySetupCore/src/androidTest/androidTest.iml | 13 - .../mediator/EasySetupServiceConfigTest.java | 74 - .../easysetup/mediator/EasySetupServiceTest.java | 158 -- .../easysetup/mediator/EasySetupStatusTest.java | 165 -- .../mediator/EnrolleeDeviceFactoryTest.java | 70 - .../service/easysetup/core/EnrolleeInfo.java | 64 - .../easysetup/core/EnrolleeOnBoardingInfo.java | 92 - .../easysetup/core/ip/WiFiSoftAPManager.java | 301 --- .../service/easysetup/mediator/CloudProp.java | 168 ++ ...ack.java => CloudPropProvisioningCallback.java} | 35 +- .../mediator/CloudPropProvisioningStatus.java | 58 + .../service/easysetup/mediator/DeviceProp.java | 263 +++ ...on.java => DevicePropProvisioningCallback.java} | 45 +- .../mediator/DevicePropProvisioningStatus.java | 51 + .../service/easysetup/mediator/ESConstants.java | 56 + .../service/easysetup/mediator/EasySetup.java | 105 + .../easysetup/mediator/EasySetupService.java | 233 -- .../easysetup/mediator/EasySetupStatus.java | 50 - .../service/easysetup/mediator/EnrolleeConf.java | 210 ++ .../service/easysetup/mediator/EnrolleeDevice.java | 173 -- .../easysetup/mediator/EnrolleeDeviceFactory.java | 81 - .../mediator/EnrolleeDeviceWiFiOnboarding.java | 193 -- .../service/easysetup/mediator/EnrolleeState.java | 88 - .../service/easysetup/mediator/EnrolleeStatus.java | 88 + ...tupError.java => GetConfigurationCallback.java} | 34 +- .../easysetup/mediator/GetConfigurationStatus.java | 69 + .../easysetup/mediator/GetEnrolleeStatus.java | 69 + ...usNativeHandler.java => GetStatusCallback.java} | 30 +- .../easysetup/mediator/IpOnBoardingConnection.java | 94 - .../easysetup/mediator/OnBoardingConfig.java | 73 - .../easysetup/mediator/ProvisioningCallback.java | 28 - .../easysetup/mediator/ProvisioningConfig.java | 73 - .../service/easysetup/mediator/RemoteEnrollee.java | 154 +- .../mediator/SecurityProvisioningCallback.java | 44 + .../mediator/SecurityProvisioningStatus.java | 67 + .../easysetup/mediator/WiFiOnBoardingConfig.java | 75 - .../service/easysetup/mediator/WiFiProvConfig.java | 79 - .../easysetup/mediator/enums/ESCloudProvState.java | 65 + .../easysetup/mediator/enums/ESErrorCode.java | 115 + .../service/easysetup/mediator/enums/ESResult.java | 54 + .../easysetup/mediator/enums/ProvStatus.java | 100 + .../enums/WIFI_AUTHTYPE.java} | 55 +- .../easysetup/mediator/enums/WIFI_ENCTYPE.java | 58 + .../easysetup/mediator/enums/WIFI_FREQ.java | 66 + .../easysetup/mediator/enums/WIFI_MODE.java | 87 + .../android/EasySetupCore/src/main/jni/Android.mk | 102 + .../EasySetupCore/src/main/jni/Application.mk | 24 + .../jni/JniCloudPropProvisioningStatusListener.cpp | 130 ++ .../jni/JniCloudPropProvisioningStatusListener.h} | 20 +- .../JniDevicePropProvisioningStatusListener.cpp} | 48 +- .../jni/JniDevicePropProvisioningStatusListener.h | 59 + .../src/main}/jni/JniEasySetup.cpp | 58 +- .../src/main}/jni/JniEasySetup.h | 12 +- .../src/main}/jni/JniEsListenerManager.h | 10 +- .../src/main}/jni/JniEsUtils.cpp | 66 +- .../{ => EasySetupCore/src/main}/jni/JniEsUtils.h | 9 +- .../main/jni/JniGetConfigurationStatusListener.cpp | 148 ++ .../main/jni/JniGetConfigurationStatusListener.h | 60 + .../src/main/jni/JniGetEnrolleeStatusListener.cpp | 153 ++ .../src/main/jni/JniGetEnrolleeStatusListener.h | 61 + .../android/EasySetupCore/src/main/jni/JniJvm.cpp | 193 ++ .../{ => EasySetupCore/src/main}/jni/JniJvm.h | 36 +- .../src/main/jni/JniRemoteEnrollee.cpp | 259 +++ .../src/main}/jni/JniRemoteEnrollee.h | 69 +- .../src/main/jni/JniSecurityStatusListener.cpp | 128 ++ .../src/main/jni/JniSecurityStatusListener.h | 59 + .../easy-setup/mediator/richsdk/android/SConscript | 80 + .../mediator/richsdk/android/android_api.iml | 19 + .../mediator/richsdk/android/build.gradle | 43 + .../mediator/richsdk/android/gradle.properties | 40 + .../mediator/richsdk/android/jni/Android.mk | 60 - .../mediator/richsdk/android/jni/Application.mk | 4 - .../mediator/richsdk/android/jni/JniJvm.cpp | 80 - .../richsdk/android/jni/JniRemoteEnrollee.cpp | 159 -- .../mediator/richsdk/android/settings.gradle | 21 + .../easy-setup/mediator/richsdk/inc/ESRichCommon.h | 917 ++++++-- .../easy-setup/mediator/richsdk/inc/EasySetup.h | 33 +- .../mediator/richsdk/inc/EnrolleeSecurity.h | 69 - .../mediator/richsdk/inc/RemoteEnrollee.h | 168 +- .../mediator/richsdk/inc/RemoteEnrolleeResource.h | 131 -- .../mediator/richsdk/src/CloudResource.cpp | 98 + .../mediator/richsdk/src/CloudResource.h | 64 + .../mediator/richsdk/{inc => src}/ESException.h | 0 .../easy-setup/mediator/richsdk/src/EasySetup.cpp | 84 +- .../mediator/richsdk/src/EnrolleeResource.cpp | 250 +++ .../mediator/richsdk/src/EnrolleeResource.h | 85 + .../mediator/richsdk/src/EnrolleeSecurity.cpp | 566 +++-- .../mediator/richsdk/src/EnrolleeSecurity.h | 100 + .../mediator/richsdk/src/RemoteEnrollee.cpp | 483 +++-- .../richsdk/src/RemoteEnrolleeResource.cpp | 485 ----- .../richsdk/unittests/ESEnrolleeSimulator.h | 95 + .../mediator/richsdk/unittests/ESMediatorTest.cpp | 479 +++++ .../richsdk/unittests/MediatorRichTest.cpp | 335 --- .../mediator/richsdk/unittests/SConscript | 96 +- .../easy-setup/sampleapp/enrollee/linux/SConscript | 9 +- .../sampleapp/enrollee/linux/easysetup_x.c | 89 + .../enrollee/linux/easysetup_x.h} | 40 +- .../sampleapp/enrollee/linux/enrolleewifi.c | 193 +- .../sampleapp/enrollee/linux/oic_svr_db_server.dat | Bin 0 -> 997 bytes .../enrollee/tizen-sdb/EnrolleeSample/SConscript | 7 +- .../tizen-sdb/EnrolleeSample/build/SConscript | 33 +- .../tizen-sdb/EnrolleeSample/build/tizen/Makefile | 65 - .../EnrolleeSample/build/tizen/SConscript | 13 +- .../EnrolleeSample/build/tizen/SConstruct | 23 - .../EnrolleeSample/build/tizen/gbsbuild.sh | 25 +- .../EnrolleeSample/com.oic.es.sample.manifest | 6 +- .../tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c | 294 +++ .../tizen-sdb/EnrolleeSample/easysetup_wifi_conn.h | 58 + .../tizen-sdb/EnrolleeSample/enrolleewifi.cpp | 383 +++- .../packaging/com.oic.es.sample.spec | 20 +- .../tizen-sdb/EnrolleeSample/scons/SConscript | 12 +- .../sampleapp/enrollee/tizen-sdb/README.txt | 10 +- .../mediator/android/EasySetup/EasySetup.iml | 19 + .../mediator/android/EasySetup/app/build.gradle | 79 +- .../android/EasySetup/app/proguard-rules.pro | 17 + .../EasySetup/app/src/main/AndroidManifest.xml | 21 +- .../app/src/main/assets/oic_svr_db_client.dat | Bin 1052 -> 1000 bytes .../app/src/main/assets/oic_svr_db_client.json | 10 +- .../service/easysetup/EasysetupActivity.java | 1116 ++++++++++ .../iotivity/service/easysetup/LoginActivity.java | 124 ++ .../iotivity/service/easysetup/MainActivity.java | 577 ----- .../app/src/main/res/layout/activity_login.xml | 15 + .../app/src/main/res/layout/activity_main.xml | 269 --- .../app/src/main/res/layout/easysetup_main.xml | 807 +++++++ .../EasySetup/app/src/main/res/values/arrays.xml | 17 + .../EasySetup/app/src/main/res/values/strings.xml | 37 +- .../mediator/android/EasySetup/build.gradle | 26 +- .../mediator/android/EasySetup/gradle.properties | 47 + .../mediator/android/EasySetup/settings.gradle | 22 +- .../sampleapp/mediator/android/SConscript | 78 + .../mediator/linux/csdk_sample/SConscript | 64 - .../mediator/linux/csdk_sample/mediator.cpp | 123 -- .../mediator/linux/richsdk_sample/SConscript | 23 +- .../mediator/linux/richsdk_sample/mediator_cpp.cpp | 406 +++- .../linux/richsdk_sample/oic_svr_db_client.dat | Bin 0 -> 3071 bytes service/notification/SConscript | 139 ++ service/notification/android/SConscript | 63 + service/notification/android/android_api.iml | 19 + service/notification/android/build.gradle | 40 + service/notification/android/gradle.properties | 40 + service/notification/android/gradlew | 164 ++ service/notification/android/gradlew.bat | 90 + .../android/notification-service/base.iml | 90 + .../android/notification-service/build.gradle | 112 + .../notification-service/proguard-rules.pro | 17 + .../src/main/AndroidManifest.xml | 2 + .../iotivity/service/ns/common/MediaContents.java | 50 + .../org/iotivity/service/ns/common/Message.java | 175 ++ .../iotivity/service/ns/common/NSErrorCode.java | 71 + .../iotivity/service/ns/common/NSException.java | 61 + .../org/iotivity/service/ns/common/SyncInfo.java | 77 + .../java/org/iotivity/service/ns/common/Topic.java | 79 + .../org/iotivity/service/ns/common/TopicsList.java | 59 + .../service/ns/consumer/ConsumerService.java | 120 ++ .../org/iotivity/service/ns/consumer/Provider.java | 193 ++ .../org/iotivity/service/ns/provider/Consumer.java | 93 + .../service/ns/provider/ProviderService.java | 208 ++ .../notification-service/src/main/jni/Android.mk | 110 + .../src/main/jni/Application.mk | 2 + .../src/main/jni/common/JniNotificationCommon.cpp | 131 ++ .../src/main/jni/common/JniNotificationCommon.h | 61 + .../main/jni/consumer/JniNotificationConsumer.cpp | 1497 +++++++++++++ .../main/jni/consumer/JniNotificationConsumer.h | 123 ++ .../main/jni/provider/JniNotificationProvider.cpp | 1355 ++++++++++++ .../main/jni/provider/JniNotificationProvider.h | 151 ++ service/notification/android/settings.gradle | 23 + service/notification/cpp-wrapper/SConscript | 36 + .../cpp-wrapper/common/NSMediaContents.cpp | 49 + .../cpp-wrapper/common/NSMediaContents.h | 93 + .../notification/cpp-wrapper/common/NSMessage.cpp | 258 +++ .../notification/cpp-wrapper/common/NSMessage.h | 246 +++ .../notification/cpp-wrapper/common/NSSyncInfo.cpp | 56 + .../notification/cpp-wrapper/common/NSSyncInfo.h | 113 + .../cpp-wrapper/common/NSTopic.cpp} | 43 +- service/notification/cpp-wrapper/common/NSTopic.h | 113 + .../cpp-wrapper/common/NSTopicsList.cpp | 87 + .../notification/cpp-wrapper/common/NSTopicsList.h | 106 + service/notification/cpp-wrapper/common/NSUtils.h | 68 + .../notification/cpp-wrapper/consumer/SConscript | 123 ++ .../cpp-wrapper/consumer/inc/NSConsumerService.h | 121 ++ .../cpp-wrapper/consumer/inc/NSProvider.h | 254 +++ .../cpp-wrapper/consumer/src/NSConsumerService.cpp | 264 +++ .../cpp-wrapper/consumer/src/NSProvider.cpp | 268 +++ .../cpp-wrapper/examples/linux/SConscript | 91 + .../examples/linux/notificationserviceconsumer.cpp | 323 +++ .../examples/linux/notificationserviceprovider.cpp | 403 ++++ .../notification/cpp-wrapper/provider/SConscript | 139 ++ .../cpp-wrapper/provider/inc/NSConsumer.h | 116 + .../cpp-wrapper/provider/inc/NSProviderService.h | 201 ++ .../cpp-wrapper/provider/src/NSConsumer.cpp | 88 + .../cpp-wrapper/provider/src/NSProviderService.cpp | 261 +++ .../unittest/NSConsumerServiceSimulator.h | 201 ++ .../cpp-wrapper/unittest/NSConsumerServiceTest.cpp | 562 +++++ .../unittest/NSProviderServiceSimulator.h | 473 +++++ .../cpp-wrapper/unittest/NSProviderServiceTest.cpp | 525 +++++ .../notification/cpp-wrapper/unittest/SConscript | 104 + service/notification/examples/SConscript | 10 + .../android/NotiConsumerExample/.gitignore | 8 + .../android/NotiConsumerExample/SConscript | 83 + .../android/NotiConsumerExample/app/.gitignore | 1 + .../android/NotiConsumerExample/app/build.gradle | 30 + .../NotiConsumerExample/app/proguard-rules.pro | 17 + .../app/src/main/AndroidManifest.xml | 36 + .../sec/noticonsumerexample/ConsumerSample.java | 285 +++ .../com/sec/noticonsumerexample/MainActivity.java | 271 +++ .../app/src/main/res/layout/activity_main.xml | 160 ++ .../app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../app/src/main/res/values-w820dp/dimens.xml | 6 + .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/dimens.xml | 5 + .../app/src/main/res/values/strings.xml | 7 + .../app/src/main/res/values/styles.xml | 20 + .../android/NotiConsumerExample/build.gradle | 28 + .../android/NotiConsumerExample/gradlew.bat | 90 + .../android/NotiConsumerExample/settings.gradle | 1 + .../android/NotiProviderExample/.gitignore | 8 + .../android/NotiProviderExample/SConscript | 84 + .../android/NotiProviderExample/app/.gitignore | 1 + .../android/NotiProviderExample/app/build.gradle | 30 + .../NotiProviderExample/app/proguard-rules.pro | 17 + .../app/src/main/AndroidManifest.xml | 45 + .../com/sec/notiproviderexample/MainActivity.java | 292 +++ .../com/sec/notiproviderexample/NotiListener.java | 141 ++ .../sec/notiproviderexample/ProviderSample.java | 274 +++ .../app/src/main/res/layout/activity_main.xml | 212 ++ .../app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes .../app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes .../app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes .../app/src/main/res/values-w820dp/dimens.xml | 6 + .../app/src/main/res/values/colors.xml | 6 + .../app/src/main/res/values/dimens.xml | 5 + .../app/src/main/res/values/strings.xml | 11 + .../app/src/main/res/values/styles.xml | 20 + .../android/NotiProviderExample/build.gradle | 28 + .../android/NotiProviderExample/gradlew.bat | 90 + .../android/NotiProviderExample/settings.gradle | 1 + service/notification/examples/android/SConscript | 22 + service/notification/examples/linux/SConscript | 83 + .../notification/examples/linux/cloud_connector.c | 225 ++ .../notification/examples/linux/cloud_connector.h | 55 + .../examples/linux/notificationconsumer.c | 302 +++ .../examples/linux/notificationprovider.c | 393 ++++ service/notification/include/NSCommon.h | 168 ++ service/notification/include/NSConsumerInterface.h | 137 ++ service/notification/include/NSProviderInterface.h | 182 ++ service/notification/src/common/NSConstants.h | 318 +++ service/notification/src/common/NSStructs.h | 149 ++ service/notification/src/common/NSUtil.c | 493 +++++ service/notification/src/common/NSUtil.h | 66 + .../notification/src/consumer/NSConsumerCommon.c | 598 ++++++ .../notification/src/consumer/NSConsumerCommon.h | 151 ++ .../src/consumer/NSConsumerCommunication.c | 916 ++++++++ .../src/consumer/NSConsumerCommunication.h | 32 +- .../src/consumer/NSConsumerDiscovery.c | 402 ++++ .../src/consumer/NSConsumerDiscovery.h} | 34 +- .../src/consumer/NSConsumerInterface.c | 224 ++ .../consumer/NSConsumerInternalTaskController.c | 722 +++++++ .../consumer/NSConsumerInternalTaskController.h | 58 + .../src/consumer/NSConsumerMemoryCache.c | 348 +++ .../src/consumer/NSConsumerMemoryCache.h | 52 + .../src/consumer/NSConsumerNetworkEventListener.c | 132 ++ .../src/consumer/NSConsumerNetworkEventListener.h} | 34 +- .../notification/src/consumer/NSConsumerQueue.c | 106 + .../notification/src/consumer/NSConsumerQueue.h | 59 + .../src/consumer/NSConsumerScheduler.c | 344 +++ .../src/consumer/NSConsumerScheduler.h} | 58 +- .../notification/src/consumer/NSConsumerSystem.c | 29 + .../notification/src/consumer/NSConsumerSystem.h | 36 + service/notification/src/consumer/NSThread.c | 121 ++ service/notification/src/consumer/NSThread.h | 70 + .../src/provider/NSProviderCallbackResponse.c | 128 ++ .../src/provider/NSProviderCallbackResponse.h | 37 + .../src/provider/NSProviderDiscovery.c | 100 + .../src/provider/NSProviderDiscovery.h | 32 + .../src/provider/NSProviderInterface.c | 467 ++++ .../notification/src/provider/NSProviderListener.c | 562 +++++ .../notification/src/provider/NSProviderListener.h | 54 + .../src/provider/NSProviderMemoryCache.c | 679 ++++++ .../src/provider/NSProviderMemoryCache.h | 63 + .../src/provider/NSProviderNotification.c | 319 +++ .../src/provider/NSProviderNotification.h | 37 + .../notification/src/provider/NSProviderResource.c | 344 +++ .../notification/src/provider/NSProviderResource.h | 68 + .../src/provider/NSProviderScheduler.c | 301 +++ .../src/provider/NSProviderScheduler.h | 58 + .../src/provider/NSProviderSubscription.c | 420 ++++ .../src/provider/NSProviderSubscription.h | 49 + .../notification/src/provider/NSProviderSystem.c | 146 ++ .../notification/src/provider/NSProviderSystem.h | 44 + .../notification/src/provider/NSProviderTopic.c | 576 +++++ .../notification/src/provider/NSProviderTopic.h | 53 + .../notification/unittest/NSConsumerSimulator.h | 234 ++ service/notification/unittest/NSConsumerTest.cpp | 627 ++++++ .../notification/unittest/NSProviderSimulator.h | 473 +++++ service/notification/unittest/NSProviderTest.cpp | 557 +++++ service/notification/unittest/SConscript | 99 + service/resource-container/SConscript | 16 +- .../src/main/jni/JniBundleResource.cpp | 7 +- .../src/main/jni/JniBundleResource.h | 6 +- service/resource-container/android/settings.gradle | 38 +- .../bundle-api/include/BundleActivator.h | 10 +- .../bundle-api/include/BundleResource.h | 10 +- .../bundle-api/include/NotificationReceiver.h | 10 +- .../bundle-api/include/ProtocolBridgeConnector.h | 10 +- .../bundle-api/include/ProtocolBridgeResource.h | 19 +- .../bundle-api/include/SoftSensorResource.h | 9 +- .../BMISensorBundle/include/BMISensorResource.h | 6 +- .../BMISensorBundle/src/BMISensorResource.cpp | 14 +- .../src/inputSensors/HeightSensorApp/SConscript | 10 +- .../BMISensorBundle/src/inputSensors/SConscript | 2 +- .../src/inputSensors/WeightSensorApp/SConscript | 4 +- .../examples/ContainerSample.cpp | 26 +- .../examples/ContainerSampleClient.cpp | 4 + .../include/DiscomfortIndexSensorResource.h | 6 +- .../src/DiscomfortIndexSensorResource.cpp | 8 +- .../src/inputSensors/SConscript | 2 +- .../src/inputSensors/THSensorApp/SConscript | 4 +- .../src/inputSensors/THSensorApp1/SConscript | 4 +- .../examples/HueSampleBundle/LICENSE.CURL | 18 + .../examples/HueSampleBundle/include/HueLight.h | 7 +- .../examples/HueSampleBundle/src/HueConnector.cpp | 2 + .../examples/HueSampleBundle/src/HueLight.cpp | 6 +- service/resource-container/include/RCSBundleInfo.h | 8 +- service/resource-container/src/BundleResource.cpp | 15 +- service/resource-container/src/Configuration.cpp | 40 +- service/resource-container/src/Configuration.h | 4 + .../src/DiscoverResourceUnit.cpp | 6 +- .../resource-container/src/DiscoverResourceUnit.h | 10 +- .../resource-container/src/RemoteResourceUnit.cpp | 12 +- .../src/ResourceContainerImpl.cpp | 79 +- .../resource-container/src/SoftSensorResource.cpp | 2 + .../unittests/ResourceContainerTest.cpp | 79 +- .../unittests/ResourceContainerTestSimulator.h | 17 +- service/resource-container/unittests/SConscript | 22 +- .../TestBundle/include/TestBundleActivator.h | 13 +- service/resource-directory/include/rd_client.h | 70 - service/resource-directory/include/rd_payload.h | 135 -- .../resource-directory/src/internal/rd_storage.c | 234 -- .../resource-directory/src/internal/rd_storage.h | 53 - service/resource-directory/src/rd_client.c | 370 ---- service/resource-encapsulation/SConscript | 20 +- .../java/org/iotivity/service/TestBase.java | 20 +- .../resource-encapsulation/android/settings.gradle | 38 +- service/resource-encapsulation/examples/SConscript | 2 +- .../android/RESampleClientApp/app/build.gradle | 2 +- .../android/RESampleServerApp/app/build.gradle | 2 +- .../examples/linux/NestedAttributesClient.cpp | 2 + .../examples/linux/NestedAttributesServer.cpp | 15 +- .../examples/linux/SConscript | 4 +- .../examples/linux/SampleResourceClient.cpp | 42 +- .../examples/linux/SampleResourceServer.cpp | 22 +- .../examples/linux/SeparateResponseServer.cpp | 10 +- .../linux/secureResourceExample/SConscript | 8 +- .../secureResourceExample/oic_svr_db_client.dat | Bin 1222 -> 1170 bytes .../secureResourceExample/oic_svr_db_client.json | 10 +- .../secureResourceExample/oic_svr_db_server.dat | Bin 1421 -> 1369 bytes .../secureResourceExample/oic_svr_db_server.json | 10 +- .../resource-encapsulation/examples/tizen/README | 2 + .../resource-encapsulation/include/RCSException.h | 6 +- .../include/RCSRemoteResourceObject.h | 29 + .../include/RCSResourceAttributes.h | 58 +- .../include/RCSResourceObject.h | 46 +- .../resource-encapsulation/src/common/SConscript | 39 +- .../expiryTimer/unittests/ExpiryTimerTest.cpp | 44 +- .../primitiveResource/include/PrimitiveResource.h | 5 + .../include/PrimitiveResourceImpl.h | 17 + .../primitiveResource/src/RCSRepresentation.cpp | 10 +- .../unittests/PresenceSubscriberTest.cpp | 3 +- .../unittests/ResourceAttributesTest.cpp | 14 +- .../src/resourceBroker/src/DevicePresence.cpp | 3 + .../src/resourceBroker/src/ResourceBroker.cpp | 6 +- .../unittest/DeviceAssociationUnitTest.cpp | 5 +- .../unittest/DevicePresenceUnitTest.cpp | 14 +- .../unittest/ResourceBrokerUnitTest.cpp | 16 +- .../unittest/ResourcePresenceUnitTest.cpp | 49 +- .../src/resourceBroker/unittest/SConscript | 7 +- .../src/resourceCache/src/DataCache.cpp | 8 +- .../src/resourceCache/unittests/DataCacheTest.cpp | 11 +- .../resourceCache/unittests/ResourceCacheTest.cpp | 11 +- .../src/resourceCache/unittests/SConscript | 18 +- .../src/resourceClient/RCSRemoteResourceObject.cpp | 40 +- .../src/serverBuilder/SConscript | 31 +- .../src/serverBuilder/src/InterfaceHandler.cpp | 3 + .../src/serverBuilder/src/RCSResourceObject.cpp | 2 +- .../unittests/RCSResourceObjectTest.cpp | 13 +- .../unittests/DiscoveryManagerTest.cpp | 13 +- .../unittests/ResourceClientTest.cpp | 38 + .../resource-encapsulation/unittests/SConscript | 30 +- service/resource-hosting/SConscript | 16 +- service/resource-hosting/SampleApp/SConscript | 2 +- .../example/sample/provider/IMessageLogger.java | 38 +- .../resource-hosting/SampleApp/linux/SConscript | 6 +- .../linux/sampleConsumer/SampleConsumer.cpp | 15 +- service/resource-hosting/src/HostingObject.cpp | 13 +- service/resource-hosting/src/HostingObject.h | 4 + service/resource-hosting/src/RequestObject.cpp | 7 +- service/resource-hosting/src/ResourceHosting.cpp | 23 +- .../unittest/HostingObjectUnitTest.cpp | 4 +- .../unittest/ResourceHostingUnitTest.cpp | 2 +- service/resource-hosting/unittest/SConscript | 16 +- service/scene-manager/SConscript | 10 +- service/scene-manager/sampleapp/SConscript | 2 +- service/scene-manager/sampleapp/linux/SConscript | 26 +- .../scene-manager/sampleapp/linux/sceneclient.cpp | 5 +- .../scene-manager/src/RemoteSceneCollection.cpp | 2 +- service/scene-manager/src/Scene.cpp | 0 service/scene-manager/src/SceneAction.cpp | 0 service/scene-manager/src/SceneCollection.cpp | 0 .../scene-manager/src/SceneCollectionResource.cpp | 4 +- .../scene-manager/src/SceneCollectionResource.h | 0 .../src/SceneCollectionResourceRequestor.cpp | 13 +- service/scene-manager/src/SceneCommons.h | 6 +- service/scene-manager/src/SceneList.cpp | 0 service/scene-manager/src/SceneListResource.cpp | 16 +- .../src/SceneListResourceRequestor.cpp | 6 +- .../src/SceneMemberResourceRequestor.cpp | 2 +- service/scene-manager/src/SceneUtils.cpp | 65 +- .../unittests/RemoteSceneActionTest.cpp | 211 +- .../unittests/RemoteSceneCollectionTest.cpp | 100 +- .../unittests/RemoteSceneListTest.cpp | 54 +- .../scene-manager/unittests/RemoteSceneTest.cpp | 129 +- service/scene-manager/unittests/SConscript | 23 +- service/simulator/examples/client/SConscript | 4 +- service/simulator/examples/server/SConscript | 4 +- service/simulator/inc/simulator_error_codes.h | 6 + .../ClientControllerPlugin/META-INF/MANIFEST.MF | 8 +- .../clientcontroller/manager/ResourceManager.java | 6 +- service/simulator/java/eclipse-plugin/README.txt | 2 +- .../ServiceProviderPlugin/META-INF/MANIFEST.MF | 8 +- .../serviceprovider/manager/ResourceManager.java | 81 +- .../serviceprovider/view/ResourceManagerView.java | 2 +- .../view/dialogs/CreateResourceWizard.java | 261 +-- .../serviceprovider/view/dialogs/LoadRamlPage.java | 210 +- .../view/dialogs/ResourceWizardDialog.java | 6 +- .../UpdateMultiInstanceCreationPropertiesPage.java | 181 ++ .../view/dialogs/UpdatePropertiesPage.java | 58 +- service/simulator/java/jni/simulator_utils_jni.cpp | 36 + .../src/org/oic/simulator/SimulatorManager.java | 1 + .../sdk/src/org/oic/simulator/SimulatorResult.java | 8 +- service/simulator/ramlparser/SConscript | 2 +- service/simulator/src/common/simulator_utils.cpp | 3 - .../src/server/simulator_resource_factory.cpp | 22 +- service/things-manager/SConscript | 8 +- service/things-manager/sampleapp/SConscript | 4 +- .../linux/configuration/FactorySetCollection.cpp | 4 +- .../sampleapp/linux/configuration/SConscript | 4 +- .../sampleapp/linux/configuration/con-client.cpp | 35 +- service/things-manager/sdk/inc/ActionSet.h | 2 - service/things-manager/sdk/java/jni/SConscript | 4 +- service/things-manager/sdk/src/ActionSet.cpp | 14 +- service/things-manager/sdk/src/GroupManager.cpp | 27 +- .../things-manager/sdk/src/ThingsConfiguration.cpp | 55 +- .../things-manager/sdk/src/ThingsMaintenance.cpp | 34 + service/things-manager/unittests/SConscript | 14 +- .../things-manager/unittests/ThingsManagerTest.cpp | 109 +- service/third_party_libs.scons | 3 + tools/darwin/mkfwk_ios.sh | 2 +- tools/darwin/mkfwk_osx.sh | 2 +- tools/scons/RunTest.py | 10 +- tools/scons/UnpackAll.py | 2 +- tools/tizen/iotivity.spec | 278 ++- 1573 files changed, 137837 insertions(+), 42918 deletions(-) create mode 100644 .gbs.conf create mode 100644 android/android_api/base/jni/JniGetAclIdByDeviceListener.cpp create mode 100644 android/android_api/base/jni/JniGetAclIdByDeviceListener.h create mode 100644 android/android_api/base/jni/JniOcAccountManager.cpp create mode 100644 android/android_api/base/jni/JniOcAccountManager.h create mode 100644 android/android_api/base/jni/JniOcCloudProvisioning.cpp create mode 100644 android/android_api/base/jni/JniOcCloudProvisioning.h create mode 100644 android/android_api/base/jni/JniOcCloudResultListener.cpp create mode 100644 android/android_api/base/jni/JniOcCloudResultListener.h create mode 100644 android/android_api/base/jni/JniOnDeleteResourceListener.cpp create mode 100644 android/android_api/base/jni/JniOnDeleteResourceListener.h create mode 100644 android/android_api/base/jni/JniOnMQSubscribeListener.cpp create mode 100644 android/android_api/base/jni/JniOnMQSubscribeListener.h create mode 100644 android/android_api/base/jni/JniOnMQTopicFoundListener.cpp create mode 100644 android/android_api/base/jni/JniOnMQTopicFoundListener.h create mode 100644 android/android_api/base/jni/JniOnPublishResourceListener.cpp create mode 100644 android/android_api/base/jni/JniOnPublishResourceListener.h create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/EncodingType.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java create mode 100755 android/android_api/base/src/main/java/org/iotivity/base/OcCloudProvisioning.java create mode 100644 android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java create mode 100755 android/examples/cloudprovisioningclient/build.gradle create mode 100755 android/examples/cloudprovisioningclient/cloudprovisioningclient.iml create mode 100755 android/examples/cloudprovisioningclient/proguard-rules.pro create mode 100755 android/examples/cloudprovisioningclient/src/main/AndroidManifest.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.dat rename resource/csdk/security/provisioning/ck_manager/unittest/test_data/CKMInfo.json => android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.json (68%) mode change 100644 => 100755 create mode 100755 android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/CloudProvisioningClient.java create mode 100755 android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/LoginActivity.java create mode 100755 android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/StringConstants.java create mode 100755 android/examples/cloudprovisioningclient/src/main/res/drawable/dash_nil_border.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/drawable/round_button.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/layout/activity_login.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/layout/main_activity.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/layout/setting_layout.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/menu/menu_cloud_provision.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100755 android/examples/cloudprovisioningclient/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100755 android/examples/cloudprovisioningclient/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100755 android/examples/cloudprovisioningclient/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100755 android/examples/cloudprovisioningclient/src/main/res/values-v21/styles.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/values-w820dp/dimens.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/values/dimens.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/values/strings.xml create mode 100755 android/examples/cloudprovisioningclient/src/main/res/values/styles.xml create mode 100644 android/examples/provisioningclient/src/main/assets/rootca.crt create mode 100644 android/examples/simplebase/.gitignore create mode 100644 android/examples/simplebase/build.gradle create mode 100644 android/examples/simplebase/libs/android-support-v4.jar create mode 100644 android/examples/simplebase/proguard-rules.pro create mode 100644 android/examples/simplebase/simplebase.iml create mode 100644 android/examples/simplebase/src/main/AndroidManifest.xml create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/BluetoothFragment.java create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/CloudFragment.java create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/Common.java create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/DrawerFragment.java create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/LoginActivity.java create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/MessageFragment.java create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/SimpleBase.java create mode 100644 android/examples/simplebase/src/main/java/org/iotivity/base/examples/TemplateFragment.java create mode 100644 android/examples/simplebase/src/main/res/drawable-hdpi/drawer_shadow.9.png create mode 100644 android/examples/simplebase/src/main/res/drawable-hdpi/ic_drawer.png create mode 100644 android/examples/simplebase/src/main/res/drawable-mdpi/drawer_shadow.9.png create mode 100644 android/examples/simplebase/src/main/res/drawable-mdpi/ic_drawer.png create mode 100644 android/examples/simplebase/src/main/res/drawable-xhdpi/drawer_shadow.9.png create mode 100644 android/examples/simplebase/src/main/res/drawable-xhdpi/ic_drawer.png create mode 100644 android/examples/simplebase/src/main/res/drawable-xxhdpi/drawer_shadow.9.png create mode 100644 android/examples/simplebase/src/main/res/drawable-xxhdpi/ic_drawer.png create mode 100644 android/examples/simplebase/src/main/res/drawable/iotivityicon.png create mode 100644 android/examples/simplebase/src/main/res/drawable/iotivitylogo.png create mode 100644 android/examples/simplebase/src/main/res/layout/activity_login.xml create mode 100644 android/examples/simplebase/src/main/res/layout/activity_simplebase.xml create mode 100644 android/examples/simplebase/src/main/res/layout/fragment_bluetooth.xml create mode 100644 android/examples/simplebase/src/main/res/layout/fragment_cloud.xml create mode 100644 android/examples/simplebase/src/main/res/layout/fragment_drawer.xml create mode 100644 android/examples/simplebase/src/main/res/layout/fragment_message.xml create mode 100644 android/examples/simplebase/src/main/res/layout/fragment_template.xml create mode 100755 android/examples/simplebase/src/main/res/layout/input.xml create mode 100644 android/examples/simplebase/src/main/res/mipmap-hdpi/iotivityicon.png create mode 100644 android/examples/simplebase/src/main/res/mipmap-mdpi/iotivityicon.png create mode 100644 android/examples/simplebase/src/main/res/mipmap-xhdpi/iotivityicon.png create mode 100644 android/examples/simplebase/src/main/res/mipmap-xxhdpi/iotivityicon.png create mode 100644 android/examples/simplebase/src/main/res/values-v21/styles.xml create mode 100644 android/examples/simplebase/src/main/res/values-w820dp/dimens.xml create mode 100644 android/examples/simplebase/src/main/res/values/dimens.xml create mode 100644 android/examples/simplebase/src/main/res/values/strings.xml create mode 100644 android/examples/simplebase/src/main/res/values/styles.xml create mode 100644 auto_build.py create mode 100644 build_common/msys_nt/SConscript create mode 100644 build_common/thread.scons delete mode 100755 build_docs.sh delete mode 100644 cloud/account/.classpath delete mode 100644 cloud/account/.gitignore delete mode 100644 cloud/account/.project create mode 100644 cloud/account/Github.jar create mode 100644 cloud/account/Google.jar create mode 100644 cloud/account/properties/config.properties delete mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/AccountServerManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/AclTable.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/CRLTable.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/CertificateTable.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/GroupTable.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/InviteTable.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/TokenTable.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/db/UserTable.java rename cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/{GitHub.java => Github.java} (59%) create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/Google.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/OAuthProvider.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/oauth/OAuthProviderFactory.java delete mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/AccountResource.java delete mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/AuthResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/session/SessionResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/tokenrefresh/TokenRefreshResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/Group.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/Ace.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/AceResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/Acl.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/AclManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/id/AclResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/verify/AclVerifyResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/verify/Permission.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/cert/CertificateConstants.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/cert/CertificateManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/cert/CertificateResource.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/cert/CertificateStorage.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/crl/CrlManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/credprov/crl/CrlResource.java delete mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/util/CoapMessageBuilder.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/util/TypeCastingManager.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/x509/cert/CSRParser.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/x509/cert/CertificateBuilder.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/x509/cert/CertificateExtension.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/x509/cert/Utility.java create mode 100644 cloud/account/src/main/java/org/iotivity/cloud/accountserver/x509/crl/CrlIssuer.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/AccountResourceTest.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/credprov/cert/CertificateResourceTest.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/credprov/cert/GenerateCSR.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/credprov/crl/CrlResourceTest.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/session/SessionResourceTest.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/tokenrefresh/TokenRefreshResourceTest.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/group/GroupResourceTest.java create mode 100644 cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteResourceTest.java delete mode 100644 cloud/account/src/test/java/org/iotivity/cloud/testaccountserver/TestAccountServer.java create mode 100644 cloud/certificate/iotivitycloud.crt create mode 100644 cloud/certificate/iotivitycloud.key create mode 100644 cloud/certificate/rootca.crt delete mode 100644 cloud/interface/.classpath delete mode 100644 cloud/interface/.gitignore delete mode 100644 cloud/interface/.project mode change 100644 => 100755 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/CloudInterfaceServer.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/DeviceServerSystem.java delete mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/protocols/CoapAuthHandler.java delete mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/protocols/CoapRelayHandler.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/DiResource.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/Account.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AccountSession.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/Acl.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclGroup.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclInvite.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/Certificate.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/Crl.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/mq/MessageQueue.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/DevicePresence.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceDirectory.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceFind.java create mode 100644 cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourcePresence.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/DeviceServerSystemTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/DiResourceTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/KeepAliveResourceTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AccountSessionTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AccountTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclGroupTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclInviteTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/CertificateTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/mq/MessageQueueTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/rd/DevicePresenceTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceDirectoryTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceFindTest.java create mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourcePresenceTest.java delete mode 100644 cloud/interface/src/test/java/org/iotivity/cloud/ciserver/testci/TestCloudInterface.java create mode 100644 cloud/messagequeue/README create mode 100644 cloud/messagequeue/pom.xml create mode 100644 cloud/messagequeue/server.properties create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/Constants.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/MessageQueueServer.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/MessageQueueUtils.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaCommonWrapper.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaConsumerWrapper.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/kafka/KafkaProducerWrapper.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/resources/MQBrokerResource.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/topic/Topic.java create mode 100644 cloud/messagequeue/src/main/java/org/iotivity/cloud/mqserver/topic/TopicManager.java create mode 100644 cloud/messagequeue/src/test/java/org/iotivity/cloud/mqserver/resources/MQBrokerResourceTest.java delete mode 100644 cloud/resourcedirectory/.classpath delete mode 100644 cloud/resourcedirectory/.gitignore delete mode 100644 cloud/resourcedirectory/.project delete mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/MongoDB.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/db/DBManager.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/db/MongoDB.java delete mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/LinksPayloadFormat.java delete mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/PublishPayloadFormat.java delete mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/ResourceDirectoryResource.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/PayloadManager.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/RDManager.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/rd/InsManager.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/rd/ResourceDirectoryResource.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/res/DiscoveryResource.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/presence/PresenceManager.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/presence/device/DevicePresenceResource.java create mode 100644 cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/presence/resource/ResPresenceResource.java create mode 100644 cloud/resourcedirectory/src/test/java/org/iotivity/cloud/testrdserver/DevicePresenceResourceTest.java create mode 100644 cloud/resourcedirectory/src/test/java/org/iotivity/cloud/testrdserver/DiscoveryResourceTest.java delete mode 100644 cloud/resourcedirectory/src/test/java/org/iotivity/cloud/testrdserver/RDServerTest.java create mode 100644 cloud/resourcedirectory/src/test/java/org/iotivity/cloud/testrdserver/RDServerTestUtils.java create mode 100644 cloud/resourcedirectory/src/test/java/org/iotivity/cloud/testrdserver/ResourceDirectoryResourceTest.java create mode 100644 cloud/resourcedirectory/src/test/java/org/iotivity/cloud/testrdserver/ResourcePresenceResourceTest.java create mode 100644 cloud/samples/client/airconditioner/aircon_controlee.cpp create mode 100644 cloud/samples/client/airconditioner/aircon_controller.cpp delete mode 100644 cloud/samples/client/cloud_connector.c create mode 100644 cloud/samples/client/group_invite/group_invite.cpp create mode 100644 cloud/samples/client/group_invite/group_light_share.cpp create mode 100644 cloud/samples/client/messagequeue/mq_publisher.cpp create mode 100644 cloud/samples/client/messagequeue/mq_subscriber.cpp delete mode 100644 cloud/samples/client/sample_device.cpp create mode 100644 cloud/samples/client/thin_light/thin_room_light.cpp delete mode 100644 cloud/stack/.classpath delete mode 100644 cloud/stack/.gitignore delete mode 100644 cloud/stack/.project create mode 100644 cloud/stack/src/main/java/log4j.properties delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/CoapClient.java delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/HttpServer.java create mode 100755 cloud/stack/src/main/java/org/iotivity/cloud/base/OICConstants.java delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/ResourceManager.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/ServerSystem.java delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/SessionManager.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/connector/CoapClient.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/connector/CoapConnector.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/connector/ConnectorPool.java rename cloud/stack/src/main/java/org/iotivity/cloud/base/{ => connector}/HttpClient.java (88%) create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/device/CoapDevice.java rename cloud/stack/src/main/java/org/iotivity/cloud/base/{Resource.java => device/Device.java} (55%) rename cloud/{account/src/main/java/org/iotivity/cloud/accountserver/resources/ResponseObject.java => stack/src/main/java/org/iotivity/cloud/base/device/HttpDevice.java} (52%) create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/device/IRequestChannel.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/device/IRequestEventHandler.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/device/IResponseEventHandler.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/exception/ClientException.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/exception/ServerException.java rename cloud/{account/src/main/java/org/iotivity/cloud/accountserver/oauth/OAuthServer.java => stack/src/main/java/org/iotivity/cloud/base/protocols/IRequest.java} (58%) rename cloud/{account/src/main/java/org/iotivity/cloud/accountserver/db/UserDevice.java => stack/src/main/java/org/iotivity/cloud/base/protocols/IResponse.java} (62%) create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/Message.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/MessageBuilder.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/coap/CoapLogHandler.java rename cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/coap/{enums => }/CoapOption.java (65%) delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/coap/enums/CoapMethod.java delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/coap/enums/CoapStatus.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/enums/ContentFormat.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/enums/Observe.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/enums/RequestMethod.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/enums/ResponseStatus.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/http/HttpMessage.java delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/protocols/proxy/CoapHttpProxyHandler.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/resource/Resource.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/resource/ResourceManager.java create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/base/resource/URIPathNode.java rename cloud/stack/src/{test/java/org/iotivity/cloud/base/CoapServerTest.java => main/java/org/iotivity/cloud/base/server/CoapServer.java} (61%) rename cloud/{account/src/main/java/org/iotivity/cloud/accountserver/db/UserSession.java => stack/src/main/java/org/iotivity/cloud/base/server/HttpServer.java} (62%) rename cloud/stack/src/main/java/org/iotivity/cloud/base/{CoapServer.java => server/Server.java} (57%) create mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/util/Bytes.java delete mode 100644 cloud/stack/src/main/java/org/iotivity/cloud/util/CoapLogHandler.java rename cloud/stack/src/main/java/org/iotivity/cloud/util/{Logger.java => Log.java} (61%) delete mode 100644 cloud/stack/src/test/java/org/iotivity/cloud/base/CoapClientTest.java delete mode 100644 cloud/stack/src/test/java/org/iotivity/cloud/base/ResourceManagerTest.java delete mode 100644 cloud/stack/src/test/java/org/iotivity/cloud/base/ResourceTest.java delete mode 100644 cloud/stack/src/test/java/org/iotivity/cloud/base/SessionManagerTest.java delete mode 100644 cloud/stack/src/test/java/org/iotivity/cloud/base/protocols/coap/CoapRequestTest.java delete mode 100644 cloud/stack/src/test/java/org/iotivity/cloud/base/protocols/coap/CoapResponseTest.java delete mode 100644 cloud/stack/src/test/java/org/iotivity/cloud/util/UtilTest.java delete mode 100644 extlibs/asn1cert/SConscript delete mode 100644 extlibs/asn1cert/certificate.asn delete mode 100644 extlibs/asn1cert/crl.asn delete mode 100644 extlibs/asn1cert/csr.asn create mode 100644 extlibs/libcoap/SConscript create mode 100644 extlibs/mbedtls/SConscript create mode 100644 extlibs/mbedtls/ocf.patch rename resource/{csdk/connectivity/inc/pkix => c_common}/byte_array.h (97%) create mode 100644 resource/c_common/windows/SConscript create mode 100644 resource/c_common/windows/include/getopt.h create mode 100644 resource/c_common/windows/include/pthread_create.h create mode 100644 resource/c_common/windows/include/vs12_snprintf.h create mode 100644 resource/c_common/windows/include/win_sleep.h create mode 100644 resource/c_common/windows/src/getopt.c create mode 100644 resource/c_common/windows/src/pthread_create.c create mode 100644 resource/c_common/windows/src/snprintf.c create mode 100644 resource/c_common/windows/src/win_sleep.c create mode 100644 resource/csdk/connectivity/inc/ca_adapter_net_ssl.h create mode 100644 resource/csdk/connectivity/inc/cafragmentation.h delete mode 100644 resource/csdk/connectivity/inc/pkix/cert.h delete mode 100644 resource/csdk/connectivity/inc/pkix/crl.h delete mode 100644 resource/csdk/connectivity/inc/pkix/crypto_adapter.h delete mode 100644 resource/csdk/connectivity/inc/pkix/der_dec.h delete mode 100644 resource/csdk/connectivity/inc/pkix/pki.h delete mode 100644 resource/csdk/connectivity/inc/pkix/pki_errors.h delete mode 100644 resource/csdk/connectivity/inc/pkix/sn_store.h delete mode 100644 resource/csdk/connectivity/lib/libcoap-4.1.1/SConscript rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/address.h (92%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/async.h (98%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/bits.h (89%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/block.h (96%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/coap.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/coap_list.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/coap_time.h (89%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/config.h (82%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/debug.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/encode.h (97%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/hashkey.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/mem.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/net.h (97%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/option.h (88%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/pdu.h (56%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/prng.h (95%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/resource.h (99%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/str.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/subscribe.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/t_list.h (93%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/uri.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/uthash.h (100%) rename resource/csdk/connectivity/lib/libcoap-4.1.1/{ => include/coap}/utlist.h (99%) create mode 100644 resource/csdk/connectivity/src/adapter_util/ca_adapter_net_ssl.c delete mode 100644 resource/csdk/connectivity/src/adapter_util/caadapternetdtls.c create mode 100644 resource/csdk/connectivity/src/adapter_util/cafragmentation.c delete mode 100644 resource/csdk/connectivity/src/adapter_util/pkix/cert.c delete mode 100644 resource/csdk/connectivity/src/adapter_util/pkix/crl.c delete mode 100644 resource/csdk/connectivity/src/adapter_util/pkix/der_dec.c delete mode 100644 resource/csdk/connectivity/src/adapter_util/pkix/pki.c delete mode 100644 resource/csdk/connectivity/src/adapter_util/pkix/sn_store.c create mode 100644 resource/csdk/connectivity/src/ip_adapter/windows/SConscript create mode 100644 resource/csdk/connectivity/src/ip_adapter/windows/caipnwmonitor.c create mode 100644 resource/csdk/connectivity/src/tcp_adapter/arduino/SConscript create mode 100644 resource/csdk/connectivity/src/tcp_adapter/arduino/catcpadapterutils_eth.cpp create mode 100644 resource/csdk/connectivity/src/tcp_adapter/arduino/catcpadapterutils_eth.h create mode 100644 resource/csdk/connectivity/src/tcp_adapter/arduino/catcpserver_eth.cpp create mode 100644 resource/csdk/connectivity/test/cablocktransfertest.cpp create mode 100644 resource/csdk/connectivity/test/ssladapter_test.cpp create mode 100644 resource/csdk/connectivity/test/ulinklist_test.cpp create mode 100644 resource/csdk/connectivity/test/uqueue_test.cpp create mode 100644 resource/csdk/connectivity/util/src/camanager/tizen/caleconnectionmanager.c create mode 100644 resource/csdk/octbstack_product.def create mode 100644 resource/csdk/octbstack_product_secured.def create mode 100644 resource/csdk/octbstack_test.def rename {service => resource/csdk}/resource-directory/SConscript (54%) create mode 100644 resource/csdk/resource-directory/include/rd_client.h create mode 100644 resource/csdk/resource-directory/include/rd_database.h rename {service => resource/csdk}/resource-directory/include/rd_server.h (95%) rename {service => resource/csdk}/resource-directory/samples/SConscript (59%) create mode 100644 resource/csdk/resource-directory/samples/oic_svr_db_server.dat rename {service => resource/csdk}/resource-directory/samples/rd_main.c (96%) rename {service => resource/csdk}/resource-directory/samples/rd_publishingClient.cpp (66%) rename {service => resource/csdk}/resource-directory/samples/rd_queryClient.cpp (84%) create mode 100644 resource/csdk/resource-directory/samples/rdclient.cpp create mode 100644 resource/csdk/resource-directory/src/internal/rd_database.c create mode 100644 resource/csdk/resource-directory/src/rd_client.c rename {service => resource/csdk}/resource-directory/src/rd_server.c (58%) rename {service/easy-setup/mediator/csdk => resource/csdk/resource-directory}/unittests/SConscript (67%) create mode 100644 resource/csdk/resource-directory/unittests/rddatabase.cpp create mode 100644 resource/csdk/resource-directory/unittests/rdtests.cpp mode change 100755 => 100644 resource/csdk/security/SConscript mode change 100755 => 100644 resource/csdk/security/include/internal/doxmresource.h rename resource/csdk/{connectivity/src/adapter_util/pkix/der_const.c => security/include/pkix_interface.h} (58%) mode change 100755 => 100644 resource/csdk/security/provisioning/SConscript delete mode 100644 resource/csdk/security/provisioning/ck_manager/SConscript delete mode 100644 resource/csdk/security/provisioning/ck_manager/include/cert_generator.h delete mode 100644 resource/csdk/security/provisioning/ck_manager/include/ck_manager.h delete mode 100644 resource/csdk/security/provisioning/ck_manager/include/ckm_info.h delete mode 100644 resource/csdk/security/provisioning/ck_manager/include/crl_generator.h delete mode 100644 resource/csdk/security/provisioning/ck_manager/include/csr_generator.h delete mode 100644 resource/csdk/security/provisioning/ck_manager/sample/Door_sample.cpp delete mode 100755 resource/csdk/security/provisioning/ck_manager/sample/Light_sample.cpp delete mode 100644 resource/csdk/security/provisioning/ck_manager/sample/README.txt delete mode 100644 resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_door.dat delete mode 100644 resource/csdk/security/provisioning/ck_manager/sample/oic_svr_db_light.dat delete mode 100644 resource/csdk/security/provisioning/ck_manager/sample/provisioningclient.c delete mode 100644 resource/csdk/security/provisioning/ck_manager/src/cert_generator.c delete mode 100644 resource/csdk/security/provisioning/ck_manager/src/ck_manager.c delete mode 100644 resource/csdk/security/provisioning/ck_manager/src/ckm_info.c delete mode 100644 resource/csdk/security/provisioning/ck_manager/src/crl_generator.c delete mode 100644 resource/csdk/security/provisioning/ck_manager/src/csr_generator.c delete mode 100644 resource/csdk/security/provisioning/ck_manager/tools/SConscript delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/SConscript delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/ckm_info_test.cpp delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/crl_generator_test.cpp delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/csr_generator_test.cpp delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/pki_test.cpp delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/test_data/01.der delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/test_data/CKMInfo.dat delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/test_data/cacert.der delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/test_data/capub.der delete mode 100755 resource/csdk/security/provisioning/ck_manager/unittest/test_data/cert_chain.dat delete mode 100644 resource/csdk/security/provisioning/ck_manager/unittest/test_data/chain.der create mode 100644 resource/csdk/security/provisioning/include/cloud/occloudprovisioning.h create mode 100644 resource/csdk/security/provisioning/include/cloud/utils.h create mode 100644 resource/csdk/security/provisioning/include/internal/multipleownershiptransfermanager.h mode change 100644 => 100755 resource/csdk/security/provisioning/include/ocprovisioningmanager.h create mode 100644 resource/csdk/security/provisioning/include/oxm/oxmpreconfpin.h create mode 100644 resource/csdk/security/provisioning/sample/README-cloud.txt rename resource/csdk/security/provisioning/{ck_manager/sample/oic_svr_db_pt.dat => sample/cloud.dat} (65%) rename resource/csdk/security/provisioning/{ck_manager/sample/oic_svr_db_pt.json => sample/cloud.json} (84%) create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudAuth.c create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudAuth.h create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudCommon.c create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudCommon.h create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudDiscovery.c create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudDiscovery.h create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudResource.c create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudResource.h create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudWrapper.c create mode 100644 resource/csdk/security/provisioning/sample/cloud/cloudWrapper.h create mode 100644 resource/csdk/security/provisioning/sample/cloudClient.c create mode 100644 resource/csdk/security/provisioning/sample/cloudServer.c create mode 100644 resource/csdk/security/provisioning/sample/oic_svr_db_subowner_client.dat rename resource/csdk/security/provisioning/{ck_manager/sample/oic_svr_db_light.json => sample/oic_svr_db_subowner_client.json} (65%) create mode 100644 resource/csdk/security/provisioning/sample/rootca.crt create mode 100644 resource/csdk/security/provisioning/sample/subownerclient.c create mode 100644 resource/csdk/security/provisioning/src/cloud/aclgroup.c create mode 100644 resource/csdk/security/provisioning/src/cloud/aclid.c create mode 100644 resource/csdk/security/provisioning/src/cloud/aclinvite.c create mode 100644 resource/csdk/security/provisioning/src/cloud/crl.c create mode 100644 resource/csdk/security/provisioning/src/cloud/csr.c create mode 100644 resource/csdk/security/provisioning/src/cloud/utils.c create mode 100644 resource/csdk/security/provisioning/src/multipleownershiptransfermanager.c mode change 100644 => 100755 resource/csdk/security/provisioning/src/ocprovisioningmanager.c create mode 100644 resource/csdk/security/provisioning/src/oxmpreconfpin.c rename service/easy-setup/enrollee/linux/wifi/softapnative.c => resource/csdk/security/src/pkix_interface.c (51%) mode change 100644 => 100755 resource/csdk/security/src/policyengine.c create mode 100644 resource/csdk/security/src/strptime.c delete mode 100644 resource/csdk/stack/include/rdpayload.h create mode 100644 resource/csdk/stack/samples/linux/SimpleClientServer/common.h delete mode 100644 resource/csdk/stack/samples/linux/secure/oic_svr_db_client.dat delete mode 100644 resource/csdk/stack/samples/linux/secure/oic_svr_db_client.json delete mode 100644 resource/csdk/stack/src/rdpayload.c create mode 100644 resource/csdk/stack/test/linux/SConscript create mode 100644 resource/examples/mediaserver.cpp create mode 100644 resource/examples/winuiclient.cpp create mode 100644 resource/examples/winuiclient.h create mode 100644 resource/examples/winuiclientgui.cpp create mode 100644 resource/include/OCAccountManager.h create mode 100755 resource/include/OCCloudProvisioning.h mode change 100644 => 100755 resource/include/OCProvisioningManager.h create mode 100644 resource/provisioning/examples/cloud.dat rename resource/{csdk/security/provisioning/ck_manager/sample/oic_svr_db_door.json => provisioning/examples/cloud.json} (56%) create mode 100644 resource/provisioning/examples/cloudAuth.cpp create mode 100644 resource/provisioning/examples/cloudAuth.h create mode 100644 resource/provisioning/examples/cloudClient.cpp create mode 100644 resource/provisioning/examples/cloudWrapper.cpp create mode 100644 resource/provisioning/examples/cloudWrapper.h create mode 100644 resource/provisioning/examples/rootca.crt create mode 100644 resource/provisioning/src/OCCloudProvisioning.cpp mode change 100644 => 100755 resource/provisioning/src/OCProvisioningManager.cpp create mode 100755 resource/provisioning/unittests/OCCloudProvisioningTest.cpp mode change 100644 => 100755 resource/provisioning/unittests/OCProvisioningTest.cpp create mode 100644 resource/src/OCAccountManager.cpp create mode 100644 resource/unittests/OCAccountManagerTest.cpp create mode 100644 resource/unittests/OCMQResourceTest.cpp create mode 100644 run.bat create mode 100644 service/coap-http-proxy/SConscript create mode 100644 service/coap-http-proxy/include/CoapHttpHandler.h create mode 100644 service/coap-http-proxy/include/CoapHttpMap.h create mode 100644 service/coap-http-proxy/include/CoapHttpParser.h create mode 100644 service/coap-http-proxy/samples/SConscript create mode 100644 service/coap-http-proxy/samples/proxy_client.c create mode 100644 service/coap-http-proxy/samples/proxy_main.c create mode 100644 service/coap-http-proxy/src/CoapHttpHandler.c create mode 100644 service/coap-http-proxy/src/CoapHttpMap.c create mode 100644 service/coap-http-proxy/src/CoapHttpParser.c create mode 100644 service/coap-http-proxy/unittests/CoAPHttpUnitTest.cpp create mode 100644 service/coap-http-proxy/unittests/SConscript delete mode 100644 service/easy-setup/enrollee/arduino/easysetup.cpp delete mode 100644 service/easy-setup/enrollee/arduino/onboarding.cpp delete mode 100644 service/easy-setup/enrollee/arduino/resourcehandler.cpp delete mode 100644 service/easy-setup/enrollee/arduino/softap.cpp delete mode 100644 service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp delete mode 100644 service/easy-setup/enrollee/arduino/wifi/networkhandler.h create mode 100755 service/easy-setup/enrollee/inc/ESEnrolleeCommon.h delete mode 100644 service/easy-setup/enrollee/linux/wifi/networkhandler.c delete mode 100644 service/easy-setup/enrollee/linux/wifi/networkhandler.h mode change 100644 => 100755 service/easy-setup/enrollee/src/easysetup.c delete mode 100644 service/easy-setup/enrollee/src/easysetupcallbacks.h delete mode 100644 service/easy-setup/enrollee/src/onboarding.c delete mode 100644 service/easy-setup/enrollee/src/onboarding.h mode change 100644 => 100755 service/easy-setup/enrollee/src/resourcehandler.c mode change 100644 => 100755 service/easy-setup/enrollee/src/resourcehandler.h delete mode 100644 service/easy-setup/enrollee/src/softap.c delete mode 100644 service/easy-setup/enrollee/src/softap.h delete mode 100644 service/easy-setup/enrollee/tizen/wifi/networkhandler.c delete mode 100644 service/easy-setup/enrollee/tizen/wifi/networkhandler.h delete mode 100644 service/easy-setup/enrollee/tizen/wifi/softapnative.c delete mode 100644 service/easy-setup/enrollee/tizen/wifi/softapnative.h create mode 100755 service/easy-setup/enrollee/unittests/ESEnrolleeTest.cpp create mode 100755 service/easy-setup/enrollee/unittests/ESMediatorSimulator.h delete mode 100644 service/easy-setup/enrollee/unittests/enrolleetests.cpp delete mode 100644 service/easy-setup/enrollee/unittests/gtesthelper.h delete mode 100644 service/easy-setup/mediator/csdk/SConscript delete mode 100755 service/easy-setup/mediator/csdk/inc/provisioning.h delete mode 100755 service/easy-setup/mediator/csdk/src/provisioning.cpp delete mode 100755 service/easy-setup/mediator/csdk/src/provisioningapi.cpp delete mode 100755 service/easy-setup/mediator/csdk/src/wifiprovisioning.cpp delete mode 100644 service/easy-setup/mediator/csdk/unittests/MediatorCSDKTest.cpp mode change 100644 => 100755 service/easy-setup/mediator/richsdk/SConscript create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/EasySetupCore.iml create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/proguard-rules.pro delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/androidTest.iml delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceConfigTest.java delete mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupServiceTest.java delete mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EasySetupStatusTest.java delete mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactoryTest.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeInfo.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeOnBoardingInfo.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ip/WiFiSoftAPManager.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudProp.java rename service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/{OnBoardingCallback.java => CloudPropProvisioningCallback.java} (51%) mode change 100644 => 100755 create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/CloudPropProvisioningStatus.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/DeviceProp.java rename service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/{OnBoardingConnection.java => DevicePropProvisioningCallback.java} (54%) create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/DevicePropProvisioningStatus.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ESConstants.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetup.java delete mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupService.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EasySetupStatus.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeConf.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDevice.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceFactory.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeDeviceWiFiOnboarding.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeState.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/EnrolleeStatus.java rename service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/{EnrolleeSetupError.java => GetConfigurationCallback.java} (57%) create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetConfigurationStatus.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/GetEnrolleeStatus.java rename service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/{IProvisionStatusNativeHandler.java => GetStatusCallback.java} (62%) delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/IpOnBoardingConnection.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/OnBoardingConfig.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningCallback.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/ProvisioningConfig.java mode change 100644 => 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/RemoteEnrollee.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/SecurityProvisioningCallback.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/SecurityProvisioningStatus.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiOnBoardingConfig.java delete mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/WiFiProvConfig.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESCloudProvState.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESErrorCode.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ESResult.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/ProvStatus.java rename service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/{core/IOnBoardingStatus.java => mediator/enums/WIFI_AUTHTYPE.java} (50%) create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/WIFI_ENCTYPE.java create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/WIFI_FREQ.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/mediator/enums/WIFI_MODE.java create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/Android.mk create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/Application.mk create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniCloudPropProvisioningStatusListener.cpp rename service/easy-setup/mediator/richsdk/android/{jni/JniProvisioningStatusListener.h => EasySetupCore/src/main/jni/JniCloudPropProvisioningStatusListener.h} (67%) mode change 100644 => 100755 rename service/easy-setup/mediator/richsdk/android/{jni/JniProvisioningStatusLisener.cpp => EasySetupCore/src/main/jni/JniDevicePropProvisioningStatusListener.cpp} (54%) mode change 100644 => 100755 create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniDevicePropProvisioningStatusListener.h rename service/easy-setup/mediator/richsdk/android/{ => EasySetupCore/src/main}/jni/JniEasySetup.cpp (54%) mode change 100644 => 100755 rename service/easy-setup/mediator/richsdk/android/{ => EasySetupCore/src/main}/jni/JniEasySetup.h (74%) mode change 100644 => 100755 rename service/easy-setup/mediator/richsdk/android/{ => EasySetupCore/src/main}/jni/JniEsListenerManager.h (92%) mode change 100644 => 100755 rename service/easy-setup/mediator/richsdk/android/{ => EasySetupCore/src/main}/jni/JniEsUtils.cpp (52%) mode change 100644 => 100755 rename service/easy-setup/mediator/richsdk/android/{ => EasySetupCore/src/main}/jni/JniEsUtils.h (86%) mode change 100644 => 100755 create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniGetConfigurationStatusListener.cpp create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniGetConfigurationStatusListener.h create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniGetEnrolleeStatusListener.cpp create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniGetEnrolleeStatusListener.h create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniJvm.cpp rename service/easy-setup/mediator/richsdk/android/{ => EasySetupCore/src/main}/jni/JniJvm.h (66%) mode change 100644 => 100755 create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniRemoteEnrollee.cpp rename service/easy-setup/mediator/richsdk/android/{ => EasySetupCore/src/main}/jni/JniRemoteEnrollee.h (51%) mode change 100644 => 100755 create mode 100755 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniSecurityStatusListener.cpp create mode 100644 service/easy-setup/mediator/richsdk/android/EasySetupCore/src/main/jni/JniSecurityStatusListener.h create mode 100755 service/easy-setup/mediator/richsdk/android/SConscript create mode 100644 service/easy-setup/mediator/richsdk/android/android_api.iml create mode 100755 service/easy-setup/mediator/richsdk/android/build.gradle create mode 100644 service/easy-setup/mediator/richsdk/android/gradle.properties delete mode 100644 service/easy-setup/mediator/richsdk/android/jni/Android.mk delete mode 100644 service/easy-setup/mediator/richsdk/android/jni/Application.mk delete mode 100644 service/easy-setup/mediator/richsdk/android/jni/JniJvm.cpp delete mode 100644 service/easy-setup/mediator/richsdk/android/jni/JniRemoteEnrollee.cpp create mode 100755 service/easy-setup/mediator/richsdk/android/settings.gradle mode change 100644 => 100755 service/easy-setup/mediator/richsdk/inc/EasySetup.h delete mode 100755 service/easy-setup/mediator/richsdk/inc/EnrolleeSecurity.h mode change 100644 => 100755 service/easy-setup/mediator/richsdk/inc/RemoteEnrollee.h delete mode 100755 service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h create mode 100755 service/easy-setup/mediator/richsdk/src/CloudResource.cpp create mode 100644 service/easy-setup/mediator/richsdk/src/CloudResource.h rename service/easy-setup/mediator/richsdk/{inc => src}/ESException.h (100%) mode change 100644 => 100755 service/easy-setup/mediator/richsdk/src/EasySetup.cpp create mode 100755 service/easy-setup/mediator/richsdk/src/EnrolleeResource.cpp create mode 100644 service/easy-setup/mediator/richsdk/src/EnrolleeResource.h create mode 100755 service/easy-setup/mediator/richsdk/src/EnrolleeSecurity.h delete mode 100755 service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp create mode 100755 service/easy-setup/mediator/richsdk/unittests/ESEnrolleeSimulator.h create mode 100755 service/easy-setup/mediator/richsdk/unittests/ESMediatorTest.cpp delete mode 100644 service/easy-setup/mediator/richsdk/unittests/MediatorRichTest.cpp create mode 100755 service/easy-setup/sampleapp/enrollee/linux/easysetup_x.c rename service/easy-setup/{mediator/csdk/inc/provisioningapi.h => sampleapp/enrollee/linux/easysetup_x.h} (52%) mode change 100644 => 100755 service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c create mode 100644 service/easy-setup/sampleapp/enrollee/linux/oic_svr_db_server.dat delete mode 100644 service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/Makefile delete mode 100644 service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/build/tizen/SConstruct create mode 100644 service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.c create mode 100644 service/easy-setup/sampleapp/enrollee/tizen-sdb/EnrolleeSample/easysetup_wifi_conn.h create mode 100755 service/easy-setup/sampleapp/mediator/android/EasySetup/EasySetup.iml create mode 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/app/proguard-rules.pro mode change 100755 => 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/AndroidManifest.xml create mode 100755 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/EasysetupActivity.java create mode 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/LoginActivity.java delete mode 100755 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java create mode 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/layout/activity_login.xml delete mode 100755 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/layout/activity_main.xml create mode 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/layout/easysetup_main.xml create mode 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/res/values/arrays.xml mode change 100644 => 100755 service/easy-setup/sampleapp/mediator/android/EasySetup/build.gradle create mode 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/gradle.properties mode change 100755 => 100644 service/easy-setup/sampleapp/mediator/android/EasySetup/settings.gradle create mode 100644 service/easy-setup/sampleapp/mediator/android/SConscript delete mode 100644 service/easy-setup/sampleapp/mediator/linux/csdk_sample/SConscript delete mode 100755 service/easy-setup/sampleapp/mediator/linux/csdk_sample/mediator.cpp create mode 100755 service/easy-setup/sampleapp/mediator/linux/richsdk_sample/oic_svr_db_client.dat create mode 100755 service/notification/SConscript create mode 100755 service/notification/android/SConscript create mode 100644 service/notification/android/android_api.iml create mode 100644 service/notification/android/build.gradle create mode 100644 service/notification/android/gradle.properties create mode 100644 service/notification/android/gradlew create mode 100644 service/notification/android/gradlew.bat create mode 100644 service/notification/android/notification-service/base.iml create mode 100644 service/notification/android/notification-service/build.gradle create mode 100644 service/notification/android/notification-service/proguard-rules.pro create mode 100644 service/notification/android/notification-service/src/main/AndroidManifest.xml create mode 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/MediaContents.java create mode 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Message.java create mode 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/NSErrorCode.java create mode 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/NSException.java create mode 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/SyncInfo.java create mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/Topic.java create mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/common/TopicsList.java create mode 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/ConsumerService.java create mode 100755 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/consumer/Provider.java create mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/Consumer.java create mode 100644 service/notification/android/notification-service/src/main/java/org/iotivity/service/ns/provider/ProviderService.java create mode 100755 service/notification/android/notification-service/src/main/jni/Android.mk create mode 100644 service/notification/android/notification-service/src/main/jni/Application.mk create mode 100755 service/notification/android/notification-service/src/main/jni/common/JniNotificationCommon.cpp create mode 100755 service/notification/android/notification-service/src/main/jni/common/JniNotificationCommon.h create mode 100755 service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.cpp create mode 100755 service/notification/android/notification-service/src/main/jni/consumer/JniNotificationConsumer.h create mode 100755 service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.cpp create mode 100644 service/notification/android/notification-service/src/main/jni/provider/JniNotificationProvider.h create mode 100644 service/notification/android/settings.gradle create mode 100755 service/notification/cpp-wrapper/SConscript create mode 100755 service/notification/cpp-wrapper/common/NSMediaContents.cpp create mode 100755 service/notification/cpp-wrapper/common/NSMediaContents.h create mode 100755 service/notification/cpp-wrapper/common/NSMessage.cpp create mode 100755 service/notification/cpp-wrapper/common/NSMessage.h create mode 100755 service/notification/cpp-wrapper/common/NSSyncInfo.cpp create mode 100755 service/notification/cpp-wrapper/common/NSSyncInfo.h rename service/{easy-setup/mediator/richsdk/unittests/UnitTestHelper.h => notification/cpp-wrapper/common/NSTopic.cpp} (59%) mode change 100644 => 100755 create mode 100755 service/notification/cpp-wrapper/common/NSTopic.h create mode 100755 service/notification/cpp-wrapper/common/NSTopicsList.cpp create mode 100755 service/notification/cpp-wrapper/common/NSTopicsList.h create mode 100755 service/notification/cpp-wrapper/common/NSUtils.h create mode 100755 service/notification/cpp-wrapper/consumer/SConscript create mode 100755 service/notification/cpp-wrapper/consumer/inc/NSConsumerService.h create mode 100755 service/notification/cpp-wrapper/consumer/inc/NSProvider.h create mode 100755 service/notification/cpp-wrapper/consumer/src/NSConsumerService.cpp create mode 100755 service/notification/cpp-wrapper/consumer/src/NSProvider.cpp create mode 100755 service/notification/cpp-wrapper/examples/linux/SConscript create mode 100755 service/notification/cpp-wrapper/examples/linux/notificationserviceconsumer.cpp create mode 100755 service/notification/cpp-wrapper/examples/linux/notificationserviceprovider.cpp create mode 100755 service/notification/cpp-wrapper/provider/SConscript create mode 100755 service/notification/cpp-wrapper/provider/inc/NSConsumer.h create mode 100755 service/notification/cpp-wrapper/provider/inc/NSProviderService.h create mode 100755 service/notification/cpp-wrapper/provider/src/NSConsumer.cpp create mode 100755 service/notification/cpp-wrapper/provider/src/NSProviderService.cpp create mode 100755 service/notification/cpp-wrapper/unittest/NSConsumerServiceSimulator.h create mode 100755 service/notification/cpp-wrapper/unittest/NSConsumerServiceTest.cpp create mode 100644 service/notification/cpp-wrapper/unittest/NSProviderServiceSimulator.h create mode 100755 service/notification/cpp-wrapper/unittest/NSProviderServiceTest.cpp create mode 100644 service/notification/cpp-wrapper/unittest/SConscript create mode 100644 service/notification/examples/SConscript create mode 100755 service/notification/examples/android/NotiConsumerExample/.gitignore create mode 100644 service/notification/examples/android/NotiConsumerExample/SConscript create mode 100755 service/notification/examples/android/NotiConsumerExample/app/.gitignore create mode 100755 service/notification/examples/android/NotiConsumerExample/app/build.gradle create mode 100755 service/notification/examples/android/NotiConsumerExample/app/proguard-rules.pro create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/AndroidManifest.xml create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/java/com/sec/noticonsumerexample/ConsumerSample.java create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/java/com/sec/noticonsumerexample/MainActivity.java create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/layout/activity_main.xml create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/values-w820dp/dimens.xml create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/values/colors.xml create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/values/dimens.xml create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/values/strings.xml create mode 100755 service/notification/examples/android/NotiConsumerExample/app/src/main/res/values/styles.xml create mode 100755 service/notification/examples/android/NotiConsumerExample/build.gradle create mode 100755 service/notification/examples/android/NotiConsumerExample/gradlew.bat create mode 100755 service/notification/examples/android/NotiConsumerExample/settings.gradle create mode 100644 service/notification/examples/android/NotiProviderExample/.gitignore create mode 100644 service/notification/examples/android/NotiProviderExample/SConscript create mode 100644 service/notification/examples/android/NotiProviderExample/app/.gitignore create mode 100755 service/notification/examples/android/NotiProviderExample/app/build.gradle create mode 100644 service/notification/examples/android/NotiProviderExample/app/proguard-rules.pro create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/AndroidManifest.xml create mode 100755 service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/MainActivity.java create mode 100755 service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/NotiListener.java create mode 100755 service/notification/examples/android/NotiProviderExample/app/src/main/java/com/sec/notiproviderexample/ProviderSample.java create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/layout/activity_main.xml create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/values-w820dp/dimens.xml create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/values/colors.xml create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/values/dimens.xml create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/values/strings.xml create mode 100644 service/notification/examples/android/NotiProviderExample/app/src/main/res/values/styles.xml create mode 100644 service/notification/examples/android/NotiProviderExample/build.gradle create mode 100644 service/notification/examples/android/NotiProviderExample/gradlew.bat create mode 100644 service/notification/examples/android/NotiProviderExample/settings.gradle create mode 100644 service/notification/examples/android/SConscript create mode 100644 service/notification/examples/linux/SConscript create mode 100644 service/notification/examples/linux/cloud_connector.c create mode 100644 service/notification/examples/linux/cloud_connector.h create mode 100644 service/notification/examples/linux/notificationconsumer.c create mode 100644 service/notification/examples/linux/notificationprovider.c create mode 100644 service/notification/include/NSCommon.h create mode 100644 service/notification/include/NSConsumerInterface.h create mode 100644 service/notification/include/NSProviderInterface.h create mode 100644 service/notification/src/common/NSConstants.h create mode 100644 service/notification/src/common/NSStructs.h create mode 100755 service/notification/src/common/NSUtil.c create mode 100755 service/notification/src/common/NSUtil.h create mode 100644 service/notification/src/consumer/NSConsumerCommon.c create mode 100644 service/notification/src/consumer/NSConsumerCommon.h create mode 100644 service/notification/src/consumer/NSConsumerCommunication.c rename cloud/samples/client/cloud_connector.h => service/notification/src/consumer/NSConsumerCommunication.h (59%) create mode 100644 service/notification/src/consumer/NSConsumerDiscovery.c rename service/{easy-setup/enrollee/linux/wifi/softapnative.h => notification/src/consumer/NSConsumerDiscovery.h} (56%) create mode 100644 service/notification/src/consumer/NSConsumerInterface.c create mode 100644 service/notification/src/consumer/NSConsumerInternalTaskController.c create mode 100644 service/notification/src/consumer/NSConsumerInternalTaskController.h create mode 100644 service/notification/src/consumer/NSConsumerMemoryCache.c create mode 100644 service/notification/src/consumer/NSConsumerMemoryCache.h create mode 100644 service/notification/src/consumer/NSConsumerNetworkEventListener.c rename service/{easy-setup/mediator/richsdk/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/mediator/Utility.java => notification/src/consumer/NSConsumerNetworkEventListener.h} (60%) create mode 100644 service/notification/src/consumer/NSConsumerQueue.c create mode 100644 service/notification/src/consumer/NSConsumerQueue.h create mode 100644 service/notification/src/consumer/NSConsumerScheduler.c rename service/{easy-setup/mediator/csdk/unittests/UnitTestHelper.h => notification/src/consumer/NSConsumerScheduler.h} (58%) create mode 100644 service/notification/src/consumer/NSConsumerSystem.c create mode 100644 service/notification/src/consumer/NSConsumerSystem.h create mode 100644 service/notification/src/consumer/NSThread.c create mode 100644 service/notification/src/consumer/NSThread.h create mode 100644 service/notification/src/provider/NSProviderCallbackResponse.c create mode 100644 service/notification/src/provider/NSProviderCallbackResponse.h create mode 100644 service/notification/src/provider/NSProviderDiscovery.c create mode 100644 service/notification/src/provider/NSProviderDiscovery.h create mode 100644 service/notification/src/provider/NSProviderInterface.c create mode 100644 service/notification/src/provider/NSProviderListener.c create mode 100644 service/notification/src/provider/NSProviderListener.h create mode 100644 service/notification/src/provider/NSProviderMemoryCache.c create mode 100644 service/notification/src/provider/NSProviderMemoryCache.h create mode 100644 service/notification/src/provider/NSProviderNotification.c create mode 100644 service/notification/src/provider/NSProviderNotification.h create mode 100644 service/notification/src/provider/NSProviderResource.c create mode 100644 service/notification/src/provider/NSProviderResource.h create mode 100755 service/notification/src/provider/NSProviderScheduler.c create mode 100755 service/notification/src/provider/NSProviderScheduler.h create mode 100644 service/notification/src/provider/NSProviderSubscription.c create mode 100644 service/notification/src/provider/NSProviderSubscription.h create mode 100644 service/notification/src/provider/NSProviderSystem.c create mode 100644 service/notification/src/provider/NSProviderSystem.h create mode 100644 service/notification/src/provider/NSProviderTopic.c create mode 100644 service/notification/src/provider/NSProviderTopic.h create mode 100644 service/notification/unittest/NSConsumerSimulator.h create mode 100644 service/notification/unittest/NSConsumerTest.cpp create mode 100644 service/notification/unittest/NSProviderSimulator.h create mode 100755 service/notification/unittest/NSProviderTest.cpp create mode 100644 service/notification/unittest/SConscript create mode 100644 service/resource-container/examples/HueSampleBundle/LICENSE.CURL delete mode 100644 service/resource-directory/include/rd_client.h delete mode 100644 service/resource-directory/include/rd_payload.h delete mode 100644 service/resource-directory/src/internal/rd_storage.c delete mode 100644 service/resource-directory/src/internal/rd_storage.h delete mode 100644 service/resource-directory/src/rd_client.c mode change 100644 => 100755 service/resource-encapsulation/android/service/src/androidTest/java/org/iotivity/service/TestBase.java mode change 100755 => 100644 service/resource-encapsulation/examples/linux/SampleResourceServer.cpp create mode 100644 service/resource-encapsulation/examples/tizen/README mode change 100644 => 100755 service/resource-encapsulation/src/serverBuilder/src/InterfaceHandler.cpp mode change 100755 => 100644 service/scene-manager/sampleapp/linux/SConscript mode change 100755 => 100644 service/scene-manager/src/Scene.cpp mode change 100755 => 100644 service/scene-manager/src/SceneAction.cpp mode change 100755 => 100644 service/scene-manager/src/SceneCollection.cpp mode change 100644 => 100755 service/scene-manager/src/SceneCollectionResource.h mode change 100644 => 100755 service/scene-manager/src/SceneCommons.h mode change 100755 => 100644 service/scene-manager/src/SceneList.cpp mode change 100644 => 100755 service/scene-manager/src/SceneListResource.cpp mode change 100644 => 100755 service/scene-manager/src/SceneUtils.cpp mode change 100644 => 100755 service/scene-manager/unittests/RemoteSceneCollectionTest.cpp mode change 100644 => 100755 service/scene-manager/unittests/RemoteSceneListTest.cpp mode change 100644 => 100755 service/scene-manager/unittests/RemoteSceneTest.cpp mode change 100755 => 100644 service/scene-manager/unittests/SConscript mode change 100644 => 100755 service/simulator/inc/simulator_error_codes.h mode change 100644 => 100755 service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java create mode 100644 service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/view/dialogs/UpdateMultiInstanceCreationPropertiesPage.java mode change 100644 => 100755 service/simulator/java/jni/simulator_utils_jni.cpp mode change 100644 => 100755 service/simulator/java/sdk/src/org/oic/simulator/SimulatorResult.java diff --git a/.gbs.conf b/.gbs.conf new file mode 100644 index 0000000..4cdf5c5 --- /dev/null +++ b/.gbs.conf @@ -0,0 +1,4 @@ +[general] +upstream_branch = upstream +upstream_tag = ${upstreamversion} +packaging_dir = tools/tizen diff --git a/.gitignore b/.gitignore index f132748..88c8a40 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,9 @@ resource/csdk/stack/samples/linux/SimpleClientServer/release/ resource/csdk/connectivity/build/out/ +# Ignore autogenerated files +resource/c_common/iotivity_config.h + resource/oc_logger/bin/ resource/oc_logger/lib/ resource/oc_logger/samples/linux/release/ @@ -49,6 +52,11 @@ service/things-manager/build/linux/release service/things-manager/build/linux/debug service/things-manager/sdk/build/linux/ +service/notification/android/.gradle/ +service/notification/android/build/ +service/notification/android/notification-service/build/ +service/notification/android/notification-service/src/main/obj/ + # Ignore any object files *.o *.os @@ -84,8 +92,11 @@ config.log os out/ platform +iotivity.pc +tmp/ # Ignore downloaded dependencies +extlibs/libcoap/libcoap extlibs/gtest/gtest-* extlibs/hippomocks-master/ extlibs/master.zip @@ -97,7 +108,7 @@ extlibs/android/sdk/android-sdk_r24.2 extlibs/android/sdk/android-sdk-linux extlibs/android/sdk/android-sdk-macosx extlibs/android/sdk/android-sdk-windows -extlibs/boost/boost_1_58_0 +extlibs/boost/* extlibs/tinycbor/tinycbor *.tgz *.zip @@ -106,14 +117,28 @@ build_common/arduino/extlibs/arduino/arduino-1.5.8 extlibs/tinydtls/dtls-client extlibs/tinydtls/dtls-server extlibs/bluez/bluez +extlibs/mbedtls/mbedtls # Ignore editor (e.g. Emacs) backup and autosave files *~ *#*# *.orig +.cproject +.gradle/ +.project # Ignore byte-compiled Python scripts *.pyc # Ignore Valgrind generated files. *.memcheck + +# Ignore generated files +*.dat + +# Ignore debian generated files +debian/files +debian/*.debhelper.log +debian/*.substvars +debian/iotivity*/* +debian/tmp/* diff --git a/Readme.scons.txt b/Readme.scons.txt index 56f5f02..1c2d0dd 100644 --- a/Readme.scons.txt +++ b/Readme.scons.txt @@ -265,6 +265,8 @@ IOS: * WITH_RA=true or false (Build with Remote Access module) * WITH_RD=1 or 0 (Build including Resource Directory) * SIMULATOR=true or false (Build with simulator module) + * Possible values for are: PUB,SUB,BROKER (Build including Message Queue) + -> PUB : publisher, SUB : subscriber, BROKER : MQ broker(not supported yet) Note1: Currently most IoTivity project doesn't support Windows, so you can't set TARGET_OS to 'windows' except the project support Windows. diff --git a/SConstruct b/SConstruct index 35ff720..ac76f39 100644 --- a/SConstruct +++ b/SConstruct @@ -56,7 +56,7 @@ build_dir = env.get('BUILD_DIR') # Build 'resource' sub-project SConscript(build_dir + 'resource/SConscript') -if target_os not in ['arduino','darwin','ios', 'android']: +if target_os not in ['arduino','darwin','ios', 'android', 'msys_nt', 'windows']: SConscript(build_dir + 'examples/OICMiddle/SConscript') # Build 'service' sub-project @@ -76,6 +76,6 @@ env.PrintTargets() if target_os == 'arduino': env.UploadHelp() -# to install the generated pc file into custome prefix location +# to install the generated pc file into custom prefix location env.UserInstallTargetPCFile('iotivity.pc', 'iotivity.pc') diff --git a/android/android_api/SConscript b/android/android_api/SConscript index 32ffb22..895ebb6 100644 --- a/android/android_api/SConscript +++ b/android/android_api/SConscript @@ -11,6 +11,46 @@ else: ANDROID_RELEASE="debug" ANDROID_SECURED = env.get('SECURED') +if env.get('WITH_CLOUD'): + ANDROID_CLOUD=1 +else: + ANDROID_CLOUD=0 + +if env.get('WITH_TCP'): + ANDROID_TCP=1 +else: + ANDROID_TCP=0 + +ANDROID_MQ = env.get('WITH_MQ') +ANDROID_MQ_SUB = 0 +ANDROID_MQ_PUB = 0 +ANDROID_MQ_BROKER = 0 +ANDROID_RD_MODE = env.get('RD_MODE') +ANDROID_TRANSPORT = env.get('TARGET_TRANSPORT') +ANDROID_TRANSPORT_EDR = 0 +ANDROID_TRANSPORT_BLE = 0 +ANDROID_TRANSPORT_NFC = 0 + +if 'SUB' in ANDROID_MQ: + ANDROID_MQ_SUB = 1 +if 'PUB' in ANDROID_MQ: + ANDROID_MQ_PUB = 1 +if 'BROKER' in ANDROID_MQ: + ANDROID_MQ_BROKER = 1 + +if 'ALL' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_EDR = 1 + ANDROID_TRANSPORT_BLE = 1 + ANDROID_TRANSPORT_NFC = 1 + print "Android Transport is ALL" +else: + if 'BT' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_EDR = 1 + if 'BLE' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_BLE = 1 + if 'NFC' in ANDROID_TRANSPORT: + ANDROID_TRANSPORT_NFC = 1 + os.environ['ANDROID_HOME'] = env.get('ANDROID_HOME') os.environ['ANDROID_NDK_HOME'] = env.get('ANDROID_NDK') @@ -48,13 +88,14 @@ def ensure_libs(target, source, env): # build android_api jdk_env = Environment(ENV=os.environ) -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED), emitter = ensure_libs) +jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + os.getcwd()+'/build.gradle -PWITH_TRANSPORT_EDR=%s -PWITH_TRANSPORT_BLE=%s -PWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER, ANDROID_TCP), emitter = ensure_libs) jdk_env['BUILD_DIR'] = env.get('BUILD_DIR') cmdBuildApi=jdk_env.Gradle(target="base/objs", source="base/src/main/java/org/iotivity/base/OcResource.java") -jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s --stacktrace' %(ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED)) +jdk_env['BUILDERS']['Gradle'] = Builder(action = env.get('ANDROID_GRADLE') + ' build -b' + 'android/examples/build.gradle -DWITH_TRANSPORT_EDR=%s -DWITH_TRANSPORT_BLE=%s -DWITH_TRANSPORT_NFC=%s -PTARGET_ARCH=%s -PRELEASE=%s -PSECURED=%s -DSECURE=%s -PWITH_CLOUD=%s -PRD_MODE=%s -PWITH_MQ_PUB=%s -PWITH_MQ_SUB=%s -PWITH_MQ_BROKER=%s -PWITH_TCP=%s --stacktrace' %(ANDROID_TRANSPORT_EDR, ANDROID_TRANSPORT_BLE, ANDROID_TRANSPORT_NFC, ANDROID_TARGET_ARCH, ANDROID_RELEASE, ANDROID_SECURED, ANDROID_SECURED, ANDROID_CLOUD, ANDROID_RD_MODE, ANDROID_MQ_PUB, ANDROID_MQ_SUB, ANDROID_MQ_BROKER, ANDROID_TCP)) cmdBuildExamples=jdk_env.Gradle(target="../examples/devicediscoveryclient/apk", source="../examples/devicediscoveryclient/src/main/java/org/iotivity/base/examples/DeviceDiscoveryClient.java") # android examples require android api to be built before being invoked Depends(cmdBuildExamples, cmdBuildApi) +env.AppendUnique(baseAAR = cmdBuildApi) diff --git a/android/android_api/base/build.gradle b/android/android_api/base/build.gradle index a0b52ae..855418d 100755 --- a/android/android_api/base/build.gradle +++ b/android/android_api/base/build.gradle @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ apply plugin: 'com.android.library' @@ -41,8 +41,17 @@ android { minSdkVersion 21 targetSdkVersion 21 versionCode 1 - versionName "1.1.1" + versionName "1.2.0" buildConfigField 'int', 'SECURED', SECURED + buildConfigField 'int', 'WITH_TCP', WITH_TCP + buildConfigField 'int', 'WITH_CLOUD', WITH_CLOUD + buildConfigField "int", 'WITH_MQ_PUB', WITH_MQ_PUB + buildConfigField "int", 'WITH_MQ_SUB', WITH_MQ_SUB + buildConfigField "int", 'WITH_MQ_BROKER', WITH_MQ_BROKER + buildConfigField "String", 'RD_MODE', "\"RD_MODE\"" + buildConfigField "int", 'WITH_TRANSPORT_EDR', WITH_TRANSPORT_EDR + buildConfigField "int", 'WITH_TRANSPORT_BLE', WITH_TRANSPORT_BLE + buildConfigField "int", 'WITH_TRANSPORT_NFC', WITH_TRANSPORT_NFC } buildTypes { release { @@ -59,6 +68,22 @@ android { manifest.srcFile 'src/main/AndroidManifest.xml' jniLibs.srcDir 'libs' jni.srcDirs = [] //disable automatic ndk-build call + java{ + if (WITH_TRANSPORT_EDR == "0") { + exclude "**/ca/CaBtPairingInterface.java" + exclude "**/ca/CaEdrInterface.java" + println 'excluded EDR interface' + } + if (WITH_TRANSPORT_BLE == "0") { + exclude "**/ca/CaLeClientInterface.java" + exclude "**/ca/CaLeServerInterface.java" + println 'excluded BLE interface' + } + if (WITH_TRANSPORT_NFC == "0") { + exclude "**/ca/CaNfcInterface.java" + println 'excluded NFC interface' + } + } } } } @@ -94,8 +119,8 @@ task buildNative(type: Exec) { if (System.env.ANDROID_NDK_HOME != null) { //for windows use 'ndk-build.cmd' //def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build.cmd') - def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build') - commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED" + def ndkBuild = new File(System.env.ANDROID_NDK_HOME, 'ndk-build') + commandLine ndkBuild, "APP_ABI=$TARGET_ARCH", "APP_OPTIM=$RELEASE", "SECURE=$SECURED", "WITH_CLOUD=$WITH_CLOUD", "RD_MODE=$RD_MODE", "WITH_MQ_PUB=$WITH_MQ_PUB", "WITH_MQ_SUB=$WITH_MQ_SUB", "WITH_MQ_BROKER=$WITH_MQ_BROKER", "WITH_TCP=$WITH_TCP" } else { println '##################' println 'Skipping NDK build' diff --git a/android/android_api/base/jni/Android.mk b/android/android_api/base/jni/Android.mk index 51d9dcd..aabb512 100644 --- a/android/android_api/base/jni/Android.mk +++ b/android/android_api/base/jni/Android.mk @@ -1,6 +1,12 @@ LOCAL_PATH := $(call my-dir) TARGET_ARCH_ABI := $(APP_ABI) SECURED := $(SECURE) +WITH_CLOUD := $(WITH_CLOUD) +WITH_TCP := $(WITH_TCP) +WITH_MQ_PUB := $(WITH_MQ_PUB) +WITH_MQ_SUB := $(WITH_MQ_SUB) +WITH_MQ_BROKER := $(WITH_MQ_BROKER) +RD_MODE := $(RD_MODE) include $(CLEAR_VARS) OIC_LIB_PATH := ../../../../out/android/$(APP_ABI)/$(APP_OPTIM) @@ -47,12 +53,36 @@ LOCAL_SRC_FILES := JniCaInterface.c LOCAL_STATIC_LIBRARIES := libandroid-ca LOCAL_LDLIBS := -llog LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/api +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/c_common include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) OIC_SRC_PATH := ../../../resource OIC_OUT_PATH := ../../../out LOCAL_MODULE := ocstack-jni + +ifeq ($(WITH_CLOUD), 1) + LOCAL_CPPFLAGS += -DWITH_CLOUD +endif + +ifeq ($(WITH_TCP), 1) + LOCAL_CPPFLAGS += -D__WITH_TLS__ +endif + +MQ_FLAG = 0 +ifeq ($(WITH_MQ_PUB), 1) +LOCAL_CFLAGS += -DWITH_MQ -DMQ_PUBLISHER +MQ_FLAG = 1 +endif +ifeq ($(WITH_MQ_SUB), 1) +LOCAL_CFLAGS += -DWITH_MQ -DMQ_SUBSCRIBER +MQ_FLAG = 1 +endif +ifeq ($(WITH_MQ_BROKER), 1) +LOCAL_CFLAGS += -DWITH_MQ -DMQ_BROKER +MQ_FLAG = 1 +endif + LOCAL_SRC_FILES := JniOcStack.cpp \ JniUtils.cpp \ JniEntityHandler.cpp \ @@ -77,7 +107,15 @@ LOCAL_SRC_FILES := JniOcStack.cpp \ JniOcSecurity.cpp \ JniOnDPDevicesFoundListener.cpp \ JniOnDirectPairingListener.cpp \ - JniOcDirectPairDevice.cpp + JniOcDirectPairDevice.cpp \ + JniOnPublishResourceListener.cpp \ + JniOnDeleteResourceListener.cpp + +ifeq ($(MQ_FLAG), 1) + LOCAL_SRC_FILES += JniOnMQTopicFoundListener.cpp \ + JniOnMQSubscribeListener.cpp +endif + ifeq ($(SECURED), 1) LOCAL_SRC_FILES += JniOcSecureResource.cpp \ JniOcProvisioning.cpp \ @@ -85,7 +123,19 @@ ifeq ($(SECURED), 1) JniProvisionResultListner.cpp \ JniPinCheckListener.cpp \ JniDisplayPinListener.cpp - endif +endif + +ifeq ($(WITH_CLOUD), 1) + LOCAL_SRC_FILES += JniOcAccountManager.cpp +endif + +ifeq ($(WITH_TCP), 1) +ifeq ($(SECURED), 1) + LOCAL_SRC_FILES += JniOcCloudProvisioning.cpp \ + JniOcCloudResultListener.cpp \ + JniGetAclIdByDeviceListener.cpp +endif +endif LOCAL_LDLIBS := -llog LOCAL_STATIC_LIBRARIES := android-oc @@ -99,6 +149,9 @@ LOCAL_STATIC_LIBRARIES += android-ocprovision LOCAL_STATIC_LIBRARIES += android-ocpmapi endif +ifeq "$(RD_MODE)" "CLIENT" +LOCAL_CPPFLAGS += -DRD_CLIENT +endif LOCAL_CPPFLAGS += -std=c++0x LOCAL_CPP_FEATURES := rtti exceptions LOCAL_C_INCLUDES := $(OIC_SRC_PATH)/include @@ -110,12 +163,15 @@ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/ocsocket/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/oc_logger/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/boost/boost_1_58_0 LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/cjson +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../extlibs/tinycbor/tinycbor/src LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/../build_common/android/compatibility LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/oxm/ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/internal +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/provisioning/include/cloud/ LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/security/include/internal LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/api -LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/lib/libcoap-4.1.1 +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/inc/pkix +LOCAL_C_INCLUDES += $(OIC_SRC_PATH)/csdk/connectivity/lib/libcoap-4.1.1/include include $(BUILD_SHARED_LIBRARY) diff --git a/android/android_api/base/jni/JniCaInterface.c b/android/android_api/base/jni/JniCaInterface.c index d641f3d..9499b55 100644 --- a/android/android_api/base/jni/JniCaInterface.c +++ b/android/android_api/base/jni/JniCaInterface.c @@ -35,6 +35,8 @@ static jobject g_foundDeviceListenerObject = NULL; static jobject g_listenerObject = NULL; static JavaVM *g_jvm = NULL; +static jclass g_jni_cls_enum = NULL; +static jmethodID g_jni_mid_enum = NULL; JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *reserved) { @@ -60,12 +62,14 @@ Java_org_iotivity_ca_CaInterface_initialize CANativeJNISetContext(env, context); } -void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, - const char *remote_address, +void CAManagerConnectionStateChangedCB(const CAEndpoint_t *info, bool connected) { - LOGI("Callback - CAManagerConnectionStateChangedCB : type(%d), address(%s), connected(%d)", - adapter, remote_address, connected); + if (!info) + { + LOGE("info is NULL"); + return; + } if (!g_listenerObject) { @@ -73,8 +77,11 @@ void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, return; } + LOGI("Callback - CAManagerConnectionStateChangedCB : type(%d), address(%s), connected(%d)", + info->adapter, info->addr, connected); + bool isAttached = false; - JNIEnv* env; + JNIEnv* env = NULL; jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); if (JNI_OK != res) { @@ -106,34 +113,22 @@ void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, goto exit_error; } - jstring jni_address = (*env)->NewStringUTF(env, remote_address); + jstring jni_address = (*env)->NewStringUTF(env, info->addr); if (!jni_address) { LOGE("jni_address is null"); goto exit_error; } - jclass jni_cls_enum = (*env)->FindClass(env, "org/iotivity/base/OcConnectivityType"); - if (!jni_cls_enum) + if (g_jni_cls_enum && g_jni_mid_enum) { - LOGE("could not get jni_cls_enum"); - goto exit_error; - } - - jmethodID jni_mid_enum = (*env)->GetStaticMethodID(env, jni_cls_enum, "getInstance", - "(I)Lorg/iotivity/base/OcConnectivityType;"); - if (!jni_mid_enum) - { - LOGE("could not get Method ID (getInstance)"); - goto exit_error; + jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, g_jni_cls_enum, + g_jni_mid_enum, info->adapter); + (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, + jni_adaptertype, jni_address, + (jboolean)connected); } - jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, jni_cls_enum, - jni_mid_enum, adapter); - (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, - jni_adaptertype, jni_address, - (jboolean)connected); - exit_error: if (isAttached) { @@ -155,7 +150,7 @@ void CAManagerAdapterStateChangedCB(CATransportAdapter_t adapter, bool enabled) } bool isAttached = false; - JNIEnv* env; + JNIEnv* env = NULL; jint res = (*g_jvm)->GetEnv(g_jvm, (void**) &env, JNI_VERSION_1_6); if (JNI_OK != res) { @@ -186,27 +181,15 @@ void CAManagerAdapterStateChangedCB(CATransportAdapter_t adapter, bool enabled) goto exit_error; } - jclass jni_cls_enum = (*env)->FindClass(env, "org/iotivity/base/OcConnectivityType"); - if (!jni_cls_enum) + if (g_jni_cls_enum && g_jni_mid_enum) { - LOGE("could not get jni_cls_enum"); - goto exit_error; - } + jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, g_jni_cls_enum, + g_jni_mid_enum, adapter); - jmethodID jni_mid_enum = (*env)->GetStaticMethodID(env, jni_cls_enum, "getInstance", - "(I)Lorg/iotivity/base/OcConnectivityType;"); - if (!jni_mid_enum) - { - LOGE("could not get Method ID (getInstance)"); - goto exit_error; + (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, + jni_adaptertype, (jboolean)enabled); } - jobject jni_adaptertype = (*env)->CallStaticObjectMethod(env, jni_cls_enum, - jni_mid_enum, adapter); - - (*env)->CallVoidMethod(env, g_listenerObject, jni_mid_listener, - jni_adaptertype, (jboolean)enabled); - exit_error: if (isAttached) { @@ -223,8 +206,25 @@ Java_org_iotivity_ca_CaInterface_caManagerInitialize(JNIEnv *env, jclass clazz, CAUtilClientInitialize(env, g_jvm, context); - g_listenerObject = (*env)->NewGlobalRef(env, listener); + if (listener) + { + g_listenerObject = (*env)->NewGlobalRef(env, listener); + } + if (g_listenerObject) + { + jclass cls = (*env)->FindClass(env, "org/iotivity/base/OcConnectivityType"); + if (cls) + { + g_jni_cls_enum = (jclass)(*env)->NewGlobalRef(env, cls); + } + + if (g_jni_cls_enum) + { + g_jni_mid_enum = (*env)->GetStaticMethodID(env, g_jni_cls_enum, "getInstance", + "(I)Lorg/iotivity/base/OcConnectivityType;"); + } + } CARegisterNetworkMonitorHandler(CAManagerAdapterStateChangedCB, CAManagerConnectionStateChangedCB); } @@ -241,6 +241,12 @@ Java_org_iotivity_ca_CaInterface_caManagerTerminate(JNIEnv *env, jclass clazz) (*env)->DeleteGlobalRef(env, g_listenerObject); g_listenerObject = NULL; } + + if (g_jni_cls_enum) + { + (*env)->DeleteGlobalRef(env, g_jni_cls_enum); + g_jni_cls_enum = NULL; + } } JNIEXPORT void JNICALL @@ -249,6 +255,11 @@ Java_org_iotivity_ca_CaInterface_caManagerSetAutoConnectionDeviceInfo(JNIEnv *en jstring jaddress) { LOGI("CaManager_setAutoConnectionDeviceInfo"); + if (!jaddress) + { + LOGE("jaddress is null"); + return; + } const char* address = (*env)->GetStringUTFChars(env, jaddress, NULL); if (!address) @@ -268,6 +279,11 @@ Java_org_iotivity_ca_CaInterface_caManagerUnsetAutoConnectionDeviceInfo(JNIEnv * jstring jaddress) { LOGI("CaManager_unsetAutoConnectionDeviceInfo"); + if (!jaddress) + { + LOGE("jaddress is null"); + return; + } const char* address = (*env)->GetStringUTFChars(env, jaddress, NULL); if (!address) @@ -329,3 +345,29 @@ Java_org_iotivity_ca_CaInterface_caBtPairingCreateBond(JNIEnv *env, jclass clazz (void)clazz; CAUtilCreateBond(env, device); } + +JNIEXPORT void JNICALL +Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl(JNIEnv *env, jclass clazz, + jint intervalTime, jint workignCount) +{ + LOGI("setLeScanIntervalTimeImpl"); + (void)env; + (void)clazz; + CAUtilSetLEScanInterval(intervalTime, workignCount); +} + +JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl + (JNIEnv *env, jclass clazz, jint cipherSuite, jint adapter) +{ + LOGI("setCipherSuiteImpl"); +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + (void)env; + (void)clazz; + CAResult_t ret = CASelectCipherSuite(cipherSuite, (CATransportAdapter_t) adapter); + return ret; +#else + LOGE("Method not supported"); + return -1; +#endif // __WITH_DTLS__ || __WITH_TLS__ +} + diff --git a/android/android_api/base/jni/JniCaInterface.h b/android/android_api/base/jni/JniCaInterface.h index 20dc995..663aef3 100644 --- a/android/android_api/base/jni/JniCaInterface.h +++ b/android/android_api/base/jni/JniCaInterface.h @@ -31,8 +31,7 @@ extern "C" { #endif - void CAManagerConnectionStateChangedCB(CATransportAdapter_t adapter, - const char *remote_address, bool connected); + void CAManagerConnectionStateChangedCB(const CAEndpoint_t *info, bool connected); void CAManagerAdapterStateChangedCB(CATransportAdapter_t adapter, bool enabled); @@ -121,6 +120,22 @@ extern "C" { JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_initialize (JNIEnv *, jclass, jobject, jobject); + /* + * Class: Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl + * Method: setLeScanIntervalTimeImpl + * Signature: (II)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_ca_CaInterface_setLeScanIntervalTimeImpl + (JNIEnv *, jclass, jint, jint); + + /* + * Class: org_iotivity_ca_CaInterface + * Method: setCipherSuiteImpl + * Signature: (Lorg/iotivity/ca/OicCipher;Lorg/iotivity/ca/CATransportAdapter;)I + */ + JNIEXPORT jint JNICALL Java_org_iotivity_ca_CaInterface_setCipherSuiteImpl + (JNIEnv *, jclass, jint, jint); + #ifdef __cplusplus } #endif diff --git a/android/android_api/base/jni/JniDisplayPinListener.cpp b/android/android_api/base/jni/JniDisplayPinListener.cpp index 25ee926..1705bdf 100644 --- a/android/android_api/base/jni/JniDisplayPinListener.cpp +++ b/android/android_api/base/jni/JniDisplayPinListener.cpp @@ -33,7 +33,7 @@ JniDisplayPinListener::~JniDisplayPinListener() LOGI("~JniDisplayPinListener()"); if (m_jgListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); if (NULL == env) return; env->DeleteGlobalRef(m_jgListener); @@ -43,9 +43,12 @@ JniDisplayPinListener::~JniDisplayPinListener() void JniDisplayPinListener::displayPinCallback(char *pinBuf, size_t pinSize) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (NULL == env) return; + if (NULL == env) + { + return; + } jclass clsL = env->GetObjectClass(m_jgListener); diff --git a/android/android_api/base/jni/JniEntityHandler.cpp b/android/android_api/base/jni/JniEntityHandler.cpp index 1d641ae..f46dde0 100644 --- a/android/android_api/base/jni/JniEntityHandler.cpp +++ b/android/android_api/base/jni/JniEntityHandler.cpp @@ -33,7 +33,7 @@ JniEntityHandler::~JniEntityHandler() LOGD("~JniEntityHandler"); if (m_jListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); if (nullptr == env) { @@ -54,7 +54,7 @@ OCEntityHandlerResult JniEntityHandler::handleEntity( const std::shared_ptr request) { LOGD("JniEntityHandler_handleEntity"); - jint envRet; + jint envRet = JNI_ERR; JNIEnv *env = GetJNIEnv(envRet); if (nullptr == env) { @@ -133,7 +133,10 @@ OCEntityHandlerResult JniEntityHandler::handleEntity( jmethodID getValue_ID = env->GetMethodID(clsResult, "getValue", "()I"); if (!getValue_ID) { - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return OC_EH_ERROR; } jint jResult = env->CallIntMethod(entityHandlerResult, getValue_ID); diff --git a/android/android_api/base/jni/JniGetAclIdByDeviceListener.cpp b/android/android_api/base/jni/JniGetAclIdByDeviceListener.cpp new file mode 100644 index 0000000..c13682f --- /dev/null +++ b/android/android_api/base/jni/JniGetAclIdByDeviceListener.cpp @@ -0,0 +1,128 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include "JniGetAclIdByDeviceListener.h" + +JniGetAclIdByDeviceListener::JniGetAclIdByDeviceListener(JNIEnv *env, jobject jListener, + RemoveCallback removeListener) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeGetAclbyIDListener = removeListener; +} + +JniGetAclIdByDeviceListener::~JniGetAclIdByDeviceListener() +{ + LOGI("~JniGetAclIdByDeviceListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniGetAclIdByDeviceListener::GetAclIdByDeviceListenerCB(int result, std::string aclID) +{ + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jmethodID midL = env->GetMethodID(clsL, "getAclIdByDeviceListener", "(ZLjava/lang/String;)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jstring jStr = env-> NewStringUTF(aclID.c_str()); + if (!jStr) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + + } + env->CallVoidMethod(jListener, midL, (jboolean)result, jStr); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + } + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniGetAclIdByDeviceListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeGetAclbyIDListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeGetAclbyIDListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniGetAclIdByDeviceListener.h b/android/android_api/base/jni/JniGetAclIdByDeviceListener.h new file mode 100644 index 0000000..8ad5b11 --- /dev/null +++ b/android/android_api/base/jni/JniGetAclIdByDeviceListener.h @@ -0,0 +1,46 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include +#include "JniOcStack.h" + +/* Header for class org_iotivity_base_OcCloudProvisioning_GetAclIdByDeviceListener */ +#ifndef _Included_org_iotivity_base_OcCloudProvisioning_JniGetAclIdByDeviceListener +#define _Included_org_iotivity_base_OcCloudProvisioning_JniGetAclIdByDeviceListener + +typedef std::function RemoveCallback; + +class JniGetAclIdByDeviceListener +{ + public: + JniGetAclIdByDeviceListener(JNIEnv *env, jobject jListener, + RemoveCallback removeListener); + ~JniGetAclIdByDeviceListener(); + + void GetAclIdByDeviceListenerCB(int result, std::string aclID); + + private: + RemoveCallback m_removeGetAclbyIDListener; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; +#endif diff --git a/android/android_api/base/jni/JniListenerManager.h b/android/android_api/base/jni/JniListenerManager.h index b082f7d..8965e85 100644 --- a/android/android_api/base/jni/JniListenerManager.h +++ b/android/android_api/base/jni/JniListenerManager.h @@ -27,6 +27,9 @@ #define _JniListenerManager class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif template class JniListenerManager @@ -51,6 +54,7 @@ public: break; } } + if (!onEventListener) { onEventListener = new T(env, jListener, owner); @@ -66,13 +70,63 @@ public: { LOGD("OnEventListener: Failed to create global listener ref."); delete onEventListener; + m_mapMutex.unlock(); + return nullptr; } LOGD("OnEventListener: new listener"); } + m_mapMutex.unlock(); return onEventListener; } +#ifdef WITH_CLOUD + T* addListener(JNIEnv* env, jobject jListener, JniOcAccountManager* owner) + { + T *onEventListener = nullptr; + + m_mapMutex.lock(); + + for (auto it = m_listenerMap.begin(); it != m_listenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onEventListener = refPair.first; + refPair.second++; + it->second = refPair; + m_listenerMap.insert(*it); + LOGD("OnEventListener: ref. count is incremented"); + break; + } + } + + if (!onEventListener) + { + onEventListener = new T(env, jListener, owner); + jobject jgListener = env->NewGlobalRef(jListener); + + if (jgListener) + { + m_listenerMap.insert( + std::pair>(jgListener, std::pair(onEventListener, 1))); + } + else + { + LOGD("OnEventListener: Failed to create global listener ref."); + delete onEventListener; + m_mapMutex.unlock(); + return nullptr; + } + LOGD("OnEventListener: new listener"); + } + + m_mapMutex.unlock(); + return onEventListener; + } +#endif + void removeListener(JNIEnv* env, jobject jListener) { m_mapMutex.lock(); @@ -94,7 +148,6 @@ public: T* listener = refPair.first; delete listener; m_listenerMap.erase(it); - LOGI("OnEventListener is removed"); } break; @@ -106,6 +159,7 @@ public: void removeAllListeners(JNIEnv* env) { m_mapMutex.lock(); + LOGI("All listeners are removed"); for (auto& pair : m_listenerMap) { diff --git a/android/android_api/base/jni/JniOcAccountManager.cpp b/android/android_api/base/jni/JniOcAccountManager.cpp new file mode 100644 index 0000000..9556111 --- /dev/null +++ b/android/android_api/base/jni/JniOcAccountManager.cpp @@ -0,0 +1,1540 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +#include "JniOcAccountManager.h" +#include "JniOcRepresentation.h" +#include "JniUtils.h" + +JniOcAccountManager::JniOcAccountManager(std::shared_ptr accountManager) + : m_sharedAccountManager(accountManager) +{ +} + +JniOcAccountManager::~JniOcAccountManager() +{ + LOGD("~JniOcAccountManager()"); + + m_sharedAccountManager = nullptr; + + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + m_onGetManager.removeAllListeners(env); + m_onPostManager.removeAllListeners(env); + m_onDeleteManager.removeAllListeners(env); + m_onObserveManager.removeAllListeners(env); + + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +std::string JniOcAccountManager::host() +{ + return m_sharedAccountManager->host(); +} + +OCConnectivityType JniOcAccountManager::connectivityType() const +{ + return m_sharedAccountManager->connectivityType(); +} + +JniOcAccountManager* JniOcAccountManager::getJniOcAccountManagerPtr(JNIEnv *env, jobject thiz) +{ + JniOcAccountManager *accountManager = GetHandle(env, thiz); + if (env->ExceptionCheck()) + { + LOGE("Failed to get native handle from OcAccountManager"); + } + if (!accountManager) + { + ThrowOcException(JNI_NO_NATIVE_POINTER, ""); + } + return accountManager; +} + +JniOnGetListener* JniOcAccountManager::addOnGetListener(JNIEnv* env, jobject jListener) +{ + return this->m_onGetManager.addListener(env, jListener, this); +} + +JniOnPostListener* JniOcAccountManager::addOnPostListener(JNIEnv* env, jobject jListener) +{ + return this->m_onPostManager.addListener(env, jListener, this); +} + +JniOnDeleteListener* JniOcAccountManager::addOnDeleteListener(JNIEnv* env, jobject jListener) +{ + return this->m_onDeleteManager.addListener(env, jListener, this); +} + +JniOnObserveListener* JniOcAccountManager::addOnObserveListener(JNIEnv* env, jobject jListener) +{ + return this->m_onObserveManager.addListener(env, jListener, this); +} + +void JniOcAccountManager::removeOnGetListener(JNIEnv* env, jobject jListener) +{ + this->m_onGetManager.removeListener(env, jListener); +} + +void JniOcAccountManager::removeOnPostListener(JNIEnv* env, jobject jListener) +{ + this->m_onPostManager.removeListener(env, jListener); +} + +void JniOcAccountManager::removeOnDeleteListener(JNIEnv* env, jobject jListener) +{ + this->m_onDeleteManager.removeListener(env, jListener); +} + +void JniOcAccountManager::removeOnObserveListener(JNIEnv* env, jobject jListener) +{ + this->m_onObserveManager.removeListener(env, jListener); +} + +OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authProvider, + const std::string& authCode, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signUp(authProvider, authCode, postCallback); +} + +OCStackResult JniOcAccountManager::signUp(JNIEnv* env, const std::string& authProvider, + const std::string& authCode, + const QueryParamsMap& options, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signUp(authProvider, authCode, options, postCallback); +} + +OCStackResult JniOcAccountManager::signIn(JNIEnv* env, const std::string& userUuid, + const std::string& accessToken, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signIn(userUuid, accessToken, postCallback); +} + +OCStackResult JniOcAccountManager::signOut(JNIEnv* env, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->signOut(postCallback); +} + +OCStackResult JniOcAccountManager::refreshAccessToken(JNIEnv* env, const std::string& userUuid, + const std::string& refreshToken, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->refreshAccessToken(userUuid, refreshToken, postCallback); +} + +OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const std::string& userUuid, + jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->searchUser(userUuid, getCallback); +} + +OCStackResult JniOcAccountManager::searchUser(JNIEnv* env, const QueryParamsMap& queryMap, + jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->searchUser(queryMap, getCallback); +} + +OCStackResult JniOcAccountManager::deleteDevice(JNIEnv* env, const std::string& deviceId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteDevice(deviceId, deleteCallback); +} + +OCStackResult JniOcAccountManager::createGroup(JNIEnv* env, AclGroupType groupType, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->createGroup(groupType, postCallback); +} + +OCStackResult JniOcAccountManager::getGroupList(JNIEnv* env, jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->getGroupList(getCallback); +} + +OCStackResult JniOcAccountManager::deleteGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteGroup(groupId, deleteCallback); +} + +OCStackResult JniOcAccountManager::joinGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->joinGroup(groupId, postCallback); +} + +OCStackResult JniOcAccountManager::addDeviceToGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, + jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->addDeviceToGroup(groupId, deviceId, postCallback); +} + +OCStackResult JniOcAccountManager::getGroupInfo(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnGetListener *onGetListener = addOnGetListener(env, jListener); + + GetCallback getCallback = [onGetListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onGetListener->onGetCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->getGroupInfo(groupId, getCallback); +} + +OCStackResult JniOcAccountManager::leaveGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->leaveGroup(groupId, deleteCallback); +} + +OCStackResult JniOcAccountManager::deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteDeviceFromGroup(groupId, deviceId, deleteCallback); +} + +OCStackResult JniOcAccountManager::observeGroup(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener); + + ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber); + }; + + return m_sharedAccountManager->observeGroup(groupId, observeCallback); +} + +OCStackResult JniOcAccountManager::cancelObserveGroup(const std::string& groupId) +{ + return m_sharedAccountManager->cancelObserveGroup(groupId); +} + +OCStackResult JniOcAccountManager::observeInvitation(JNIEnv* env, jobject jListener) +{ + JniOnObserveListener *onObserveListener = addOnObserveListener(env, jListener); + + ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber); + }; + + return m_sharedAccountManager->observeInvitation(observeCallback); +} + +OCStackResult JniOcAccountManager::cancelObserveInvitation() +{ + return m_sharedAccountManager->cancelObserveInvitation(); +} + +OCStackResult JniOcAccountManager::sendInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedAccountManager->sendInvitation(groupId, userUuid, postCallback); +} + +OCStackResult JniOcAccountManager::cancelInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->cancelInvitation(groupId, userUuid, deleteCallback); +} + +OCStackResult JniOcAccountManager::deleteInvitation(JNIEnv* env, const std::string& groupId, + jobject jListener) +{ + JniOnDeleteListener *onDeleteListener = addOnDeleteListener(env, jListener); + + DeleteCallback deleteCallback = [onDeleteListener](const HeaderOptions& opts, + const int eCode) + { + onDeleteListener->onDeleteCallback(opts, eCode); + }; + + return m_sharedAccountManager->deleteInvitation(groupId, deleteCallback); +} + + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getHost +* Signature: ()Ljava/lang/String; +*/ +JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcAccountManager_getHost + (JNIEnv *env, jobject thiz) +{ + LOGD("OcAccountManager_getHost"); + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return nullptr; + } + + return env->NewStringUTF(accountManager->host().c_str()); +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getConnectivityTypeN +* Signature: ()I +*/ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcAccountManager_getConnectivityTypeN + (JNIEnv *env, jobject thiz) +{ + LOGD("OcAccountManager_getConnectivityType"); + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return -1; + } + + OCConnectivityType connectivityType = accountManager->connectivityType(); + return static_cast(connectivityType); +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signUp0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 + (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jListener) +{ + LOGD("OcAccountManager_signUp"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string authProvider; + std::string authCode; + if (jAuthProvider) + { + authProvider = env->GetStringUTFChars(jAuthProvider, nullptr); + } + if (jAuthCode) + { + authCode = env->GetStringUTFChars(jAuthCode, nullptr); + } + + try + { + OCStackResult result = accountManager->signUp(env, + authProvider, + authCode, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signUp"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signUp1 +* Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 + (JNIEnv *env, jobject thiz, jstring jAuthProvider, jstring jAuthCode, jobject jOptionsMap, + jobject jListener) +{ + LOGD("OcAccountManager_signUp"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + if (!jOptionsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "options cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string authProvider; + std::string authCode; + if (jAuthProvider) + { + authProvider = env->GetStringUTFChars(jAuthProvider, nullptr); + } + if (jAuthCode) + { + authCode = env->GetStringUTFChars(jAuthCode, nullptr); + } + + QueryParamsMap optionsMap; + JniUtils::convertJavaMapToQueryParamsMap(env, jOptionsMap, optionsMap); + + try + { + OCStackResult result = accountManager->signUp(env, + authProvider, + authCode, + optionsMap, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signUp"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signIn0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 + (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jAccessToken, jobject jListener) +{ + LOGD("OcAccountManager_signIn"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string userUuid; + std::string accessToken; + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + if (jAccessToken) + { + accessToken = env->GetStringUTFChars(jAccessToken, nullptr); + } + + try + { + OCStackResult result = accountManager->signIn(env, + userUuid, + accessToken, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signIn"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: signOut0 +* Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0 + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcAccountManager_signOut"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->signOut(env, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_signOut"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: refreshAccessToken0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToken0 + (JNIEnv *env, jobject thiz, jstring jUserUuid, jstring jRefreshAccessToken, jobject jListener) +{ + LOGD("OcAccountManager_refreshAccessToken"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string userUuid; + std::string refreshAccessToken; + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + if (jRefreshAccessToken) + { + refreshAccessToken = env->GetStringUTFChars(jRefreshAccessToken, nullptr); + } + + try + { + OCStackResult result = accountManager->refreshAccessToken(env, + userUuid, + refreshAccessToken, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_refreshAccessToken"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: searchUser0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0 + (JNIEnv *env, jobject thiz, jstring jUserUuid, jobject jListener) +{ + LOGD("OcAccountManager_searchUser"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string userUuid; + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + + try + { + OCStackResult result = accountManager->searchUser(env, + userUuid, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_searchUser"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: searchUser1 +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 + (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener) +{ + LOGD("OcAccountManager_searchUser"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + if (!jQueryMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryMap cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + QueryParamsMap queryMap; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryMap, queryMap); + + try + { + OCStackResult result = accountManager->searchUser(env, + queryMap, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_searchUser"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteDevice0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 + (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener) +{ + LOGD("OcAccountManager_deleteDevice"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string deviceId; + if (jDeviceId) + { + deviceId = env->GetStringUTFChars(jDeviceId, nullptr); + } + + try + { + OCStackResult result = accountManager->deleteDevice(env, + deviceId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteDevice"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: createGroup0 +* Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 + (JNIEnv *env, jobject thiz, jint groupType, jobject jListener) +{ + LOGD("OcAccountManager_createGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->createGroup(env, + JniUtils::getAclGroupType(env, static_cast(groupType)), + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_createGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getGroupList0 +* Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0 + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcAccountManager_getGroupList"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->getGroupList(env, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_getGroupList"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_deleteGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->deleteGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: joinGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_joinGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->joinGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_joinGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: addDeviceToGroup0 +* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener) +{ + LOGD("OcAccountManager_addDeviceToGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + if (!jDeviceIdArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + std::vector deviceIds; + JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds); + + try + { + OCStackResult result = accountManager->addDeviceToGroup(env, + groupId, + deviceIds, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_addDeviceToGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: getGroupInfo0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_getGroupInfo"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onGetListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->getGroupInfo(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_getGroupInfo"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: leaveGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_leaveGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->leaveGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_leaveGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteDeviceFromGroup0 +* Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener) +{ + LOGD("OcAccountManager_deleteDeviceFromGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + if (!jDeviceIdArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "deviceId cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + std::vector deviceIds; + JniUtils::convertJavaStrArrToStrVector(env, jDeviceIdArray, deviceIds); + + try + { + OCStackResult result = accountManager->deleteDeviceFromGroup(env, + groupId, + deviceIds, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteDeviceFromGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: observeGroup0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_observeGroup"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->observeGroup(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_observeGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: cancelObserveGroup0 +* Signature: (Ljava/lang/String;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId) +{ + LOGD("OcAccountManager_cancelObserveGroup"); + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->cancelObserveGroup(groupId); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_cancelObserveGroup"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: observeInvitation0 +* Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0 + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcAccountManager_observeInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->observeInvitation(env, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_observeInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: cancelObserveInvitation0 +* Signature: ()V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0 + (JNIEnv *env, jobject thiz) +{ + LOGD("OcAccountManager_cancelObserveInvitation"); + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + try + { + OCStackResult result = accountManager->cancelObserveInvitation(); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_cancelObserveInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: sendInvitation0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener) +{ + LOGD("OcAccountManager_sendInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId, userUuid; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + + try + { + OCStackResult result = accountManager->sendInvitation(env, + groupId, + userUuid, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_sendInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: cancelInvitation0 +* Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener) +{ + LOGD("OcAccountManager_cancelInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId, userUuid; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + if (jUserUuid) + { + userUuid = env->GetStringUTFChars(jUserUuid, nullptr); + } + + try + { + OCStackResult result = accountManager->cancelInvitation(env, + groupId, + userUuid, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_cancelInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcAccountManager +* Method: deleteInvitation0 +* Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener) +{ + LOGD("OcAccountManager_deleteInvitation"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteListener cannot be null"); + return; + } + + JniOcAccountManager *accountManager = JniOcAccountManager::getJniOcAccountManagerPtr(env, + thiz); + if (!accountManager) + { + return; + } + + std::string groupId; + if (jGroupId) + { + groupId = env->GetStringUTFChars(jGroupId, nullptr); + } + + try + { + OCStackResult result = accountManager->deleteInvitation(env, + groupId, + jListener); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcAccountManager_deleteInvitation"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + + diff --git a/android/android_api/base/jni/JniOcAccountManager.h b/android/android_api/base/jni/JniOcAccountManager.h new file mode 100644 index 0000000..7ff841e --- /dev/null +++ b/android/android_api/base/jni/JniOcAccountManager.h @@ -0,0 +1,308 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +#ifndef _Included_org_iotivity_base_OcAccountManager +#define _Included_org_iotivity_base_OcAccountManager + +#include "JniOcStack.h" +#include "OCAccountManager.h" +#include "JniListenerManager.h" +#include "JniOnGetListener.h" +#include "JniOnPostListener.h" +#include "JniOnDeleteListener.h" +#include "JniOnObserveListener.h" + +using namespace OC; + +class JniOcAccountManager +{ +public: + JniOcAccountManager(std::shared_ptr accountManager); + ~JniOcAccountManager(); + + std::string host(); + OCConnectivityType connectivityType() const; + + static JniOcAccountManager* getJniOcAccountManagerPtr(JNIEnv *env, jobject thiz); + + OCStackResult signUp(JNIEnv* env, const std::string& authProvider, const std::string& authCode, + jobject jListener); + OCStackResult signUp(JNIEnv* env, const std::string& authProvider, const std::string& authCode, + const QueryParamsMap& options, jobject jListener); + OCStackResult signIn(JNIEnv* env, const std::string& userUuid, const std::string& accessToken, + jobject jListener); + OCStackResult signOut(JNIEnv* env, jobject jListener); + OCStackResult refreshAccessToken(JNIEnv* env, const std::string& userUuid, + const std::string& refreshToken, jobject jListener); + OCStackResult searchUser(JNIEnv* env, const std::string& userUuid, jobject jListener); + OCStackResult searchUser(JNIEnv* env, const QueryParamsMap& queryMap, jobject jListener); + OCStackResult deleteDevice(JNIEnv* env, const std::string& deviceId, jobject jListener); + OCStackResult createGroup(JNIEnv* env, AclGroupType groupType, jobject jListener); + OCStackResult getGroupList(JNIEnv* env, jobject jListener); + OCStackResult deleteGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult joinGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult addDeviceToGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, jobject jListener); + OCStackResult getGroupInfo(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult leaveGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult deleteDeviceFromGroup(JNIEnv* env, const std::string& groupId, + const std::vector& deviceId, + jobject jListener); + OCStackResult observeGroup(JNIEnv* env, const std::string& groupId, jobject jListener); + OCStackResult cancelObserveGroup(const std::string& groupId); + OCStackResult observeInvitation(JNIEnv* env, jobject jListener); + OCStackResult cancelObserveInvitation(); + OCStackResult sendInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener); + OCStackResult cancelInvitation(JNIEnv* env, const std::string& groupId, + const std::string& userUuid, jobject jListener); + OCStackResult deleteInvitation(JNIEnv* env, const std::string& groupId, jobject jListener); + + JniOnGetListener* addOnGetListener(JNIEnv* env, jobject jListener); + JniOnPostListener* addOnPostListener(JNIEnv* env, jobject jListener); + JniOnDeleteListener* addOnDeleteListener(JNIEnv* env, jobject jListener); + JniOnObserveListener* addOnObserveListener(JNIEnv* env, jobject jListener); + + void removeOnGetListener(JNIEnv* env, jobject jListener); + void removeOnPostListener(JNIEnv* env, jobject jListener); + void removeOnDeleteListener(JNIEnv* env, jobject jListener); + void removeOnObserveListener(JNIEnv* env, jobject jListener); + +private: + JniListenerManager m_onGetManager; + JniListenerManager m_onPostManager; + JniListenerManager m_onDeleteManager; + JniListenerManager m_onObserveManager; + + std::shared_ptr m_sharedAccountManager; +}; + +/* DO NOT EDIT THIS FILE BEYOND THIS LINE - it is machine generated */ + +#ifdef __cplusplus +extern "C" { +#endif + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getHost + * Signature: ()Ljava/lang/String; + */ + JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcAccountManager_getHost + (JNIEnv *, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getConnectivityTypeN + * Signature: ()I + */ + JNIEXPORT jint JNICALL Java_org_iotivity_base_OcAccountManager_getConnectivityTypeN + (JNIEnv *, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signUp0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp0 + (JNIEnv *, jobject, jstring, jstring, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signUp1 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signUp1 + (JNIEnv *, jobject, jstring, jstring, jobject, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signIn0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signIn0 + (JNIEnv *, jobject, jstring, jstring, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: signOut0 + * Signature: (Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_signOut0 + (JNIEnv *, jobject, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: refreshAccessToken0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_refreshAccessToken0 + (JNIEnv *, jobject, jstring, jstring, jobject); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: searchUser0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser0 + (JNIEnv *env, jobject thiz, jstring juserUuid, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: searchUser1 + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_searchUser1 + (JNIEnv *env, jobject thiz, jobject jQueryMap, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteDevice0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDevice0 + (JNIEnv *env, jobject thiz, jstring jDeviceId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: createGroup0 + * Signature: (Lorg/iotivity/base/AclGroupType;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_createGroup0 + (JNIEnv *env, jobject thiz, jint groupType, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getGroupList0 + * Signature: (Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupList0 + (JNIEnv *env, jobject thiz, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: joinGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_joinGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: addDeviceToGroup0 + * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_addDeviceToGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: getGroupInfo0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnGetListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_getGroupInfo0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: leaveGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_leaveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteDeviceFromGroup0 + * Signature: (Ljava/lang/String;[Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteDeviceFromGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobjectArray jDeviceIdArray, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: observeGroup0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcResource/OnObserveListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: cancelObserveGroup0 + * Signature: (Ljava/lang/String;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveGroup0 + (JNIEnv *env, jobject thiz, jstring jGroupId); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: observeInvitation0 + * Signature: (Lorg/iotivity/base/OcResource/OnObserveListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_observeInvitation0 + (JNIEnv *env, jobject thiz, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: cancelObserveInvitation0 + * Signature: ()V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelObserveInvitation0 + (JNIEnv *env, jobject thiz); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: sendInvitation0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/OnPostListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_sendInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: cancelInvitation0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_cancelInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jstring jUserUuid, jobject jListener); + + /* + * Class: org_iotivity_base_OcAccountManager + * Method: deleteInvitation0 + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcAccountManager/onDeleteListener;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcAccountManager_deleteInvitation0 + (JNIEnv *env, jobject thiz, jstring jGroupId, jobject jListener); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/android_api/base/jni/JniOcCloudProvisioning.cpp b/android/android_api/base/jni/JniOcCloudProvisioning.cpp new file mode 100644 index 0000000..c1bac6a --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudProvisioning.cpp @@ -0,0 +1,576 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcCloudProvisioning.h" +#include "oic_malloc.h" + +namespace PH = std::placeholders; + +JniOcCloudProvisioning::JniOcCloudProvisioning(std::shared_ptr p) + : m_sharedCloudObject(p) +{} + +JniOcCloudProvisioning::~JniOcCloudProvisioning() +{ + LOGD("~JniOcCloudProvisioning"); + m_sharedCloudObject = nullptr; +} + +JniOcCloudResultListener* JniOcCloudProvisioning::AddCloudResultListener(JNIEnv* env, + jobject jListener) +{ + JniOcCloudResultListener *resultListener = NULL; + resultMapLock.lock(); + + for (auto it = resultMap.begin(); it != resultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + resultListener = refPair.first; + refPair.second++; + it->second = refPair; + resultMap.insert(*it); + LOGD("Cloud Provision resultListener: ref. count incremented"); + break; + } + } + if (!resultListener) + { + resultListener = new JniOcCloudResultListener(env, jListener, + RemoveCallback(std::bind(&JniOcCloudProvisioning::RemoveCloudResultListener, + this, PH::_1, PH::_2))); + jobject jgListener = env->NewGlobalRef(jListener); + + resultMap.insert(std::pair < jobject, std::pair < JniOcCloudResultListener*, + int >> (jgListener, std::pair(resultListener, 1))); + LOGD("Cloud Provision resultListener: new listener"); + } + resultMapLock.unlock(); + return resultListener; +} + +void JniOcCloudProvisioning::RemoveCloudResultListener(JNIEnv* env, jobject jListener) +{ + resultMapLock.lock(); + + for (auto it = resultMap.begin(); it != resultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + resultMap.insert(*it); + LOGI("Cloud Provision resultListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOcCloudResultListener* listener = refPair.first; + delete listener; + resultMap.erase(it); + LOGI("Cloud Provision resultListener removed"); + } + break; + } + } + resultMapLock.unlock(); +} + +JniGetAclIdByDeviceListener* JniOcCloudProvisioning::AddGetAclByDeviceListener(JNIEnv* env, + jobject jListener) +{ + JniGetAclIdByDeviceListener *resultListener = NULL; + aclresultMapLock.lock(); + + for (auto it = aclresultMap.begin(); it != aclresultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + resultListener = refPair.first; + refPair.second++; + it->second = refPair; + aclresultMap.insert(*it); + LOGD("GetACLByDeviceID Listener: ref. count incremented"); + break; + } + } + if (!resultListener) + { + resultListener = new JniGetAclIdByDeviceListener(env, jListener, + RemoveCallback(std::bind(&JniOcCloudProvisioning::RemoveGetAclByDeviceIdListener, + this, PH::_1, PH::_2))); + jobject jgListener = env->NewGlobalRef(jListener); + + aclresultMap.insert(std::pair < jobject, std::pair < JniGetAclIdByDeviceListener*, + int >> (jgListener, std::pair(resultListener, 1))); + LOGD("GetACLByDeviceID Listener: new listener"); + } + aclresultMapLock.unlock(); + return resultListener; +} + +void JniOcCloudProvisioning::RemoveGetAclByDeviceIdListener(JNIEnv* env, jobject jListener) +{ + aclresultMapLock.lock(); + + for (auto it = aclresultMap.begin(); it != aclresultMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + aclresultMap.insert(*it); + LOGI("GetACLByDeviceID Listener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniGetAclIdByDeviceListener* listener = refPair.first; + delete listener; + aclresultMap.erase(it); + LOGI("GetACLByDeviceID Listener removed"); + } + break; + } + } + aclresultMapLock.unlock(); +} +JniOcCloudProvisioning * Create_native_object(JNIEnv *env, jobject thiz) +{ + jstring jip = (jstring)env->CallObjectMethod(thiz, g_mid_OcCloudProvisioning_getIP); + if (!jip || env->ExceptionCheck()) + { + return nullptr; + } + const char *str = env->GetStringUTFChars(jip, NULL); + std::string ipaddress(str); + env->ReleaseStringUTFChars(jip, str); + + jint port = env->CallIntMethod(thiz, g_mid_OcCloudProvisioning_getPort); + if (env->ExceptionCheck()) + { + return nullptr; + } + JniOcCloudProvisioning *cloud = new JniOcCloudProvisioning( + std::shared_ptr(new OCCloudProvisioning(ipaddress, (uint16_t)port))); + SetHandle(env, thiz, cloud); + return cloud; +} + +JniOcCloudProvisioning* JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(JNIEnv *env, jobject thiz) +{ + JniOcCloudProvisioning *cloud = GetHandle(env, thiz); + + if (env->ExceptionCheck()) + { + LOGE("Failed to get native handle from OcCloudProvisioning class"); + } + + return cloud; +} + +OCStackResult JniOcCloudProvisioning::requestCertificate(JNIEnv* env, jobject jListener) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::REQUEST_CERTIFICATE); + }; + + return m_sharedCloudObject->requestCertificate(responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::getIndividualAclInfo(JNIEnv* env, jobject jListener, std::string &aclID) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::GET_ACLINFO); + }; + + return m_sharedCloudObject->getIndividualAclInfo(aclID, responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::getCRL(JNIEnv* env, jobject jListener) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::GET_CRL); + }; + + return m_sharedCloudObject->getCRL(responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::postCRL(JNIEnv* env, const std::string& thisUpdate, + const std::string& nextUpdate, const OCByteString *crl, + const stringArray_t *serialNumbers, jobject jListener) +{ + JniOcCloudResultListener *resultListener = AddCloudResultListener(env, jListener); + + ResponseCallBack responseCallBack = [resultListener](OCStackResult result, void *data) + { + resultListener->CloudResultListenerCB(result, data, ListenerFunc::POST_CRL); + }; + + return m_sharedCloudObject->postCRL(thisUpdate, nextUpdate, crl, serialNumbers, + responseCallBack); +} + +OCStackResult JniOcCloudProvisioning::getAclIdByDevice(JNIEnv* env, std::string deviceId, + jobject jListener) +{ + JniGetAclIdByDeviceListener *resultListener = AddGetAclByDeviceListener(env, jListener); + + AclIdResponseCallBack aclIdResponseCallBack = [resultListener](OCStackResult result, + std::string aclId) + { + resultListener->GetAclIdByDeviceListenerCB(result, aclId); + }; + + return m_sharedCloudObject->getAclIdByDevice(deviceId, aclIdResponseCallBack); +} +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: requestCertificate + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/RequestCertificateListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_requestCertificate + (JNIEnv* env, jobject thiz, jobject jListener) +{ + LOGD("OcCloudProvisioning_requestCertificate"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_requestCertificate, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_requestCertificate," + "Can not Create Native object"); + return; + } + } + + try + { + OCStackResult result = cloud->requestCertificate(env, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_requestCertificate"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getAclIdByDevice + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetAclIdByDeviceListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getAclIdByDevice + (JNIEnv *env, jobject thiz, jstring jdeviceId, jobject jListener) +{ + LOGD("OcCloudProvisioning_getAclIdByDevice"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + + if (!jdeviceId) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "deviceID can not be null"); + return; + } + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getAclIdByDevice, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getAclIdByDevice," + "Can not Create Native object"); + return; + } + } + + const char *str = env->GetStringUTFChars(jdeviceId, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_getAclIdByDevice"); + return; + } + std::string deviceId(str); + env->ReleaseStringUTFChars(jdeviceId, str); + + try + { + OCStackResult result = cloud->getAclIdByDevice(env, deviceId, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_getAclIdByDevice"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getIndividualAclInfo + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getIndividualAclInfo + (JNIEnv *env, jobject thiz, jstring jaclID, jobject jListener) +{ + LOGD("OcCloudProvisioning_getIndividualAclInfo"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + if (!jaclID) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "aclID cannot be null"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getIndividualAclInfo, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getIndividualAclInfo," + "Can not Create Native object"); + return; + } + } + + const char *str = env->GetStringUTFChars(jaclID, NULL); + std::string aclID(str); + env->ReleaseStringUTFChars(jaclID, str); + + try + { + OCStackResult result = cloud->getIndividualAclInfo(env, jListener, aclID); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_getIndividualAclInf"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getCRL + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/GetCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getCRL + (JNIEnv *env, jobject thiz, jobject jListener) +{ + LOGD("OcCloudProvisioning_getCRL"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Listener cannot be null"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getCRL, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_getCRL," + "Can not Create Native object"); + return; + } + } + + try + { + OCStackResult result = cloud->getCRL(env, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_requestCertificate"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: postCRL0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;Lorg/iotivity/base/OcCloudProvisioning/PostCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_postCRL0 + (JNIEnv *env , jobject thiz, jstring jthisUpdate, jstring jnextUpdate, jstring jcrl, + jobjectArray jserialnumArray, jobject jListener) +{ + LOGD("OcCloudProvisioning_postCRL0"); + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK,"Listener can not be null"); + return; + } + if (!jthisUpdate || !jnextUpdate || !jserialnumArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, " Invalid parameter (NULL param)"); + return; + } + + JniOcCloudProvisioning *cloud = JniOcCloudProvisioning::getJniOcCloudProvisioningPtr(env, thiz); + if (!cloud) + { + LOGD("OcCloudProvisioning_getCRL, No native object, creating now"); + cloud = Create_native_object(env, thiz); + if (!cloud) + { + ThrowOcException(OC_STACK_ERROR, "OcCloudProvisioning_PostCRL0," + "Can not Create Native object"); + return; + } + } + + const char *str = env->GetStringUTFChars(jthisUpdate, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + std::string thisUpdate(str); + env->ReleaseStringUTFChars(jthisUpdate, str); + + str = env->GetStringUTFChars(jnextUpdate, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + std::string nextUpdate(str); + env->ReleaseStringUTFChars(jnextUpdate, str); + + OCByteString *crl = NULL; + if (jcrl) + { + str = env->GetStringUTFChars(jcrl, NULL); + if (!str || env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + crl = (OCByteString*)OICCalloc(1, sizeof(OCByteString)); + crl->len = (size_t)(strlen(str)); + crl->bytes = (uint8_t*)OICCalloc(crl->len, sizeof(uint8_t)); + + for (size_t i = 0 ; i < crl->len; i++) + { + crl->bytes[i] = (uint8_t)str[i]; + } + } + + jsize len = env->GetArrayLength(jserialnumArray); + + stringArray_t *serialNumArray = (stringArray_t*)OICCalloc(1, sizeof(stringArray_t)); + serialNumArray->array = (char**)OICCalloc(len, sizeof(char*)); + serialNumArray->length = len; + + for (jsize i = 0; i < len; ++i) + { + jstring jStr = (jstring)env->GetObjectArrayElement(jserialnumArray, i); + if (!jStr) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + serialNumArray->array[i] = (char*)env->GetStringUTFChars(jStr, nullptr); + if (env->ExceptionCheck()) + { + ThrowOcException(OC_STACK_ERROR,"OcCloudProvisioning_PostCRL0"); + return; + } + env->DeleteLocalRef(jStr); + } + + try + { + OCStackResult result = cloud->postCRL(env, thisUpdate, nextUpdate, crl, + serialNumArray, jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcCloudProvisioning_PostCRL0"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return; +} diff --git a/android/android_api/base/jni/JniOcCloudProvisioning.h b/android/android_api/base/jni/JniOcCloudProvisioning.h new file mode 100644 index 0000000..58693c7 --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudProvisioning.h @@ -0,0 +1,110 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ + +#include "JniOcStack.h" +#include "OCCloudProvisioning.h" +#include "JniOcCloudResultListener.h" +#include "JniGetAclIdByDeviceListener.h" +#include + + +using namespace OC; + +#ifndef _Included_org_iotivity_base_OcCloudProvisioning +#define _Included_org_iotivity_base_OcCloudProvisioning +class JniOcCloudProvisioning +{ + public: + JniOcCloudProvisioning(std::shared_ptr cloudObject); + ~JniOcCloudProvisioning(); + + static JniOcCloudProvisioning* getJniOcCloudProvisioningPtr(JNIEnv *env, jobject thiz); + JniOcCloudResultListener* AddCloudResultListener(JNIEnv* env, jobject jListener); + JniGetAclIdByDeviceListener* AddGetAclByDeviceListener(JNIEnv* env, jobject jListener); + void RemoveCloudResultListener(JNIEnv* env, jobject jListener); + void RemoveGetAclByDeviceIdListener(JNIEnv*, jobject); + + OCStackResult requestCertificate(JNIEnv* env, jobject jListener); + OCStackResult getAclIdByDevice(JNIEnv*, std::string, jobject); + OCStackResult getIndividualAclInfo(JNIEnv*, jobject, std::string &); + OCStackResult getCRL(JNIEnv* env, jobject jListener); + OCStackResult postCRL(JNIEnv* env, const std::string& thisUpdate, + const std::string& nextUpdate, const OCByteString *crl, + const stringArray_t *serialNumbers, jobject jListener); + + private: + std::map> resultMap; + std::map> aclresultMap; + std::mutex resultMapLock; + std::mutex aclresultMapLock; + std::shared_ptrm_sharedCloudObject; +}; + + +/* DO NOT EDIT THIS FILE - it is machine generated */ +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: requestCertificate + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/RequestCertificateListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_requestCertificate + (JNIEnv *, jobject, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getAclIdByDevice + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetAclIdByDeviceListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getAclIdByDevice + (JNIEnv *, jobject, jstring, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getIndividualAclInfo + * Signature: (Ljava/lang/String;Lorg/iotivity/base/OcCloudProvisioning/GetIndividualAclInfoListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getIndividualAclInfo + (JNIEnv *, jobject, jstring, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: getCRL + * Signature: (Lorg/iotivity/base/OcCloudProvisioning/GetCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_getCRL + (JNIEnv *, jobject, jobject); + +/* + * Class: org_iotivity_base_OcCloudProvisioning + * Method: postCRL0 + * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/ArrayList;Lorg/iotivity/base/OcCloudProvisioning/PostCRLListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcCloudProvisioning_postCRL0 + (JNIEnv *, jobject, jstring, jstring, jstring, jobjectArray, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/android/android_api/base/jni/JniOcCloudResultListener.cpp b/android/android_api/base/jni/JniOcCloudResultListener.cpp new file mode 100644 index 0000000..9894fa2 --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudResultListener.cpp @@ -0,0 +1,155 @@ +/* +* //****************************************************************** +* // +* // Copyright 2016 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include "JniOcCloudResultListener.h" + +JniOcCloudResultListener::JniOcCloudResultListener(JNIEnv *env, jobject jListener, + RemoveCallback removeCloudResultListener) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeCloudResultListener = removeCloudResultListener; +} + +JniOcCloudResultListener::~JniOcCloudResultListener() +{ + LOGI("~JniOcCloudResultListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOcCloudResultListener::CloudResultListenerCB(int result, void *data, + ListenerFunc func) +{ + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + std::string calledFunc; + switch (func) + { + case ListenerFunc::REQUEST_CERTIFICATE: + { + calledFunc = "requestCertificateListener"; + } + break; + case ListenerFunc::GET_ACLINFO: + { + calledFunc = "getIndividualAclInfoListener"; + } + break; + case ListenerFunc::GET_CRL: + { + calledFunc = "getCRLListener"; + } + break; + case ListenerFunc::POST_CRL: + { + calledFunc = "postCRLListener"; + } + break; + default: + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + return; + } + + jmethodID midL = env->GetMethodID(clsL, calledFunc.c_str(), "(Z)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + env->CallVoidMethod(jListener, midL, (jboolean)result); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + } + + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOcCloudResultListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeCloudResultListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeCloudResultListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOcCloudResultListener.h b/android/android_api/base/jni/JniOcCloudResultListener.h new file mode 100644 index 0000000..3cb826a --- /dev/null +++ b/android/android_api/base/jni/JniOcCloudResultListener.h @@ -0,0 +1,52 @@ +/* +* //****************************************************************** +* // +* // Copyright 2015 Samsung Electronics All Rights Reserved. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +* // +* // Licensed under the Apache License, Version 2.0 (the "License"); +* // you may not use this file except in compliance with the License. +* // You may obtain a copy of the License at +* // +* // http://www.apache.org/licenses/LICENSE-2.0 +* // +* // Unless required by applicable law or agreed to in writing, software +* // distributed under the License is distributed on an "AS IS" BASIS, +* // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* // See the License for the specific language governing permissions and +* // limitations under the License. +* // +* //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +*/ +#include +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcCloudProvisioning_JniOcCloudResultListener +#define _Included_org_iotivity_base_OcCloudProvisioning_JniOcCloudResultListener + +typedef std::function RemoveCallback; + +enum class ListenerFunc +{ + REQUEST_CERTIFICATE = 1, + GET_ACLINFO, + GET_CRL, + POST_CRL +}; + +class JniOcCloudResultListener +{ + public: + JniOcCloudResultListener(JNIEnv *env, jobject jListener, + RemoveCallback removeCloudResultListener); + ~JniOcCloudResultListener(); + + void CloudResultListenerCB(int result, void *data, ListenerFunc func); + + private: + RemoveCallback m_removeCloudResultListener; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; +#endif diff --git a/android/android_api/base/jni/JniOcDirectPairDevice.cpp b/android/android_api/base/jni/JniOcDirectPairDevice.cpp index 535bebc..ff4e626 100644 --- a/android/android_api/base/jni/JniOcDirectPairDevice.cpp +++ b/android/android_api/base/jni/JniOcDirectPairDevice.cpp @@ -28,7 +28,8 @@ namespace PH = std::placeholders; JniOcDirectPairDevice::JniOcDirectPairDevice(std::shared_ptr directPairingDevice) : m_sharedDirectPairDevice(directPairingDevice) -{} +{ +} JniOcDirectPairDevice::~JniOcDirectPairDevice() { @@ -77,7 +78,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcDirectPairDevice_getHost LOGD("OcDirectPairing_getHost"); JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz); - if (!device) return nullptr; + if (!device) + { + return nullptr; + } std::string dev = device->getHost(); return env->NewStringUTF(dev.c_str()); @@ -91,7 +95,10 @@ JNIEXPORT jintArray JNICALL Java_org_iotivity_base_OcDirectPairDevice_getPairing std::vector pairingMethodList; JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz); - if (!device) return nullptr; + if (!device) + { + return nullptr; + } std::vector pairingMethods = device->getPairingMethods(); return JniOcDirectPairDevice::JconvertIntVectorToJavaList(env,pairingMethods); @@ -104,7 +111,10 @@ jintArray JniOcDirectPairDevice::JconvertIntVectorToJavaList(JNIEnv *env, std::v jsize len = static_cast(vector.size()); jintArray intArray = env->NewIntArray(len); - if (!intArray) return nullptr; + if (!intArray) + { + return nullptr; + } env->SetIntArrayRegion(intArray, (jsize)0, len, (const jint*)&vector[0]); @@ -125,7 +135,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcDirectPairDevice_getConnectivity { LOGD("OcDirectPairDevice_getConnectivityType"); JniOcDirectPairDevice* device = JniOcDirectPairDevice::getJniOcDirectPairDevicePtr(env,thiz); - if (!device) return -1; + if (!device) + { + return -1; + } OCConnectivityType connectivityType = device->connectivityType(); return static_cast(connectivityType); diff --git a/android/android_api/base/jni/JniOcPlatform.cpp b/android/android_api/base/jni/JniOcPlatform.cpp index 82f693f..a746cfe 100644 --- a/android/android_api/base/jni/JniOcPlatform.cpp +++ b/android/android_api/base/jni/JniOcPlatform.cpp @@ -29,6 +29,10 @@ #include "JniUtils.h" #include "ocpayload.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif + using namespace OC; JniOnResourceFoundListener* AddOnResourceFoundListener(JNIEnv* env, jobject jListener) @@ -322,6 +326,74 @@ void RemoveOnPresenceListener(JNIEnv* env, jobject jListener) presenceMapLock.unlock(); } +JniOnObserveListener* AddOnObserveListener(JNIEnv* env, jobject jListener) +{ + JniOnObserveListener *onObserveListener = nullptr; + + observeMapLock.lock(); + + for (auto it = onObserveListenerMap.begin(); it != onObserveListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onObserveListener = refPair.first; + refPair.second++; + it->second = refPair; + onObserveListenerMap.insert(*it); + LOGD("OnObserveListener: ref. count incremented"); + break; + } + } + if (!onObserveListener) + { + onObserveListener = new JniOnObserveListener(env, jListener, (JniOcResource*)nullptr); + jobject jgListener = env->NewGlobalRef(jListener); + onObserveListenerMap.insert( + std::pair>( + jgListener, + std::pair(onObserveListener, 1))); + LOGI("OnObserveListener: new listener"); + } + observeMapLock.unlock(); + return onObserveListener; +} + +void RemoveOnObserveListener(JNIEnv* env, jobject jListener) +{ + observeMapLock.lock(); + bool isFound = false; + for (auto it = onObserveListenerMap.begin(); it != onObserveListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onObserveListenerMap.insert(*it); + LOGI("OnObserveListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnObserveListener* listener = refPair.first; + delete listener; + onObserveListenerMap.erase(it); + LOGI("OnObserveListener is removed"); + } + isFound = true; + break; + } + } + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "OnObserveListener not found"); + } + observeMapLock.unlock(); +} + JniOnDPDevicesFoundListener* AddOnDPDevicesFoundListener(JNIEnv* env, jobject jListener) { JniOnDPDevicesFoundListener *onDPDeviceListener = nullptr; @@ -464,6 +536,172 @@ void RemoveOnDirectPairingListener(JNIEnv* env, jobject jListener) directPairingListenerMapLock.unlock(); } +JniOnPublishResourceListener* AddOnPublishResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGD("env is null"); + return nullptr; + } + + JniOnPublishResourceListener *onPublishResourceListener = nullptr; + + publishResourceListenerMapLock.lock(); + + for (auto it = onPublishResourceListenerMap.begin(); it != + onPublishResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onPublishResourceListener = refPair.first; + refPair.second++; + it->second = refPair; + onPublishResourceListenerMap.insert(*it); + LOGD("onPublishResourceListener: ref. count incremented"); + break; + } + } + if (!onPublishResourceListener) + { + onPublishResourceListener = new JniOnPublishResourceListener(env, jListener, + RemoveOnPublishResourceListener); + jobject jgListener = env->NewGlobalRef(jListener); + onPublishResourceListenerMap.insert( + std::pair>( + jgListener, + std::pair(onPublishResourceListener, 1))); + LOGI("onPublishResourceListener: new listener"); + } + publishResourceListenerMapLock.unlock(); + return onPublishResourceListener; +} + +void RemoveOnPublishResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGE("env is null"); + return; + } + + publishResourceListenerMapLock.lock(); + bool isFound = false; + for (auto it = onPublishResourceListenerMap.begin(); it != + onPublishResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onPublishResourceListenerMap.insert(*it); + LOGI("onPublishResourceListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnPublishResourceListener* listener = refPair.first; + delete listener; + onPublishResourceListenerMap.erase(it); + LOGI("onPublishResourceListener is removed"); + } + isFound = true; + break; + } + } + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "onPublishResourceListener not found"); + } + publishResourceListenerMapLock.unlock(); +} + +JniOnDeleteResourceListener* AddOnDeleteResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGD("env is null"); + return nullptr; + } + + JniOnDeleteResourceListener *onDeleteResourceListener = nullptr; + + deleteResourceListenerMapLock.lock(); + + for (auto it = onDeleteResourceListenerMap.begin(); it != + onDeleteResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + onDeleteResourceListener = refPair.first; + refPair.second++; + it->second = refPair; + onDeleteResourceListenerMap.insert(*it); + LOGD("onDeleteResourceListener: ref. count incremented"); + break; + } + } + if (!onDeleteResourceListener) + { + onDeleteResourceListener = new JniOnDeleteResourceListener(env, jListener, + RemoveOnDeleteResourceListener); + jobject jgListener = env->NewGlobalRef(jListener); + onDeleteResourceListenerMap.insert( + std::pair>( + jgListener, + std::pair(onDeleteResourceListener, 1))); + LOGI("onDeleteResourceListener: new listener"); + } + deleteResourceListenerMapLock.unlock(); + return onDeleteResourceListener; +} + +void RemoveOnDeleteResourceListener(JNIEnv* env, jobject jListener) +{ + if (!env) + { + LOGE("env is null"); + return; + } + + deleteResourceListenerMapLock.lock(); + bool isFound = false; + for (auto it = onDeleteResourceListenerMap.begin(); it != + onDeleteResourceListenerMap.end(); ++it) + { + if (env->IsSameObject(jListener, it->first)) + { + auto refPair = it->second; + if (refPair.second > 1) + { + refPair.second--; + it->second = refPair; + onDeleteResourceListenerMap.insert(*it); + LOGI("onDeleteResourceListener: ref. count decremented"); + } + else + { + env->DeleteGlobalRef(it->first); + JniOnDeleteResourceListener* listener = refPair.first; + delete listener; + onDeleteResourceListenerMap.erase(it); + LOGI("onDeleteResourceListener is removed"); + } + isFound = true; + break; + } + } + if (!isFound) + { + ThrowOcException(JNI_EXCEPTION, "onDeleteResourceListener not found"); + } + deleteResourceListenerMapLock.unlock(); +} + /* * Class: org_iotivity_base_OcPlatform * Method: configure @@ -520,7 +758,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers0 JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( env, jResourceHandle); - if (!jniOcResourceHandle) return; + if (!jniOcResourceHandle) + { + return; + } try { @@ -563,7 +804,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_notifyAllObservers1 return; } - try{ + try { OCStackResult result = OCPlatform::notifyAllObservers( jniOcResourceHandle->getOCResourceHandle(), JniUtils::getQOS(env, static_cast(jQoS))); @@ -766,13 +1007,19 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource0( onResFoundListener->foundResourceCallback(resource); }; + FindErrorCallback findErrorCallback = [onResFoundListener](const std::string& uri, const int eCode) + { + onResFoundListener->findResourceErrorCallback(uri, eCode); + }; + try { OCStackResult result = OCPlatform::findResource( host, resourceUri, static_cast(jConnectivityType), - findCallback); + findCallback, + findErrorCallback); if (OC_STACK_OK != result) { @@ -824,6 +1071,11 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1( onResFoundListener->foundResourceCallback(resource); }; + FindErrorCallback findErrorCallback = [onResFoundListener](const std::string& uri, const int eCode) + { + onResFoundListener->findResourceErrorCallback(uri, eCode); + }; + try { OCStackResult result = OCPlatform::findResource( @@ -831,6 +1083,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_findResource1( resourceUri, static_cast(jConnectivityType), findCallback, + findErrorCallback, JniUtils::getQOS(env, static_cast(jQoS))); if (OC_STACK_OK != result) @@ -1188,12 +1441,12 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1( ThrowOcException(OC_STACK_INVALID_PARAM, "onPlatformFoundListener cannot be null"); return; } - JniOnDeviceInfoListener *onDeviceInfoListener = AddOnDeviceInfoListener(env, jListener); + JniOnPlatformInfoListener *onPlatformInfoListener = AddOnPlatformInfoListener(env, jListener); - FindDeviceCallback findDeviceCallback = - [onDeviceInfoListener](const OCRepresentation& ocRepresentation) + FindPlatformCallback findPlatformCallback = + [onPlatformInfoListener](const OCRepresentation& ocRepresentation) { - onDeviceInfoListener->foundDeviceCallback(ocRepresentation); + onPlatformInfoListener->foundPlatformCallback(ocRepresentation); }; try @@ -1202,7 +1455,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_getPlatformInfo1( host, resourceUri, static_cast(jConnectivityType), - findDeviceCallback, + findPlatformCallback, JniUtils::getQOS(env, static_cast(jQoS))); if (OC_STACK_OK != result) @@ -1232,7 +1485,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_registerResource0( return nullptr; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, jResource); - if (!resource) return nullptr; + if (!resource) + { + return nullptr; + } OCResourceHandle resourceHandle; try @@ -1371,10 +1627,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0( } OCDeviceInfo deviceInfo; + memset(&deviceInfo, 0, sizeof(deviceInfo)); try { DuplicateString(&deviceInfo.deviceName, env->GetStringUTFChars(jDeviceName, nullptr)); - deviceInfo.types = NULL; jsize len = env->GetArrayLength(jDeviceTypes); for (jsize i = 0; i < len; ++i) @@ -1382,12 +1638,17 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_registerDeviceInfo0( jstring jStr = (jstring)env->GetObjectArrayElement(jDeviceTypes, i); if (!jStr) { + delete deviceInfo.deviceName; ThrowOcException(OC_STACK_INVALID_PARAM, "device type cannot be null"); return; } OCResourcePayloadAddStringLL(&deviceInfo.types, env->GetStringUTFChars(jStr, nullptr)); - if (env->ExceptionCheck()) return; + if (env->ExceptionCheck()) + { + delete deviceInfo.deviceName; + return; + } env->DeleteLocalRef(jStr); } @@ -1606,7 +1867,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindResource0 } JniOcResourceHandle* jniOcResourceCollectionHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceCollectionHandle); - if (!jniOcResourceCollectionHandle) return; + if (!jniOcResourceCollectionHandle) + { + return; + } JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr( env, jResourceHandle); @@ -1857,7 +2121,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_bindTypeToResource0( JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle); - if (!jniOcResourceHandle) return; + if (!jniOcResourceHandle) + { + return; + } try { @@ -2150,18 +2417,106 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_unsubscribePresence0( ThrowOcException(result, "unsubscribe presence has failed"); return; } - jweak jwOnPresenceListener = - jniPresenceHandle->getJniOnPresenceListener()->getJWListener(); - if (jwOnPresenceListener) + + JniOnPresenceListener* jniPresenceListener = jniPresenceHandle->getJniOnPresenceListener(); + if (jniPresenceListener) + { + jweak jwOnPresenceListener = jniPresenceListener->getJWListener(); + if (jwOnPresenceListener) + { + RemoveOnPresenceListener(env, jwOnPresenceListener); + } + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: subscribeDevicePresence0 +* Signature: (Ljava/lang/String;[Ljava/lang/String;I +Lorg/iotivity/base/OcResource/OnObserveListener;)Lorg/iotivity/base/OcPresenceHandle; +*/ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribeDevicePresence0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jobjectArray jDiArray, + jint jConnectivityType, + jobject jListener) +{ + LOGD("OcPlatform_subscribeDevicePresence0"); +#ifdef WITH_CLOUD + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + + if (!jDiArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device id List cannot be null"); + return nullptr; + } + + std::vector di; + JniUtils::convertJavaStrArrToStrVector(env, jDiArray, di); + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return nullptr; + } + + JniOnObserveListener *onObserveListener = AddOnObserveListener(env, jListener); + + ObserveCallback observeCallback = [onObserveListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onObserveListener->onObserveCallback(opts, rep, eCode, sequenceNumber); + }; + + OCPlatform::OCPresenceHandle presenceHandle; + try + { + OCStackResult result = OCPlatform::subscribeDevicePresence( + presenceHandle, + host, + di, + static_cast(jConnectivityType), + observeCallback); + + if (OC_STACK_OK != result) { - RemoveOnPresenceListener(env, jwOnPresenceListener); + ThrowOcException(result, "subscribe device presence has failed"); } } catch (OCException& e) { LOGE("%s", e.reason().c_str()); ThrowOcException(e.code(), e.reason().c_str()); + return nullptr; + } + + JniOcPresenceHandle* jniPresenceHandle = + new JniOcPresenceHandle(onObserveListener, presenceHandle); + jlong jhandle = reinterpret_cast(jniPresenceHandle); + jobject jPresenceHandle = + env->NewObject(g_cls_OcPresenceHandle, g_mid_OcPresenceHandle_N_ctor, jhandle); + if (!jPresenceHandle) + { + LOGE("Failed to create OcPresenceHandle"); + delete jniPresenceHandle; } + return jPresenceHandle; +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return nullptr; +#endif } /* @@ -2223,7 +2578,6 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructResourceObj } JniOcResource *jniOcResource = new JniOcResource(resource); - jlong handle = reinterpret_cast(jniOcResource); jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); if (!jResource) @@ -2257,7 +2611,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0( JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, jResourceResponse); - if (!jniResponse) return; + if (!jniResponse) + { + return; + } try { @@ -2275,3 +2632,444 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_sendResponse0( ThrowOcException(e.code(), e.reason().c_str()); } } + +/* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_publishResourceToRD"); +#ifdef RD_CLIENT + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPublishResourceListener cannot be null"); + return; + } + JniOnPublishResourceListener *onPubResListener = AddOnPublishResourceListener(env, jListener); + + PublishResourceCallback pubResCallback = [onPubResListener]( + const OCRepresentation& ocRepresentation, + const int eCode) + { + onPubResListener->onPublishResourceCallback(ocRepresentation, eCode); + }; + + try + { + OCStackResult result = OCPlatform::publishResourceToRD( + host, + static_cast(jConnectivityType), + pubResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Publish resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD1( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobjectArray jResourceHandleArray, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_publishResourceToRD"); +#ifdef RD_CLIENT + if (!env) + { + LOGE("env is null"); + return; + } + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPublishResourceListener cannot be null"); + return; + } + if (!jResourceHandleArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); + return; + } + JniOnPublishResourceListener *onPubResListener = AddOnPublishResourceListener(env, jListener); + + PublishResourceCallback pubResCallback = [onPubResListener]( + const OCRepresentation& ocRepresentation, + const int eCode) + { + onPubResListener->onPublishResourceCallback(ocRepresentation, eCode); + }; + + std::vector resourceHandleList; + size_t len = env->GetArrayLength(jResourceHandleArray); + for (size_t i = 0; i < len; ++i) + { + jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i); + if (!jResourceHandle) + { + ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = + JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle); + if (!jniOcResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resource handle is invalid"); + return; + } + + resourceHandleList.push_back(jniOcResourceHandle->getOCResourceHandle()); + } + + try + { + OCStackResult result = OCPlatform::publishResourceToRD( + host, + static_cast(jConnectivityType), + resourceHandleList, + pubResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Publish resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_deleteResourceFromRD"); +#ifdef RD_CLIENT + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteResourceListener cannot be null"); + return; + } + JniOnDeleteResourceListener *onDelResListener = AddOnDeleteResourceListener(env, jListener); + + DeleteResourceCallback delResCallback = [onDelResListener](const int eCode) + { + onDelResListener->onDeleteResourceCallback(eCode); + }; + + try + { + OCStackResult result = OCPlatform::deleteResourceFromRD( + host, + static_cast(jConnectivityType), + delResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Delete resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD1( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType, + jobjectArray jResourceHandleArray, + jobject jListener, + jint jQoS) +{ + LOGD("OcPlatform_deleteResourceFromRD"); +#ifdef RD_CLIENT + if (!env) + { + LOGE("env is null"); + return; + } + std::string host; + if (jHost) + { + host = env->GetStringUTFChars(jHost, nullptr); + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onDeleteResourceListener cannot be null"); + return; + } + if (!jResourceHandleArray) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resourceHandleList cannot be null"); + return; + } + JniOnDeleteResourceListener *onDelResListener = AddOnDeleteResourceListener(env, jListener); + + DeleteResourceCallback delResCallback = [onDelResListener](const int eCode) + { + onDelResListener->onDeleteResourceCallback(eCode); + }; + + std::vector resourceHandleList; + size_t len = env->GetArrayLength(jResourceHandleArray); + for (size_t i = 0; i < len; ++i) + { + jobject jResourceHandle = env->GetObjectArrayElement(jResourceHandleArray, i); + if (!jResourceHandle) + { + ThrowOcException(JNI_EXCEPTION, "resource handle cannot be null"); + return; + } + + JniOcResourceHandle* jniOcResourceHandle = + JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle); + if (!jniOcResourceHandle) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "resource handle is invalid"); + return; + } + + resourceHandleList.push_back(jniOcResourceHandle->getOCResourceHandle()); + } + + try + { + OCStackResult result = OCPlatform::deleteResourceFromRD( + host, + static_cast(jConnectivityType), + resourceHandleList, + delResCallback, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Delete resource has failed"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "Not supported"); + return; +#endif +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: constructAccountManagerObject0 +* Signature: (Ljava/lang/String;I)Lorg/iotivity/base/OcAccountManager; +*/ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructAccountManagerObject0( + JNIEnv *env, + jclass clazz, + jstring jHost, + jint jConnectivityType) +{ +#ifndef WITH_CLOUD + ThrowOcException(OC_STACK_ERROR, + "OCAccountManager is not supported. (Please build with WITH_CLOUD=1 option)"); + return nullptr; +#else + LOGD("OcPlatform_constructAccountManagerObject"); + if (!jHost) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "host cannot be null"); + return nullptr; + } + + const char* charHost = env->GetStringUTFChars(jHost, nullptr); + if (!charHost) + { + ThrowOcException(JNI_EXCEPTION, "charHost is null"); + return nullptr; + } + std::string host(charHost); + env->ReleaseStringUTFChars(jHost, charHost); + + std::shared_ptr accountManager = OCPlatform::constructAccountManagerObject( + host, + static_cast(jConnectivityType)); + + if (!accountManager) + { + ThrowOcException(OC_STACK_ERROR, "Failed to create OCAccountManager"); + return nullptr; + } + + JniOcAccountManager *jniOcAccountManager = new JniOcAccountManager(accountManager); + + jobject jAccountManager = env->NewObject(g_cls_OcAccountManager, g_mid_OcAccountManager_ctor); + if (!jAccountManager) + { + delete jniOcAccountManager; + return nullptr; + } + SetHandle(env, jAccountManager, jniOcAccountManager); + if (env->ExceptionCheck()) + { + delete jniOcAccountManager; + return nullptr; + } + return jAccountManager; +#endif +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: getDeviceId +* Signature: (I)V +*/ +JNIEXPORT jbyteArray JNICALL Java_org_iotivity_base_OcPlatform_getDeviceId +(JNIEnv *env, jobject thiz) +{ + LOGD("OcPlatform_getDeviceId"); + OCUUIdentity deviceId; + + jbyteArray ret = env->NewByteArray(UUID_IDENTITY_SIZE); + jbyte uuid[UUID_IDENTITY_SIZE]; + try + { + + OCStackResult result = OCPlatform::getDeviceId(&deviceId); + LOGD("OcPlatform_getDeviceId return from CPP"); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Error while getting my device Id"); + } + else + { + for(int i=0;i < UUID_IDENTITY_SIZE; i++) + { + uuid[i] =(jbyte) deviceId.id[i]; + } + } + + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + + env->SetByteArrayRegion(ret, 0, UUID_IDENTITY_SIZE, uuid); + + return ret; +} + +/* +* Class: org_iotivity_base_OcPlatform +* Method: setDeviceId +* Signature: (Ljava/lang/byte;)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setDeviceId( + JNIEnv *env, jobject thiz, jbyteArray data) +{ + LOGI("OcPlatform_setDeviceId"); + OCUUIdentity deviceId; + try + { + OCStackResult result; + jbyte* uuid = env->GetByteArrayElements(data, 0); + jsize arrayLength = env->GetArrayLength(data); + if(arrayLength!=UUID_IDENTITY_SIZE) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "Byte length not equal to UUID_IDENTITY_SIZE"); + } + else + { + for(int i=0;i < UUID_IDENTITY_SIZE; i++) + { + deviceId.id[i]=(jchar)uuid[i]; + } + result = OCPlatform::setDeviceId(&deviceId); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "Failed to set DeviceId"); + } + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +} diff --git a/android/android_api/base/jni/JniOcPlatform.h b/android/android_api/base/jni/JniOcPlatform.h index a45f059..cf6e20f 100644 --- a/android/android_api/base/jni/JniOcPlatform.h +++ b/android/android_api/base/jni/JniOcPlatform.h @@ -26,6 +26,9 @@ #include "JniOnDPDevicesFoundListener.h" #include "JniOnDirectPairingListener.h" #include "JniOnPresenceListener.h" +#include "JniOnObserveListener.h" +#include "JniOnPublishResourceListener.h" +#include "JniOnDeleteResourceListener.h" #include #ifndef _Included_org_iotivity_base_OcPlatform @@ -45,26 +48,40 @@ void RemoveOnPlatformInfoListener(JNIEnv* env, jobject jListener); JniOnPresenceListener* AddOnPresenceListener(JNIEnv* env, jobject jListener); void RemoveOnPresenceListener(JNIEnv* env, jobject jListener); +JniOnObserveListener* AddOnObserveListener(JNIEnv* env, jobject jListener); +void RemoveOnObserveListener(JNIEnv* env, jobject jListener); + JniOnDPDevicesFoundListener* AddOnDPDevicesFoundListener(JNIEnv* env, jobject jListener); void RemoveOnDPDevicesFoundListener(JNIEnv* env, jobject jListener); JniOnDirectPairingListener* AddOnDirectPairingListener(JNIEnv* env, jobject jListener); void RemoveOnDirectPairingListener(JNIEnv* env, jobject jListener); +JniOnPublishResourceListener* AddOnPublishResourceListener(JNIEnv* env, jobject jListener); +void RemoveOnPublishResourceListener(JNIEnv* env, jobject jListener); + +JniOnDeleteResourceListener* AddOnDeleteResourceListener(JNIEnv* env, jobject jListener); +void RemoveOnDeleteResourceListener(JNIEnv* env, jobject jListener); std::map> onResourceFoundListenerMap; std::map> onDeviceInfoListenerMap; std::map> onPlatformInfoListenerMap; std::map> onPresenceListenerMap; +std::map> onObserveListenerMap; std::map> onDPDevicesFoundListenerMap; std::map> directPairingListenerMap; +std::map> onPublishResourceListenerMap; +std::map> onDeleteResourceListenerMap; std::mutex resourceFoundMapLock; std::mutex deviceInfoMapLock; std::mutex platformInfoMapLock; std::mutex presenceMapLock; +std::mutex observeMapLock; std::mutex dpDevicesFoundListenerMapLock; std::mutex directPairingListenerMapLock; +std::mutex publishResourceListenerMapLock; +std::mutex deleteResourceListenerMapLock; #ifdef __cplusplus extern "C" { @@ -287,6 +304,15 @@ extern "C" { /* * Class: org_iotivity_base_OcPlatform + * Method: subscribeDevicePresence0 + * Signature: (Ljava/lang/String;[Ljava/lang/String;I + * Lorg/iotivity/base/OcResource/OnObserveListener;)Lorg/iotivity/base/OcPresenceHandle; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_subscribeDevicePresence0 + (JNIEnv *, jclass, jstring, jobjectArray, jint, jobject); + + /* + * Class: org_iotivity_base_OcPlatform * Method: constructResourceObject0 * Signature: (Ljava/lang/String;Ljava/lang/String;IZ[Ljava/lang/String;[Ljava/lang/String;)Lorg/iotivity/base/OcResource; */ @@ -325,6 +351,64 @@ extern "C" { */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_doDirectPairing0 (JNIEnv *, jclass, jobject, jint, jstring, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD0 + (JNIEnv *, jclass, jstring, jint, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: publishResourceToRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle + * ;Lorg/iotivity/base/OcPlatform/OnPublishResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_publishResourceToRD1 + (JNIEnv *, jclass, jstring, jint, jobjectArray, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD0 + * Signature: (Ljava/lang/String;ILorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD0 + (JNIEnv *, jclass, jstring, jint, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: deleteResourceFromRD1 + * Signature: (Ljava/lang/String;I[Lorg/iotivity/base/OcResourceHandle;Lorg/iotivity/base/OcPlatform/OnDeleteResourceListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_deleteResourceFromRD1 + (JNIEnv *, jclass, jstring, jint, jobjectArray, jobject, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: constructAccountManagerObject0 + * Signature: (Ljava/lang/String;I)Lorg/iotivity/base/OcAccountManager; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcPlatform_constructAccountManagerObject0 + (JNIEnv *, jclass, jstring, jint); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: getDeviceId + * Signature: (I)V + */ + JNIEXPORT jbyteArray JNICALL Java_org_iotivity_base_OcPlatform_getDeviceId + (JNIEnv *, jobject); + + /* + * Class: org_iotivity_base_OcPlatform + * Method: setDeviceId + * Signature: (Ljava/lang/byte;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcPlatform_setDeviceId( + JNIEnv *, jobject, jbyteArray); + #ifdef __cplusplus } #endif diff --git a/android/android_api/base/jni/JniOcPresenceHandle.cpp b/android/android_api/base/jni/JniOcPresenceHandle.cpp index 00f81a1..9d74e23 100644 --- a/android/android_api/base/jni/JniOcPresenceHandle.cpp +++ b/android/android_api/base/jni/JniOcPresenceHandle.cpp @@ -23,8 +23,14 @@ #include "OCPlatform.h" JniOcPresenceHandle::JniOcPresenceHandle(JniOnPresenceListener* jniListener, OCPresenceHandle presenceHandle) - : m_jniListener(jniListener), m_presenceHandle(presenceHandle) -{} + : m_jniListener(jniListener), m_presenceHandle(presenceHandle), m_jniObserveListener(nullptr) +{ +} + +JniOcPresenceHandle::JniOcPresenceHandle(JniOnObserveListener* jniListener, OCPresenceHandle presenceHandle) + : m_jniObserveListener(jniListener), m_presenceHandle(presenceHandle), m_jniListener(nullptr) +{ +} JniOcPresenceHandle::~JniOcPresenceHandle() { @@ -59,6 +65,11 @@ JniOnPresenceListener* JniOcPresenceHandle::getJniOnPresenceListener() return this->m_jniListener; } +JniOnObserveListener* JniOcPresenceHandle::getJniOnObserveListener() +{ + return this->m_jniObserveListener; +} + /* * Class: org_iotivity_base_OcPresenceHandle * Method: dispose @@ -70,4 +81,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcPresenceHandle_dispose LOGD("OcPresenceHandle_dispose"); JniOcPresenceHandle *presenceHandle = JniOcPresenceHandle::getJniOcPresenceHandlePtr(env, thiz); delete presenceHandle; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOcPresenceHandle.h b/android/android_api/base/jni/JniOcPresenceHandle.h index 4052cec..9c543e6 100644 --- a/android/android_api/base/jni/JniOcPresenceHandle.h +++ b/android/android_api/base/jni/JniOcPresenceHandle.h @@ -20,6 +20,7 @@ * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ #include "JniOcStack.h" +#include "JniOnObserveListener.h" #include "JniOnPresenceListener.h" #include "OCPlatform.h" @@ -33,6 +34,7 @@ class JniOcPresenceHandle public: JniOcPresenceHandle(JniOnPresenceListener* jniListener, OCPresenceHandle presenceHandle); + JniOcPresenceHandle(JniOnObserveListener* jniListener, OCPresenceHandle presenceHandle); ~JniOcPresenceHandle(); JniOcPresenceHandle(const JniOcPresenceHandle &) = delete; void operator=(const JniOcPresenceHandle &) = delete; @@ -41,9 +43,11 @@ public: OCPresenceHandle getOCPresenceHandle(); JniOnPresenceListener* getJniOnPresenceListener(); + JniOnObserveListener* getJniOnObserveListener(); private: JniOnPresenceListener* m_jniListener; + JniOnObserveListener* m_jniObserveListener; OCPresenceHandle m_presenceHandle; }; diff --git a/android/android_api/base/jni/JniOcProvisioning.cpp b/android/android_api/base/jni/JniOcProvisioning.cpp index 52d5bc9..5fe0b90 100644 --- a/android/android_api/base/jni/JniOcProvisioning.cpp +++ b/android/android_api/base/jni/JniOcProvisioning.cpp @@ -93,7 +93,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_ownershipTransferCB } else { - result = OC_STACK_ERROR; + result = OC_STACK_INVALID_CALLBACK; } } @@ -267,7 +267,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "displayPinListener can't be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "displayPinListener can't be null"); return; } delete jniDisplayPinListener; @@ -288,3 +288,39 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen ThrowOcException(OC_STACK_ERROR, e.reason().c_str()); } } +/* + * Class: org_iotivity_base_OcProvisioning + * Method: saveTrustCertChain1 + * Signature: (Lorg/iotivity/base/OcProvisioning/provisionTrustCertChain1;)V + */ + JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1 +(JNIEnv *env, jobject thiz, jbyteArray trustCertChain, jint encodingType) +{ + LOGD("OcProvisioning_saveTrustCertChain1"); +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + jbyte* trustCertChainBytes = env->GetByteArrayElements(trustCertChain, 0); + jsize arrayLength = env->GetArrayLength(trustCertChain); + uint16_t credId; + unsigned char* trustedCertChar = new unsigned char[arrayLength]; + try + { + env->GetByteArrayRegion (trustCertChain, 0, arrayLength, reinterpret_cast(trustedCertChar)); + OCStackResult result = OCSecure::saveTrustCertChain((uint8_t*)trustedCertChar, arrayLength, + (OicEncodingType_t)encodingType, &credId); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcProvisioning_saveTrustCertChain1"); + return -1; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } + return (jint)credId; +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled"); + return -1; +#endif // __WITH_DTLS__ || __WITH_TLS__ +} diff --git a/android/android_api/base/jni/JniOcProvisioning.h b/android/android_api/base/jni/JniOcProvisioning.h index 05d3bf6..290744e 100644 --- a/android/android_api/base/jni/JniOcProvisioning.h +++ b/android/android_api/base/jni/JniOcProvisioning.h @@ -85,7 +85,13 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcProvisioning_setDisplayPinListen */ JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcProvisioning_getDeviceStatusList1 (JNIEnv *, jclass, jint); - +/* + * Class: org_iotivity_base_OcProvisioning + * Method: saveTrustCertChain1 + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_iotivity_base_OcProvisioning_saveTrustCertChain1 + (JNIEnv *, jobject, jbyteArray, jint); #ifdef __cplusplus } #endif diff --git a/android/android_api/base/jni/JniOcRepresentation.cpp b/android/android_api/base/jni/JniOcRepresentation.cpp index c3c37ad..042e2a4 100644 --- a/android/android_api/base/jni/JniOcRepresentation.cpp +++ b/android/android_api/base/jni/JniOcRepresentation.cpp @@ -19,6 +19,9 @@ * // * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ + +#include + #include "JniOcRepresentation.h" #include "JniUtils.h" @@ -40,6 +43,37 @@ OCRepresentation* JniOcRepresentation::getOCRepresentationPtr(JNIEnv *env, jobje /* * Class: org_iotivity_base_OcRepresentation +* Method: getValues +* Signature: ()Ljava/util/Map; +*/ +JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues +(JNIEnv *env, jobject thiz) +{ + LOGD("OcRepresentation_getValues"); + OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); + if (!rep) + { + return nullptr; + } + + std::map values = rep->getValues(); + jobject jHashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor); + if (!jHashMap) + { + return nullptr; + } + + for (std::map::const_iterator it = values.begin(); it != values.end(); it++) + { + jobject key = static_cast(env->NewStringUTF(it->first.c_str())); + jobject val = boost::apply_visitor(JObjectConverter(env), it->second); + env->CallObjectMethod(jHashMap, g_mid_HashMap_put, key, val); + } + return jHashMap; +} + +/* +* Class: org_iotivity_base_OcRepresentation * Method: getValueN * Signature: (Ljava/lang/String;)Ljava/lang/Object; */ @@ -53,7 +87,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValueN return nullptr; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return nullptr; + if (!rep) + { + return nullptr; + } std::string key = env->GetStringUTFChars(jKey, nullptr); @@ -81,7 +118,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string str = env->GetStringUTFChars(jKey, nullptr); rep->setValue(str, static_cast(jValue)); @@ -102,7 +142,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string str = env->GetStringUTFChars(jKey, nullptr); rep->setValue(str, static_cast(jValue)); @@ -123,7 +166,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string str = env->GetStringUTFChars(jKey, nullptr); rep->setValue(str, static_cast(jValue)); @@ -144,7 +190,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringN return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); std::string value = env->GetStringUTFChars(jValue, nullptr); @@ -167,14 +216,20 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); if (jValue) { OCRepresentation *value = JniOcRepresentation::getOCRepresentationPtr(env, jValue); - if (!value) return; + if (!value) + { + return; + } rep->setValue(key, *value); } else @@ -209,7 +264,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueIntegerAr env->ReleaseIntArrayElements(jValue, ints, JNI_ABORT); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -247,7 +305,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger2D } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -293,7 +354,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueInteger3D } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -325,7 +389,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDoubleArr env->ReleaseDoubleArrayElements(jValue, doubles, JNI_ABORT); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -363,7 +430,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble2DA } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -409,7 +479,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueDouble3DA } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -441,7 +514,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBooleanAr env->ReleaseBooleanArrayElements(jValue, booleans, JNI_ABORT); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -480,7 +556,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean2D } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -527,7 +606,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueBoolean3D } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -552,7 +634,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueStringArr JniUtils::convertJavaStrArrToStrVector(env, jValue, value); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -584,7 +669,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString2DA } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -624,8 +712,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueString3DA } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; - + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); } @@ -649,7 +739,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent JniUtils::convertJavaRepresentationArrToVector(env, jValue, value); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -681,7 +774,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -721,7 +817,45 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueRepresent } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } + + std::string key = env->GetStringUTFChars(jKey, nullptr); + rep->setValue(key, value); +} + +/* +* Class: org_iotivity_base_OcRepresentation +* Method: setValueByteArray +* Signature: (Ljava/lang/String;[B)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueByteArray +(JNIEnv *env, jobject thiz, jstring jKey, jbyteArray jValue) +{ + LOGD("OcRepresentation_setValueByteArray"); + if (!jKey) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "key cannot be null"); + return; + } + + const jsize len = env->GetArrayLength(jValue); + jbyte* bytes = env->GetByteArrayElements(jValue, nullptr); + + std::vector value; + for (jsize i = 0; i < len; ++i) + { + value.push_back(static_cast(bytes[i])); + } + env->ReleaseByteArrayElements(jValue, bytes, JNI_ABORT); + + OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); + if (!rep) + { + return; + } std::string key = env->GetStringUTFChars(jKey, nullptr); rep->setValue(key, value); @@ -737,10 +871,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_addChild { LOGD("OcRepresentation_addChild"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } OCRepresentation *child = JniOcRepresentation::getOCRepresentationPtr(env, jOcRepresentation); - if (!child) return; + if (!child) + { + return; + } rep->addChild(*child); } @@ -755,7 +895,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_clearChildren { LOGD("OcRepresentation_clearChildren"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } rep->clearChildren(); } @@ -770,7 +913,10 @@ JNIEXPORT jobjectArray JNICALL Java_org_iotivity_base_OcRepresentation_getChildr { LOGD("OcRepresentation_getChildrenArray"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return nullptr; + if (!rep) + { + return nullptr; + } return JniUtils::convertRepresentationVectorToJavaArray(env, rep->getChildren()); } @@ -785,7 +931,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getUri { LOGD("OcRepresentation_getUri"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return nullptr; + if (!rep) + { + return nullptr; + } std::string uri(rep->getUri()); return env->NewStringUTF(uri.c_str()); @@ -801,7 +950,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcRepresentation_getHost { LOGD("OcRepresentation_getHost"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return nullptr; + if (!rep) + { + return nullptr; + } std::string uri(rep->getHost()); return env->NewStringUTF(uri.c_str()); @@ -822,7 +974,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setUri return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } rep->setUri(env->GetStringUTFChars(jUri, nullptr)); } @@ -837,7 +992,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_hasAttribute return false; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return false; + if (!rep) + { + return false; + } std::string str = env->GetStringUTFChars(jstr, nullptr); return rep->hasAttribute(str); @@ -853,7 +1011,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceTyp { LOGD("OcRepresentation_getResourceTypes"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return nullptr; + if (!rep) + { + return nullptr; + } std::vector resourceTypes = rep->getResourceTypes(); return JniUtils::convertStrVectorToJavaStrList(env, resourceTypes); @@ -874,7 +1035,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceTypeAr return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::vector resourceTypes; JniUtils::convertJavaStrArrToStrVector(env, jResourceTypeArray, resourceTypes); @@ -890,7 +1054,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getResourceInt { LOGD("OcRepresentation_getResourceInterfaces"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return nullptr; + if (!rep) + { + return nullptr; + } std::vector resourceInterfaces = rep->getResourceInterfaces(); return JniUtils::convertStrVectorToJavaStrList(env, resourceInterfaces); @@ -911,7 +1078,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setResourceInterf return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::vector resourceInterfaces; JniUtils::convertJavaStrArrToStrVector(env, jResourceInterfaceArray, resourceInterfaces); @@ -928,7 +1098,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isEmpty { LOGD("OcRepresentation_isEmpty"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return false; + if (!rep) + { + return false; + } return static_cast(rep->empty()); } @@ -943,7 +1116,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcRepresentation_size { LOGD("OcRepresentation_size"); OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return -1; + if (!rep) + { + return -1; + } return static_cast(rep->numberOfAttributes()); } @@ -963,7 +1139,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_remove return false; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return false; + if (!rep) + { + return false; + } std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr); return static_cast(rep->erase(attributeKey)); @@ -984,7 +1163,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setNull return; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return; + if (!rep) + { + return; + } std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr); rep->setNULL(attributeKey); @@ -1005,7 +1187,10 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcRepresentation_isNull return false; } OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, thiz); - if (!rep) return false; + if (!rep) + { + return false; + } std::string attributeKey = env->GetStringUTFChars(jAttributeKey, nullptr); return static_cast(rep->isNULL(attributeKey)); diff --git a/android/android_api/base/jni/JniOcRepresentation.h b/android/android_api/base/jni/JniOcRepresentation.h index ee8f222..dc85747 100644 --- a/android/android_api/base/jni/JniOcRepresentation.h +++ b/android/android_api/base/jni/JniOcRepresentation.h @@ -35,9 +35,15 @@ public: struct JObjectConverter : boost::static_visitor < jobject > { - JObjectConverter(JNIEnv *env) : env(env){} + JObjectConverter(JNIEnv *env) : env(env) + { + } + + jobject operator()(const NullType&) const + { + return nullptr; + } - jobject operator()(const NullType&) const { return nullptr; } jobject operator()(const int& val) const { jobject jobj = env->NewObject( @@ -87,7 +93,10 @@ struct JObjectConverter : boost::static_visitor < jobject > { size_t len = val.size(); jintArray jIntArray = env->NewIntArray(len); - if (!jIntArray) return nullptr; + if (!jIntArray) + { + return nullptr; + } const int* ints = &val[0]; env->SetIntArrayRegion(jIntArray, 0, len, reinterpret_cast(ints)); return jIntArray; @@ -96,7 +105,10 @@ struct JObjectConverter : boost::static_visitor < jobject > { size_t len = val.size(); jdoubleArray jDoubleArray = env->NewDoubleArray(len); - if (!jDoubleArray) return nullptr; + if (!jDoubleArray) + { + return nullptr; + } const double* doubles = &val[0]; env->SetDoubleArrayRegion(jDoubleArray, 0, len, reinterpret_cast(doubles)); return jDoubleArray; @@ -105,13 +117,20 @@ struct JObjectConverter : boost::static_visitor < jobject > { size_t len = val.size(); jbooleanArray jBooleanArray = env->NewBooleanArray(len); - if (!jBooleanArray) return nullptr; + if (!jBooleanArray) + { + return nullptr; + } jboolean* booleans = new jboolean[len]; - for (size_t i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) + { booleans[i] = static_cast(val[i]); } env->SetBooleanArrayRegion(jBooleanArray, 0, len, booleans); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->ReleaseBooleanArrayElements(jBooleanArray, booleans, 0); return jBooleanArray; } @@ -119,21 +138,127 @@ struct JObjectConverter : boost::static_visitor < jobject > { size_t len = val.size(); jobjectArray strArr = env->NewObjectArray(len, g_cls_String, nullptr); - if (!strArr) return nullptr; + if (!strArr) + { + return nullptr; + } for (size_t i = 0; i < len; ++i) { jstring jString = env->NewStringUTF(val[i].c_str()); env->SetObjectArrayElement(strArr, static_cast(i), jString); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jString); } return strArr; } + // OCByteString and arrays: + jobject operator()(const OCByteString &val) const + { + jbyteArray jByteArray = env->NewByteArray(val.len); + if (!jByteArray) + { + return nullptr; + } + env->SetByteArrayRegion(jByteArray, 0, val.len, reinterpret_cast(val.bytes)); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jByteArray); + return nullptr; + } + return jByteArray; + } + jobject operator()(const std::vector &val) const + { + jsize lenOuter = static_cast(val.size()); + jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_byte1DArray, nullptr); + if (!jOuterArr) + { + return nullptr; + } + for (jsize i = 0; i < lenOuter; ++i) + { + jbyteArray jByteArray = (jbyteArray) operator()(val[i]); + if (!jByteArray) + { + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->SetObjectArrayElement(jOuterArr, i, static_cast(jByteArray)); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jByteArray); + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->DeleteLocalRef(jByteArray); + } + return jOuterArr; + } + jobject operator()(const std::vector> &val) const + { + jsize lenOuter = static_cast(val.size()); + jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_byte2DArray, nullptr); + if (!jOuterArr) + { + return nullptr; + } + for (jsize i = 0; i < lenOuter; ++i) + { + jobjectArray jMiddleArr = (jobjectArray) operator()(val[i]); + if (!jMiddleArr) + { + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->SetObjectArrayElement(jOuterArr, i, jMiddleArr); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jMiddleArr); + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->DeleteLocalRef(jMiddleArr); + } + return jOuterArr; + } + jobject operator()(const std::vector>> &val) const + { + jsize lenOuter = static_cast(val.size()); + jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_byte3DArray, nullptr); + if (!jOuterArr) + { + return nullptr; + } + for (jsize i = 0; i < lenOuter; ++i) + { + jobjectArray jMiddleArr = (jobjectArray) operator()(val[i]); + if (!jMiddleArr) + { + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->SetObjectArrayElement(jOuterArr, i, jMiddleArr); + if (env->ExceptionCheck()) + { + env->DeleteLocalRef(jMiddleArr); + env->DeleteLocalRef(jOuterArr); + return nullptr; + } + env->DeleteLocalRef(jMiddleArr); + } + return jOuterArr; + } jobject operator()(const std::vector& val) const { jsize len = static_cast(val.size()); jobjectArray repArr = env->NewObjectArray(len, g_cls_OcRepresentation, nullptr); - if (!repArr) return nullptr; + if (!repArr) + { + return nullptr; + } for (jsize i = 0; i < len; ++i) { OCRepresentation* rep = new OCRepresentation(val[i]); @@ -155,6 +280,18 @@ struct JObjectConverter : boost::static_visitor < jobject > } return repArr; } + jobject operator()(const std::vector& val) const + { + size_t len = val.size(); + jbyteArray jByteArray = env->NewByteArray(len); + if (!jByteArray) + { + return nullptr; + } + const uint8_t* bytes = &val[0]; + env->SetByteArrayRegion(jByteArray, 0, len, reinterpret_cast(bytes)); + return jByteArray; + } // Nested sequences: jobject operator()(const std::vector>& val) const @@ -169,12 +306,21 @@ struct JObjectConverter : boost::static_visitor < jobject > { size_t lenInner = val[i].size(); jintArray jIntArray = env->NewIntArray(lenInner); - if (!jIntArray) return nullptr; + if (!jIntArray) + { + return nullptr; + } const int* ints = &val[i][0]; env->SetIntArrayRegion(jIntArray, 0, lenInner, reinterpret_cast(ints)); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->SetObjectArrayElement(jOuterArr, i, static_cast(jIntArray)); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jIntArray); } return jOuterArr; @@ -183,26 +329,46 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_int2DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } + for (jsize k = 0; k < lenOuter; ++k) { jsize lenMiddle = static_cast(val[k].size()); jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_int1DArray, nullptr); - if (!jMiddleArr) return nullptr; + if (!jMiddleArr) + { + return nullptr; + } + for (jsize i = 0; i < lenMiddle; ++i) { jsize lenInner = static_cast(val[k][i].size()); jintArray jIntArray = env->NewIntArray(lenInner); - if (!jIntArray) return nullptr; + if (!jIntArray) + { + return nullptr; + } const int* ints = &val[k][i][0]; env->SetIntArrayRegion(jIntArray, 0, lenInner, reinterpret_cast(ints)); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->SetObjectArrayElement(jMiddleArr, i, jIntArray); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jIntArray); } env->SetObjectArrayElement(jOuterArr, k, jMiddleArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jMiddleArr); } return jOuterArr; @@ -212,17 +378,31 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_double1DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } + for (jsize i = 0; i < lenOuter; ++i) { size_t lenInner = val[i].size(); jdoubleArray jDoubleArray = env->NewDoubleArray(lenInner); - if (!jDoubleArray) return nullptr; + if (!jDoubleArray) + { + return nullptr; + } + const double* doubles = &val[i][0]; env->SetDoubleArrayRegion(jDoubleArray, 0, lenInner, reinterpret_cast(doubles)); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->SetObjectArrayElement(jOuterArr, i, jDoubleArray); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jDoubleArray); } @@ -232,26 +412,44 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_double2DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } for (jsize k = 0; k < lenOuter; ++k) { jsize lenMiddle = static_cast(val[k].size()); jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_double1DArray, nullptr); - if (!jMiddleArr) return nullptr; + if (!jMiddleArr) + { + return nullptr; + } for (jsize i = 0; i < lenMiddle; ++i) { jsize lenInner = static_cast(val[k][i].size()); jdoubleArray jDoubleArray = env->NewDoubleArray(lenInner); - if (!jDoubleArray) return nullptr; + if (!jDoubleArray) + { + return nullptr; + } const double* doubles = &val[k][i][0]; env->SetDoubleArrayRegion(jDoubleArray, 0, lenInner, reinterpret_cast(doubles)); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->SetObjectArrayElement(jMiddleArr, i, jDoubleArray); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jDoubleArray); } env->SetObjectArrayElement(jOuterArr, k, jMiddleArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jMiddleArr); } return jOuterArr; @@ -261,22 +459,38 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_boolean1DArray, 0); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } for (jsize i = 0; i < lenOuter; ++i) { size_t lenInner = val[i].size(); jbooleanArray jBooleanArray = env->NewBooleanArray(lenInner); - if (!jBooleanArray) return nullptr; + if (!jBooleanArray) + { + return nullptr; + } jboolean* booleans = new jboolean[lenInner]; - for (size_t j = 0; j < lenInner; ++j) { + for (size_t j = 0; j < lenInner; ++j) + { booleans[j] = static_cast(val[i][j]); } env->SetBooleanArrayRegion(jBooleanArray, 0, lenInner, booleans); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->SetObjectArrayElement(jOuterArr, i, jBooleanArray); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->ReleaseBooleanArrayElements(jBooleanArray, booleans, 0); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jBooleanArray); } return jOuterArr; @@ -285,31 +499,49 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_boolean2DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } for (jsize k = 0; k < lenOuter; ++k) { jsize lenMiddle = static_cast(val[k].size()); jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_boolean1DArray, nullptr); - if (!jMiddleArr) return nullptr; + if (!jMiddleArr) + { + return nullptr; + } for (jsize i = 0; i < lenMiddle; ++i) { size_t lenInner = val[k][i].size(); jbooleanArray jBooleanArray = env->NewBooleanArray(lenInner); jboolean* booleans = new jboolean[lenInner]; - for (size_t j = 0; j < lenInner; ++j) { + for (size_t j = 0; j < lenInner; ++j) + { booleans[j] = val[k][i][j]; } env->SetBooleanArrayRegion(jBooleanArray, 0, lenInner, booleans); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->SetObjectArrayElement(jMiddleArr, i, jBooleanArray); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->ReleaseBooleanArrayElements(jBooleanArray, booleans, 0); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jBooleanArray); } env->SetObjectArrayElement(jOuterArr, k, jMiddleArr); - if (env->ExceptionCheck()) return nullptr; - env->DeleteLocalRef(jMiddleArr); + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jMiddleArr); } return jOuterArr; } @@ -318,21 +550,33 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_String1DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } for (jsize i = 0; i < lenOuter; ++i) { jsize lenInner = static_cast(val[i].size()); jobjectArray strArr = env->NewObjectArray(lenInner, g_cls_String, nullptr); - if (!strArr) return nullptr; + if (!strArr) + { + return nullptr; + } for (jsize j = 0; j < lenInner; ++j) { jstring jString = env->NewStringUTF(val[i][j].c_str()); env->SetObjectArrayElement(strArr, j, jString); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jString); } env->SetObjectArrayElement(jOuterArr, i, strArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(strArr); } @@ -342,30 +586,48 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_String2DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } for (jsize k = 0; k < lenOuter; ++k) { jsize lenMiddle = static_cast(val[k].size()); jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_String1DArray, nullptr); - if (!jMiddleArr) return nullptr; + if (!jMiddleArr) + { + return nullptr; + } for (jsize i = 0; i < lenMiddle; ++i) { jsize lenInner = static_cast(val[k][i].size()); jobjectArray strArr = env->NewObjectArray(lenInner, g_cls_String, nullptr); - if (!strArr) return nullptr; + if (!strArr) + { + return nullptr; + } for (jsize j = 0; j < lenInner; ++j) { jstring jString = env->NewStringUTF(val[k][i][j].c_str()); env->SetObjectArrayElement(strArr, j, jString); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jString); } env->SetObjectArrayElement(jMiddleArr, i, strArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(strArr); } env->SetObjectArrayElement(jOuterArr, k, jMiddleArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jMiddleArr); } return jOuterArr; @@ -375,12 +637,18 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_OcRepresentation1DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } for (jsize i = 0; i < lenOuter; ++i) { jsize lenInner = static_cast(val[i].size()); jobjectArray repArr = env->NewObjectArray(lenInner, g_cls_OcRepresentation, nullptr); - if (!repArr) return nullptr; + if (!repArr) + { + return nullptr; + } for (jsize j = 0; j < lenInner; ++j) { OCRepresentation* rep = new OCRepresentation(val[i][j]); @@ -393,11 +661,17 @@ struct JObjectConverter : boost::static_visitor < jobject > return nullptr; } env->SetObjectArrayElement(repArr, j, jRepresentation); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jRepresentation); } env->SetObjectArrayElement(jOuterArr, i, repArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(repArr); } return jOuterArr; @@ -406,17 +680,26 @@ struct JObjectConverter : boost::static_visitor < jobject > { jsize lenOuter = static_cast(val.size()); jobjectArray jOuterArr = env->NewObjectArray(lenOuter, g_cls_OcRepresentation2DArray, nullptr); - if (!jOuterArr) return nullptr; + if (!jOuterArr) + { + return nullptr; + } for (jsize k = 0; k < lenOuter; ++k) { jsize lenMiddle = static_cast(val[k].size()); jobjectArray jMiddleArr = env->NewObjectArray(lenMiddle, g_cls_OcRepresentation1DArray, nullptr); - if (!jMiddleArr) return nullptr; + if (!jMiddleArr) + { + return nullptr; + } for (jsize i = 0; i < lenMiddle; ++i) { jsize lenInner = static_cast(val[k][i].size()); jobjectArray repArr = env->NewObjectArray(lenInner, g_cls_OcRepresentation, nullptr); - if (!repArr) return nullptr; + if (!repArr) + { + return nullptr; + } for (jsize j = 0; j < lenInner; ++j) { OCRepresentation* rep = new OCRepresentation(val[k][i][j]); @@ -429,15 +712,24 @@ struct JObjectConverter : boost::static_visitor < jobject > return nullptr; } env->SetObjectArrayElement(repArr, j, jRepresentation); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jRepresentation); } env->SetObjectArrayElement(jMiddleArr, i, repArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(repArr); } env->SetObjectArrayElement(jOuterArr, k, jMiddleArr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jMiddleArr); } return jOuterArr; @@ -453,6 +745,14 @@ extern "C" { /* * Class: org_iotivity_base_OcRepresentation + * Method: getValues + * Signature: ()Ljava/util/Map; + */ + JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcRepresentation_getValues + (JNIEnv *, jobject); + + /* + * Class: org_iotivity_base_OcRepresentation * Method: getValueN * Signature: (Ljava/lang/String;)Ljava/lang/Object; */ @@ -621,6 +921,14 @@ extern "C" { /* * Class: org_iotivity_base_OcRepresentation + * Method: setValueByteArray + * Signature: (Ljava/lang/String;[B)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcRepresentation_setValueByteArray + (JNIEnv *, jobject, jstring, jbyteArray); + + /* + * Class: org_iotivity_base_OcRepresentation * Method: addChild * Signature: (Lorg/iotivity/base/OcRepresentation;)V */ diff --git a/android/android_api/base/jni/JniOcRequestHandle.cpp b/android/android_api/base/jni/JniOcRequestHandle.cpp index b916490..9585c55 100644 --- a/android/android_api/base/jni/JniOcRequestHandle.cpp +++ b/android/android_api/base/jni/JniOcRequestHandle.cpp @@ -22,7 +22,8 @@ #include "JniOcRequestHandle.h" JniOcRequestHandle::JniOcRequestHandle(OCRequestHandle requestHandle) : m_requestHandle(requestHandle) -{} +{ +} JniOcRequestHandle::~JniOcRequestHandle() { @@ -60,4 +61,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcRequestHandle_dispose LOGD("OcRequestHandle_dispose"); JniOcRequestHandle *handle = JniOcRequestHandle::getJniOcRequestHandlePtr(env, thiz); delete handle; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOcResource.cpp b/android/android_api/base/jni/JniOcResource.cpp index 9e6925a..44f1eb3 100644 --- a/android/android_api/base/jni/JniOcResource.cpp +++ b/android/android_api/base/jni/JniOcResource.cpp @@ -26,7 +26,8 @@ JniOcResource::JniOcResource(std::shared_ptr resource) : m_sharedResource(resource) -{} +{ +} JniOcResource::~JniOcResource() { @@ -34,17 +35,27 @@ JniOcResource::~JniOcResource() m_sharedResource = nullptr; - jint envRet; + jint envRet = JNI_ERR; JNIEnv *env = GetJNIEnv(envRet); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } m_onGetManager.removeAllListeners(env); m_onPutManager.removeAllListeners(env); m_onPostManager.removeAllListeners(env); m_onDeleteManager.removeAllListeners(env); m_onObserveManager.removeAllListeners(env); +#ifdef WITH_MQ + m_onFoundTopicResourceManager.removeAllListeners(env); + m_onSubcribeTopicManager.removeAllListeners(env); +#endif - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } OCStackResult JniOcResource::get(JNIEnv* env, const QueryParamsMap &queryParametersMap, jobject jListener) @@ -286,7 +297,9 @@ OCStackResult JniOcResource::observe(JNIEnv* env, ObserveType observeType, OCStackResult JniOcResource::cancelObserve(JNIEnv* env, QualityOfService qos) { - if (QualityOfService::HighQos != qos) + // In Low case, after delete the callback and send empty message when client receive the notify. + // But TCP does not support EMPTY message. + if ((CT_ADAPTER_IP & connectivityType()) && QualityOfService::HighQos != qos) { this->m_onObserveManager.removeAllListeners(env); } @@ -393,6 +406,28 @@ void JniOcResource::removeOnObserveListener(JNIEnv* env, jobject jListener) this->m_onObserveManager.removeListener(env, jListener); } +#ifdef WITH_MQ +JniOnMQTopicFoundListener* JniOcResource::addOnTopicFoundListener(JNIEnv* env, jobject jListener) +{ + return this->m_onFoundTopicResourceManager.addListener(env, jListener, this); +} + +void JniOcResource::removeOnTopicFoundListener(JNIEnv* env, jobject jListener) +{ + this->m_onFoundTopicResourceManager.removeListener(env, jListener); +} + +JniOnMQSubscribeListener* JniOcResource::addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener) +{ + return this->m_onSubcribeTopicManager.addListener(env, jListener, this); +} + +void JniOcResource::removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener) +{ + this->m_onSubcribeTopicManager.removeListener(env, jListener); +} +#endif + std::shared_ptr JniOcResource::getOCResource() { return this->m_sharedResource; @@ -412,6 +447,90 @@ JniOcResource* JniOcResource::getJniOcResourcePtr(JNIEnv *env, jobject thiz) return resource; } +#ifdef WITH_MQ +OCStackResult JniOcResource::discoveryMQTopics(JNIEnv* env, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnMQTopicFoundListener *onTopicFoundListener = addOnTopicFoundListener(env, jListener); + + MQTopicCallback findCallback = [onTopicFoundListener](const int& eCode, + const std::string& uri, std::shared_ptr resource) + { + onTopicFoundListener->foundTopicCallback(eCode, uri, resource); + }; + + return m_sharedResource->discoveryMQTopics(queryParametersMap, findCallback, QoS); +} + +OCStackResult JniOcResource::createMQTopic(JNIEnv* env, + const OCRepresentation &representation, const std::string &targetUri, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnMQTopicFoundListener *onTopicCreatedListener = addOnTopicFoundListener(env, jListener); + + MQTopicCallback createCallback = [onTopicCreatedListener](const int& eCode, + const std::string& uri, std::shared_ptr resource) + { + onTopicCreatedListener->createdTopicCallback(eCode, uri, resource); + }; + + return m_sharedResource->createMQTopic(representation, targetUri, + queryParametersMap, + createCallback, QoS); +} +#endif +#ifdef MQ_SUBSCRIBER +OCStackResult JniOcResource::subscribeMQTopic(JNIEnv* env, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnMQSubscribeListener *onSubscribeListener = addOnMQTopicSubscribeListener(env, jListener); + + ObserveCallback subscribeCallback = [onSubscribeListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int& eCode, const int& sequenceNumber) + { + onSubscribeListener->onSubscribeCallback(opts, rep, eCode, sequenceNumber); + }; + + return m_sharedResource->subscribeMQTopic(ObserveType::Observe, queryParametersMap, + subscribeCallback, QoS); +} + +OCStackResult JniOcResource::unsubscribeMQTopic(QualityOfService QoS) +{ + return m_sharedResource->unsubscribeMQTopic(QoS); +} + +OCStackResult JniOcResource::requestMQPublish(JNIEnv* env, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedResource->requestMQPublish(queryParametersMap, postCallback, QoS); +} +#endif +#ifdef MQ_PUBLISHER +OCStackResult JniOcResource::publishMQTopic(JNIEnv* env, const OCRepresentation &representation, + const QueryParamsMap &queryParametersMap, jobject jListener, QualityOfService QoS) +{ + JniOnPostListener *onPostListener = addOnPostListener(env, jListener); + + PostCallback postCallback = [onPostListener](const HeaderOptions& opts, + const OCRepresentation& rep, const int eCode) + { + onPostListener->onPostCallback(opts, rep, eCode); + }; + + return m_sharedResource->publishMQTopic(representation, queryParametersMap, + postCallback, QoS); +} +#endif + /* * Class: org_iotivity_base_OcResource * Method: get @@ -432,7 +551,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -476,7 +598,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_get1 return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -533,7 +658,10 @@ jobject jQueryParamsMap, jobject jListener) return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -590,7 +718,10 @@ jobject jQueryParamsMap, jobject jListener, jint jQoS) resourceInterface = env->GetStringUTFChars(jResourceInterface, nullptr); } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -643,10 +774,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_put return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -698,10 +835,16 @@ jobject jListener, jint jQoS) return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -764,10 +907,16 @@ jobject jRepresentation, jobject jQueryParamsMap, jobject jListener) return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -832,10 +981,16 @@ jobject jQueryParamsMap, jobject jListener, jint jQoS) } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -888,10 +1043,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -941,10 +1102,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_post1 return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -1008,10 +1175,16 @@ jobject jRepresentation, jobject jQueryParamsMap, jobject jListener) } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -1076,10 +1249,16 @@ jobject jRepresentation, jobject jQueryParamsMap, jobject jListener, jint jQoS) } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; + if (!representation) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -1122,7 +1301,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } try { @@ -1157,7 +1339,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_deleteResource1 return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } try { @@ -1199,7 +1384,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_observe return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -1246,7 +1434,10 @@ jobject jListener, jint jQoS) return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } QueryParamsMap qpm; JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); @@ -1282,7 +1473,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_cancelObserve1 { LOGD("OcResource_cancelObserve1"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } try { @@ -1317,7 +1511,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_setHeaderOptions return; } JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } HeaderOptions headerOptions; JniUtils::convertJavaHeaderOptionsArrToVector(env, jheaderOptionArr, headerOptions); @@ -1335,7 +1532,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsetHeaderOptions { LOGD("OcResource_unsetHeaderOptions"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return; + if (!resource) + { + return; + } resource->unsetHeaderOptions(); } @@ -1350,7 +1550,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getHost { LOGD("OcResource_getHost"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return nullptr; + if (!resource) + { + return nullptr; + } return env->NewStringUTF(resource->host().c_str()); } @@ -1365,7 +1568,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getUri { LOGD("OcResource_getUri"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return nullptr; + if (!resource) + { + return nullptr; + } return env->NewStringUTF(resource->uri().c_str()); } @@ -1380,7 +1586,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResource_getConnectivityTypeN { LOGD("OcResource_getConnectivityType"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return -1; + if (!resource) + { + return -1; + } OCConnectivityType connectivityType = resource->connectivityType(); return static_cast(connectivityType); @@ -1396,6 +1605,11 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResource_isObservable { LOGD("OcResource_isObservable"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return false; + } + return (jboolean)resource->isObservable(); } @@ -1409,7 +1623,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceTypes { LOGD("OcResource_getResourceTypes"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return nullptr; + if (!resource) + { + return nullptr; + } std::vector resourceTypes = resource->getResourceTypes(); @@ -1426,7 +1643,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getResourceInterface { LOGD("OcResource_getResourceInterfaces"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return nullptr; + if (!resource) + { + return nullptr; + } std::vector resourceInterfaces = resource->getResourceInterfaces(); @@ -1443,11 +1663,17 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResource_getUniqueIdentifier { LOGD("OcResource_getUniqueIdentifier"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return nullptr; + if (!resource) + { + return nullptr; + } JniOcResourceIdentifier *jniResourceIdentifier = new JniOcResourceIdentifier(resource->uniqueIdentifier()); - if (!jniResourceIdentifier) return nullptr; + if (!jniResourceIdentifier) + { + return nullptr; + } jlong handle = reinterpret_cast(jniResourceIdentifier); jobject jResourceIdentifier = env->NewObject(g_cls_OcResourceIdentifier, @@ -1469,7 +1695,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResource_getServerId { LOGD("OcResource_getServerId"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); - if (!resource) return nullptr; + if (!resource) + { + return nullptr; + } return env->NewStringUTF(resource->sid().c_str()); } @@ -1485,4 +1714,347 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose LOGD("OcResource_dispose"); JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); delete resource; -} \ No newline at end of file +} + +/* +* Class: org_iotivity_base_OcResource +* Method: discoveryMQTopicsImpl +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcPlatform/OnResourceFoundListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl +(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_discoveryMQTopicsImpl"); + +#ifdef WITH_MQ + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->discoveryMQTopics( + env, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_discoveryMQTopicsImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: createMQTopicImpl +* Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map +* ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl +(JNIEnv *env, jobject thiz, jobject jRepresentation, jstring jUri, + jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_createMQTopicImpl"); + +#ifdef WITH_MQ + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "listener cannot be null"); + return; + } + + if (!jRepresentation) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "representation null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + std::string targetUri; + if (jUri) + { + targetUri = env->GetStringUTFChars(jUri, nullptr); + } + + OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, + jRepresentation); + if (!representation) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->createMQTopic( + env, + *representation, + targetUri, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_createMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: subscribeMQTopic +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl +(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_subscribeMQTopicImpl"); +#ifdef MQ_SUBSCRIBER + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onObserveListener cannot be null"); + return; + } + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->subscribeMQTopic( + env, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_subscribeMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: unsubscribeMQTopicImpl +* Signature: (I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl +(JNIEnv *env, jobject thiz, jint jQoS) +{ + LOGD("OcResource_unsubscribeMQTopicImpl"); +#ifdef MQ_SUBSCRIBER + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + try + { + OCStackResult result = resource->unsubscribeMQTopic( + JniUtils::getQOS(env, static_cast(jQoS))); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_unsubscribeMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: requestMQPublishImpl +* Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl +(JNIEnv *env, jobject thiz, jobject jQueryParamsMap, jobject jListener, jint jQoS) +{ + LOGD("OcResource_requestMQPublishImpl"); +#ifdef MQ_SUBSCRIBER + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->requestMQPublish( + env, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_requestMQPublishImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} + +/* +* Class: org_iotivity_base_OcResource +* Method: publishMQTopicImpl +* Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map; +* Lorg/iotivity/base/OcResource/OnPostListener;I)V +*/ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl +(JNIEnv *env, jobject thiz, jobject jRepresentation, jobject jQueryParamsMap, + jobject jListener, jint jQoS) +{ + LOGD("OcResource_publishMQTopicImpl"); +#ifdef MQ_PUBLISHER + if (!jRepresentation) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "representation cannot be null"); + return; + } + + if (!jQueryParamsMap) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "queryParamsMap cannot be null"); + return; + } + + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "onPostListener cannot be null"); + return; + } + + JniOcResource *resource = JniOcResource::getJniOcResourcePtr(env, thiz); + if (!resource) + { + return; + } + + OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, + jRepresentation); + if (!representation) + { + return; + } + + QueryParamsMap qpm; + JniUtils::convertJavaMapToQueryParamsMap(env, jQueryParamsMap, qpm); + + try + { + OCStackResult result = resource->publishMQTopic( + env, + *representation, + qpm, + jListener, + JniUtils::getQOS(env, static_cast(jQoS))); + + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcResource_publishMQTopicImpl"); + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(JNI_NO_SUPPORT, "not support"); +#endif +} diff --git a/android/android_api/base/jni/JniOcResource.h b/android/android_api/base/jni/JniOcResource.h index a038312..7dfacd3 100644 --- a/android/android_api/base/jni/JniOcResource.h +++ b/android/android_api/base/jni/JniOcResource.h @@ -29,6 +29,10 @@ #include "JniOnDeleteListener.h" #include "JniOnObserveListener.h" #include "JniOcResourceIdentifier.h" +#ifdef WITH_MQ +#include "JniOnMQTopicFoundListener.h" +#include "JniOnMQSubscribeListener.h" +#endif #ifndef _Included_org_iotivity_base_OcResource #define _Included_org_iotivity_base_OcResource @@ -84,8 +88,8 @@ public: std::string uri(); OCConnectivityType connectivityType() const; bool isObservable(); - std::vector< std::string > getResourceTypes() const; - std::vector< std::string > getResourceInterfaces(void) const; + std::vector< std::string > getResourceTypes() const; + std::vector< std::string > getResourceInterfaces(void) const; OCResourceIdentifier uniqueIdentifier() const; std::string sid() const; @@ -105,12 +109,43 @@ public: static JniOcResource* getJniOcResourcePtr(JNIEnv *env, jobject thiz); +#ifdef WITH_MQ + JniOnMQTopicFoundListener* addOnTopicFoundListener(JNIEnv* env, jobject jListener); + void removeOnTopicFoundListener(JNIEnv* env, jobject jListener); + + JniOnMQSubscribeListener* addOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener); + void removeOnMQTopicSubscribeListener(JNIEnv* env, jobject jListener); + + OCStackResult discoveryMQTopics(JNIEnv* env, const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); + OCStackResult createMQTopic(JNIEnv* env, const OCRepresentation &representation, + const std::string &targetUri, + const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); +#endif +#ifdef MQ_SUBSCRIBER + OCStackResult subscribeMQTopic(JNIEnv* env, const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); + OCStackResult unsubscribeMQTopic(QualityOfService QoS); + OCStackResult requestMQPublish(JNIEnv* env, const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); +#endif +#ifdef MQ_PUBLISHER + OCStackResult publishMQTopic(JNIEnv* env, const OCRepresentation &representation, + const QueryParamsMap &queryParametersMap, + jobject jListener, QualityOfService QoS); +#endif + private: JniListenerManager m_onGetManager; JniListenerManager m_onPutManager; JniListenerManager m_onPostManager; JniListenerManager m_onDeleteManager; JniListenerManager m_onObserveManager; +#ifdef WITH_MQ + JniListenerManager m_onFoundTopicResourceManager; + JniListenerManager m_onSubcribeTopicManager; +#endif std::shared_ptr m_sharedResource; }; @@ -345,7 +380,57 @@ extern "C" { JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_dispose (JNIEnv *, jobject); + /* + * Class: org_iotivity_base_OcResource + * Method: subscribeMQTopicImpl + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnObserveListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_subscribeMQTopicImpl + (JNIEnv *, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: unsubscribeMQTopicImpl + * Signature: (I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_unsubscribeMQTopicImpl + (JNIEnv *, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: requestMQPublishImpl + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnPostListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_requestMQPublishImpl + (JNIEnv *, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: publishMQTopicImpl + * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/Map + * ;Lorg/iotivity/base/OcResource/OnPostListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_publishMQTopicImpl + (JNIEnv *, jobject, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: discoveryMQTopicsImpl + * Signature: (Ljava/util/Map;Lorg/iotivity/base/OcResource/OnMQTopicFoundListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_discoveryMQTopicsImpl + (JNIEnv *, jobject, jobject, jobject, jint); + + /* + * Class: org_iotivity_base_OcResource + * Method: createMQTopicImpl + * Signature: (Lorg/iotivity/base/OcRepresentation;Ljava/util/String;Ljava/util/Map + * ;Lorg/iotivity/base/OcPlatform/OnMQTopicCreatedListener;I)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcResource_createMQTopicImpl + (JNIEnv *, jobject, jobject, jstring, jobject, jobject, jint); + #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOcResourceHandle.cpp b/android/android_api/base/jni/JniOcResourceHandle.cpp index 2d438f2..92371f4 100644 --- a/android/android_api/base/jni/JniOcResourceHandle.cpp +++ b/android/android_api/base/jni/JniOcResourceHandle.cpp @@ -25,7 +25,8 @@ using namespace OC; JniOcResourceHandle::JniOcResourceHandle(OCResourceHandle resourceHandle) : m_resourceHandle(resourceHandle) -{} +{ +} JniOcResourceHandle::~JniOcResourceHandle() { @@ -63,4 +64,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceHandle_dispose LOGD("OcResourceHandle_dispose"); JniOcResourceHandle *resourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, thiz); delete resourceHandle; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOcResourceIdentifier.cpp b/android/android_api/base/jni/JniOcResourceIdentifier.cpp index b0b7d65..beeb724 100644 --- a/android/android_api/base/jni/JniOcResourceIdentifier.cpp +++ b/android/android_api/base/jni/JniOcResourceIdentifier.cpp @@ -24,7 +24,8 @@ JniOcResourceIdentifier::JniOcResourceIdentifier(OC::OCResourceIdentifier resourceIdentifier) : m_resourceIdentifier(resourceIdentifier) -{} +{ +} JniOcResourceIdentifier::~JniOcResourceIdentifier() { @@ -60,10 +61,16 @@ JNIEXPORT jboolean JNICALL Java_org_iotivity_base_OcResourceIdentifier_equalsN (JNIEnv *env, jobject jThiz, jobject jOther) { JniOcResourceIdentifier *thiz = JniOcResourceIdentifier::getJniOcResourceIdentifierPtr(env, jThiz); - if (!thiz) return false; + if (!thiz) + { + return false; + } JniOcResourceIdentifier *other = JniOcResourceIdentifier::getJniOcResourceIdentifierPtr(env, jOther); - if (!other) return false; + if (!other) + { + return false; + } if (thiz->getOCResourceIdentifier() == other->getOCResourceIdentifier()) { @@ -86,4 +93,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceIdentifier_dispose LOGD("JniOcResourceIdentifier_dispose"); JniOcResourceIdentifier *identifier = JniOcResourceIdentifier::getJniOcResourceIdentifierPtr(env, thiz); delete identifier; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOcResourceRequest.cpp b/android/android_api/base/jni/JniOcResourceRequest.cpp index c943f70..c977bac 100644 --- a/android/android_api/base/jni/JniOcResourceRequest.cpp +++ b/android/android_api/base/jni/JniOcResourceRequest.cpp @@ -29,10 +29,12 @@ using namespace OC; JniOcResourceRequest::JniOcResourceRequest(const std::shared_ptr request) : m_request(request) -{} +{ +} JniOcResourceRequest::~JniOcResourceRequest() -{} +{ +} std::string JniOcResourceRequest::getRequestType() @@ -119,8 +121,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResourceRequest_getRequestTyp { LOGD("OcResourceRequest_getRequestTypeNative"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; - + if (!request) + { + return nullptr; + } std::string requestType = request->getRequestType(); return env->NewStringUTF(requestType.c_str()); } @@ -135,7 +139,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getQueryParam { LOGD("OcResourceRequest_getQueryParameters"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; + if (!request) + { + return nullptr; + } return JniUtils::convertQueryParamsMapToJavaMap(env, request->getQueryParameters()); } @@ -150,7 +157,10 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcResourceRequest_getRequestHandle { LOGD("OcResourceRequest_getRequestHandlerFlagNative"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return -1; + if (!request) + { + return -1; + } return static_cast(request->getRequestHandlerFlag()); } @@ -165,10 +175,16 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getResourceRe { LOGD("OcResourceRequest_getResourceRepresentation"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; + if (!request) + { + return nullptr; + } OCRepresentation *ocRepresentation = new OCRepresentation(request->getResourceRepresentation()); - if (!ocRepresentation) return nullptr; + if (!ocRepresentation) + { + return nullptr; + } jlong handle = reinterpret_cast(ocRepresentation); jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, g_mid_OcRepresentation_N_ctor_bool, @@ -192,8 +208,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getObservatio { LOGD("OcResourceRequest_getObservationInfo"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; - + if (!request) + { + return nullptr; + } ObservationInfo oInfo = request->getObservationInfo(); jobject jObservationInfo = env->NewObject(g_cls_ObservationInfo, g_mid_ObservationInfo_N_ctor, @@ -222,8 +240,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceRequest_setResourceUri return; } JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return; - + if (!request) + { + return; + } request->setResourceUri(env->GetStringUTFChars(jUri, 0)); } @@ -237,8 +257,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResourceRequest_getResourceUr { LOGD("OcResourceRequest_getResourceUri"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; - + if (!request) + { + return nullptr; + } std::string requestUri = request->getResourceUri(); return env->NewStringUTF(requestUri.c_str()); } @@ -253,8 +275,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getHeaderOpti { LOGD("OcResourceRequest_getHeaderOptions"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; - + if (!request) + { + return nullptr; + } return JniUtils::convertHeaderOptionsVectorToJavaList(env, request->getHeaderOptions()); } @@ -268,7 +292,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getRequestHan { LOGD("OcResourceRequest_getRequestHandle"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; + if (!request) + { + return nullptr; + } JniOcRequestHandle* jniHandle = new JniOcRequestHandle(request->getRequestHandle()); jlong handle = reinterpret_cast(jniHandle); @@ -292,7 +319,10 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcResourceRequest_getResourceHa { LOGD("OcResourceRequest_getResourceHandle"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); - if (!request) return nullptr; + if (!request) + { + return nullptr; + } JniOcResourceHandle* jniHandle = new JniOcResourceHandle( request->getResourceHandle()); @@ -318,4 +348,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceRequest_dispose LOGD("OcResourceRequest_dispose"); JniOcResourceRequest *request = JniOcResourceRequest::getJniOcResourceRequestPtr(env, thiz); delete request; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOcResourceResponse.cpp b/android/android_api/base/jni/JniOcResourceResponse.cpp index 0781d9f..8189073 100644 --- a/android/android_api/base/jni/JniOcResourceResponse.cpp +++ b/android/android_api/base/jni/JniOcResourceResponse.cpp @@ -30,10 +30,13 @@ using namespace OC; JniOcResourceResponse::JniOcResourceResponse (std::shared_ptr resourceResponse) -: m_response(resourceResponse){} +: m_response(resourceResponse) +{ +} JniOcResourceResponse::~JniOcResourceResponse() -{} +{ +} void JniOcResourceResponse::setErrorCode(const int eCode) { @@ -111,8 +114,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setErrorCode { LOGD("OcResourceResponse_setErrorCode"); JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!response) return; - + if (!response) + { + return; + } response->setErrorCode(static_cast(eCode)); } @@ -126,8 +131,10 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcResourceResponse_getNewResour { LOGD("OcResourceResponse_getNewResourceUri"); JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!response) return nullptr; - + if (!response) + { + return nullptr; + } return env->NewStringUTF(response->getNewResourceUri().c_str()); } @@ -141,8 +148,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setNewResourceU { LOGD("OcResourceResponse_setNewResourceUri"); JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!response) return; - + if (!response) + { + return; + } response->setNewResourceUri(env->GetStringUTFChars(jstr, 0)); } @@ -161,8 +170,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setHeaderOption return; } JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!jniResponse) return; - + if (!jniResponse) + { + return; + } HeaderOptions headerOptions; JniUtils::convertJavaHeaderOptionsArrToVector(env, jHeaderOptions, headerOptions); @@ -184,11 +195,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setRequestHandl return; } JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!jniResponse) return; - + if (!jniResponse) + { + return; + } JniOcRequestHandle* jniOcRequestHandle = JniOcRequestHandle::getJniOcRequestHandlePtr(env, jRequestHandle); - if (!jniOcRequestHandle) return; - + if (!jniOcRequestHandle) + { + return; + } jniResponse->setRequestHandle(jniOcRequestHandle->getOCRequestHandle()); } @@ -207,11 +222,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResourceHand return; } JniOcResourceResponse *jniResponse = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!jniResponse) return; - + if (!jniResponse) + { + return; + } JniOcResourceHandle* jniOcResourceHandle = JniOcResourceHandle::getJniOcResourceHandlePtr(env, jResourceHandle); - if (!jniOcResourceHandle) return; - + if (!jniOcResourceHandle) + { + return; + } jniResponse->setResourceHandle(jniOcResourceHandle->getOCResourceHandle()); } @@ -225,8 +244,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResponseResu { LOGD("OcResourceResponse_setResponseResult"); JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!response) return; - + if (!response) + { + return; + } response->setResponseResult(JniUtils::getOCEntityHandlerResult(env, static_cast(responseResult))); } @@ -252,12 +273,16 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResourceRepr JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!response) return; - + if (!response) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); - if (!representation) return; - + if (!representation) + { + return; + } response->setResourceRepresentation(*representation, env->GetStringUTFChars(jstr, 0)); } @@ -276,8 +301,10 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_setResourceRepr return; } JniOcResourceResponse *response = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); - if (!response) return; - + if (!response) + { + return; + } OCRepresentation *representation = JniOcRepresentation::getOCRepresentationPtr(env, jRepresentation); @@ -317,4 +344,4 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcResourceResponse_dispose LOGD("OcResourceResponse_dispose"); JniOcResourceResponse *resp = JniOcResourceResponse::getJniOcResourceResponsePtr(env, thiz); delete resp; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOcSecureResource.cpp b/android/android_api/base/jni/JniOcSecureResource.cpp index 4b12e52..2c6274b 100644 --- a/android/android_api/base/jni/JniOcSecureResource.cpp +++ b/android/android_api/base/jni/JniOcSecureResource.cpp @@ -209,6 +209,22 @@ OCStackResult JniOcSecureResource::provisionCredentials(JNIEnv* env, jint type, resultCallback); } +#if defined(__WITH_TLS__) +OCStackResult JniOcSecureResource::provisionTrustCertChain(JNIEnv* env, jint type, jint credId, + jobject jListener) +{ + JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); + + ResultCallBack resultCallback = [resultListener](PMResultList_t *result, int hasError) + { + resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONTRUSTCERTCHAIN); + }; + + return m_sharedSecureResource->provisionTrustCertChain((OicSecCredType_t)type, credId, + resultCallback); +} +#endif + OCStackResult JniOcSecureResource::provisionACL(JNIEnv* env, jobject _acl, jobject jListener) { OCStackResult ret; @@ -222,20 +238,20 @@ OCStackResult JniOcSecureResource::provisionACL(JNIEnv* env, jobject _acl, jobje if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl, acl)) { - JniSecureUtils::FreeACLList(acl); + DeleteACLList(acl); return OC_STACK_ERROR; } ResultCallBack resultCallback = [acl, resultListener](PMResultList_t *result, int hasError) { - JniSecureUtils::FreeACLList(acl); + DeleteACLList(acl); resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONACL); }; ret = m_sharedSecureResource->provisionACL(acl, resultCallback); if (ret != OC_STACK_OK) { - JniSecureUtils::FreeACLList(acl); + DeleteACLList(acl); } return ret; } @@ -327,7 +343,10 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty jobject _acl1, jobject _device2, jobject _acl2, jobject jListener) { OCStackResult ret; - + if(!jListener) + { + return OC_STACK_INVALID_CALLBACK; + } JniProvisionResultListner *resultListener = AddProvisionResultListener(env, jListener); JniOcSecureResource *device2 = JniOcSecureResource::getJniOcSecureResourcePtr(env, _device2); if (!device2) @@ -350,7 +369,7 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl1, acl1)) { - JniSecureUtils::FreeACLList(acl1); + DeleteACLList(acl1); return OC_STACK_ERROR; } } @@ -360,14 +379,13 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty acl2 = (OicSecAcl_t*)OICCalloc(1, sizeof(OicSecAcl_t)); if (!acl2) { - JniSecureUtils::FreeACLList(acl1); + DeleteACLList(acl1); return OC_STACK_NO_MEMORY; } if (OC_STACK_OK != JniSecureUtils::convertJavaACLToOCAcl(env, _acl2, acl2)) { - JniSecureUtils::FreeACLList(acl1); - JniSecureUtils::FreeACLList(acl2); + DeleteACLList(acl2); return OC_STACK_ERROR; } } @@ -375,18 +393,19 @@ OCStackResult JniOcSecureResource::provisionPairwiseDevices(JNIEnv* env, jint ty ResultCallBack resultCallback = [acl1, acl2, resultListener](PMResultList_t *result, int hasError) { - JniSecureUtils::FreeACLList(acl1); - JniSecureUtils::FreeACLList(acl2); + DeleteACLList(acl1); + DeleteACLList(acl2); resultListener->ProvisionResultCallback(result, hasError, ListenerFunc::PROVISIONPAIRWISEDEVICES); }; + ret = m_sharedSecureResource->provisionPairwiseDevices(cred, acl1, *device2->getDevicePtr(), acl2, resultCallback); if (ret != OC_STACK_OK) { - JniSecureUtils::FreeACLList(acl1); - JniSecureUtils::FreeACLList(acl2); + DeleteACLList(acl1); + DeleteACLList(acl2); } return ret; } @@ -402,13 +421,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_doOwnershipTransf LOGD("OcSecureResource_doOwnershipTransfer"); if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -445,13 +465,14 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_removeDevice if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -480,15 +501,21 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices (JNIEnv *env, jobject thiz, jobject device2, jobject jListener) { LOGD("OcSecureResource_unlinkDevices"); - if (!jListener || !device2) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener or device2 cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); + return; + } + if (!device2) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device2 cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -513,19 +540,25 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices * Method: provisionCredentials1 * Signature: (Lorg/iotivity/base/OcSecureResource/provisionCredentials;)V */ -JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 + JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 (JNIEnv *env, jobject thiz, jint type, jint keySize, jobject device2, jobject jListener) { LOGD("OcSecureResource_provisionCredentials"); - if (!jListener || !device2) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener or device2 cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); + return; + } + if (!device2) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device2 cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -548,6 +581,49 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredenti /* * Class: org_iotivity_base_OcSecureResource + * Method: provisionTrustCertChain1 + * Signature: (Lorg/iotivity/base/OcSecureResource/provisionTrustCertChain1;)V + */ + JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionTrustCertChain1 +(JNIEnv *env, jobject thiz, jint type, jint credId, jobject jListener) +{ + LOGD("OcSecureResource_provisionTrustCertChain1"); +#if defined(__WITH_DTLS__) || defined(__WITH_TLS__) + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionTrustCertChainListener cannot be null"); + return; + } + + JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); + if (!secureResource) + { + return; + } + + try + { + OCStackResult result = secureResource->provisionTrustCertChain(env, type, credId, + jListener); + if (OC_STACK_OK != result) + { + ThrowOcException(result, "OcSecureResource_provisionTrustCertChain1"); + return; + } + } + catch (OCException& e) + { + LOGE("%s", e.reason().c_str()); + ThrowOcException(e.code(), e.reason().c_str()); + } +#else + ThrowOcException(OC_STACK_INVALID_PARAM, "WITH_TLS not enabled"); + return; +#endif // __WITH_DTLS__ || __WITH_TLS__ +} + +/* + * Class: org_iotivity_base_OcSecureResource * Method: provisionACL * Signature: (Lorg/iotivity/base/OcSecureResource/provisionACL;)V */ @@ -555,15 +631,21 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL (JNIEnv *env, jobject thiz, jobject acl, jobject jListener) { LOGD("OcSecureResource_provisionACL"); - if (!jListener || !acl) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "provisionResultListener or acl cannot be null"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "provisionResultListener cannot be null"); + return; + } + if (!acl) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "acl cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -593,15 +675,21 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionPairwise jobject acl2, jobject jListener) { LOGD("OcSecureResource_provisionPairwiseDevices"); - if (!jListener || !device2) + if (!jListener) { - ThrowOcException(OC_STACK_INVALID_PARAM, "Invalid Parameters"); + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid Callback"); + return; + } + if (!device2) + { + ThrowOcException(OC_STACK_INVALID_PARAM, "device2 cannot be null"); return; } JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -632,7 +720,12 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionDirectPa jint jedp, jobject jListener) { LOGD("OcSecureResource_provisionDirectPairing"); - if (!jListener || !pdacls || !jpin || ! jprmType) + if (!jListener) + { + ThrowOcException(OC_STACK_INVALID_CALLBACK, "Invalid Callback"); + return; + } + if (!pdacls || !jpin || ! jprmType) { ThrowOcException(OC_STACK_INVALID_PARAM, "Invalid Parameters"); return; @@ -642,6 +735,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionDirectPa JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return; } @@ -685,6 +779,7 @@ JNIEXPORT jobject JNICALL Java_org_iotivity_base_OcSecureResource_getLinkedDevic JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + ThrowOcException(OC_STACK_ERROR, "getJniOcSecureResourcePtr failed"); return nullptr; } @@ -718,6 +813,7 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getIpAddr JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return nullptr; } @@ -736,6 +832,7 @@ JNIEXPORT jstring JNICALL Java_org_iotivity_base_OcSecureResource_getDeviceID JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return nullptr; } @@ -754,6 +851,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_deviceStatus JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return -1; } @@ -772,6 +870,7 @@ JNIEXPORT jint JNICALL Java_org_iotivity_base_OcSecureResource_ownedStatus JniOcSecureResource *secureResource = JniOcSecureResource::getJniOcSecureResourcePtr(env, thiz); if (!secureResource) { + LOGD("getJniOcSecureResourcePtr failed"); return -1; } diff --git a/android/android_api/base/jni/JniOcSecureResource.h b/android/android_api/base/jni/JniOcSecureResource.h index d071e96..213f20d 100644 --- a/android/android_api/base/jni/JniOcSecureResource.h +++ b/android/android_api/base/jni/JniOcSecureResource.h @@ -53,6 +53,8 @@ class JniOcSecureResource jobject acl1, jobject device2, jobject acl2, jobject jListener); OCStackResult provisionCredentials(JNIEnv* env, jint type, jint keySize, jobject device2, jobject jListener); + OCStackResult provisionTrustCertChain(JNIEnv* env, jint type, jint credId, + jobject jListener); OCStackResult unlinkDevices(JNIEnv* env, jobject device2, jobject jListener); OCStackResult removeDevice(JNIEnv* env, jint timeout, jobject jListener); OCStackResult provisionDirectPairing(JNIEnv* env, jobjectArray jpdacls,jobject jListener, @@ -99,7 +101,15 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_unlinkDevices * Signature: (IILjava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionCredentialsListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredentials1 - (JNIEnv *, jobject, jint, jint, jobject, jobject); + (JNIEnv *, jobject, jint, jint, jobject, jobject); + +/* + * Class: org_iotivity_base_OcSecureResource + * Method: provisionTrustCertChain1 + * Signature: (Lorg/iotivity/base/OcSecureResource/ProvisionTrustCertChainListener;)V + */ +JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionTrustCertChain1 + (JNIEnv *, jobject, jint, jint, jobject); /* * Class: org_iotivity_base_OcSecureResource @@ -107,7 +117,7 @@ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionCredenti * Signature: (Ljava/lang/Object;Lorg/iotivity/base/OcSecureResource/ProvisionAclListener;)V */ JNIEXPORT void JNICALL Java_org_iotivity_base_OcSecureResource_provisionACL - (JNIEnv *, jobject, jobject, jobject); + (JNIEnv *, jobject, jobject, jobject); /* * Class: org_iotivity_base_OcSecureResource diff --git a/android/android_api/base/jni/JniOcStack.cpp b/android/android_api/base/jni/JniOcStack.cpp index 18d0160..03cb4ad 100644 --- a/android/android_api/base/jni/JniOcStack.cpp +++ b/android/android_api/base/jni/JniOcStack.cpp @@ -39,6 +39,9 @@ JavaVM* g_jvm = nullptr; +jclass g_cls_byte1DArray = nullptr; +jclass g_cls_byte2DArray = nullptr; +jclass g_cls_byte3DArray = nullptr; jclass g_cls_Integer = nullptr; jclass g_cls_int1DArray = nullptr; jclass g_cls_int2DArray = nullptr; @@ -79,6 +82,12 @@ jclass g_cls_OcOicSecAcl_resr = nullptr; jclass g_cls_OcOicSecAcl_validity = nullptr; jclass g_cls_OcOicSecPdAcl = nullptr; jclass g_cls_OcDirectPairDevice = nullptr; +#ifdef __WITH_TLS__ +jclass g_cls_OcCloudProvisioning = nullptr; +#endif +#ifdef WITH_CLOUD +jclass g_cls_OcAccountManager = nullptr; +#endif jmethodID g_mid_Integer_ctor = nullptr; jmethodID g_mid_Double_ctor = nullptr; @@ -102,6 +111,7 @@ jmethodID g_mid_OcResourceRequest_N_ctor = nullptr; jmethodID g_mid_OcResourceResponse_N_ctor = nullptr; jmethodID g_mid_OcResourceHandle_N_ctor = nullptr; jmethodID g_mid_OcPresenceHandle_N_ctor = nullptr; + jmethodID g_mid_OcRequestHandle_N_ctor = nullptr; jmethodID g_mid_OcHeaderOption_ctor = nullptr; jmethodID g_mid_OcHeaderOption_get_id = nullptr; @@ -113,6 +123,9 @@ jmethodID g_mid_OcProvisionResult_ctor = nullptr; jmethodID g_mid_OcSecureResource_ctor = nullptr; jmethodID g_mid_OcDirectPairDevice_ctor = nullptr; jmethodID g_mid_OcDirectPairDevice_dev_ctor = nullptr; +#ifdef WITH_CLOUD +jmethodID g_mid_OcAccountManager_ctor = nullptr; +#endif jmethodID g_mid_OcOicSecPdAcl_get_resources_cnt = nullptr; jmethodID g_mid_OcOicSecPdAcl_get_resources = nullptr; @@ -137,6 +150,11 @@ jmethodID g_mid_OcOicSecAcl_validity_get_recurrenceLen = nullptr; jmethodID g_mid_OcOicSecAcl_resr_get_interfaceLen = nullptr; jmethodID g_mid_OcOicSecAcl_get_rownerID = nullptr; +#ifdef __WITH_TLS__ +jmethodID g_mid_OcCloudProvisioning_getIP = nullptr; +jmethodID g_mid_OcCloudProvisioning_getPort = nullptr; +#endif + jobject getOcException(JNIEnv* env, const char* file, const char* functionName, const int line, const int code, const char* message) { @@ -186,6 +204,22 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) jclass clazz = nullptr; + //byte + clazz = env->FindClass("[B"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_byte1DArray = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + clazz = env->FindClass("[[B"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_byte2DArray = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + clazz = env->FindClass("[[[B"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_byte3DArray = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + //Integer clazz = env->FindClass("java/lang/Integer"); VERIFY_VARIABLE_NULL(clazz); @@ -476,6 +510,17 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) VERIFY_VARIABLE_NULL(g_mid_OcDirectPairDevice_dev_ctor); env->DeleteLocalRef(clazz); +#ifdef WITH_CLOUD + //OcAccountManager + clazz = env->FindClass("org/iotivity/base/OcAccountManager"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_OcAccountManager = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + g_mid_OcAccountManager_ctor = env->GetMethodID(g_cls_OcAccountManager, "", "(J)V"); + VERIFY_VARIABLE_NULL(g_mid_OcAccountManager_ctor); +#endif + //OicSecAcl clazz = env->FindClass("org/iotivity/base/OicSecAcl"); VERIFY_VARIABLE_NULL(clazz); @@ -568,14 +613,26 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) g_mid_OcOicSecPdAcl_get_recurrences = env->GetMethodID(g_cls_OcOicSecPdAcl, "getRecurrences", "(I)Ljava/lang/String;"); VERIFY_VARIABLE_NULL(g_mid_OcOicSecPdAcl_get_recurrences); +#ifdef __WITH_TLS__ + //OcCloudProvisioning + clazz = env->FindClass("org/iotivity/base/OcCloudProvisioning"); + VERIFY_VARIABLE_NULL(clazz); + g_cls_OcCloudProvisioning = (jclass)env->NewGlobalRef(clazz); + env->DeleteLocalRef(clazz); + + g_mid_OcCloudProvisioning_getIP = env->GetMethodID(g_cls_OcCloudProvisioning, "getIP", "()Ljava/lang/String;"); + VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getIP); + g_mid_OcCloudProvisioning_getPort = env->GetMethodID(g_cls_OcCloudProvisioning, "getPort", "()I"); + VERIFY_VARIABLE_NULL(g_mid_OcCloudProvisioning_getPort); +#endif return JNI_CURRENT_VERSION; } JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) { LOGI("JNI_OnUnload"); - JNIEnv* env; + JNIEnv* env = nullptr; if (vm->GetEnv((void **)&env, JNI_CURRENT_VERSION) != JNI_OK) { @@ -583,42 +640,55 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) return; } - env->DeleteGlobalRef(g_cls_Integer); - env->DeleteGlobalRef(g_cls_int1DArray); - env->DeleteGlobalRef(g_cls_int2DArray); - env->DeleteGlobalRef(g_cls_Double); - env->DeleteGlobalRef(g_cls_double1DArray); - env->DeleteGlobalRef(g_cls_double2DArray); - env->DeleteGlobalRef(g_cls_Boolean); - env->DeleteGlobalRef(g_cls_boolean1DArray); - env->DeleteGlobalRef(g_cls_boolean2DArray); - env->DeleteGlobalRef(g_cls_String); - env->DeleteGlobalRef(g_cls_String1DArray); - env->DeleteGlobalRef(g_cls_String2DArray); - env->DeleteGlobalRef(g_cls_LinkedList); - env->DeleteGlobalRef(g_cls_Map); - env->DeleteGlobalRef(g_cls_MapEntry); - env->DeleteGlobalRef(g_cls_Set); - env->DeleteGlobalRef(g_cls_Iterator); - env->DeleteGlobalRef(g_cls_HashMap); - env->DeleteGlobalRef(g_cls_OcResource); - env->DeleteGlobalRef(g_cls_OcException); - env->DeleteGlobalRef(g_cls_OcRepresentation); - env->DeleteGlobalRef(g_cls_OcRepresentation1DArray); - env->DeleteGlobalRef(g_cls_OcRepresentation2DArray); - env->DeleteGlobalRef(g_cls_OcResourceRequest); - env->DeleteGlobalRef(g_cls_OcResourceResponse); - env->DeleteGlobalRef(g_cls_OcResourceHandle); - env->DeleteGlobalRef(g_cls_OcPresenceHandle); - env->DeleteGlobalRef(g_cls_OcRequestHandle); - env->DeleteGlobalRef(g_cls_OcPresenceStatus); - env->DeleteGlobalRef(g_cls_OcHeaderOption); - env->DeleteGlobalRef(g_cls_ObservationInfo); - env->DeleteGlobalRef(g_cls_OcResourceIdentifier); - env->DeleteGlobalRef(g_cls_OcSecureResource); - env->DeleteGlobalRef(g_cls_OcProvisionResult); - env->DeleteGlobalRef(g_cls_OcOicSecAcl); - env->DeleteGlobalRef(g_cls_OcOicSecAcl_ace); - env->DeleteGlobalRef(g_cls_OcOicSecAcl_resr); - env->DeleteGlobalRef(g_cls_OcOicSecAcl_validity); + if (env) + { + env->DeleteGlobalRef(g_cls_Integer); + env->DeleteGlobalRef(g_cls_int1DArray); + env->DeleteGlobalRef(g_cls_int2DArray); + env->DeleteGlobalRef(g_cls_Double); + env->DeleteGlobalRef(g_cls_double1DArray); + env->DeleteGlobalRef(g_cls_double2DArray); + env->DeleteGlobalRef(g_cls_Boolean); + env->DeleteGlobalRef(g_cls_boolean1DArray); + env->DeleteGlobalRef(g_cls_boolean2DArray); + env->DeleteGlobalRef(g_cls_String); + env->DeleteGlobalRef(g_cls_String1DArray); + env->DeleteGlobalRef(g_cls_String2DArray); + env->DeleteGlobalRef(g_cls_LinkedList); + env->DeleteGlobalRef(g_cls_Map); + env->DeleteGlobalRef(g_cls_MapEntry); + env->DeleteGlobalRef(g_cls_Set); + env->DeleteGlobalRef(g_cls_Iterator); + env->DeleteGlobalRef(g_cls_HashMap); + env->DeleteGlobalRef(g_cls_OcResource); + env->DeleteGlobalRef(g_cls_OcException); + env->DeleteGlobalRef(g_cls_OcRepresentation); + env->DeleteGlobalRef(g_cls_OcRepresentation1DArray); + env->DeleteGlobalRef(g_cls_OcRepresentation2DArray); + env->DeleteGlobalRef(g_cls_OcResourceRequest); + env->DeleteGlobalRef(g_cls_OcResourceResponse); + env->DeleteGlobalRef(g_cls_OcResourceHandle); + env->DeleteGlobalRef(g_cls_OcPresenceHandle); + env->DeleteGlobalRef(g_cls_OcRequestHandle); + env->DeleteGlobalRef(g_cls_OcPresenceStatus); + env->DeleteGlobalRef(g_cls_OcHeaderOption); + env->DeleteGlobalRef(g_cls_ObservationInfo); + env->DeleteGlobalRef(g_cls_OcResourceIdentifier); + env->DeleteGlobalRef(g_cls_OcSecureResource); + env->DeleteGlobalRef(g_cls_OcProvisionResult); + env->DeleteGlobalRef(g_cls_OcDirectPairDevice); + env->DeleteGlobalRef(g_cls_byte1DArray); + env->DeleteGlobalRef(g_cls_byte2DArray); + env->DeleteGlobalRef(g_cls_byte3DArray); +#ifdef WITH_CLOUD + env->DeleteGlobalRef(g_cls_OcAccountManager); +#endif +#ifdef __WITH_TLS__ + env->DeleteGlobalRef(g_cls_OcCloudProvisioning); +#endif + env->DeleteGlobalRef(g_cls_OcOicSecAcl); + env->DeleteGlobalRef(g_cls_OcOicSecAcl_ace); + env->DeleteGlobalRef(g_cls_OcOicSecAcl_resr); + env->DeleteGlobalRef(g_cls_OcOicSecAcl_validity); + } } diff --git a/android/android_api/base/jni/JniOcStack.h b/android/android_api/base/jni/JniOcStack.h index 243ce4c..db5ea1e 100644 --- a/android/android_api/base/jni/JniOcStack.h +++ b/android/android_api/base/jni/JniOcStack.h @@ -38,6 +38,7 @@ #define JNI_NO_NATIVE_POINTER 1001 #define JNI_INVALID_VALUE 1002 #define JNI_NO_SUCH_KEY 1003 +#define JNI_NO_SUPPORT 1004 jobject getOcException(JNIEnv* env, const char* file, const char* functionName, const int line, const int code, const char* message); @@ -47,6 +48,9 @@ void throwOcException(JNIEnv* env, jobject ex); extern JavaVM* g_jvm; +extern jclass g_cls_byte1DArray; +extern jclass g_cls_byte2DArray; +extern jclass g_cls_byte3DArray; extern jclass g_cls_Integer; extern jclass g_cls_int1DArray; extern jclass g_cls_int2DArray; @@ -84,6 +88,12 @@ extern jclass g_cls_OcSecureResource; extern jclass g_cls_OcOicSecAcl; extern jclass g_cls_OcOicSecPdAcl; extern jclass g_cls_OcDirectPairDevice; +#ifdef WITH_CLOUD +extern jclass g_cls_OcAccountManager; +#endif +#ifdef __WITH_TLS__ +extern jclass g_cls_OcCloudProvisioning; +#endif extern jclass g_cls_OcOicSecAcl_ace; extern jclass g_cls_OcOicSecAcl_resr; @@ -122,6 +132,13 @@ extern jmethodID g_mid_OcProvisionResult_ctor; extern jmethodID g_mid_OcSecureResource_ctor; extern jmethodID g_mid_OcDirectPairDevice_ctor; extern jmethodID g_mid_OcDirectPairDevice_dev_ctor; +#ifdef WITH_CLOUD +extern jmethodID g_mid_OcAccountManager_ctor; +#endif +#ifdef __WITH_TLS__ +extern jmethodID g_mid_OcCloudProvisioning_getIP; +extern jmethodID g_mid_OcCloudProvisioning_getPort; +#endif extern jmethodID g_mid_OcOicSecAcl_get_rownerID; extern jmethodID g_mid_OcOicSecAcl_get_aces; @@ -145,6 +162,7 @@ extern jmethodID g_mid_OcOicSecPdAcl_get_periods_cnt; extern jmethodID g_mid_OcOicSecPdAcl_get_periods; extern jmethodID g_mid_OcOicSecPdAcl_get_recurrences; + typedef void(*RemoveListenerCallback)(JNIEnv* env, jobject jListener); static jfieldID GetHandleField(JNIEnv *env, jobject jobj) diff --git a/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp b/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp index 5c5d900..a0ffd05 100644 --- a/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp +++ b/android/android_api/base/jni/JniOnDPDevicesFoundListener.cpp @@ -77,26 +77,38 @@ JniOnDPDevicesFoundListener::~JniOnDPDevicesFoundListener() LOGI("~JniOnDPDevicesFoundListener()"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices paringDevicesList, DPFunc func) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -105,7 +117,10 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -122,10 +137,14 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par { calledFunc = "onGetDirectPairedListener"; } + break; default: { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } return; } @@ -135,7 +154,10 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -146,7 +168,10 @@ void JniOnDPDevicesFoundListener::directPairingDevicesCallback(PairedDevices par } checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnDPDevicesFoundListener::checkExAndRemoveListener(JNIEnv* env) diff --git a/android/android_api/base/jni/JniOnDeleteListener.cpp b/android/android_api/base/jni/JniOnDeleteListener.cpp index 87ebd71..bb0f5db 100644 --- a/android/android_api/base/jni/JniOnDeleteListener.cpp +++ b/android/android_api/base/jni/JniOnDeleteListener.cpp @@ -23,46 +23,75 @@ #include "JniOnDeleteListener.h" #include "JniOcResource.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif JniOnDeleteListener::JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnDeleteListener::JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + JniOnDeleteListener::~JniOnDeleteListener() { if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; - + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, const int eCode) { - jint envRet; + jint envRet = JNI_ERR; JNIEnv *env = GetJNIEnv(envRet); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jclass clsL = env->GetObjectClass(jListener); if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -72,14 +101,20 @@ void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, c if (!ex) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onDeleteFailed", "(Ljava/lang/Throwable;)V"); if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, ex); @@ -90,7 +125,10 @@ void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, c if (!jHeaderOptionList) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -98,14 +136,20 @@ void JniOnDeleteListener::onDeleteCallback(const HeaderOptions& headerOptions, c if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, jHeaderOptionList); } checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } void JniOnDeleteListener::checkExAndRemoveListener(JNIEnv* env) @@ -114,11 +158,33 @@ void JniOnDeleteListener::checkExAndRemoveListener(JNIEnv* env) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnDeleteListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnDeleteListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnDeleteListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnDeleteListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnDeleteListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnDeleteListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnDeleteListener.h b/android/android_api/base/jni/JniOnDeleteListener.h index 20de33f..9354232 100644 --- a/android/android_api/base/jni/JniOnDeleteListener.h +++ b/android/android_api/base/jni/JniOnDeleteListener.h @@ -27,11 +27,17 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnDeleteListener { public: JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcResource* owner); +#ifdef WITH_CLOUD + JniOnDeleteListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner); +#endif ~JniOnDeleteListener(); void onDeleteCallback(const HeaderOptions&, const int eCode); @@ -39,7 +45,10 @@ public: private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnDeleteResourceListener.cpp b/android/android_api/base/jni/JniOnDeleteResourceListener.cpp new file mode 100644 index 0000000..3520c07 --- /dev/null +++ b/android/android_api/base/jni/JniOnDeleteResourceListener.cpp @@ -0,0 +1,112 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOnDeleteResourceListener.h" + +JniOnDeleteResourceListener::JniOnDeleteResourceListener(JNIEnv *env, jobject jListener, + RemoveListenerCallback removeListenerCallback) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeListenerCallback = removeListenerCallback; +} + +JniOnDeleteResourceListener::~JniOnDeleteResourceListener() +{ + LOGI("~JniOnDeleteResourceListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnDeleteResourceListener::onDeleteResourceCallback(const int eCode) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jint jres = static_cast(eCode); + jmethodID midL = env->GetMethodID(clsL, "onDeleteResourceCompleted", "(I)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + env->CallVoidMethod(jListener, midL, jres); + + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnDeleteResourceListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeListenerCallback(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeListenerCallback(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnDeleteResourceListener.h b/android/android_api/base/jni/JniOnDeleteResourceListener.h new file mode 100644 index 0000000..267646f --- /dev/null +++ b/android/android_api/base/jni/JniOnDeleteResourceListener.h @@ -0,0 +1,40 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcPlatform_OnDeleteResourceListener +#define _Included_org_iotivity_base_OcPlatform_OnDeleteResourceListener + +using namespace OC; + +class JniOnDeleteResourceListener +{ +public: + JniOnDeleteResourceListener(JNIEnv *env, jobject listener, + RemoveListenerCallback removeListenerCallback); + ~JniOnDeleteResourceListener(); + void onDeleteResourceCallback(const int eCode); +private: + RemoveListenerCallback m_removeListenerCallback; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnDeviceInfoListener.cpp b/android/android_api/base/jni/JniOnDeviceInfoListener.cpp index 28d8e44..520cdfd 100644 --- a/android/android_api/base/jni/JniOnDeviceInfoListener.cpp +++ b/android/android_api/base/jni/JniOnDeviceInfoListener.cpp @@ -34,29 +34,41 @@ JniOnDeviceInfoListener::~JniOnDeviceInfoListener() LOGI("~JniOnDeviceInfoListener"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& ocRepresentation) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { LOGI("Java onDeviceInfoListener object is already destroyed, quiting"); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -68,7 +80,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -77,7 +92,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onDeviceFound", "(Lorg/iotivity/base/OcRepresentation;)V"); @@ -85,7 +103,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -97,7 +118,10 @@ void JniOnDeviceInfoListener::foundDeviceCallback(const OC::OCRepresentation& oc checkExAndRemoveListener(env); } - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnDeviceInfoListener::checkExAndRemoveListener(JNIEnv* env) @@ -113,4 +137,4 @@ void JniOnDeviceInfoListener::checkExAndRemoveListener(JNIEnv* env) { m_removeListenerCallback(env, m_jwListener); } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnDirectPairingListener.cpp b/android/android_api/base/jni/JniOnDirectPairingListener.cpp index f580079..085c2b9 100644 --- a/android/android_api/base/jni/JniOnDirectPairingListener.cpp +++ b/android/android_api/base/jni/JniOnDirectPairingListener.cpp @@ -38,56 +38,79 @@ JniOnDirectPairingListener::~JniOnDirectPairingListener() LOGI("~JniOnDirectPairingListener()"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptr dpDev, OCStackResult result) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jclass clsL = env->GetObjectClass(jListener); - if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } JniOcDirectPairDevice *device = new JniOcDirectPairDevice(dpDev); - if (!device) return; + if (!device) + { + return; + } jstring jStr = env->NewStringUTF((dpDev->getDeviceID()).c_str()); if (!jStr) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); - return ; + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; } jobject jresult = env->NewObject(g_cls_OcDirectPairDevice, g_mid_OcDirectPairDevice_ctor); if (!jresult) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); - return ; + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; } SetHandle(env, jresult, device); @@ -99,7 +122,10 @@ void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptrDetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -110,7 +136,11 @@ void JniOnDirectPairingListener::doDirectPairingCB(std::shared_ptrDetachCurrentThread(); + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnDirectPairingListener::checkExAndRemoveListener(JNIEnv* env) diff --git a/android/android_api/base/jni/JniOnGetListener.cpp b/android/android_api/base/jni/JniOnGetListener.cpp index 2bc8624..9a801f1 100644 --- a/android/android_api/base/jni/JniOnGetListener.cpp +++ b/android/android_api/base/jni/JniOnGetListener.cpp @@ -23,41 +23,68 @@ #include "JniOcResource.h" #include "JniOcRepresentation.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif JniOnGetListener::JniOnGetListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnGetListener::JniOnGetListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + JniOnGetListener::~JniOnGetListener() { LOGD("~JniOnGetListener"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions, const OCRepresentation& ocRepresentation, const int eCode) { - jint envRet; + jint envRet = JNI_ERR; JNIEnv *env = GetJNIEnv(envRet); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jclass clsL = env->GetObjectClass(jListener); @@ -65,7 +92,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions, if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -75,14 +105,20 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions, if (!ex) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onGetFailed", "(Ljava/lang/Throwable;)V"); if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, ex); @@ -93,7 +129,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions, if (!jHeaderOptionList) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -105,7 +144,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions, { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -115,7 +157,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions, { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, jHeaderOptionList, jRepresentation); @@ -127,7 +172,10 @@ void JniOnGetListener::onGetCallback(const HeaderOptions& headerOptions, } checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } void JniOnGetListener::checkExAndRemoveListener(JNIEnv* env) @@ -136,11 +184,33 @@ void JniOnGetListener::checkExAndRemoveListener(JNIEnv* env) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnGetListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnGetListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnGetListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnGetListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnGetListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnGetListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnGetListener.h b/android/android_api/base/jni/JniOnGetListener.h index a37b423..abffaa0 100644 --- a/android/android_api/base/jni/JniOnGetListener.h +++ b/android/android_api/base/jni/JniOnGetListener.h @@ -27,17 +27,27 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnGetListener { public: JniOnGetListener(JNIEnv *env, jobject listener, JniOcResource* resource); +#ifdef WITH_CLOUD + JniOnGetListener(JNIEnv *env, jobject listener, JniOcAccountManager* resource); +#endif ~JniOnGetListener(); void onGetCallback(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); + private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnMQSubscribeListener.cpp b/android/android_api/base/jni/JniOnMQSubscribeListener.cpp new file mode 100644 index 0000000..705f644 --- /dev/null +++ b/android/android_api/base/jni/JniOnMQSubscribeListener.cpp @@ -0,0 +1,208 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "JniOnMQSubscribeListener.h" +#include "JniOcResource.h" +#include "JniOcRepresentation.h" +#include "JniUtils.h" + +JniOnMQSubscribeListener::JniOnMQSubscribeListener(JNIEnv *env, + jobject jListener, + JniOcResource* owner) + : m_ownerResource(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); +} + +JniOnMQSubscribeListener::~JniOnMQSubscribeListener() +{ + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnMQSubscribeListener::onSubscribeCallback(const HeaderOptions headerOptions, + const OCRepresentation& ocRepresentation, const int& eCode, const int& sequenceNumber) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_DELETED != eCode && OC_STACK_RESOURCE_CHANGED != eCode) + { + jobject ex = GetOcException(eCode, "stack error in onSubScribeCallback"); + if (!ex) + { + goto JNI_EXIT; + } + jmethodID midL = env->GetMethodID(clsL, "onSubScribeFailed", "(Ljava/lang/Throwable;)V"); + if (!midL) + { + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, ex); + } + else + { + OCRepresentation * rep = new OCRepresentation(ocRepresentation); + jlong handle = reinterpret_cast(rep); + jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, + g_mid_OcRepresentation_N_ctor_bool, handle, true); + if (!jRepresentation) + { + delete rep; + goto JNI_EXIT; + } + + if (sequenceNumber != 1 + MAX_SEQUENCE_NUMBER) + { + jmethodID midL = env->GetMethodID(clsL, "onSubScribeCompleted", + "(Ljava/util/List;Lorg/iotivity/base/OcRepresentation;I)V"); + if (!midL) + { + delete rep; + env->DeleteLocalRef(jRepresentation); + goto JNI_EXIT; + } + + jobject jHeaderOptionList = JniUtils::convertHeaderOptionsVectorToJavaList(env, + headerOptions); + if (!jHeaderOptionList) + { + delete rep; + env->DeleteLocalRef(jRepresentation); + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, jHeaderOptionList, jRepresentation, + static_cast(sequenceNumber)); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete rep; + env->DeleteLocalRef(jRepresentation); + env->DeleteLocalRef(jHeaderOptionList); + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + } + else + { + jmethodID midL = env->GetMethodID(clsL, "onUnsubScribeCompleted", + "(Lorg/iotivity/base/OcRepresentation;I)V"); + if (!midL) + { + delete rep; + env->DeleteLocalRef(jRepresentation); + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, jRepresentation, + static_cast(sequenceNumber)); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete rep; + env->DeleteLocalRef(jRepresentation); + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + + checkExAndRemoveListener(env); + } + } + + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnMQSubscribeListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_ownerResource->removeOnMQTopicSubscribeListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnMQSubscribeListener.h b/android/android_api/base/jni/JniOnMQSubscribeListener.h new file mode 100644 index 0000000..6b7c059 --- /dev/null +++ b/android/android_api/base/jni/JniOnMQSubscribeListener.h @@ -0,0 +1,45 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcResource_OnMQSubscribeListener +#define _Included_org_iotivity_base_OcResource_OnMQSubscribeListener + +#define MAX_SEQUENCE_NUMBER 0xFFFFFF + +using namespace OC; + +class JniOcResource; + +class JniOnMQSubscribeListener +{ +public: + JniOnMQSubscribeListener(JNIEnv *env, jobject jListener, JniOcResource* owner); + ~JniOnMQSubscribeListener(); + void onSubscribeCallback(const HeaderOptions headerOptions, const OCRepresentation& rep, + const int& eCode, const int& sequenceNumber); +private: + jweak m_jwListener; + JniOcResource* m_ownerResource; + void checkExAndRemoveListener(JNIEnv *env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnMQTopicFoundListener.cpp b/android/android_api/base/jni/JniOnMQTopicFoundListener.cpp new file mode 100644 index 0000000..6fb1845 --- /dev/null +++ b/android/android_api/base/jni/JniOnMQTopicFoundListener.cpp @@ -0,0 +1,265 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +#include "JniOnMQTopicFoundListener.h" +#include "JniOcResource.h" +#include "JniOcRepresentation.h" +#include "JniUtils.h" + +JniOnMQTopicFoundListener::JniOnMQTopicFoundListener(JNIEnv *env, jobject jListener, + JniOcResource* owner) + : m_ownerResource(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); +} + +JniOnMQTopicFoundListener::~JniOnMQTopicFoundListener() +{ + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnMQTopicFoundListener::foundTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource) +{ + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode) + { + jobject ex = GetOcException(eCode, "stack error"); + if (!ex) + { + goto JNI_EXIT; + } + jmethodID midL = env->GetMethodID(clsL, "onDiscoveryTopicFailed", + "(Ljava/lang/Throwable;Ljava/lang/String;)V"); + if (!midL) + { + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, ex, env->NewStringUTF(uri.c_str())); + } + else + { + + jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); + if (!jResource) + { + goto JNI_EXIT; + } + + JniOcResource *jniOcResource = new JniOcResource(resource); + SetHandle(env, jResource, jniOcResource); + if (env->ExceptionCheck()) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + + jmethodID midL = env->GetMethodID(clsL, "onTopicDiscoveried", "(Lorg/iotivity/base/OcResource;)V"); + if (!midL) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + env->CallVoidMethod(jListener, midL, jResource); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + } + + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnMQTopicFoundListener::createdTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_CHANGED != eCode) + { + jobject ex = GetOcException(eCode, "stack error"); + if (!ex) + { + goto JNI_EXIT; + } + jmethodID midL = env->GetMethodID(clsL, "onCreateTopicFailed", + "(Ljava/lang/Throwable;Ljava/lang/String;)V"); + if (!midL) + { + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, ex, env->NewStringUTF(uri.c_str())); + } + else + { + // create Resource object + jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); + if (!jResource) + { + goto JNI_EXIT; + } + + JniOcResource *jniOcResource = new JniOcResource(resource); + SetHandle(env, jResource, jniOcResource); + if (env->ExceptionCheck()) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + + jmethodID midL = env->GetMethodID(clsL, "onTopicResourceCreated", + "(Lorg/iotivity/base/OcResource;)V"); + if (!midL) + { + delete jniOcResource; + env->DeleteLocalRef(jResource); + goto JNI_EXIT; + } + + env->CallVoidMethod(jListener, midL, jResource); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + env->DeleteLocalRef(jResource); + delete jniOcResource; + } + } + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnMQTopicFoundListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_ownerResource->removeOnTopicFoundListener(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_ownerResource->removeOnTopicFoundListener(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnMQTopicFoundListener.h b/android/android_api/base/jni/JniOnMQTopicFoundListener.h new file mode 100644 index 0000000..45b73a0 --- /dev/null +++ b/android/android_api/base/jni/JniOnMQTopicFoundListener.h @@ -0,0 +1,46 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcResource_JniOnMQTopicFoundListener +#define _Included_org_iotivity_base_OcResource_JniOnMQTopicFoundListener + +using namespace OC; + +class JniOcResource; + +class JniOnMQTopicFoundListener +{ +public: + JniOnMQTopicFoundListener(JNIEnv *env, jobject jListener, JniOcResource* owner); + ~JniOnMQTopicFoundListener(); + + void foundTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource); + void createdTopicCallback(const int eCode, const std::string& uri, + std::shared_ptr resource); + +private: + jweak m_jwListener; + JniOcResource* m_ownerResource; + void checkExAndRemoveListener(JNIEnv* env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnObserveListener.cpp b/android/android_api/base/jni/JniOnObserveListener.cpp index 3ad1d11..060b19e 100644 --- a/android/android_api/base/jni/JniOnObserveListener.cpp +++ b/android/android_api/base/jni/JniOnObserveListener.cpp @@ -23,65 +23,108 @@ #include "JniOcResource.h" #include "JniOcRepresentation.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif + +#define CA_OBSERVE_MAX_SEQUENCE_NUMBER 0xFFFFFF JniOnObserveListener::JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnObserveListener::JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + JniOnObserveListener::~JniOnObserveListener() { if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions, const OCRepresentation& ocRepresentation, const int& eCode, const int& sequenceNumber) { - jint envRet; + jint envRet = JNI_ERR; JNIEnv *env = GetJNIEnv(envRet); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } + + if (nullptr == m_jwListener) + { + LOGE("listener is not available"); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } + jclass clsL = env->GetObjectClass(jListener); if (!clsL) { + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } - if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && OC_STACK_RESOURCE_DELETED != eCode) + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_DELETED != eCode && OC_STACK_RESOURCE_CHANGED != eCode) { jobject ex = GetOcException(eCode, "stack error in onObserveCallback"); if (!ex) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + goto JNI_EXIT; } + jmethodID midL = env->GetMethodID(clsL, "onObserveFailed", "(Ljava/lang/Throwable;)V"); if (!midL) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + env->DeleteLocalRef(ex); + goto JNI_EXIT; } env->CallVoidMethod(jListener, midL, ex); } @@ -90,9 +133,7 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions, jobject jHeaderOptionList = JniUtils::convertHeaderOptionsVectorToJavaList(env, headerOptions); if (!jHeaderOptionList) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + goto JNI_EXIT; } OCRepresentation * rep = new OCRepresentation(ocRepresentation); @@ -102,18 +143,17 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions, if (!jRepresentation) { delete rep; - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + env->DeleteLocalRef(jHeaderOptionList); + goto JNI_EXIT; } jmethodID midL = env->GetMethodID(clsL, "onObserveCompleted", "(Ljava/util/List;Lorg/iotivity/base/OcRepresentation;I)V"); if (!midL) { - checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); - return; + env->DeleteLocalRef(jRepresentation); + env->DeleteLocalRef(jHeaderOptionList); + goto JNI_EXIT; } env->CallVoidMethod(jListener, midL, jHeaderOptionList, jRepresentation, @@ -122,32 +162,89 @@ void JniOnObserveListener::onObserveCallback(const HeaderOptions headerOptions, { LOGE("Java exception is thrown"); delete rep; + env->DeleteLocalRef(jRepresentation); + env->DeleteLocalRef(jHeaderOptionList); jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnObserveListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnObserveListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnObserveListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } - if (OC_OBSERVE_DEREGISTER == sequenceNumber) + if (CA_OBSERVE_MAX_SEQUENCE_NUMBER + 1 == sequenceNumber) { - checkExAndRemoveListener(env); + LOGI("Observe De-registration action is successful"); + goto JNI_EXIT; } } - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + +JNI_EXIT: + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } void JniOnObserveListener::checkExAndRemoveListener(JNIEnv* env) { + LOGI("checkExAndRemoveListener"); if (env->ExceptionCheck()) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnObserveListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnObserveListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnObserveListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnObserveListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnObserveListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnObserveListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} + +jweak JniOnObserveListener::getJWListener() +{ + return this->m_jwListener; +} diff --git a/android/android_api/base/jni/JniOnObserveListener.h b/android/android_api/base/jni/JniOnObserveListener.h index 38f9aae..3fc478d 100644 --- a/android/android_api/base/jni/JniOnObserveListener.h +++ b/android/android_api/base/jni/JniOnObserveListener.h @@ -27,18 +27,28 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnObserveListener { public: JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcResource* owner); +#ifdef WITH_CLOUD + JniOnObserveListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner); +#endif ~JniOnObserveListener(); void onObserveCallback(const HeaderOptions headerOptions, const OCRepresentation& rep, const int& eCode, const int& sequenceNumber); + jweak getJWListener(); private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnPlatformInfoListener.cpp b/android/android_api/base/jni/JniOnPlatformInfoListener.cpp index 03e2ed8..7a220bf 100644 --- a/android/android_api/base/jni/JniOnPlatformInfoListener.cpp +++ b/android/android_api/base/jni/JniOnPlatformInfoListener.cpp @@ -34,29 +34,41 @@ JniOnPlatformInfoListener::~JniOnPlatformInfoListener() LOGI("~JniOnPlatformInfoListener"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation& ocRepresentation) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { LOGI("Java onPlatformInfoListener object is already destroyed, quiting"); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -68,7 +80,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -77,7 +92,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onPlatformFound", "(Lorg/iotivity/base/OcRepresentation;)V"); @@ -85,7 +103,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -97,7 +118,10 @@ void JniOnPlatformInfoListener::foundPlatformCallback(const OC::OCRepresentation checkExAndRemoveListener(env); } - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnPlatformInfoListener::checkExAndRemoveListener(JNIEnv* env) diff --git a/android/android_api/base/jni/JniOnPostListener.cpp b/android/android_api/base/jni/JniOnPostListener.cpp index 575748e..62f6e96 100644 --- a/android/android_api/base/jni/JniOnPostListener.cpp +++ b/android/android_api/base/jni/JniOnPostListener.cpp @@ -23,64 +23,101 @@ #include "JniOcResource.h" #include "JniOcRepresentation.h" #include "JniUtils.h" +#ifdef WITH_CLOUD +#include "JniOcAccountManager.h" +#endif JniOnPostListener::JniOnPostListener(JNIEnv *env, jobject jListener, JniOcResource* owner) : m_ownerResource(owner) { m_jwListener = env->NewWeakGlobalRef(jListener); +#ifdef WITH_CLOUD + m_ownerAccountManager = nullptr; +#endif } +#ifdef WITH_CLOUD +JniOnPostListener::JniOnPostListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner) + : m_ownerAccountManager(owner) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_ownerResource = nullptr; +} +#endif + JniOnPostListener::~JniOnPostListener() { if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions, const OCRepresentation& ocRepresentation, const int eCode) { - jint envRet; + jint envRet = JNI_ERR; JNIEnv *env = GetJNIEnv(envRet); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jclass clsL = env->GetObjectClass(jListener); if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } - if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode) + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode && + OC_STACK_RESOURCE_CHANGED != eCode) { jobject ex = GetOcException(eCode, "stack error in onPostCallback"); if (!ex) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onPostFailed", "(Ljava/lang/Throwable;)V"); if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, ex); @@ -91,7 +128,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions, if (!jHeaderOptionList) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -103,7 +143,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions, { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -112,7 +155,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions, if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -125,7 +171,10 @@ void JniOnPostListener::onPostCallback(const HeaderOptions& headerOptions, } checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } void JniOnPostListener::checkExAndRemoveListener(JNIEnv* env) @@ -134,11 +183,33 @@ void JniOnPostListener::checkExAndRemoveListener(JNIEnv* env) { jthrowable ex = env->ExceptionOccurred(); env->ExceptionClear(); +#ifndef WITH_CLOUD m_ownerResource->removeOnPostListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnPostListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnPostListener(env, m_jwListener); + } +#endif env->Throw((jthrowable)ex); } else { +#ifndef WITH_CLOUD m_ownerResource->removeOnPostListener(env, m_jwListener); +#else + if (nullptr != m_ownerResource) + { + m_ownerResource->removeOnPostListener(env, m_jwListener); + } + if (nullptr != m_ownerAccountManager) + { + m_ownerAccountManager->removeOnPostListener(env, m_jwListener); + } +#endif } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnPostListener.h b/android/android_api/base/jni/JniOnPostListener.h index 5dfe525..bf3387c 100644 --- a/android/android_api/base/jni/JniOnPostListener.h +++ b/android/android_api/base/jni/JniOnPostListener.h @@ -27,11 +27,17 @@ using namespace OC; class JniOcResource; +#ifdef WITH_CLOUD +class JniOcAccountManager; +#endif class JniOnPostListener { public: JniOnPostListener(JNIEnv *env, jobject jListener, JniOcResource* owner); +#ifdef WITH_CLOUD + JniOnPostListener(JNIEnv *env, jobject jListener, JniOcAccountManager* owner); +#endif ~JniOnPostListener(); void onPostCallback(const HeaderOptions& headerOptions, const OCRepresentation& rep, const int eCode); @@ -39,7 +45,10 @@ public: private: jweak m_jwListener; JniOcResource* m_ownerResource; +#ifdef WITH_CLOUD + JniOcAccountManager* m_ownerAccountManager; +#endif void checkExAndRemoveListener(JNIEnv *env); }; -#endif \ No newline at end of file +#endif diff --git a/android/android_api/base/jni/JniOnPresenceListener.cpp b/android/android_api/base/jni/JniOnPresenceListener.cpp index 023c61d..9223250 100644 --- a/android/android_api/base/jni/JniOnPresenceListener.cpp +++ b/android/android_api/base/jni/JniOnPresenceListener.cpp @@ -34,14 +34,20 @@ JniOnPresenceListener::~JniOnPresenceListener() LOGD("~JniOnPresenceListener"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } @@ -49,17 +55,26 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig const std::string& hostAddress) { LOGI("JniOnPresenceListener::onPresenceCallback"); - if (!m_jwListener) return; + if (!m_jwListener) + { + return; + } - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } if (OC_STACK_OK != result && OC_STACK_PRESENCE_STOPPED != result && OC_STACK_PRESENCE_TIMEOUT != result && OC_STACK_PRESENCE_DO_NOT_HANDLE != result) { ThrowOcException(result, "onPresenceCallback: stack failure"); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -67,7 +82,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig if (enumField.empty()) { ThrowOcException(JNI_INVALID_VALUE, "Unexpected OCStackResult value"); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -76,7 +94,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig if (!jPresenceStatus) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -84,7 +105,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -92,7 +116,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onPresence", @@ -100,7 +127,10 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -111,7 +141,11 @@ void JniOnPresenceListener::onPresenceCallback(OCStackResult result, const unsig LOGE("Java exception is thrown"); checkExAndRemoveListener(env); } - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnPresenceListener::checkExAndRemoveListener(JNIEnv* env) @@ -132,4 +166,4 @@ void JniOnPresenceListener::checkExAndRemoveListener(JNIEnv* env) jweak JniOnPresenceListener::getJWListener() { return this->m_jwListener; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnPublishResourceListener.cpp b/android/android_api/base/jni/JniOnPublishResourceListener.cpp new file mode 100644 index 0000000..4adc14a --- /dev/null +++ b/android/android_api/base/jni/JniOnPublishResourceListener.cpp @@ -0,0 +1,158 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOnPublishResourceListener.h" + +JniOnPublishResourceListener::JniOnPublishResourceListener(JNIEnv *env, jobject jListener, + RemoveListenerCallback removeListenerCallback) +{ + m_jwListener = env->NewWeakGlobalRef(jListener); + m_removeListenerCallback = removeListenerCallback; +} + +JniOnPublishResourceListener::~JniOnPublishResourceListener() +{ + LOGI("~JniOnPublishResourceListener()"); + if (m_jwListener) + { + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + env->DeleteWeakGlobalRef(m_jwListener); + m_jwListener = nullptr; + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + } +} + +void JniOnPublishResourceListener::onPublishResourceCallback( + const OCRepresentation& ocRepresentation, + const int eCode) +{ + jint envRet = JNI_ERR; + JNIEnv *env = GetJNIEnv(envRet); + if (nullptr == env) + { + return; + } + + if (nullptr == m_jwListener) + { + LOGE("listener is not available"); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + jclass clsL = env->GetObjectClass(jListener); + + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CREATED != eCode + && OC_STACK_RESOURCE_DELETED != eCode && OC_STACK_CONTINUE != eCode + && OC_STACK_RESOURCE_CHANGED != eCode) + { + jobject ex = GetOcException(eCode, "stack error in onPublishResourceCallback"); + if (!ex) + { + goto CLEANUP; + } + jmethodID midL = env->GetMethodID(clsL, "onPublishResourceFailed", + "(Ljava/lang/Throwable;)V"); + if (!midL) + { + goto CLEANUP; + } + env->CallVoidMethod(jListener, midL, ex); + } + else + { + OCRepresentation* rep = new OCRepresentation(ocRepresentation); + jlong handle = reinterpret_cast(rep); + jobject jRepresentation = env->NewObject(g_cls_OcRepresentation, + g_mid_OcRepresentation_N_ctor_bool, + handle, true); + if (!jRepresentation) + { + delete rep; + goto CLEANUP; + } + + jmethodID midL = env->GetMethodID(clsL, "onPublishResourceCompleted", + "(Lorg/iotivity/base/OcRepresentation;)V"); + if (!midL) + { + delete rep; + goto CLEANUP; + } + env->CallVoidMethod(jListener, midL, jRepresentation); + if (env->ExceptionCheck()) + { + LOGE("Java exception is thrown"); + delete rep; + } + } + +CLEANUP: + checkExAndRemoveListener(env); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnPublishResourceListener::checkExAndRemoveListener(JNIEnv* env) +{ + if (env->ExceptionCheck()) + { + jthrowable ex = env->ExceptionOccurred(); + env->ExceptionClear(); + m_removeListenerCallback(env, m_jwListener); + env->Throw((jthrowable)ex); + } + else + { + m_removeListenerCallback(env, m_jwListener); + } +} diff --git a/android/android_api/base/jni/JniOnPublishResourceListener.h b/android/android_api/base/jni/JniOnPublishResourceListener.h new file mode 100644 index 0000000..a147ba2 --- /dev/null +++ b/android/android_api/base/jni/JniOnPublishResourceListener.h @@ -0,0 +1,40 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ +#include "JniOcStack.h" + +#ifndef _Included_org_iotivity_base_OcPlatform_OnPublishResourceListener +#define _Included_org_iotivity_base_OcPlatform_OnPublishResourceListener + +using namespace OC; + +class JniOnPublishResourceListener +{ +public: + JniOnPublishResourceListener(JNIEnv *env, jobject listener, + RemoveListenerCallback removeListenerCallback); + ~JniOnPublishResourceListener(); + void onPublishResourceCallback(const OCRepresentation& rep, const int eCode); +private: + RemoveListenerCallback m_removeListenerCallback; + jweak m_jwListener; + void checkExAndRemoveListener(JNIEnv* env); +}; + +#endif diff --git a/android/android_api/base/jni/JniOnPutListener.cpp b/android/android_api/base/jni/JniOnPutListener.cpp index 7f375b9..5e2dd4a 100644 --- a/android/android_api/base/jni/JniOnPutListener.cpp +++ b/android/android_api/base/jni/JniOnPutListener.cpp @@ -34,53 +34,74 @@ JniOnPutListener::~JniOnPutListener() { if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions, const OCRepresentation& ocRepresentation, const int eCode) { - jint envRet; + jint envRet = JNI_ERR; JNIEnv *env = GetJNIEnv(envRet); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jclass clsL = env->GetObjectClass(jListener); if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } - if (OC_STACK_OK != eCode) + if (OC_STACK_OK != eCode && OC_STACK_RESOURCE_CHANGED != eCode) { jobject ex = GetOcException(eCode, "stack error in onPutCallback"); if (!ex) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onPutFailed", "(Ljava/lang/Throwable;)V"); if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, ex); @@ -91,7 +112,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions, if (!jHeaderOptionList) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -103,7 +127,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions, { delete rep; checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -113,7 +140,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions, if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -126,7 +156,10 @@ void JniOnPutListener::onPutCallback(const HeaderOptions& headerOptions, } checkExAndRemoveListener(env); - if (JNI_EDETACHED == envRet) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == envRet) + { + g_jvm->DetachCurrentThread(); + } } void JniOnPutListener::checkExAndRemoveListener(JNIEnv* env) @@ -142,4 +175,4 @@ void JniOnPutListener::checkExAndRemoveListener(JNIEnv* env) { m_ownerResource->removeOnPutListener(env, m_jwListener); } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnResourceFoundListener.cpp b/android/android_api/base/jni/JniOnResourceFoundListener.cpp index cdc68d3..cbbbbb0 100644 --- a/android/android_api/base/jni/JniOnResourceFoundListener.cpp +++ b/android/android_api/base/jni/JniOnResourceFoundListener.cpp @@ -34,34 +34,50 @@ JniOnResourceFoundListener::~JniOnResourceFoundListener() LOGI("~JniOnResourceFoundListener()"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); m_jwListener = nullptr; - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptr resource) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (nullptr == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jobject jResource = env->NewObject(g_cls_OcResource, g_mid_OcResource_ctor); if (!jResource) { + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -70,24 +86,40 @@ void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptrExceptionCheck()) { delete jniOcResource; + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jclass clsL = env->GetObjectClass(jListener); if (!clsL) { delete jniOcResource; + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "onResourceFound", "(Lorg/iotivity/base/OcResource;)V"); if (!midL) { delete jniOcResource; + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, jResource); @@ -95,12 +127,87 @@ void JniOnResourceFoundListener::foundResourceCallback(std::shared_ptrDeleteLocalRef(clsL); + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + env->DeleteLocalRef(clsL); + env->DeleteLocalRef(jResource); + env->DeleteLocalRef(jListener); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } +} + +void JniOnResourceFoundListener::findResourceErrorCallback(const std::string& uri, const int eCode) +{ + LOGI("findResource error callback value : %d", eCode); + jint ret = JNI_ERR; + JNIEnv *env = GetJNIEnv(ret); + if (nullptr == env) + { + return; + } + + jobject jListener = env->NewLocalRef(m_jwListener); + if (!jListener) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jclass clsL = env->GetObjectClass(jListener); + if (!clsL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + + jobject ex = GetOcException(eCode, "stack error in onFindResourceErrorCallback"); + if (!ex) + { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + + jmethodID midL = env->GetMethodID(clsL, "onFindResourceFailed", + "(Ljava/lang/Throwable;Ljava/lang/String;)V"); + if (!midL) + { + checkExAndRemoveListener(env); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; + } + env->CallVoidMethod(jListener, midL, ex, env->NewStringUTF(uri.c_str())); + + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniOnResourceFoundListener::checkExAndRemoveListener(JNIEnv* env) @@ -116,4 +223,4 @@ void JniOnResourceFoundListener::checkExAndRemoveListener(JNIEnv* env) { m_removeListenerCallback(env, m_jwListener); } -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniOnResourceFoundListener.h b/android/android_api/base/jni/JniOnResourceFoundListener.h index 909cc4e..bac7d45 100644 --- a/android/android_api/base/jni/JniOnResourceFoundListener.h +++ b/android/android_api/base/jni/JniOnResourceFoundListener.h @@ -33,6 +33,7 @@ public: ~JniOnResourceFoundListener(); void foundResourceCallback(std::shared_ptr resource); + void findResourceErrorCallback(const std::string& uri, const int eCode); private: RemoveListenerCallback m_removeListenerCallback; diff --git a/android/android_api/base/jni/JniPinCheckListener.cpp b/android/android_api/base/jni/JniPinCheckListener.cpp index 55cdfba..12377d1 100644 --- a/android/android_api/base/jni/JniPinCheckListener.cpp +++ b/android/android_api/base/jni/JniPinCheckListener.cpp @@ -32,40 +32,57 @@ JniPinCheckListener::~JniPinCheckListener() LOGI("~JniPinCheckListener()"); if (m_jListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (NULL == env) return; + if (nullptr == env) + { + return; + } env->DeleteGlobalRef(m_jListener); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize) { - jint ret; - + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (NULL == env) return; + if (nullptr == env) + { + return; + } jclass clsL = env->GetObjectClass(m_jListener); if (!clsL) { - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jmethodID midL = env->GetMethodID(clsL, "pinCallbackListener", "()Ljava/lang/String;"); if (!midL) { - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } jstring jpin = (jstring)env->CallObjectMethod(m_jListener, midL); if (env->ExceptionCheck()) { LOGE("Java exception is thrown"); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -73,5 +90,8 @@ void JniPinCheckListener::PinCallback(char *pinBuf, size_t bufSize) OICStrcpy(pinBuf, bufSize, str); env->ReleaseStringUTFChars(jpin, str); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } diff --git a/android/android_api/base/jni/JniProvisionResultListner.cpp b/android/android_api/base/jni/JniProvisionResultListner.cpp index a600e64..a25f015 100644 --- a/android/android_api/base/jni/JniProvisionResultListner.cpp +++ b/android/android_api/base/jni/JniProvisionResultListner.cpp @@ -35,26 +35,38 @@ JniProvisionResultListner::~JniProvisionResultListner() LOGI("~JniProvisionResultListner()"); if (m_jwListener) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (NULL == env) return; + if (nullptr == env) + { + return; + } env->DeleteWeakGlobalRef(m_jwListener); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } } void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, int hasError, ListenerFunc func) { - jint ret; + jint ret = JNI_ERR; JNIEnv *env = GetJNIEnv(ret); - if (NULL == env) return; + if (nullptr == env) + { + return; + } jobject jListener = env->NewLocalRef(m_jwListener); if (!jListener) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -63,7 +75,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, if (!clsL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -72,7 +87,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, if (!jResultList) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } @@ -94,6 +112,11 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, calledFunc = "provisionCredentialsListener"; } break; + case ListenerFunc::PROVISIONTRUSTCERTCHAIN: + { + calledFunc = "provisionTrustCertChainListener"; + } + break; case ListenerFunc::UNLINKDEVICES: { calledFunc = "unlinkDevicesListener"; @@ -117,7 +140,11 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, default: { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } + return; } return; } @@ -126,7 +153,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, if (!midL) { checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } return; } env->CallVoidMethod(jListener, midL, jResultList, (jint)hasError); @@ -136,7 +166,10 @@ void JniProvisionResultListner::ProvisionResultCallback(PMResultList_t *result, } checkExAndRemoveListener(env); - if (JNI_EDETACHED == ret) g_jvm->DetachCurrentThread(); + if (JNI_EDETACHED == ret) + { + g_jvm->DetachCurrentThread(); + } } void JniProvisionResultListner::checkExAndRemoveListener(JNIEnv* env) diff --git a/android/android_api/base/jni/JniProvisionResultListner.h b/android/android_api/base/jni/JniProvisionResultListner.h index 8bf5242..59a0945 100644 --- a/android/android_api/base/jni/JniProvisionResultListner.h +++ b/android/android_api/base/jni/JniProvisionResultListner.h @@ -33,6 +33,7 @@ enum class ListenerFunc OWNERSHIPTRANSFER = 1, PROVISIONACL, PROVISIONCREDENTIALS, + PROVISIONTRUSTCERTCHAIN, UNLINKDEVICES, REMOVEDEVICE, PROVISIONPAIRWISEDEVICES, diff --git a/android/android_api/base/jni/JniSecureUtils.cpp b/android/android_api/base/jni/JniSecureUtils.cpp index 718bb4a..e18de5b 100644 --- a/android/android_api/base/jni/JniSecureUtils.cpp +++ b/android/android_api/base/jni/JniSecureUtils.cpp @@ -150,45 +150,6 @@ jobject JniSecureUtils::convertUUIDVectorToJavaStrList(JNIEnv *env, UuidList_t & return jList; } -static void freeValidities(OicSecValidity_t *head) -{ - OicSecValidity_t *tmp = head; - while(tmp != NULL) - { - head = head->next; - free(tmp->recurrences); - free(tmp); - tmp = head; - } -} - -static void freeResources(OicSecRsrc_t *head) -{ - OicSecRsrc_t *tmp = head; - while(tmp != NULL) - { - head = head->next; - free(tmp->types); - free(tmp->interfaces); - free(tmp); - tmp = head; - } -} - -void JniSecureUtils::FreeACLList(OicSecAcl_t *acl) -{ - if (acl) - { - if (acl->aces) - { - freeResources(acl->aces->resources); - freeValidities(acl->aces->validities); - OICFree(acl->aces); - } - OICFree(acl); - } -} - static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject) { jstring jData; @@ -204,38 +165,21 @@ static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject) for (int i = 0 ; i < nr_validities; i++) { OicSecValidity_t *tmp = (OicSecValidity_t*)OICCalloc(1, sizeof(OicSecValidity_t)); - if (NULL == tmp) - { - LOGE("Failed to allocate memory"); - freeValidities(valHead); - return nullptr; - } - jobject element = env->GetObjectArrayElement(valList, i); if (!element || env->ExceptionCheck()) { - OICFree(tmp); - freeValidities(valHead); return nullptr; } jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_validity_get_getPeriod); if (!jData || env->ExceptionCheck()) { - OICFree(tmp); - freeValidities(valHead); return nullptr; } tmp->period = (char*)env->GetStringUTFChars(jData, 0); jint jrecurrenceLen = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_validity_get_recurrenceLen); - if (env->ExceptionCheck()) - { - OICFree(tmp); - freeValidities(valHead); - return nullptr; - } tmp->recurrenceLen = (int)jrecurrenceLen; if (jrecurrenceLen > 0) @@ -249,9 +193,6 @@ static OicSecValidity_t* getValiditiesList(JNIEnv *env, jobject validityObject) jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_validity_get_recurrences, argv); if (!jData || env->ExceptionCheck()) { - OICFree(tmp->recurrences); - OICFree(tmp); - freeValidities(valHead); return nullptr; } tmp->recurrences[i] = (char*)env->GetStringUTFChars(jData, 0); @@ -289,24 +230,14 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) for (int i = 0 ; i < nr_resc; i++) { OicSecRsrc_t *tmp = (OicSecRsrc_t*)OICCalloc(1, sizeof(OicSecRsrc_t)); - if (NULL == tmp) - { - LOGE("Failed to allocate memory"); - freeResources(rescHead); - return nullptr; - } jobject element = env->GetObjectArrayElement(rescList, i); if (!element || env->ExceptionCheck()) { - OICFree(tmp); - freeResources(rescHead); return nullptr; } jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_href); if (!jData || env->ExceptionCheck()) { - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->href = (char*)env->GetStringUTFChars(jData, 0); @@ -314,29 +245,16 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) jData = (jstring)env->CallObjectMethod(element, g_mid_OcOicSecAcl_resr_get_rel); if (!jData || env->ExceptionCheck()) { - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->rel = (char*)env->GetStringUTFChars(jData, 0); jint len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_typeLen); - if (env->ExceptionCheck()) - { - OICFree(tmp); - freeResources(rescHead); - return nullptr; - } tmp->typeLen = (int)len; if (len > 0) { jvalue argv[1]; tmp->types = (char**)OICCalloc(len, sizeof(char*)); - if (NULL == tmp->types) - { - LOGE("Failed to allocate memory"); - return nullptr; - } for (int i = 0 ; i < len; i++) { @@ -344,9 +262,6 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_resr_get_types, argv); if (!jData || env->ExceptionCheck()) { - OICFree(tmp->types); - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->types[i] = (char*)env->GetStringUTFChars(jData, 0); @@ -354,13 +269,6 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) } len = (jint) env->CallIntMethod(element, g_mid_OcOicSecAcl_resr_get_interfaceLen); - if (env->ExceptionCheck()) - { - OICFree(tmp->types); - OICFree(tmp); - freeResources(rescHead); - return nullptr; - } tmp->interfaceLen = len; if (len > 0) { @@ -373,9 +281,6 @@ static OicSecRsrc_t * getResourcesList(JNIEnv *env, jobject resourceObject) jData = (jstring)env->CallObjectMethodA(element, g_mid_OcOicSecAcl_resr_get_interfaces, argv); if (!jData || env->ExceptionCheck()) { - OICFree(tmp->types); - OICFree(tmp); - freeResources(rescHead); return nullptr; } tmp->interfaces[i] = (char*)env->GetStringUTFChars(jData, 0); @@ -409,10 +314,6 @@ OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, Oic } char *str = (char*) env->GetStringUTFChars(jData, 0); - if (!str) - { - return OC_STACK_ERROR; - } if (OC_STACK_OK == ConvertStrToUuid(str, &acl->rownerID)) { env->ReleaseStringUTFChars(jData, str); @@ -450,11 +351,6 @@ OCStackResult JniSecureUtils::convertJavaACLToOCAcl(JNIEnv *env, jobject in, Oic } str = (char*) env->GetStringUTFChars(jData, 0); - - if (!str) - { - return OC_STACK_ERROR; - } if (OC_STACK_OK == ConvertStrToUuid(str, &tmp->subjectuuid)) { env->ReleaseStringUTFChars(jData, str); diff --git a/android/android_api/base/jni/JniSecureUtils.h b/android/android_api/base/jni/JniSecureUtils.h index c16457d..c7226a5 100644 --- a/android/android_api/base/jni/JniSecureUtils.h +++ b/android/android_api/base/jni/JniSecureUtils.h @@ -29,7 +29,6 @@ class JniSecureUtils static std::string convertUUIDtoStr(OicUuid_t uuid); static void convertStrToUUID(char *str, OicUuid_t &uuid); public: - static void FreeACLList(OicSecAcl_t *acl); static jobject convertProvisionresultVectorToJavaList(JNIEnv *, const OC::PMResultList_t *); static jobjectArray convertDeviceVectorToJavaArray(JNIEnv *env, diff --git a/android/android_api/base/jni/JniUtils.cpp b/android/android_api/base/jni/JniUtils.cpp index 4e3f276..3ee3ada 100644 --- a/android/android_api/base/jni/JniUtils.cpp +++ b/android/android_api/base/jni/JniUtils.cpp @@ -26,13 +26,22 @@ jobject JniUtils::convertStrVectorToJavaStrList(JNIEnv *env, std::vector &vector) { jobject jList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor); - if (!jList) return nullptr; + if (!jList) + { + return nullptr; + } for (size_t i = 0; i < vector.size(); ++i) { jstring jStr = env->NewStringUTF(vector[i].c_str()); - if (!jStr) return nullptr; + if (!jStr) + { + return nullptr; + } env->CallBooleanMethod(jList, g_mid_LinkedList_add_object, jStr); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jStr); } return jList; @@ -40,15 +49,24 @@ jobject JniUtils::convertStrVectorToJavaStrList(JNIEnv *env, std::vector &vector) { - if (!jStrArr) return; + if (!jStrArr) + { + return; + } jsize len = env->GetArrayLength(jStrArr); for (jsize i = 0; i < len; ++i) { jstring jStr = (jstring)env->GetObjectArrayElement(jStrArr, i); - if (!jStr) return; + if (!jStr) + { + return; + } vector.push_back(env->GetStringUTFChars(jStr, nullptr)); - if (env->ExceptionCheck()) return; + if (env->ExceptionCheck()) + { + return; + } env->DeleteLocalRef(jStr); } } @@ -56,12 +74,19 @@ void JniUtils::convertJavaStrArrToStrVector(JNIEnv *env, jobjectArray jStrArr, s void JniUtils::convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHeaderOptions, OC::HeaderOptions &headerOptions) { - if (!jHeaderOptions) return; + if (!jHeaderOptions) + { + return; + } + jsize len = env->GetArrayLength(jHeaderOptions); for (jsize i = 0; i < len; ++i) { jobject header = env->GetObjectArrayElement(jHeaderOptions, i); - if (!header) return; + if (!header) + { + return; + } jint jId = env->CallIntMethod(header, g_mid_OcHeaderOption_get_id); jstring jData = (jstring)env->CallObjectMethod(header, g_mid_OcHeaderOption_get_data); OC::HeaderOption::OCHeaderOption hopt( @@ -70,7 +95,10 @@ void JniUtils::convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHe headerOptions.push_back(hopt); - if (env->ExceptionCheck()) return; + if (env->ExceptionCheck()) + { + return; + } env->DeleteLocalRef(header); env->DeleteLocalRef(jData); } @@ -79,7 +107,10 @@ void JniUtils::convertJavaHeaderOptionsArrToVector(JNIEnv *env, jobjectArray jHe jobject JniUtils::convertHeaderOptionsVectorToJavaList(JNIEnv *env, const OC::HeaderOptions& headerOptions) { jobject jHeaderOptionList = env->NewObject(g_cls_LinkedList, g_mid_LinkedList_ctor); - if (!jHeaderOptionList) return nullptr; + if (!jHeaderOptionList) + { + return nullptr; + } for (size_t i = 0; i < headerOptions.size(); ++i) { @@ -89,10 +120,16 @@ jobject JniUtils::convertHeaderOptionsVectorToJavaList(JNIEnv *env, const OC::He static_cast(headerOptions[i].getOptionID()), env->NewStringUTF(headerOptions[i].getOptionData().c_str()) ); - if (!jHeaderOption) return nullptr; + if (!jHeaderOption) + { + return nullptr; + } env->CallBooleanMethod(jHeaderOptionList, g_mid_LinkedList_add_object, jHeaderOption); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jHeaderOption); } @@ -101,25 +138,43 @@ jobject JniUtils::convertHeaderOptionsVectorToJavaList(JNIEnv *env, const OC::He void JniUtils::convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap, OC::QueryParamsMap &map) { - if (!hashMap) return; + if (!hashMap) + { + return; + } jobject jEntrySet = env->CallObjectMethod(hashMap, g_mid_Map_entrySet); jobject jIterator = env->CallObjectMethod(jEntrySet, g_mid_Set_iterator); - if (!jEntrySet || !jIterator || env->ExceptionCheck()) return; + if (!jEntrySet || !jIterator || env->ExceptionCheck()) + { + return; + } while (env->CallBooleanMethod(jIterator, g_mid_Iterator_hasNext)) { jobject jEntry = env->CallObjectMethod(jIterator, g_mid_Iterator_next); - if (!jEntry) return; + if (!jEntry) + { + return; + } jstring jKey = (jstring)env->CallObjectMethod(jEntry, g_mid_MapEntry_getKey); - if (!jKey) return; + if (!jKey) + { + return; + } jstring jValue = (jstring)env->CallObjectMethod(jEntry, g_mid_MapEntry_getValue); - if (!jValue) return; + if (!jValue) + { + return; + } map.insert(std::make_pair(env->GetStringUTFChars(jKey, nullptr), env->GetStringUTFChars(jValue, nullptr))); - if (env->ExceptionCheck()) return; + if (env->ExceptionCheck()) + { + return; + } env->DeleteLocalRef(jEntry); env->DeleteLocalRef(jKey); env->DeleteLocalRef(jValue); @@ -129,7 +184,10 @@ void JniUtils::convertJavaMapToQueryParamsMap(JNIEnv *env, jobject hashMap, OC:: jobject JniUtils::convertQueryParamsMapToJavaMap(JNIEnv *env, const OC::QueryParamsMap &map) { jobject hashMap = env->NewObject(g_cls_HashMap, g_mid_HashMap_ctor); - if (!hashMap) return nullptr; + if (!hashMap) + { + return nullptr; + } for (auto it = map.begin(); it != map.end(); ++it) { @@ -140,7 +198,10 @@ jobject JniUtils::convertQueryParamsMapToJavaMap(JNIEnv *env, const OC::QueryPar g_mid_HashMap_put, env->NewStringUTF(key.c_str()), env->NewStringUTF(value.c_str())); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } } return hashMap; @@ -150,16 +211,25 @@ void JniUtils::convertJavaRepresentationArrToVector(JNIEnv *env, jobjectArray jRepresentationArray, std::vector& representationVector) { - if (!jRepresentationArray) return; + if (!jRepresentationArray) + { + return; + } jsize len = env->GetArrayLength(jRepresentationArray); for (jsize i = 0; i < len; ++i) { jobject jRep = env->GetObjectArrayElement(jRepresentationArray, i); - if (!jRep) return; + if (!jRep) + { + return; + } OC::OCRepresentation *rep = JniOcRepresentation::getOCRepresentationPtr(env, jRep); representationVector.push_back(*rep); - if (env->ExceptionCheck()) return; + if (env->ExceptionCheck()) + { + return; + } env->DeleteLocalRef(jRep); } } @@ -169,7 +239,10 @@ jobjectArray JniUtils::convertRepresentationVectorToJavaArray(JNIEnv *env, { jsize len = static_cast(representationVector.size()); jobjectArray repArr = env->NewObjectArray(len, g_cls_OcRepresentation, nullptr); - if (!repArr) return nullptr; + if (!repArr) + { + return nullptr; + } for (jsize i = 0; i < len; ++i) { OCRepresentation* rep = new OCRepresentation(representationVector[i]); @@ -182,9 +255,12 @@ jobjectArray JniUtils::convertRepresentationVectorToJavaArray(JNIEnv *env, return nullptr; } env->SetObjectArrayElement(repArr, i, jRepresentation); - if (env->ExceptionCheck()) return nullptr; + if (env->ExceptionCheck()) + { + return nullptr; + } env->DeleteLocalRef(jRepresentation); } return repArr; -} \ No newline at end of file +} diff --git a/android/android_api/base/jni/JniUtils.h b/android/android_api/base/jni/JniUtils.h index fcfa2a1..5297293 100644 --- a/android/android_api/base/jni/JniUtils.h +++ b/android/android_api/base/jni/JniUtils.h @@ -47,84 +47,103 @@ public: static OC::ServiceType getServiceType(JNIEnv *env, int type) { - switch (type) { - case 0: - return OC::ServiceType::InProc; - case 1: - return OC::ServiceType::OutOfProc; - default: - ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected service type"); - return OC::ServiceType::OutOfProc; + switch (type) + { + case 0: + return OC::ServiceType::InProc; + case 1: + return OC::ServiceType::OutOfProc; + default: + ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected service type"); + return OC::ServiceType::OutOfProc; }; } static OC::ModeType getModeType(JNIEnv *env, int type) { - switch (type) { - case 0: - return OC::ModeType::Server; - case 1: - return OC::ModeType::Client; - case 2: - return OC::ModeType::Both; - case 3: - return OC::ModeType::Gateway; - default: - ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected mode type"); - return OC::ModeType::Both; + switch (type) + { + case 0: + return OC::ModeType::Server; + case 1: + return OC::ModeType::Client; + case 2: + return OC::ModeType::Both; + case 3: + return OC::ModeType::Gateway; + default: + ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected mode type"); + return OC::ModeType::Both; }; } static OC::QualityOfService getQOS(JNIEnv *env, int type) { - switch (type) { - case 0: - return OC::QualityOfService::LowQos; - case 1: - return OC::QualityOfService::MidQos; - case 2: - return OC::QualityOfService::HighQos; - case 3: - return OC::QualityOfService::NaQos; - default: - ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected quality of service"); - return OC::QualityOfService::NaQos; + switch (type) + { + case 0: + return OC::QualityOfService::LowQos; + case 1: + return OC::QualityOfService::MidQos; + case 2: + return OC::QualityOfService::HighQos; + case 3: + return OC::QualityOfService::NaQos; + default: + ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected quality of service"); + return OC::QualityOfService::NaQos; }; } static OC::ObserveType getObserveType(JNIEnv *env, int type) { - switch (type) { - case 0: - return OC::ObserveType::Observe; - case 1: - return OC::ObserveType::ObserveAll; - default: - ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected observe type"); - return OC::ObserveType::ObserveAll; + switch (type) + { + case 0: + return OC::ObserveType::Observe; + case 1: + return OC::ObserveType::ObserveAll; + default: + ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected observe type"); + return OC::ObserveType::ObserveAll; }; } - +#ifdef WITH_CLOUD + static OC::AclGroupType getAclGroupType(JNIEnv *env, int type) + { + switch (type) + { + case 0: + return OC::AclGroupType::PUBLIC; + case 1: + return OC::AclGroupType::PRIVATE; + default: + ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected acl group type"); + return OC::AclGroupType::PUBLIC; + }; + } +#endif static OCEntityHandlerResult getOCEntityHandlerResult(JNIEnv *env, int type) { - switch (type) { - case 0: - return OCEntityHandlerResult::OC_EH_OK; - case 1: - return OCEntityHandlerResult::OC_EH_ERROR; - case 2: - return OCEntityHandlerResult::OC_EH_RESOURCE_CREATED; - case 3: - return OCEntityHandlerResult::OC_EH_RESOURCE_DELETED; - case 4: - return OCEntityHandlerResult::OC_EH_SLOW; - case 5: - return OCEntityHandlerResult::OC_EH_FORBIDDEN; - case 6: - return OCEntityHandlerResult::OC_EH_RESOURCE_NOT_FOUND; - default: - ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected OCEntityHandlerResult"); - return OCEntityHandlerResult::OC_EH_ERROR; + switch (type) + { + case 0: + return OCEntityHandlerResult::OC_EH_OK; + case 1: + return OCEntityHandlerResult::OC_EH_ERROR; + case 2: + return OCEntityHandlerResult::OC_EH_RESOURCE_CREATED; + case 3: + return OCEntityHandlerResult::OC_EH_RESOURCE_DELETED; + case 4: + return OCEntityHandlerResult::OC_EH_SLOW; + case 5: + return OCEntityHandlerResult::OC_EH_FORBIDDEN; + case 6: + return OCEntityHandlerResult::OC_EH_RESOURCE_NOT_FOUND; + default: + ThrowOcException(OC_STACK_INVALID_PARAM, "Unexpected OCEntityHandlerResult"); + return OCEntityHandlerResult::OC_EH_ERROR; }; } @@ -132,106 +151,108 @@ public: { switch (result) { - /** Success status code - START HERE.*/ - case OC_STACK_OK: - return "OK"; - case OC_STACK_RESOURCE_CREATED: - return "RESOURCE_CREATED"; - case OC_STACK_RESOURCE_DELETED: - return "RESOURCE_DELETED"; - case OC_STACK_CONTINUE: - return "CONTINUE"; - /* Error status code - START HERE */ - case OC_STACK_INVALID_URI: - return "INVALID_URI"; - case OC_STACK_INVALID_QUERY: - return "INVALID_QUERY"; - case OC_STACK_INVALID_IP: - return "INVALID_IP"; - case OC_STACK_INVALID_PORT: - return "INVALID_PORT"; - case OC_STACK_INVALID_CALLBACK: - return "INVALID_CALLBACK"; - case OC_STACK_INVALID_METHOD: - return "INVALID_METHOD"; - /** Invalid parameter.*/ - case OC_STACK_INVALID_PARAM: - return "INVALID_PARAM"; - case OC_STACK_INVALID_OBSERVE_PARAM: - return "INVALID_OBSERVE_PARAM"; - case OC_STACK_NO_MEMORY: - return "NO_MEMORY"; - case OC_STACK_COMM_ERROR: - return "COMM_ERROR"; - case OC_STACK_TIMEOUT: - return "TIMEOUT"; - case OC_STACK_ADAPTER_NOT_ENABLED: - return "ADAPTER_NOT_ENABLED"; - case OC_STACK_NOTIMPL: - return "NOTIMPL"; - /** Resource not found.*/ - case OC_STACK_NO_RESOURCE: - return "NO_RESOURCE"; - /** e.g: not supported method or interface.*/ - case OC_STACK_RESOURCE_ERROR: - return "RESOURCE_ERROR"; - case OC_STACK_SLOW_RESOURCE: - return "SLOW_RESOURCE"; - case OC_STACK_DUPLICATE_REQUEST: - return "DUPLICATE_REQUEST"; - /** Resource has no registered observers.*/ - case OC_STACK_NO_OBSERVERS: - return "NO_OBSERVERS"; - case OC_STACK_OBSERVER_NOT_FOUND: - return "OBSERVER_NOT_FOUND"; - case OC_STACK_VIRTUAL_DO_NOT_HANDLE: - return "VIRTUAL_DO_NOT_HANDLE"; - case OC_STACK_INVALID_OPTION: - return "INVALID_OPTION"; - /** The remote reply contained malformed data.*/ - case OC_STACK_MALFORMED_RESPONSE: - return "MALFORMED_RESPONSE"; - case OC_STACK_PERSISTENT_BUFFER_REQUIRED: - return "PERSISTENT_BUFFER_REQUIRED"; - case OC_STACK_INVALID_REQUEST_HANDLE: - return "INVALID_REQUEST_HANDLE"; - case OC_STACK_INVALID_DEVICE_INFO: - return "INVALID_DEVICE_INFO"; - case OC_STACK_INVALID_JSON: - return "INVALID_JSON"; - /** Request is not authorized by Resource Server. */ - case OC_STACK_UNAUTHORIZED_REQ: - return "UNAUTHORIZED_REQ"; - /** Error code from PDM */ - case OC_STACK_PDM_IS_NOT_INITIALIZED: - return "PDM_IS_NOT_INITIALIZED"; - case OC_STACK_DUPLICATE_UUID: - return "DUPLICATE_UUID"; - case OC_STACK_INCONSISTENT_DB: - return "INCONSISTENT_DB"; - /** Error code from OTM */ - case OC_STACK_AUTHENTICATION_FAILURE: - return "AUTHENTICATION_FAILURE"; - /** Insert all new error codes here!.*/ + /** Success status code - START HERE.*/ + case OC_STACK_OK: + return "OK"; + case OC_STACK_RESOURCE_CREATED: + return "RESOURCE_CREATED"; + case OC_STACK_RESOURCE_DELETED: + return "RESOURCE_DELETED"; + case OC_STACK_RESOURCE_CHANGED: + return "RESOURCE_CHANGED"; + case OC_STACK_CONTINUE: + return "CONTINUE"; + /* Error status code - START HERE */ + case OC_STACK_INVALID_URI: + return "INVALID_URI"; + case OC_STACK_INVALID_QUERY: + return "INVALID_QUERY"; + case OC_STACK_INVALID_IP: + return "INVALID_IP"; + case OC_STACK_INVALID_PORT: + return "INVALID_PORT"; + case OC_STACK_INVALID_CALLBACK: + return "INVALID_CALLBACK"; + case OC_STACK_INVALID_METHOD: + return "INVALID_METHOD"; + /** Invalid parameter.*/ + case OC_STACK_INVALID_PARAM: + return "INVALID_PARAM"; + case OC_STACK_INVALID_OBSERVE_PARAM: + return "INVALID_OBSERVE_PARAM"; + case OC_STACK_NO_MEMORY: + return "NO_MEMORY"; + case OC_STACK_COMM_ERROR: + return "COMM_ERROR"; + case OC_STACK_TIMEOUT: + return "TIMEOUT"; + case OC_STACK_ADAPTER_NOT_ENABLED: + return "ADAPTER_NOT_ENABLED"; + case OC_STACK_NOTIMPL: + return "NOTIMPL"; + /** Resource not found.*/ + case OC_STACK_NO_RESOURCE: + return "NO_RESOURCE"; + /** e.g: not supported method or interface.*/ + case OC_STACK_RESOURCE_ERROR: + return "RESOURCE_ERROR"; + case OC_STACK_SLOW_RESOURCE: + return "SLOW_RESOURCE"; + case OC_STACK_DUPLICATE_REQUEST: + return "DUPLICATE_REQUEST"; + /** Resource has no registered observers.*/ + case OC_STACK_NO_OBSERVERS: + return "NO_OBSERVERS"; + case OC_STACK_OBSERVER_NOT_FOUND: + return "OBSERVER_NOT_FOUND"; + case OC_STACK_VIRTUAL_DO_NOT_HANDLE: + return "VIRTUAL_DO_NOT_HANDLE"; + case OC_STACK_INVALID_OPTION: + return "INVALID_OPTION"; + /** The remote reply contained malformed data.*/ + case OC_STACK_MALFORMED_RESPONSE: + return "MALFORMED_RESPONSE"; + case OC_STACK_PERSISTENT_BUFFER_REQUIRED: + return "PERSISTENT_BUFFER_REQUIRED"; + case OC_STACK_INVALID_REQUEST_HANDLE: + return "INVALID_REQUEST_HANDLE"; + case OC_STACK_INVALID_DEVICE_INFO: + return "INVALID_DEVICE_INFO"; + case OC_STACK_INVALID_JSON: + return "INVALID_JSON"; + /** Request is not authorized by Resource Server. */ + case OC_STACK_UNAUTHORIZED_REQ: + return "UNAUTHORIZED_REQ"; + /** Error code from PDM */ + case OC_STACK_PDM_IS_NOT_INITIALIZED: + return "PDM_IS_NOT_INITIALIZED"; + case OC_STACK_DUPLICATE_UUID: + return "DUPLICATE_UUID"; + case OC_STACK_INCONSISTENT_DB: + return "INCONSISTENT_DB"; + /** Error code from OTM */ + case OC_STACK_AUTHENTICATION_FAILURE: + return "AUTHENTICATION_FAILURE"; + /** Insert all new error codes here!.*/ #ifdef WITH_PRESENCE - case OC_STACK_PRESENCE_STOPPED: - return "PRESENCE_STOPPED"; - case OC_STACK_PRESENCE_TIMEOUT: - return "PRESENCE_TIMEOUT"; - case OC_STACK_PRESENCE_DO_NOT_HANDLE: - return "PRESENCE_DO_NOT_HANDLE"; + case OC_STACK_PRESENCE_STOPPED: + return "PRESENCE_STOPPED"; + case OC_STACK_PRESENCE_TIMEOUT: + return "PRESENCE_TIMEOUT"; + case OC_STACK_PRESENCE_DO_NOT_HANDLE: + return "PRESENCE_DO_NOT_HANDLE"; #endif - case OC_STACK_ERROR: - return "ERROR"; + case OC_STACK_ERROR: + return "ERROR"; - case JNI_EXCEPTION: - return "JNI_EXCEPTION"; - case JNI_NO_NATIVE_POINTER: - return "JNI_NO_NATIVE_POINTER"; - case JNI_INVALID_VALUE: - return "JNI_INVALID_VALUE"; - default: - return ""; + case JNI_EXCEPTION: + return "JNI_EXCEPTION"; + case JNI_NO_NATIVE_POINTER: + return "JNI_NO_NATIVE_POINTER"; + case JNI_INVALID_VALUE: + return "JNI_INVALID_VALUE"; + default: + return ""; } } }; diff --git a/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java b/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java index c7b5f30..043eda0 100644 --- a/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java +++ b/android/android_api/base/src/androidTest/java/org/iotivity/base/OcRepresentationTest.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -309,6 +309,18 @@ public class OcRepresentationTest extends InstrumentationTestCase { rep.setValue(representationK, representationArrVEmpty); OcRepresentation[] representationArrVEmptyA = rep.getValue(representationK); assertEquals(representationArrVEmpty.length, representationArrVEmptyA.length); + + //byte + String byteK = "byteK"; + byte[] byteArrV = {1, 2, 3, 4, 0, 5, 6, 7}; + rep.setValue(byteK, byteArrV); + byte[] byteArrVa = rep.getValue(byteK); + assertTrue(Arrays.equals(byteArrV, byteArrVa)); + + byte[] byteArrVEmpty = {}; + rep.setValue(byteK, byteArrVEmpty); + byte[] byteArrVEmptyA = rep.getValue(byteK); + assertTrue(Arrays.equals(byteArrVEmpty, byteArrVEmptyA)); } public void testAttributeAccessBy2DType() throws OcException { @@ -580,4 +592,4 @@ public class OcRepresentationTest extends InstrumentationTestCase { } } } -} \ No newline at end of file +} diff --git a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java index 4842eca..a3a2ba7 100644 --- a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java +++ b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -85,6 +85,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -157,6 +162,11 @@ public class SmokeTest extends InstrumentationTestCase { assertTrue(false); } } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -263,6 +273,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -430,6 +445,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -603,6 +623,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -731,6 +756,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -895,6 +925,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1094,6 +1129,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal1.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener2 = new OcPlatform.OnResourceFoundListener() { @@ -1101,6 +1141,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal2.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener3 = new OcPlatform.OnResourceFoundListener() { @@ -1108,6 +1153,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal3.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener4 = new OcPlatform.OnResourceFoundListener() { @@ -1115,6 +1165,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal4.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener5 = new OcPlatform.OnResourceFoundListener() { @@ -1122,6 +1177,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal5.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; OcPlatform.OnResourceFoundListener resourceFoundListener6 = new OcPlatform.OnResourceFoundListener() { @@ -1129,6 +1189,11 @@ public class SmokeTest extends InstrumentationTestCase { public void onResourceFound(OcResource resource) { signal6.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1270,7 +1335,12 @@ public class SmokeTest extends InstrumentationTestCase { headerOptionList.add(new OcHeaderOption(2885, "OptionData1")); headerOptionList.add(new OcHeaderOption(2886, "OptionData2")); - resource.setHeaderOptions(headerOptionList); + try { + resource.setHeaderOptions(headerOptionList); + } catch (OcException e) { + Log.e(TAG, "onResourceFound, error in setHeaderOptions -- " + e.getMessage()); + } + resource.unsetHeaderOptions(); OcResourceIdentifier resourceIdentifier = resource.getUniqueIdentifier(); @@ -1279,6 +1349,11 @@ public class SmokeTest extends InstrumentationTestCase { signal.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1359,6 +1434,11 @@ public class SmokeTest extends InstrumentationTestCase { } signal.countDown(); } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { @@ -1557,6 +1637,11 @@ public class SmokeTest extends InstrumentationTestCase { } } } + + @Override + public void onFindResourceFailed(Throwable ex, String uri) { + Log.i(TAG, "Find Resource Failed for Uri: " + uri + " Error: " + ex.getMessage()); + } }; try { //server diff --git a/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java b/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java new file mode 100644 index 0000000..abacec9 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/AclGroupType.java @@ -0,0 +1,38 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum AclGroupType { + PUBLIC(0), + PRIVATE(1),; + + private int value; + + private AclGroupType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/CredType.java b/android/android_api/base/src/main/java/org/iotivity/base/CredType.java index bbaeda7..87a33eb 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/CredType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/CredType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java index b569da8..0eefcaf 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/DeviceStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/EncodingType.java b/android/android_api/base/src/main/java/org/iotivity/base/EncodingType.java new file mode 100644 index 0000000..944eadb --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/EncodingType.java @@ -0,0 +1,42 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +public enum EncodingType { + + OIC_ENCODING_UNKNOW (0), + OIC_ENCODING_RAW (1), + OIC_ENCODING_BASE64 (2), + OIC_ENCODING_PEM (3), + OIC_ENCODING_DER (4); + + private int value; + + private EncodingType(int value) { + this.value = value; + } + + public int getValue() { + return this.value; + } +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java b/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java index 17fe3f4..3306230 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/EntityHandlerResult.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java b/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java index bba664e..7318a0c 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ErrorCode.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -28,6 +28,7 @@ public enum ErrorCode { RESOURCE_CREATED("RESOURCE_CREATED", ""), RESOURCE_DELETED("RESOURCE_DELETED", ""), CONTINUE("CONTINUE", ""), + RESOURCE_CHANGED("RESOURCE_CHANGED", ""), /** Success status code - END HERE.*/ /* Error status code - START HERE */ INVALID_URI("INVALID_URI", ""), diff --git a/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java b/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java index 6243db6..83c5799 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/KeySize.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java b/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java index 52dfb66..d12cab7 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ModeType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java b/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java index 89876e1..064eeaf 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ObservationInfo.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java b/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java index 085ddf3..5506749 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ObserveAction.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java b/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java index 13b5b18..ca990a9 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ObserveType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java b/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java new file mode 100644 index 0000000..e9bb9e8 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcAccountManager.java @@ -0,0 +1,509 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.util.EnumSet; +import java.util.List; +import java.util.Map; + +public final class OcAccountManager { + + private OcAccountManager(long nativeHandle) { + this.mNativeHandle = nativeHandle; + } + + /** + * Method to get the host address of account server + * + * @return String host address + */ + public native String getHost(); + + /** + * Method to get the connectivity type for account server + * + * @return EnumSet connectivity type set + */ + public EnumSet getConnectivityTypeSet() { + return OcConnectivityType.convertToEnumSet( + this.getConnectivityTypeN() + ); + } + + private native int getConnectivityTypeN(); + + /** + * Method for account registration to account server + * + * @param authProvider Provider name used for authentication. + * @param authCode The authorization code obtained by using an authorization server + * as an intermediary between the client and resource owner. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signUp(String authProvider, + String authCode, + OnPostListener onPostListener) throws OcException { + this.signUp0(authProvider, authCode, onPostListener); + } + + private native void signUp0(String authProvider, + String authCode, + OnPostListener onPostListener) throws OcException; + + /** + * overload + * + * @param authProvider Provider name used for authentication. + * @param authCode The authorization code obtained by using an authorization server + * as an intermediary between the client and resource owner. + * @param options The option values depends on auth provider. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signUp(String authProvider, + String authCode, + Map options, + OnPostListener onPostListener) throws OcException { + this.signUp1(authProvider, authCode, options, onPostListener); + } + + private native void signUp1(String authProvider, + String authCode, + Map options, + OnPostListener onPostListener) throws OcException; + + /** + * Method for sign-in to account server + * + * @param userUuid Identifier of the user obtained by account registration. + * @param accessToken Identifier of the resource obtained by account registration. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signIn(String userUuid, + String accessToken, + OnPostListener onPostListener) throws OcException { + this.signIn0(userUuid, accessToken, onPostListener); + } + + private native void signIn0(String userUuid, + String accessToken, + OnPostListener onPostListener) throws OcException; + + /** + * Method for sign-out to account server + * + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void signOut(OnPostListener onPostListener) throws OcException { + this.signOut0(onPostListener); + } + + private native void signOut0(OnPostListener onPostListener) throws OcException; + + /** + * Method to refresh access token to account server + * + * @param userUuid Identifier of the user obtained by account registration. + * @param refreshToken Refresh token used for access token refresh. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void refreshAccessToken(String userUuid, + String refreshToken, + OnPostListener onPostListener) throws OcException { + this.refreshAccessToken0(userUuid, refreshToken, onPostListener); + } + + private native void refreshAccessToken0(String userUuid, + String refreshToken, + OnPostListener onPostListener) throws OcException; + + /** + * Method to get information of the user to account server + * + * @param userUuid Identifier of the user to get information. + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * @throws OcException if failure + */ + public void searchUser(String userUuid, + OnGetListener onGetListener) throws OcException { + this.searchUser0(userUuid, onGetListener); + } + + private native void searchUser0(String userUuid, + OnGetListener onGetListener) throws OcException; + + /** + * Overload + * + * @param queryMap Map which can have the query key and value for specific users. + * account server can response information of more than one user. + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * @throws OcException if failure + */ + public void searchUser(Map queryMap, + OnGetListener onGetListener) throws OcException { + this.searchUser1(queryMap, onGetListener); + } + + private native void searchUser1(Map queryMap, + OnGetListener onGetListener) throws OcException; + + /** + * Method to delete the device registered on the account signed-in + * + * @param deviceId Device ID to delete. + * @param onDeleteListener event handler The event handler will have headerOptionList + * @throws OcException if failure + */ + public void deleteDevice(String deviceId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteDevice0(deviceId, onDeleteListener); + } + + private native void deleteDevice0(String deviceId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to delete the device registered on the account signed-in + * + * @param groupType Group type that can be used for referencing default group ACL creation. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @throws OcException if failure + */ + public void createGroup(AclGroupType groupType, + OnPostListener onPostListener) throws OcException { + this.createGroup0(groupType.getValue(), onPostListener); + } + + private native void createGroup0(int groupType, + OnPostListener onPostListener) throws OcException; + + /** + * Method to get a list of groups joined from account server + * + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * + * @return Returns ::OC_STACK_OK if success + */ + public void getGroupList(OnGetListener onGetListener) throws OcException { + this.getGroupList0(onGetListener); + } + + private native void getGroupList0(OnGetListener onGetListener) throws OcException; + + /** + * Method to delete the group from account server + * + * @param groupId Group ID to delete. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void deleteGroup(String groupId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteGroup0(groupId, onDeleteListener); + } + + private native void deleteGroup0(String groupId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to join the group on account server + * + * @param groupId Group ID to join + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * + * @return Returns ::OC_STACK_OK if success + */ + public void joinGroup(String groupId, + OnPostListener onPostListener) throws OcException { + this.joinGroup0(groupId, onPostListener); + } + + private native void joinGroup0(String groupId, + OnPostListener onPostListener) throws OcException; + + /** + * Method to add devices to the group on account server + * + * @param groupId Group ID to add devices. + * @param deviceId List of devices to add. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * + * @return Returns ::OC_STACK_OK if success + */ + public void addDeviceToGroup(String groupId, + List deviceId, + OnPostListener onPostListener) throws OcException { + this.addDeviceToGroup0(groupId, deviceId.toArray(new String[deviceId.size()]), + onPostListener); + } + + private native void addDeviceToGroup0(String groupId, + String[] deviceId, + OnPostListener onPostListener) throws OcException; + + /** + * Method to get information of the group from account server + * + * @param groupId Group ID to get information. + * @param onGetListener The event handler will be invoked with a map of attribute name and + * values. The event handler will also have the result from this Get + * operation This will have error codes + * + * @return Returns ::OC_STACK_OK if success + */ + public void getGroupInfo(String groupId, + OnGetListener onGetListener) throws OcException { + this.getGroupInfo0(groupId, onGetListener); + } + + private native void getGroupInfo0(String groupId, + OnGetListener onGetListener) throws OcException; + + /** + * Method to leave the group joined on account server + * + * @param groupId Group ID to leave. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void leaveGroup(String groupId, + OnDeleteListener onDeleteListener) throws OcException { + this.leaveGroup0(groupId, onDeleteListener); + } + + private native void leaveGroup0(String groupId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to delete devices from the group on account server + * + * @param groupId Group ID to delete devices. + * @param deviceId List of devices to delete. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void deleteDeviceFromGroup(String groupId, + List deviceId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteDeviceFromGroup0(groupId, deviceId.toArray(new String[deviceId.size()]), + onDeleteListener); + } + + private native void deleteDeviceFromGroup0(String groupId, + String[] deviceId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to register observe to the group on account server + * User can receive a notify when the group get changed (eg. new user/device added) + * + * @param groupId Group ID to observe. + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + public void observeGroup(String groupId, + OnObserveListener onObserveListener) throws OcException { + this.observeGroup0(groupId, onObserveListener); + } + + private native void observeGroup0(String groupId, + OnObserveListener onObserveListener) throws OcException; + + /** + * Method to cancel observe to the group on account server + * + * @param groupId Group ID to observe. + * + * @return Returns ::OC_STACK_OK if success + */ + public void cancelObserveGroup(String groupId) throws OcException { + this.cancelObserveGroup0(groupId); + } + + private native void cancelObserveGroup0(String groupId) throws OcException; + + /** + * Method to register observe to invitation resource on account server + * User can receive a invitation which is including group ID to join + * Once receive a invitation, user should call 'deleteInvitation' to delete a invitation + * on account server. + * + * @param cloudConnectHandler Callback function that will get the result of the operation. + * + * @return Returns ::OC_STACK_OK if success + */ + public void observeInvitation(OnObserveListener onObserveListener) throws OcException { + this.observeInvitation0(onObserveListener); + } + + private native void observeInvitation0(OnObserveListener onObserveListener) throws OcException; + + /** + * Method to cancel observe to invitation resource on account server + * + * @return Returns ::OC_STACK_OK if success + */ + public void cancelObserveInvitation() throws OcException { + this.cancelObserveInvitation0(); + } + + private native void cancelObserveInvitation0() throws OcException; + + /** + * Method to send a invitation to invite a user into a group + * + * @param groupId Group ID for inviting. + * @param userUuid Identifier of the user to invite. + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * + * @return Returns ::OC_STACK_OK if success + */ + public void sendInvitation(String groupId, + String userUuid, + OnPostListener onPostListener) throws OcException { + this.sendInvitation0(groupId, userUuid, onPostListener); + } + + private native void sendInvitation0(String groupId, + String userUuid, + OnPostListener onPostListener) throws OcException; + + /** + * Method to cancel a invitation on account server that user has sent + * + * @param groupId Group ID to cancel a invitation. + * @param userUuid Identifier of the user to cancel a invitation. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void cancelInvitation(String groupId, + String userUuid, + OnDeleteListener onDeleteListener) throws OcException { + this.cancelInvitation0(groupId, userUuid, onDeleteListener); + } + + private native void cancelInvitation0(String groupId, + String userUuid, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * Method to delete a invitation on account server that user has received + * + * @param groupId Group ID to delete a invitation. + * @param onDeleteListener event handler The event handler will have headerOptionList. + * + * @return Returns ::OC_STACK_OK if success + */ + public void deleteInvitation(String groupId, + OnDeleteListener onDeleteListener) throws OcException { + this.deleteInvitation0(groupId, onDeleteListener); + } + + private native void deleteInvitation0(String groupId, + OnDeleteListener onDeleteListener) throws OcException; + + /** + * An OnGetListener can be registered via the resource get call. + * Event listeners are notified asynchronously + */ + public interface OnGetListener { + public void onGetCompleted(List headerOptionList, + OcRepresentation ocRepresentation); + + public void onGetFailed(Throwable ex); + } + + /** + * An OnPostListener can be registered via the resource post call. + * Event listeners are notified asynchronously + */ + public interface OnPostListener { + public void onPostCompleted(List headerOptionList, + OcRepresentation ocRepresentation); + + public void onPostFailed(Throwable ex); + } + + /** + * An OnDeleteListener can be registered via the resource delete call. + * Event listeners are notified asynchronously + */ + public interface OnDeleteListener { + public void onDeleteCompleted(List headerOptionList); + + public void onDeleteFailed(Throwable ex); + } + + /** + * An OnObserveListener can be registered via the resource observe call. + * Event listeners are notified asynchronously + */ + public interface OnObserveListener { + /** + * To Register. + */ + public static final int REGISTER = 0; + /** + * To Deregister. + */ + public static final int DEREGISTER = 1; + /** + * Others. + */ + public static final int NO_OPTION = 2; + + public void onObserveCompleted(List headerOptionList, + OcRepresentation ocRepresentation, + int sequenceNumber); + + public void onObserveFailed(Throwable ex); + } + + private long mNativeHandle; +} + diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcCloudProvisioning.java b/android/android_api/base/src/main/java/org/iotivity/base/OcCloudProvisioning.java new file mode 100755 index 0000000..31a071c --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcCloudProvisioning.java @@ -0,0 +1,138 @@ +/* + ******************************************************************* + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base; + +import java.util.List; +import java.util.EnumSet; +import java.util.Map; +import java.util.ArrayList; + + + +/** + * OcCloudProvisioning class is responsible for providing methods for cloud + * provisioning. + */ +public class OcCloudProvisioning { + + private long mNativeHandle; + private String mIp; + private int mPort; + + /** + * API to construct the CloudProvisioning + * + * @param ipAddr address of the cloud server + * @param port port of the cloud server + */ + public OcCloudProvisioning(String ip, int port) { + this.mIp = ip; + this.mPort = port; + } + + public String getIP() { + return mIp; + } + + public int getPort() { + return mPort; + } + + private void setNativeHandle(long nativeHandle) { + this.mNativeHandle = nativeHandle; + } + + public interface RequestCertificateListener { + public void requestCertificateListener(boolean result); + } + + public interface GetAclIdByDeviceListener { + public void getAclIdByDeviceListener(boolean result,String aclId); + } + + public interface GetIndividualAclInfoListener { + public void getIndividualAclInfoListener(boolean result); + } + + public interface GetCRLListener { + public void getCRLListener(boolean result); + } + + public interface PostCRLListener { + public void postCRLListener(boolean result); + } + + /** + * Method to Request a certificate from the cloud + * @param certificateIssueRequestListener function called by the stack on completion of request. + * @throws OcException + */ + public native void requestCertificate( + RequestCertificateListener certificateIssueRequestListener) throws OcException; + + /** + * Method to get ACL ID for the device + * @param deviceId device ID for which the Acl ID is requested + * @param cloudAclIdGetByDeviceHandler function called by the stack on completion of request. + * @throws OcException + */ + public native void getAclIdByDevice(String deviceId, + GetAclIdByDeviceListener cloudAclIdGetByDeviceHandler) throws OcException; + + /** + * Method to get ACL information about the given Acl ID + * @param aclId ACL ID for which the Acl information is requested + * @param cloudAclIndividualGetInfoHandler function called by the stack on completion of request. + * @throws OcException + */ + public native void getIndividualAclInfo(String aclId, + GetIndividualAclInfoListener cloudAclIndividualGetInfoHandler) throws OcException; + + /** + * Method to get certificate revocation list + * @param cloudGetCRLHandler function called by the stack on completion of request. + * @throws OcException + */ + public native void getCRL(GetCRLListener cloudGetCRLHandler) + throws OcException; + + /** + * Method to post the certificate revocation list to cloud + * @param thisUpdate thisUpdate [mandatory param]. + * @param nextUpdate nextUpdate [mandatory param]. + * @param crl revocation list [optional]. + * @param serialNumbers [optional]. + * @param cloudPostCRLHandler function called by the stack on completion of request. + * @throws OcException + */ + public void postCRL(String thisUpdate, String nextUpdate, String crl, ArrayList serialNumbers, + PostCRLListener cloudPostCRLHandler) throws OcException + { + String[] serialNums = new String[serialNumbers.size()]; + serialNums = serialNumbers.toArray(serialNums); + this.postCRL0(thisUpdate, nextUpdate, crl, serialNums, cloudPostCRLHandler); + } + public native void postCRL0(String thisUpdate, String nextUpdate, String crl, String[] serialNumbers, + PostCRLListener cloudPostCRLHandler) throws OcException; +} + diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java b/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java index 2d42a3e..0eb951a 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcConnectivityType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -131,4 +131,4 @@ public enum OcConnectivityType { return CT_DEFAULT; } } -} \ No newline at end of file +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java b/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java index 062405f..4320ad1 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcDeviceInfo.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcException.java b/android/android_api/base/src/main/java/org/iotivity/base/OcException.java index 1d56947..23af6ae 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcException.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcException.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java b/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java index 6bf442f..bcabc663 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcHeaderOption.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; 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 76cd649..6155cea 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 @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -172,6 +172,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 +215,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; @@ -631,6 +639,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 +685,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( @@ -834,6 +852,43 @@ public final class OcPlatform { OcPresenceHandle ocPresenceHandle) throws OcException; /** + * Subscribes to a server's device presence change events. + * + * @param host The IP address/addressable name of the server to subscribe to. + * @param di Vector which can have the devices id. + * @param connectivityTypeSet Set of connectivity types, e.g. IP. + * @param onObserveListener The handler method will be invoked with a map + * of attribute name and values. + * @return a handle object that can be used to identify this subscription request. + * It can be used to unsubscribe from these events in the future. + * @throws OcException if failure. + */ + public static OcPresenceHandle subscribeDevicePresence( + String host, + List di, + EnumSet connectivityTypeSet, + OcResource.OnObserveListener onObserveListener) throws OcException { + OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + connTypeInt |= connType.getValue(); + } + return OcPlatform.subscribeDevicePresence0( + host, + di.toArray(new String[di.size()]), + connTypeInt, + onObserveListener); + } + + private static native OcPresenceHandle subscribeDevicePresence0( + String host, + String[] di, + int connectivityType, + OcResource.OnObserveListener onObserveListener) throws OcException; + + /** * Creates a resource proxy object so that get/put/observe functionality can be used without * discovering the object in advance. Note that the consumer of this method needs to provide * all of the details required to correctly contact and observe the object. If the consumer @@ -950,6 +1005,313 @@ 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 */ @@ -981,6 +1343,7 @@ public final class OcPlatform { */ public interface OnResourceFoundListener { public void onResourceFound(OcResource resource); + public void onFindResourceFailed(Throwable ex, String uri); } /** @@ -1010,6 +1373,14 @@ public final class OcPlatform { /** * An EntityHandler can be registered via the OcPlatform.registerResource call. * Event listeners are notified asynchronously + * + * @note entityhandler callback : + * When you set specific return value like EntityHandlerResult.OK, SLOW + * and etc in entity handler callback, + * ocstack will be not send response automatically to client + * except for error return value like EntityHandlerResult.ERROR + * If you want to send response to client with specific result, + * sendResponse API should be called with the result value. */ public interface EntityHandler { public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest); @@ -1031,4 +1402,49 @@ public final class OcPlatform { OcPlatform.initCheck(); return sPlatformQualityOfService; } + + /** + * Create an account manager object that can be used for doing request to account server. + * You can only create this object if OCPlatform was initialized to be a Client or + * Client/Server. Otherwise, this will return an empty shared ptr. + * + * @note For now, OCPlatform SHOULD be initialized to be a Client/Server(Both) for the + * methods of this object to work since device id is not generated on Client mode. + * + * @param host Host IP Address of a account server. + * @param connectivityTypeSet Set of types of connectivity. Example: CT_ADAPTER_IP + * @return new AccountManager object + * @throws OcException if failure + */ + public static OcAccountManager constructAccountManagerObject( + String host, + EnumSet connectivityTypeSet) throws OcException { + OcPlatform.initCheck(); + int connTypeInt = 0; + + for (OcConnectivityType connType : OcConnectivityType.values()) { + if (connectivityTypeSet.contains(connType)) + { + connTypeInt |= connType.getValue(); + } + } + return OcPlatform.constructAccountManagerObject0( + host, + connTypeInt + ); + } + + 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; } diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java index 89af6a2..e896428 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformInfo.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java index 3087e5a..c41eb37 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPlatformStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java index ae7ed15..1107854 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceHandle.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java index 02b774f..4bc4baa 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcPresenceStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java b/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java index e7debe7..8cb282b 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcProvisioning.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -112,4 +112,17 @@ public class OcProvisioning { return Arrays.asList(OcProvisioning.getDeviceStatusList1(timeout)); } private static native OcSecureResource[] getDeviceStatusList1(int timeout) throws OcException; + + /** + * Method to save the Trust certificate chain to SVR. + * + * @param byte[] trustCertChain + * @param EncodingType encodingType + * @throws OcException + */ + public static int saveTrustCertChain(byte[] trustCertChain, EncodingType encodingType) throws OcException { + return saveTrustCertChain1(trustCertChain,encodingType.getValue()); + } + private static native int saveTrustCertChain1(byte[] trustCertChain, int encodingType) + throws OcException; } diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java b/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java index 309ab70..24d8b88 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcRepresentation.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -25,6 +25,7 @@ package org.iotivity.base; import java.security.InvalidParameterException; import java.util.Arrays; import java.util.List; +import java.util.Map; /** * @@ -52,6 +53,8 @@ public class OcRepresentation { this.mNativeNeedsDelete = nativeNeedsDelete; } + public native Map getValues(); + public T getValue(String key) throws OcException { Object obj = this.getValueN(key); @SuppressWarnings("unchecked") @@ -141,6 +144,10 @@ public class OcRepresentation { this.setValueRepresentation3DArray(key, value); } + public void setValue(String key, byte[] value) throws OcException { + this.setValueByteArray(key, value); + } + private native void setValueInteger(String key, int value) throws OcException; private native void setValueDouble(String key, double value) throws OcException; @@ -181,6 +188,8 @@ public class OcRepresentation { private native void setValueRepresentation3DArray(String key, OcRepresentation[][][] value) throws OcException; + private native void setValueByteArray(String key, byte[] value) throws OcException; + /** * @deprecated use {@link #getValue(String key)} instead. */ @@ -355,4 +364,4 @@ public class OcRepresentation { private long mNativeHandle; private boolean mNativeNeedsDelete; -} \ No newline at end of file +} diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java b/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java index 7e021dc..69216a8 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcRequestHandle.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java index bb22465..f9cc04f 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResource.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -65,6 +65,11 @@ public class OcResource { public void get(Map queryParamsMap, OnGetListener onGetListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.get1(queryParamsMap, onGetListener, qualityOfService.getValue()); } @@ -116,6 +121,11 @@ public class OcResource { Map queryParamsMap, OnGetListener onGetListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.get3( resourceType, resourceInterface, @@ -157,6 +167,11 @@ public class OcResource { Map queryParamsMap, OnPutListener onPutListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.put1( ocRepresentation, queryParamsMap, @@ -217,6 +232,11 @@ public class OcResource { Map queryParamsMap, OnPutListener onPutListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.put3( resourceType, resourceInterface, @@ -260,6 +280,11 @@ public class OcResource { Map queryParamsMap, OnPostListener onPostListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.post1( ocRepresentation, queryParamsMap, @@ -320,6 +345,11 @@ public class OcResource { Map queryParamsMap, OnPostListener onPostListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.post3( resourceType, resourceInterface, @@ -351,6 +381,11 @@ public class OcResource { */ public void deleteResource(OnDeleteListener onDeleteListener, QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.deleteResource1(onDeleteListener, qualityOfService.getValue()); } @@ -370,6 +405,11 @@ public class OcResource { public void observe(ObserveType observeType, Map queryParamsMap, OnObserveListener onObserveListener) throws OcException { + + if (observeType == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null"); + } + this.observe( observeType.getValue(), queryParamsMap, @@ -394,6 +434,15 @@ public class OcResource { Map queryParamsMap, OnObserveListener onObserveListener, QualityOfService qualityOfService) throws OcException { + + if (observeType == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null"); + } + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.observe1( observeType.getValue(), queryParamsMap, @@ -422,6 +471,11 @@ public class OcResource { * @throws OcException */ public void cancelObserve(QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + this.cancelObserve1(qualityOfService.getValue()); } @@ -432,8 +486,14 @@ public class OcResource { * * @param headerOptionList List where header information(header optionID and * optionData is passed + * @throws OcException */ - public void setHeaderOptions(List headerOptionList) { + public void setHeaderOptions(List headerOptionList) throws OcException { + + if (headerOptionList == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "headerOptionList cannot be null"); + } + this.setHeaderOptions(headerOptionList.toArray( new OcHeaderOption[headerOptionList.size()]) ); @@ -591,4 +651,205 @@ public class OcResource { private native void dispose(); private long mNativeHandle; + + /** + * Method to discovery Topics + * + * @param queryParamsMap map which can have the query parameter name and value + * @param onTopicFoundListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void discoveryMQTopics(Map queryParamsMap, + OnMQTopicFoundListener onTopicFoundListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.discoveryMQTopicsImpl(queryParamsMap, onTopicFoundListener, + qualityOfService.getValue()); + } + + private synchronized native void discoveryMQTopicsImpl( + Map queryParamsMap, + OnMQTopicFoundListener onTopicFoundListener, + int qualityOfService) throws OcException; + + /** + * Method to create Topic into MQ Brober. + * + * @param ocRepresentation representation of the MQ Broker. + * @param uri new MQ Topic uri which want to create. + * @param queryParamsMap map which can have the query parameter name and value. + * @param onTopicCreatedListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void createMQTopic(OcRepresentation ocRepresentation, + String uri, + Map queryParamsMap, + OnMQTopicCreatedListener onTopicCreatedListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.createMQTopicImpl(ocRepresentation, uri, queryParamsMap, + onTopicCreatedListener, qualityOfService.getValue()); + } + + private synchronized native void createMQTopicImpl( + OcRepresentation ocRepresentation, + String uri, + Map queryParamsMap, + OnMQTopicCreatedListener onTopicCreatedListener, + int qualityOfService) throws OcException; + + /** + * Method to set subscribe on the Topic. + * + * @param queryParamsMap map which can have the query parameter name and value. + * @param onObserveListener event handler The handler method will be invoked with a map + * of attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void subscribeMQTopic(Map queryParamsMap, + OnObserveListener onObserveListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.subscribeMQTopicImpl(queryParamsMap, + onObserveListener, + qualityOfService.getValue()); + } + + private synchronized native void subscribeMQTopicImpl(Map queryParamsMap, + OnObserveListener onObserveListener, + int qualityOfService) throws OcException; + + /** + * Method to cancel the observation on the Topic. + * + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void unsubscribeMQTopic(QualityOfService qualityOfService) throws OcException{ + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.unsubscribeMQTopicImpl(qualityOfService.getValue()); + } + + private native void unsubscribeMQTopicImpl( + int qualityOfService) throws OcException; + + /** + * Method to requestMQPublish on a Topic + * + * @param queryParamsMap Map which can have the query parameter name and value + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void requestMQPublish(Map queryParamsMap, + OnPostListener onPostListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.requestMQPublishImpl(queryParamsMap, + onPostListener, + qualityOfService.getValue()); + } + + private native void requestMQPublishImpl(Map queryParamsMap, + OnPostListener onPostListener, + int qualityOfService) throws OcException; + + /** + * Method to publishMQTopic on a Topic + * + * @param ocRepresentation representation of the resource + * @param queryParamsMap Map which can have the query parameter name and value + * @param onPostListener event handler The event handler will be invoked with a map of + * attribute name and values. + * @param qualityOfService the quality of communication. + * @throws OcException + */ + public void publishMQTopic(OcRepresentation ocRepresentation, + Map queryParamsMap, + OnPostListener onPostListener, + QualityOfService qualityOfService) throws OcException { + + if (qualityOfService == null) { + throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null"); + } + + this.publishMQTopicImpl(ocRepresentation, + queryParamsMap, + onPostListener, + qualityOfService.getValue()); + } + + private native void publishMQTopicImpl(OcRepresentation ocRepresentation, + Map queryParamsMap, + OnPostListener onPostListener, + int qualityOfService) throws OcException; + + /** + * An OnMQTopicFoundListener can be registered via the OcResource.discoveryMQTopics call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicFoundListener { + public void onTopicDiscoveried(OcResource resource); + public void onDiscoveryTopicFailed(Throwable ex, String uri); + } + + /** + * An OnMQTopicCreatedListener can be registered via the OcResource.createMQTopic call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicCreatedListener { + public void onTopicResourceCreated(OcResource resource); + public void onCreateTopicFailed(Throwable ex, String uri); + } + + /** + * An OnMQTopicSubscribeListener can be registered via the OcResource.subscribeMQTopic call. + * Event listeners are notified asynchronously + */ + public interface OnMQTopicSubscribeListener { + /** + * To Subscriber. + */ + public static final int SUBSCRIBER = 0; + /** + * To Unrubscriber. + */ + public static final int UNSUBSCRIBER = 1; + /** + * Others. + */ + public static final int NO_OPTION = 2; + public void onSubScribeCompleted(List headerOptionList, + OcRepresentation ocRepresentation, + int sequenceNumber); + public void onUnsubScribeCompleted(OcRepresentation ocRepresentation, + int sequenceNumber); + public void onSubScribeFailed(Throwable ex); + } } diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java index b55ce65..ac6e098 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceHandle.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java index b1ce94a..751d37b 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceIdentifier.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java index 7e0367f..b94689c 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceRequest.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java index 0356b85..4e0879f 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcResourceResponse.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java b/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java index b1daf6c..0a6d096 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OcSecureResource.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; @@ -90,6 +90,30 @@ public class OcSecureResource { throws OcException; /** + * Method to provision the Trust certificate chain to secured device. + * + * @param EnumSet OR'ed Cred Types + * @param int credId + * @param ProvisionTrustCertChainListener Callback function, which will be called after + * proviosion trust certificate chain. + * @throws OcException + */ + public void provisionTrustCertChain(EnumSet credTypeSet, int credId, + ProvisionTrustCertChainListener provisionTrustCertChainListener) throws OcException { + int credTypeInt = 0; + + for (CredType credType : CredType.values()) { + if (credTypeSet.contains(credType)) + credTypeInt |= credType.getValue(); + } + this.provisionTrustCertChain1(credTypeInt, credId, + provisionTrustCertChainListener); + } + private native void provisionTrustCertChain1(int credType, int credId, + ProvisionTrustCertChainListener provisionTrustCertChainListener) + throws OcException; + + /** * Method send ACL information to resource. * * @param jobject Acl @@ -210,6 +234,16 @@ public class OcSecureResource { int hasError); } + /** + * provisionTrustCertChainListener can be registered with ProvisionTrustCertChainListener + * call. + * Listener notified asynchronously. + */ + public interface ProvisionTrustCertChainListener { + public void provisionTrustCertChainListener(List provisionResultList, + int hasError); + } + /** * provisionAclListener can be registered with provisionAclListener * call. diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java b/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java index 1c90578..4abfc3e 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OwnedStatus.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java b/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java index 177105e..c8247de 100755 --- a/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/OxmType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Samsung Electronics All Rights Reserved. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java b/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java index 487f6a9..b41b65c 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/PlatformConfig.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java b/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java index e6d6659..5da2be1 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/QualityOfService.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java b/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java index b67cee8..3536f78 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/RequestHandlerFlag.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java b/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java index 832c891..8c55a74 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/RequestType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java b/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java index 71e8b6f..705565b 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ResourceProperty.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java b/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java index 929c4da..4d9027e 100644 --- a/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java +++ b/android/android_api/base/src/main/java/org/iotivity/base/ServiceType.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.base; diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java index 57b8738..e06d574 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaBtPairingInterface.java @@ -31,7 +31,9 @@ public class CaBtPairingInterface { private static Context mContext; private CaBtPairingInterface(Context context) { - mContext = context; + synchronized(CaBtPairingInterface.class) { + mContext = context; + } registerIntentFilter(); } diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java index 7a07b24..aaf8bc6 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaEdrInterface.java @@ -26,12 +26,15 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.util.Log; public class CaEdrInterface { private static Context mContext; private CaEdrInterface(Context context) { - mContext = context; + synchronized(CaEdrInterface.class) { + mContext = context; + } registerIntentFilter(); } @@ -39,6 +42,7 @@ public class CaEdrInterface { IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED); + filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); mContext.registerReceiver(mReceiver, filter); return filter; } @@ -52,6 +56,8 @@ public class CaEdrInterface { private native static void caEdrBondStateChangedCallback(String addr); + private native static void caEdrConnectionStateChangedCallback(String addr, int isConnected); + private static final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -87,6 +93,15 @@ public class CaEdrInterface { } } } + + if (action != null && action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) { + BluetoothDevice device + = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); + if (BluetoothDevice.DEVICE_TYPE_CLASSIC == device.getType()) + { + caEdrConnectionStateChangedCallback(device.getAddress(), 0); + } + } } }; } diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java index 3711f97..6924eb4 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaInterface.java @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ package org.iotivity.ca; @@ -177,4 +177,26 @@ public class CaInterface { private static native void caBtPairingStartScan(); private static native void caBtPairingStopScan(); private static native void caBtPairingCreateBond(BluetoothDevice device); -} \ No newline at end of file + + /** + * set BLE scan interval time and working count. + * scanning logic (start scan -> stop scan) will be worked repeatly for workingCount. + * and if you choose '0' value for workingCount parameter, + * scanning will be worked continually as interval time. + * @param intervalTime interval time(Seconds). + * @param workingCount working count with interval time. + */ + + public synchronized static void setLeScanIntervalTime(int intervalTime, int workingCount){ + CaInterface.setLeScanIntervalTimeImpl(intervalTime, workingCount); + } + + private static native void setLeScanIntervalTimeImpl(int intervalTime, int workingCount); + + + public synchronized static int setCipherSuite(OicCipher cipher, OcConnectivityType connType){ + return CaInterface.setCipherSuiteImpl(cipher.getValue(), connType.getValue()); + } + private static native int setCipherSuiteImpl(int cipher, int adapter); + +} diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java index 2314df9..a747953 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaIpInterface.java @@ -53,7 +53,9 @@ public class CaIpInterface { } private CaIpInterface(Context context) { - mContext = context; + synchronized(CaIpInterface.class) { + mContext = context; + } registerIpStateReceiver(); } diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java index 8b383a7..695359b 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaLeClientInterface.java @@ -47,10 +47,14 @@ public class CaLeClientInterface { private CaLeClientInterface(Context context) { caLeRegisterLeScanCallback(mLeScanCallback); caLeRegisterGattCallback(mGattCallback); - mContext = context; + synchronized(CaLeClientInterface.class) { + mContext = context; + } registerIntentFilter(); } + + public static void getLeScanCallback() { caLeRegisterLeScanCallback(mLeScanCallback); } @@ -91,6 +95,11 @@ public class CaLeClientInterface { private native static void caLeGattServicesDiscoveredCallback(BluetoothGatt gatt, int status); + private native static void caLeGattNWServicesDiscoveredCallback(BluetoothGatt gatt, + int status); + + private native static void caLeGattNWDescriptorWriteCallback(BluetoothGatt gatt, int status); + private native static void caLeGattCharacteristicWriteCallback( BluetoothGatt gatt, byte[] data, int status); @@ -211,6 +220,7 @@ public class CaLeClientInterface { caLeGattServicesDiscoveredCallback(gatt, status); caManagerLeServicesDiscoveredCallback(gatt, status); + caLeGattNWServicesDiscoveredCallback(gatt, status); } @Override @@ -247,6 +257,7 @@ public class CaLeClientInterface { super.onDescriptorWrite(gatt, descriptor, status); caLeGattDescriptorWriteCallback(gatt, status); + caLeGattNWDescriptorWriteCallback(gatt, status); } @Override diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java b/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java index ebb273b..dee2ac1 100644 --- a/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java +++ b/android/android_api/base/src/main/java/org/iotivity/ca/CaNfcInterface.java @@ -49,7 +49,9 @@ public class CaNfcInterface implements NfcAdapter.CreateNdefMessageCallback { private CaNfcInterface(Context context, Activity activity) { Log.d(MYTAG, "NFC registerNfcReceiver"); - mContext = context; + synchronized(CaNfcInterface.class) { + mContext = context; + } mActivity = activity; mAdapter = NfcAdapter.getDefaultAdapter(mContext); diff --git a/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java b/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java new file mode 100644 index 0000000..60f9f16 --- /dev/null +++ b/android/android_api/base/src/main/java/org/iotivity/ca/OicCipher.java @@ -0,0 +1,38 @@ +/* **************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************/ + +package org.iotivity.ca; + +public enum OicCipher { + TLS_ECDH_anon_WITH_AES_128_CBC_SHA(0xC018), + TLS_PSK_WITH_AES_128_CCM_8(0xC0A8), + TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8(0xC0AE), + TLS_RSA_WITH_AES_256_CBC_SHA(0x35); + + private int cipher; + + private OicCipher(int cipher) { + this.cipher = cipher; + } + + public int getValue(){ + return cipher; + } +} diff --git a/android/android_api/build.gradle b/android/android_api/build.gradle index b8a6bed..cfcb3a2 100755 --- a/android/android_api/build.gradle +++ b/android/android_api/build.gradle @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2014 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2014 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ // Top-level build file where you can add configuration options common to all sub-projects/modules. diff --git a/android/android_api/gradlew b/android/android_api/gradlew index 583ae08..91a7e26 100755 --- a/android/android_api/gradlew +++ b/android/android_api/gradlew @@ -1,164 +1,164 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/android/android_api/settings.gradle b/android/android_api/settings.gradle index d1bcc8a..5d0d834 100755 --- a/android/android_api/settings.gradle +++ b/android/android_api/settings.gradle @@ -1,23 +1,23 @@ /* - * //****************************************************************** - * // - * // Copyright 2015 Intel Corporation. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= - * // - * // Licensed under the Apache License, Version 2.0 (the "License"); - * // you may not use this file except in compliance with the License. - * // You may obtain a copy of the License at - * // - * // http://www.apache.org/licenses/LICENSE-2.0 - * // - * // Unless required by applicable law or agreed to in writing, software - * // distributed under the License is distributed on an "AS IS" BASIS, - * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * // See the License for the specific language governing permissions and - * // limitations under the License. - * // - * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + ******************************************************************* + * + * Copyright 2015 Intel Corporation. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ include ':base' diff --git a/android/examples/DirectPairing/src/main/assets/oic_svr_db_client_directpairing.dat b/android/examples/DirectPairing/src/main/assets/oic_svr_db_client_directpairing.dat index 43b7a1c5c8c4fd2c89a669014ac050c3c3ded40f..146d24033255e000475a1279116098cc3327e164 100644 GIT binary patch literal 996 zcmbV~K~lmn6owIIJc%o38c<6aPT&=AXPdmrD{0etNdcFj*Kpy;Mla!YJOF!50%8XT z5VOeZYu-2g|37`_F_$;Z>qTlSYV#~&4toAF(p8cHH&ulqK1TwrDzYaJ3o#@}hi!$t zZQmwjW|@6vlM!<*rZaRcrc6psAa7Sd>H*=#hwE`+hv#ZNoWvR=7T^ypOuyK&&X$MS ztOUwYYg9#Zr=7=@y4z(U;g1={rmzuIb(qU literal 778 zcmb7>OHRWu5Qh7ZI0-AHCV-#|@Au3<;}6K7yc~W$M*nMlh zEkg*g&`Z@R(+aAlPY@V#nd?!MTZLa~5C3i9VRzger$>d=Hx=6O0n1~Su#5DJO(S-m zCQ&+Jr%_1wiy=#sgiTY1jiK4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/examples/cloudprovisioningclient/proguard-rules.pro b/android/examples/cloudprovisioningclient/proguard-rules.pro new file mode 100755 index 0000000..4fd6c93 --- /dev/null +++ b/android/examples/cloudprovisioningclient/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/sandeep/iot/android-sdk/android-sdk-linux/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/android/examples/cloudprovisioningclient/src/main/AndroidManifest.xml b/android/examples/cloudprovisioningclient/src/main/AndroidManifest.xml new file mode 100755 index 0000000..5de8a6a --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + diff --git a/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.dat b/android/examples/cloudprovisioningclient/src/main/assets/oic_svr_db_client.dat new file mode 100755 index 0000000000000000000000000000000000000000..4b5b91881ba480a4828e70405952a02ec9c50892 GIT binary patch literal 1046 zcmbVLOHRWu5H0OhSRvH~HFedSlpTpZX(vtMU_1RRTh74((G6UJ>u>;AgU6|&s3@w! zA{vi9&-32+kGe zr0qU&YqnW2N-^Fer5Lj`6&liq3J`mMr1IsdT)N_eIu%EuffRG_hYqa&V2dWUxQtB- z&>0$oD(|<-IaKU2&(44tNwv*tO`7@CX*#FbV3*g}!r0IfctxT#tMWE<7k-T%LgjI@ zhtJ!3RO%jUhO!7zW4@pZ@`_}=)pkddXQI_62Ti8fUh_L1aLH#w4nZ*FlPMqa86UgV zWHOz&WiY;_M&1vaIe(Em&L;_eO7rJ8iAELQiG(!@=+HrAy~w&xWrN6MgMU%H^k9;F zF#mj~VD`P30;D}*guMb9iR?~1bxJ! list, + OcRepresentation ocRepresentation) { + logMessage("signUp was successful"); + try { + String mUserUuid = ocRepresentation.getValue("uid"); + String mAccesstoken = ocRepresentation.getValue("accesstoken"); + + String mRefreshtoken = ocRepresentation.getValue("refreshtoken"); + String tokenType = ocRepresentation.getValue("tokentype"); + + SharedPreferences.Editor editor = settingPreference.edit(); + editor.putString("useruuid", mUserUuid); + editor.putString("accesstoken", mAccesstoken); + editor.commit(); + + logMessage("\tuserID: " + mUserUuid); + logMessage("\taccessToken: " + mAccesstoken); + logMessage("\trefreshToken: " + mRefreshtoken); + logMessage("\ttokenType: " + tokenType); + + if (ocRepresentation.hasAttribute("expiresin")) { + int expiresIn = ocRepresentation.getValue("expiresin"); + logMessage("\texpiresIn: " + expiresIn); + } + + runOnUiThread(new Runnable() { + @Override + public void run() { + signupLyt.setVisibility(View.GONE); + signinLyt.setVisibility(View.VISIBLE); + } + }); + + + } catch (OcException e) { + Log.e(TAG, e.toString()); + } + } + + + @Override + public synchronized void onPostFailed(Throwable throwable) { + logMessage("Failed to signUp"); + if (throwable instanceof OcException) { + OcException ocEx = (OcException) throwable; + Log.e(TAG, ocEx.toString()); + ErrorCode errCode = ocEx.getErrorCode(); + logMessage("Error code: " + errCode); + } + } + }; + OcAccountManager.OnPostListener onSignIn = new OcAccountManager.OnPostListener() { + @Override + public synchronized void onPostCompleted(List list, + OcRepresentation ocRepresentation) { + logMessage("signIn was successful"); + runOnUiThread(new Runnable() { + @Override + public void run() { + signinLyt.setVisibility(View.GONE); + userid.setText(settingPreference.getString("useruuid", "")); + lyt1.setVisibility(View.VISIBLE); + lyt2.setVisibility(View.VISIBLE); + } + }); + + + } + + @Override + public synchronized void onPostFailed(Throwable throwable) { + logMessage("Failed to signIn"); + if (throwable instanceof OcException) { + OcException ocEx = (OcException) throwable; + Log.e(TAG, ocEx.toString()); + ErrorCode errCode = ocEx.getErrorCode(); + logMessage("Error code: " + errCode); + } + } + }; + OcCloudProvisioning.GetIndividualAclInfoListener getIndividualAclInfoListener = + new OcCloudProvisioning.GetIndividualAclInfoListener() { + @Override + public void getIndividualAclInfoListener(boolean result) { + Log.d(TAG, "Inside getIndividualAclInfoListener "); + if (!result) { + logMessage("Individual ACL Info Successfull !!"); + } else { + logMessage("Error: Individual ACL Info failed !!"); + } + } + }; + OcCloudProvisioning.RequestCertificateListener requestCertificateListener = + new OcCloudProvisioning.RequestCertificateListener() { + @Override + public void requestCertificateListener(boolean result) { + Log.d(TAG, "Inside requestCertificateListener "); + if (!result) { + logMessage("Request certificate Successfull !!"); + } else { + logMessage("Error: Request certificate failed !!"); + } + } + }; + OcCloudProvisioning.GetCRLListener getCRLListener = + new OcCloudProvisioning.GetCRLListener() { + @Override + public void getCRLListener(boolean result) { + Log.d(TAG, "Inside getCRLListener "); + if (!result) { + logMessage("Get CRL Successfull !!"); + } else { + logMessage("Error: Get CRL failed !!"); + } + } + }; + OcCloudProvisioning.PostCRLListener postCRLListener = + new OcCloudProvisioning.PostCRLListener() { + @Override + public void postCRLListener(boolean result) { + Log.d(TAG, "Inside postCRLListener "); + if (!result) { + logMessage("Post CRL Successfull !!"); + } else { + logMessage("Error: Post CRL failed !!"); + } + } + }; + private static final int BUFFER_SIZE = 1024; + private final int REQUEST_LOGIN = 1; + Button signUp, signIn, signOut, getAclId, getAclInfo, requestCert, postCrl, getCrl; + TextView userid; + LinearLayout lyt1, lyt2, signupLyt, signinLyt; + // private TextView eventView; + SharedPreferences settingPreference; + OcCloudProvisioning ocCloudProvisioning; + String acl_Id; + OcCloudProvisioning.GetAclIdByDeviceListener getAclIdByDeviceListener = + new OcCloudProvisioning.GetAclIdByDeviceListener() { + @Override + public void getAclIdByDeviceListener(boolean result, String aclId) { + Log.d(TAG, "Inside getAclIdByDeviceListener "); + if (!result) { + acl_Id = aclId; + logMessage("Acl Id by device !!" + acl_Id); + } else { + logMessage("Error: Acl Id by device failed !!"); + } + } + }; + private OcAccountManager mAccountManager; + private String filePath = ""; + private TextView mEventsTextView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main_activity); + + signUp = (Button) findViewById(R.id.signup); + signIn = (Button) findViewById(R.id.signin); + signOut = (Button) findViewById(R.id.signout); + getAclId = (Button) findViewById(R.id.getAclId); + getAclInfo = (Button) findViewById(R.id.getAclInfo); + requestCert = (Button) findViewById(R.id.request); + postCrl = (Button) findViewById(R.id.postCRL); + getCrl = (Button) findViewById(R.id.getCRL); + + lyt1 = (LinearLayout) findViewById(R.id.lyt1); + lyt2 = (LinearLayout) findViewById(R.id.lyt2); + signupLyt = (LinearLayout) findViewById(R.id.signupLyt); + signinLyt = (LinearLayout) findViewById(R.id.signinLyt); + + + userid = (TextView) findViewById(R.id.userid); + + mEventsTextView = (TextView) findViewById(R.id.eventView); + + filePath = getFilesDir().getPath() + "/"; // data/data//files/ + //copy CBOR file when application runs first time + settingPreference = PreferenceManager.getDefaultSharedPreferences(this); + boolean isFirstRun = settingPreference.getBoolean("FIRSTRUN", true); + if (isFirstRun) { + copyCborFromAsset(); + SharedPreferences.Editor editor = settingPreference.edit(); + editor.putBoolean("FIRSTRUN", false); + editor.putString("IP", StringConstants.DEFAULT_COAP_DERVER_IP); + editor.putString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT); + editor.putString("DEVICEID", StringConstants.DEFAULT_DEVICE_ID); + editor.commit(); + } + if (settingPreference.getString("useruuid", "").equals("")) { + + lyt1.setVisibility(View.GONE); + lyt2.setVisibility(View.GONE); + signupLyt.setVisibility(View.VISIBLE); + signinLyt.setVisibility(View.GONE); + + + } else { + userid.setText(settingPreference.getString("useruuid", "")); + lyt1.setVisibility(View.VISIBLE); + lyt2.setVisibility(View.VISIBLE); + signupLyt.setVisibility(View.GONE); + signinLyt.setVisibility(View.VISIBLE); + } + + initOICStack(); + ocCloudProvisioning = new OcCloudProvisioning(settingPreference.getString("IP", ""), + Integer.valueOf(settingPreference.getString("PORT", ""))); + + signUp.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + signUp(); + } + }); + signIn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + signIn(); + } + }); + signOut.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + signOut(); + } + }); + getAclId.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getAclId(); + } + }); + getAclInfo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getAclInfo(); + } + }); + requestCert.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + requestCert(); + } + }); + postCrl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + postCrl(); + } + }); + getCrl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + getCrl(); + } + }); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_cloud_provision, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_settings: + setDefualtSettings(); + return (true); + + + } + return (super.onOptionsItemSelected(item)); + } + + private void signIn() { + try { + logMessage("signIn"); + if(mAccountManager==null) + { + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + ":" + + settingPreference.getString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + } + + mAccountManager.signIn(settingPreference.getString("useruuid", ""), + settingPreference.getString("accesstoken", ""), onSignIn); + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void signOut() { + try { + logMessage("signOut"); + if(mAccountManager==null) + { + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + ":" + + settingPreference.getString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + } + + mAccountManager.signOut(CloudProvisioningClient.this); + lyt1.setVisibility(View.GONE); + lyt2.setVisibility(View.GONE); + signinLyt.setVisibility(View.VISIBLE); + } catch (OcException e) { + e.printStackTrace(); + } + } + + + private void getAclId() { + try { + logMessage("getAclId"); + logMessage("\tdeviceId= " + settingPreference.getString("DEVICEID", "")); + ocCloudProvisioning.getAclIdByDevice(settingPreference.getString("DEVICEID", ""), getAclIdByDeviceListener); + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void getAclInfo() { + try { + logMessage("getAclInfo"); + logMessage("\taclid="+acl_Id); + ocCloudProvisioning.getIndividualAclInfo(acl_Id, getIndividualAclInfoListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void requestCert() { + try { + logMessage("requestCert"); + ocCloudProvisioning = new OcCloudProvisioning(settingPreference.getString("IP", ""), + Integer.valueOf(settingPreference.getString("PORT", ""))); + ocCloudProvisioning.requestCertificate(requestCertificateListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void postCrl() { + try { + logMessage("postCrl"); + ArrayList arrayList = new ArrayList<>(); + arrayList.add("1234"); + + ocCloudProvisioning.postCRL("20160727000000", "20161027000000", null, arrayList, postCRLListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void getCrl() { + try { + logMessage("getCrl"); + ocCloudProvisioning.getCRL(getCRLListener); + + } catch (OcException e) { + e.printStackTrace(); + } + } + + private void signUp() { + try { + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + settingPreference.getString("PORT", + StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + logMessage(StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + settingPreference.getString("PORT", + StringConstants.DEFAULT_COAP_DERVER_PORT)); + } catch (OcException e) { + e.printStackTrace(); + } + + Intent intentLogin = new Intent(this, LoginActivity.class); + startActivityForResult(intentLogin, REQUEST_LOGIN); + } + + + /** + * configure OIC platform and call findResource + */ + private void initOICStack() { + //create platform config + PlatformConfig cfg = new PlatformConfig( + this, + ServiceType.IN_PROC, + ModeType.CLIENT_SERVER, + "0.0.0.0", // bind to all available interfaces + 0, + QualityOfService.LOW, filePath + StringConstants.OIC_CLIENT_CBOR_DB_FILE); + OcPlatform.Configure(cfg); + try { + /* + * Initialize DataBase + */ + String sqlDbPath = getFilesDir().getAbsolutePath().replace("files", "databases") + + File.separator; + File file = new File(sqlDbPath); + //check files directory exists + if (!(file.isDirectory())) { + file.mkdirs(); + Log.d(TAG, "Sql db directory created at " + sqlDbPath); + } + Log.d(TAG, "Sql db directory exists at " + sqlDbPath); + OcProvisioning.provisionInit(sqlDbPath + StringConstants.OIC_SQL_DB_FILE); + } catch (OcException e) { + logMessage(TAG + "provisionInit error: " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LOGIN) { + String mAuthCode = data.getStringExtra("authCode"); + + + logMessage("\tauthCode: " + mAuthCode); + + try { + logMessage("Sign Up"); + mAccountManager = OcPlatform.constructAccountManagerObject( + StringConstants.COAP_TCP + settingPreference.getString("IP", + StringConstants.DEFAULT_COAP_DERVER_IP) + ":" + + settingPreference.getString("PORT", StringConstants.DEFAULT_COAP_DERVER_PORT), + EnumSet.of(OcConnectivityType.CT_ADAPTER_TCP)); + + mAccountManager.signUp("github", mAuthCode, onSignUp); + } catch (OcException e) { + e.printStackTrace(); + } + } + } + + + /** + * Copy svr db CBOR dat file from assets folder to app data files dir + */ + private void copyCborFromAsset() { + InputStream inputStream = null; + OutputStream outputStream = null; + int length; + byte[] buffer = new byte[BUFFER_SIZE]; + try { + inputStream = getAssets().open(StringConstants.OIC_CLIENT_CBOR_DB_FILE); + File file = new File(filePath); + //check files directory exists + if (!(file.exists() && file.isDirectory())) { + file.mkdirs(); + } + outputStream = new FileOutputStream(filePath + StringConstants.OIC_CLIENT_CBOR_DB_FILE); + while ((length = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, length); + } + } catch (NullPointerException e) { + logMessage(TAG + "Null pointer exception " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } catch (FileNotFoundException e) { + logMessage(TAG + "CBOR svr db file not found " + e.getMessage()); + Log.e(TAG, e.getMessage()); + } catch (IOException e) { + logMessage(TAG + StringConstants.OIC_CLIENT_CBOR_DB_FILE + " file copy failed"); + Log.e(TAG, e.getMessage()); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + Log.e(TAG, e.getMessage()); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + Log.e(TAG, e.getMessage()); + } + } + } + } + + public void logMessage(String text) { + logMsg(text); + } + + public void logMsg(final String text) { + runOnUiThread(new Runnable() { + public void run() { + Message msg = new Message(); + msg.obj = text; + mEventsTextView.append(text); + mEventsTextView.append("\n"); + } + }); + Log.i(TAG, text); + Intent intent = new Intent(getPackageName()); + intent.putExtra(StringConstants.MESSAGE, text); + sendBroadcast(intent); + } + + + private void setDefualtSettings() { + View setingLayout = getLayoutInflater().inflate(R.layout.setting_layout, null); + + final EditText ip = (EditText) setingLayout.findViewById(R.id.ip); + final EditText port = (EditText) setingLayout.findViewById(R.id.port); + final EditText deviceId = (EditText) setingLayout.findViewById(R.id.deviceId); + + ip.setText(settingPreference.getString("IP", "")); + port.setText(settingPreference.getString("PORT", "")); + deviceId.setText(settingPreference.getString("DEVICEID", "")); + + + final AlertDialog.Builder builder = new AlertDialog.Builder(CloudProvisioningClient.this); + builder.setView(setingLayout); + builder.setPositiveButton("Submit", null).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + Log.d(TAG, "AlertDialog onClick"); + + } + }); + final AlertDialog alertDialog = builder.create(); + alertDialog.setMessage("Settings"); + alertDialog.show(); + alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + String ip_address = ip.getText().toString(); + String port_num = port.getText().toString(); + String deviceId_val = deviceId.getText().toString(); + + SharedPreferences.Editor editor = settingPreference.edit(); + + editor.putString("IP", ip_address); + editor.putString("PORT", port_num); + editor.putString("DEVICEID", deviceId_val); + editor.commit(); + + alertDialog.cancel(); + } + }); + alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + alertDialog.cancel(); + } + }); + + } + + @Override + public void onPostCompleted(List ocHeaderOptions, OcRepresentation ocRepresentation) { + + } + + @Override + public void onPostFailed(Throwable throwable) { + + } + + + /** + * to display on Server Message on Client screen + */ + public class MessageReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + final String message = intent.getStringExtra(StringConstants.MESSAGE); + logMessage(message); + } + } +} diff --git a/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/LoginActivity.java b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/LoginActivity.java new file mode 100755 index 0000000..09f8087 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/LoginActivity.java @@ -0,0 +1,86 @@ +/* + * ****************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ + +package org.iotivity.base.examples.cloudprovisioningclient; + +import android.app.Activity; +import android.content.Intent; +import android.net.UrlQuerySanitizer; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import org.iotivity.base.examples.cloudprovisioningclient.R; + +/** + * This class is for login to the provider. + * Can be get auth code via web page. + */ +public class LoginActivity extends Activity { + private static final String TAG = "OIC_SIMPLE_LOGIN"; + + private WebView mWebView = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + + mWebView = (WebView) findViewById(R.id.webView); + mWebView.setInitialScale(200); + mWebView.getSettings().setJavaScriptEnabled(true); + mWebView.getSettings().setBuiltInZoomControls(true); + mWebView.setWebViewClient(new WebViewClientClass()); + + mWebView.loadUrl("https://github.com/login?return_to=%2Flogin%2Foauth" + + "%2Fauthorize%3Fclient_id%3Dea9c18f540323b0213d0%26redirect_uri" + + "%3Dhttp%253A%252F%252Fwww.example.com%252Foauth_callback%252F"); + } + + private class WebViewClientClass extends WebViewClient { + + @Override + public void onPageFinished(WebView view, String url) { + Log.i(TAG, "called url=" + url); + + if (url.contains("http://www.example.com/oauth_callback")) { + + mWebView.setVisibility(View.INVISIBLE); + + // parsing url + UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(); + sanitizer.setAllowUnregisteredParamaters(true); + sanitizer.parseUrl(url); + + String mAuthCode = sanitizer.getValue("code"); + + Intent intent = getIntent(); + intent.putExtra("authCode", mAuthCode); + setResult(RESULT_OK, intent); + + finish(); + } + } + } +} diff --git a/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/StringConstants.java b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/StringConstants.java new file mode 100755 index 0000000..18c4974 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/java/org/iotivity/base/examples/cloudprovisioningclient/StringConstants.java @@ -0,0 +1,35 @@ +/* + * ****************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + */ +package org.iotivity.base.examples.cloudprovisioningclient; + +public interface StringConstants { + + public static final String DEFAULT_DEVICE_ID = "9cfbeb8e-5a1e-4d1c-9d01-2ae6fdb"; + public static final String COAP_TCP = "coap+tcp://"; + public static final String DEFAULT_COAP_DERVER_IP = "107.109.229.111"; + public static final String DEFAULT_COAP_DERVER_PORT = "5684"; + + public static final String OIC_CLIENT_CBOR_DB_FILE = "oic_svr_db_client.dat"; + public static final String MESSAGE = "message"; + public static final String OIC_SQL_DB_FILE = "Pdm.db"; + +} diff --git a/android/examples/cloudprovisioningclient/src/main/res/drawable/dash_nil_border.xml b/android/examples/cloudprovisioningclient/src/main/res/drawable/dash_nil_border.xml new file mode 100755 index 0000000..be27758 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/drawable/dash_nil_border.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/examples/cloudprovisioningclient/src/main/res/drawable/round_button.xml b/android/examples/cloudprovisioningclient/src/main/res/drawable/round_button.xml new file mode 100755 index 0000000..f4ccab0 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/drawable/round_button.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/android/examples/cloudprovisioningclient/src/main/res/layout/activity_login.xml b/android/examples/cloudprovisioningclient/src/main/res/layout/activity_login.xml new file mode 100755 index 0000000..dfd8e3c --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/layout/activity_login.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/android/examples/cloudprovisioningclient/src/main/res/layout/main_activity.xml b/android/examples/cloudprovisioningclient/src/main/res/layout/main_activity.xml new file mode 100755 index 0000000..3ce36d2 --- /dev/null +++ b/android/examples/cloudprovisioningclient/src/main/res/layout/main_activity.xml @@ -0,0 +1,207 @@ + + + + + + + + + + +