078e9995cd9dc52967a855076d57653f74febc23
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / clientcontroller / SimulatorRemoteResource.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * This file contains a class which has a set of native methods for
19  * communicating with a remote resource.
20  */
21 package org.oic.simulator.clientcontroller;
22
23 import java.util.LinkedList;
24 import java.util.Map;
25
26 import org.oic.simulator.SimulatorResourceModel;
27
28 /**
29  * SimulatorRemoteResource represents a Resource running in the remote Simulator
30  * Server. It comes with a well-defined contract or interface onto which you can
31  * perform different operations or subscribe for event notifications.
32  */
33 public class SimulatorRemoteResource {
34
35     private SimulatorRemoteResource(long nativeHandle) {
36         this.nativeHandle = nativeHandle;
37     }
38
39     /**
40      * Method to get the URI for this resource
41      * 
42      * @return resource URI
43      */
44     public String getUri() {
45         return mUri;
46     }
47
48     /**
49      * Method to get the observe capability of this resource
50      * 
51      * @return true if the resource is observable, otherwise false.
52      */
53     public boolean getIsObservable() {
54         return mIsObservable;
55     }
56
57     /**
58      * Method to get the connectivity type for this resource
59      * 
60      * @return Connectivity type.
61      */
62     public String getConnectivityType() {
63         return mConnType;
64     }
65
66     /**
67      * Method to get the list of resource types
68      * 
69      * @return List of resource types
70      */
71     public LinkedList<String> getResourceTypes() {
72         return mResTypes;
73     }
74
75     /**
76      * Method to get the list of resource interfaces
77      * 
78      * @return List of resource interface
79      */
80     public LinkedList<String> getResourceInterfaces() {
81         return mResInterfaces;
82     }
83
84     /**
85      * Method to get a string representation of the resource's server ID. This
86      * is unique per-server independent on how it was discovered.
87      * 
88      * @return server ID
89      */
90     public String getServerId() {
91         return mSid;
92     }
93
94     /**
95      * Method to get a unique Id of the resource.
96      * 
97      * @return Unique ID.
98      */
99     public String getUid() {
100         return mUid;
101     }
102
103     /**
104      * Method to set observation on the resource
105      * 
106      * @param observeType
107      *            allows the client to specify how it wants to observe
108      * @param queryParamsMap
109      *            map which can have the query parameter name and value
110      * @param onObserveListener
111      *            event handler The handler method will be invoked with a map of
112      *            attribute name and values.
113      * 
114      */
115     public native void observe(SimulatorObserveType observeType,
116             Map<String, String> queryParamsMap,
117             IObserveListener onObserveListener);
118
119     /**
120      * Method to cancel the observation on the resource
121      */
122     public native void cancelObserve();
123
124     /**
125      * Method to get the attributes of a resource.
126      * 
127      * @param queryParamsMap
128      *            map which can have the query parameter name and value
129      * @param onGetListener
130      *            The event handler will be invoked with a map of attribute name
131      *            and values. The event handler will also have the result from
132      *            this Get operation This will have error codes
133      */
134     public void get(Map<String, String> queryParamsMap,
135             IGetListener onGetListener) {
136         this.get(null, queryParamsMap, onGetListener);
137     }
138
139     /**
140      * Method to get the attributes of a resource.
141      * 
142      * @param resourceInterface
143      *            interface type of the resource to operate on
144      * @param queryParamsMap
145      *            map which can have the query parameter name and value
146      * @param onGetListener
147      *            The event handler will be invoked with a map of attribute name
148      *            and values. The event handler will also have the result from
149      *            this Get operation This will have error codes
150      */
151     public native void get(String resourceInterface,
152             Map<String, String> queryParamsMap, IGetListener onGetListener);
153
154     /**
155      * Method to set the representation of a resource (via PUT)
156      * 
157      * @param representation
158      *            representation of the resource
159      * @param queryParamsMap
160      *            Map which can have the query parameter name and value
161      * @param onPutListener
162      *            event handler The event handler will be invoked with a map of
163      *            attribute name and values.
164      */
165     public void put(SimulatorResourceModel representation,
166             Map<String, String> queryParamsMap, IPutListener onPutListener) {
167         this.put(null, representation, queryParamsMap, onPutListener);
168     }
169
170     /**
171      * Method to set the representation of a resource (via PUT)
172      * 
173      * @param resourceInterface
174      *            interface type of the resource to operate on
175      * @param representation
176      *            representation of the resource
177      * @param queryParamsMap
178      *            Map which can have the query parameter name and value
179      * @param onPutListener
180      *            event handler The event handler will be invoked with a map of
181      *            attribute name and values.
182      */
183     private native int put(String resourceInterface,
184             SimulatorResourceModel representation,
185             Map<String, String> queryParamsMap, IPutListener onPutListener);
186
187     /**
188      * Method to POST on a resource
189      * 
190      * @param representation
191      *            representation of the resource
192      * @param queryParamsMap
193      *            Map which can have the query parameter name and value
194      * @param onPostListener
195      *            event handler The event handler will be invoked with a map of
196      *            attribute name and values.
197      */
198     public void post(SimulatorResourceModel representation,
199             Map<String, String> queryParamsMap, IPostListener onPostListener) {
200         this.post(null, representation, queryParamsMap, onPostListener);
201     }
202
203     /**
204      * Method to POST on a resource
205      * 
206      * @param resourceInterface
207      *            interface type of the resource to operate on
208      * @param representation
209      *            representation of the resource
210      * @param queryParamsMap
211      *            Map which can have the query parameter name and value
212      * @param onPostListener
213      *            event handler The event handler will be invoked with a map of
214      *            attribute name and values.
215      */
216     private native int post(String resourceInterface,
217             SimulatorResourceModel representation,
218             Map<String, String> queryParamsMap, IPostListener onPostListener);
219
220     /**
221      * Method to set the RAML file path from application
222      * 
223      * @param ramlPath
224      *            RAML configuration file path
225      */
226     public native void configureRAMLPath(String ramlPath);
227
228     /**
229      * Method to start verification of a resource using automation
230      * 
231      * @param requestType
232      *            request type to verify
233      * 
234      * @param onVerifyListener
235      *            event handler The event handler will be invoked with the
236      *            automation ID.
237      * 
238      * @return Automation ID.
239      * 
240      */
241     public native int startVerification(int requestType,
242             IVerificationListener onVerifyListener);
243
244     /**
245      * Method to stop verification of a resource previously started.
246      * 
247      * @param id
248      *            Automation ID.
249      * 
250      */
251     public native void stopVerification(int id);
252
253     @Override
254     protected void finalize() throws Throwable {
255         super.finalize();
256
257         dispose();
258     }
259
260     private native void dispose();
261
262     private long               nativeHandle;
263     private String             mUri;
264     private String             mConnType;
265     private String             mSid;
266     private String             mUid;
267     private boolean            mIsObservable;
268     private LinkedList<String> mResTypes;
269     private LinkedList<String> mResInterfaces;
270 }