* @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());
}
* 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);
/*
* 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)
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);
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;
}
/*
env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));
return ret;
}
-#endif
\ No newline at end of file
+#endif