1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 #include "ResourceContainerImpl.h"
23 #include "org_iotivity_resourcecontainer_bundle_api_BaseActivator.h"
24 #include "JavaBundleResource.h"
26 using namespace OIC::Service;
28 std::map< string, BundleResource::Ptr > java_resources;
31 * Class: org_iotivity_resourcecontainer_bundle_api_BaseActivator
32 * Method: registerJavaResource
33 * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
35 JNIEXPORT void JNICALL
36 Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_registerJavaResource
37 (JNIEnv *env, jobject obj, jobject bundleResource, jobjectArray attributes, jstring bundleId,
38 jstring uri, jstring resourceType, jstring res_name)
40 const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
41 const char *str_uri = env->GetStringUTFChars(uri, 0);
42 const char *str_resourceType = env->GetStringUTFChars(resourceType, 0);
43 const char *str_res_name = env->GetStringUTFChars(res_name, 0);
45 BundleResource::Ptr javaBundleResource = std::make_shared< JavaBundleResource >
46 (env, obj, bundleResource, str_bundleId, attributes);
47 ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
49 javaBundleResource->m_uri = string(str_uri, strlen(str_uri));
50 javaBundleResource->m_resourceType = string(str_resourceType, strlen(str_resourceType));
51 javaBundleResource->m_name = string(str_res_name, strlen(str_res_name));
52 container->registerResource(javaBundleResource);
54 java_resources[str_uri] = javaBundleResource;
58 * Class: org_iotivity_resourcecontainer_bundle_api_BaseActivator
59 * Method: unregisterJavaResource
60 * Signature: (Lorg/iotivity/resourcecontainer/bundle/api/BundleResource;)V
62 JNIEXPORT void JNICALL
63 Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_unregisterJavaResource
64 (JNIEnv *env, jobject obj, jobject bundleResource, jstring uri)
68 const char *str_uri = env->GetStringUTFChars(uri, 0);
70 if (java_resources[str_uri] != NULL)
72 ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
73 container->unregisterResource(java_resources[str_uri]);
74 java_resources.erase(str_uri);
79 * Class: org_iotivity_resourcecontainer_bundle_api_BaseActivator
80 * Method: getNumberOfConfiguredResources
81 * Signature: (Ljava/lang/String;)I
83 JNIEXPORT jint JNICALL
84 Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getNumberOfConfiguredResources(
85 JNIEnv *env, jobject obj, jstring bundleId)
88 const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
90 ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
91 vector< resourceInfo > resourceConfig;
92 container->getResourceConfiguration(str_bundleId, &resourceConfig);
94 return resourceConfig.size();
98 * Class: org_iotivity_resourcecontainer_bundle_api_BaseActivator
99 * Method: getConfiguredResourceParams
100 * Signature: (Ljava/lang/String;I)[Ljava/lang/String;
102 JNIEXPORT jobjectArray JNICALL
103 Java_org_iotivity_resourcecontainer_bundle_api_BaseActivator_getConfiguredResourceParams(
104 JNIEnv *env, jobject obj, jstring bundleId, jint resourceId)
108 const char *str_bundleId = env->GetStringUTFChars(bundleId, 0);
110 ResourceContainerImpl *container = ResourceContainerImpl::getImplInstance();
111 vector< resourceInfo > resourceConfig;
112 container->getResourceConfiguration(str_bundleId, &resourceConfig);
113 resourceInfo conf = resourceConfig[resourceId];
114 ret = (jobjectArray) env->NewObjectArray(4, env->FindClass("java/lang/String"),
115 env->NewStringUTF(""));
117 env->SetObjectArrayElement(ret, 0, env->NewStringUTF(conf.name.c_str()));
118 env->SetObjectArrayElement(ret, 1, env->NewStringUTF(conf.uri.c_str()));
119 env->SetObjectArrayElement(ret, 2, env->NewStringUTF(conf.resourceType.c_str()));
120 env->SetObjectArrayElement(ret, 3, env->NewStringUTF(conf.address.c_str()));