RC android: load bundle classes from library
[platform/upstream/iotivity.git] / service / resource-container / android / resource-container / src / main / jni / JniBundleResource.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef JNI_BUNDLERESOURCE_H_
22 #define JNI_BUNDLERESOURCE_H_
23
24 #include <map>
25 #include <vector>
26 #include <string>
27 #include <jni.h>
28 #include "BundleResource.h"
29 #include "SoftSensorResource.h"
30 #include "ResourceContainerImpl.h"
31
32 #include <jni.h>
33
34 class JNIEnvWrapper;
35
36 void initRCSJniBundleResource(JNIEnvWrapper *);
37
38 using namespace std;
39
40 namespace OIC
41 {
42     namespace Service
43     {
44         class JniBundleResource: public SoftSensorResource
45         {
46         public:
47             JniBundleResource();
48             JniBundleResource(JNIEnv *env, jobject obj, jobject bundleResource, string bundleId,
49                     jobjectArray attributes);
50             virtual ~JniBundleResource();
51
52             void handleSetAttributeRequest(const std::string& key,
53                     RCSResourceAttributes::Value&&);
54
55             RCSResourceAttributes::Value handleGetAttributeRequest(const std::string& key);
56
57             virtual void handleSetAttributesRequest(RCSResourceAttributes &attrs);
58
59             virtual RCSResourceAttributes& handleGetAttributesRequest();
60
61             /**
62             * SoftSensor logic. Has to be provided by the soft sensor developer.
63             * This function will be executed if an input attribute is updated.
64             *
65             * @return void
66             */
67             virtual void executeLogic();
68
69             /**
70             * Callback from the client module in the container.
71             * This function will be called if input data from remote resources are updated.
72             * SoftSensor resource can get a vector of input data from multiple input resources
73             *    which have attributeName that softsensor needs to execute its logic.
74             *
75             * @param attributeName Attribute key of input data
76             *
77             * @param values Vector of input data value
78             *
79             * @return void
80             */
81             virtual void onUpdatedInputResource(const std::string attributeName,
82                                                 std::vector<RCSResourceAttributes::Value> values);
83
84             virtual void initAttributes();
85         private:
86             // needs to be a GlobalRef
87             jobject m_bundleResource;
88             jobjectArray m_attributes;
89             jclass m_bundleResourceClass;
90             jmethodID m_attributeSetRequestHandler;
91             jmethodID m_attributeGetRequestHandler;
92             jmethodID m_onUpdatedInputResource;
93             jclass m_vectorClazz;
94             jmethodID m_vectorAddMethod;
95             string m_bundleId;
96             jclass m_superclass;
97             jclass m_classClass;
98             JNIEnv *m_env;
99             JavaVM *m_jvm;
100             jfieldID g_field_mNativeHandle;
101         };
102     }
103 }
104
105 #ifdef __cplusplus
106 extern "C" {
107 #endif
108 /*
109  * Class:     org_iotivity_service_resourcecontainer_JniBundleResource
110  * Method:    updateNativeInstance
111  * Signature: (Lorg/iotivity/service/resourcecontainer/RcsResourceAttributes;)V
112  */
113 JNIEXPORT void JNICALL Java_org_iotivity_service_resourcecontainer_BundleResource_updateNativeInstance
114   (JNIEnv *, jobject, jobject);
115
116 #ifdef __cplusplus
117 }
118 #endif
119 #endif
120