resource-container: add return of status code for registerResource() also to JAVA API
authorHauke Mehrtens <hauke.mehrtens@lantiq.com>
Mon, 16 Nov 2015 10:23:48 +0000 (11:23 +0100)
committerMadan Lanka <lanka.madan@samsung.com>
Tue, 24 Nov 2015 05:32:10 +0000 (05:32 +0000)
This forwards the return code of the registerResource() function also to the
JAVA API, so java application can also make use of it.

This is an extension to commit b449dcc5e7 "resource-container: make
registerResource() return status code"

Change-Id: Icdb71447486ea77b8ea1ef4f0b2f645c9ffbf6d2
Signed-off-by: Hauke Mehrtens <hauke.mehrtens@lantiq.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4305
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Markus Jung <markus.jung85@gmail.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/resource-container/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BaseActivator.java
service/resource-container/bundle-java-api/src/main/java/org/iotivity/resourcecontainer/bundle/api/BundleActivator.java
service/resource-container/src/BaseActivator.cpp

index b8e2e88..b7aab58 100644 (file)
@@ -73,10 +73,14 @@ public class BaseActivator implements BundleActivator {
         * @param resource
         *            bundle resource instance that should be made available as OIC
         *            resource
-        */
-       public void registerResource(BundleResource resource) {
+         * @return int
+         *       0        in case of an success
+         *       -EEXIST  when the resource already exists and was not registered
+         *       -EINVAL  when it was not possible to create such a resource
+         */
+       public int registerResource(BundleResource resource) {
                bundleResources.add(resource);
-               registerJavaResource(resource, resource.getAttributeKeys(), bundleId,
+               return registerJavaResource(resource, resource.getAttributeKeys(), bundleId,
                                resource.getURI(), resource.getResourceType(),
                                resource.getName());
        }
@@ -117,8 +121,13 @@ public class BaseActivator implements BundleActivator {
         *            unique bundle identifier
         * @param uri
         *            Uri that should be used to register the resource
-        */
-       private native void registerJavaResource(BundleResource resource,
+         *
+         * @return int
+         *       0        in case of an success
+         *       -EEXIST  when the resource already exists and was not registered
+         *       -EINVAL  when it was not possible to create such a resource
+         */
+       private native int registerJavaResource(BundleResource resource,
                        String[] attributes, String bundleId, String uri,
                        String resourceType, String name);
 
index 67d5692..46f7d52 100644 (file)
@@ -41,7 +41,7 @@ public interface BundleActivator {
      * Registers a single resource instance at the resource container
      * @param resource Instance of a BundleResource
      */
-    public void registerResource(BundleResource resource);
+    public int registerResource(BundleResource resource);
 
     /**
      * Unregisters a single resource instance at the resource container
index e5cf71c..c4533ba 100644 (file)
@@ -30,9 +30,9 @@ std::map< string, BundleResource::Ptr > java_resources;
 /*
  * Class:     org_iotivity_resourcecontainer_bundle_api_BaseActivator
  * Method:    registerJavaResource
- * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I
  */
-JNIEXPORT void JNICALL
+JNIEXPORT jint JNICALL
 Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
 (JNIEnv *env, jobject obj, jobject bundleResource, jobjectArray attributes, jstring bundleId,
  jstring uri, jstring resourceType, jstring res_name)
@@ -41,6 +41,7 @@ Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResourc
     const char *str_uri = env->GetStringUTFChars(uri, 0);
     const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
     const char *str_res_name = env->GetStringUTFChars(res_name, 0);
+    int ret;
 
     BundleResource::Ptr javaBundleResource = std::make_shared< JavaBundleResource >
             (env, obj, bundleResource, str_bundleId, attributes);
@@ -49,9 +50,11 @@ Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResourc
     javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
     javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
     javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
-    container->registerResource(javaBundleResource);
+    ret = container->registerResource(javaBundleResource);
 
     java_resources[str_uri] = javaBundleResource;
+
+    return ret;
 }
 
 /*
@@ -120,4 +123,4 @@ Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResour
     env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));
     return ret;
 }
-#endif
\ No newline at end of file
+#endif