2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This file contains a class which has a set of native methods for manipulating
19 * the simulated resource by adding and removing attributes to its model,
20 * automating the attribute value updates, and changing the range of
21 * acceptable values of the attributes.
23 package org.oic.simulator.serviceprovider;
25 import java.util.Vector;
27 import org.oic.simulator.IAutomation;
28 import org.oic.simulator.SimulatorResourceModel;
31 * This class represents a resource in the simulator. It provides a set of
32 * native methods for manipulating the attributes.
34 public class SimulatorResourceServer {
36 private String resourceName;
37 private String resourceURI;
38 private String resourceType;
39 private String interfaceType;
41 private long nativeHandle;
43 private SimulatorResourceServer(long nativeHandle) {
44 this.nativeHandle = nativeHandle;
48 * API to set the name of the resource. Example: Light, Fan, etc.
51 * Name of the resource.
53 public void setName(String resourceName) {
54 this.resourceName = resourceName;
58 * API to set the URI of the resource. Example: /oic/light, /oic/fan, etc.
61 * URI of the resource.
63 private void setURI(String resourceURI) {
64 this.resourceURI = resourceURI;
68 * API to set the type of the resource. Example: oic.light, oic.fan, etc.
71 * Type of the resource.
73 private void setResourceType(String resourceType) {
74 this.resourceType = resourceType;
78 * API to set the interface type of the resource. Example: oic.if.baseline,
81 * @param interfaceType
82 * Interface type of the resource.
84 private void setInterfaceType(String interfaceType) {
85 this.interfaceType = interfaceType;
89 * API to get the resource name. Example: Light, Fan, etc.
91 * @return Resource name.
93 public String getName() {
98 * API to get the resource URI. Example: /oic/light, /oic/fan, etc.
100 * @return Resource URI.
102 public String getURI() {
107 * API to get the resource Type. Example: oic.light, oic.fan, etc.
109 * @return Resource type.
111 public String getResourceType() {
116 * API to get the interface type of the resource. Example: oic.if.baseline,
119 * @return Interface type of the resource.
121 public String getInterfaceType() {
122 return interfaceType;
126 protected void finalize() throws Throwable {
131 * Native function to get the {@link SimulatorResourceModel} of the
132 * corresponding resource.
134 * @return {@link SimulatorResourceModel} object on success, otherwise null.
136 public native SimulatorResourceModel getModel();
139 * Native function to automatically update the value of an attribute from
140 * its allowed values.
143 * Name of the attribute
146 * Index of the value in the allowed values.
148 public native void updateAttributeFromAllowedValues(String attrName,
152 * Native function to set the range of allowed values. This function is
153 * intended to be used for integral type attributes.
156 * Name of the attribute
158 * Minimum value in the range.
160 * Maximum value in the range.
162 public native void setRange(String attrName, int min, int max);
165 * Native function to add an attribute whose value is of type int.
168 * Name of the attribute
170 * Initial value of the attribute
172 public native void addAttributeInteger(String key, int value);
175 * Native function to add an attribute whose value is of type double.
178 * Name of the attribute
180 * Initial value of the attribute
182 public native void addAttributeDouble(String key, double value);
185 * Native function to add an attribute whose value is of type Boolean.
188 * Name of the attribute
190 * Initial value of the attribute
192 public native void addAttributeBoolean(String key, Boolean value);
195 * Native function to add an attribute whose value is of type String.
198 * Name of the attribute
200 * Initial value of the attribute
202 public native void addAttributeStringN(String key, String value);
205 * Native function to update the value of an attribute whose value is of
209 * Name of the attribute
211 * New value of the attribute
213 public native void updateAttributeInteger(String key, int value);
216 * Native function to update the value of an attribute whose value is of
220 * Name of the attribute
222 * New value of the attribute
224 public native void updateAttributeDouble(String key, double value);
227 * Native function to update the value of an attribute whose value is of
231 * Name of the attribute
233 * New value of the attribute
235 public native void updateAttributeBoolean(String key, Boolean value);
238 * Native function to update the value of an attribute whose value is of
242 * Name of the attribute
244 * New value of the attribute
246 public native void updateAttributeStringN(String key, String value);
249 * Native function to set the allowed values of attribute whose value is of
253 * Name of the attribute
254 * @param allowedValues
255 * Allowed values of the attribute
257 public native void setAllowedValuesInteger(String key,
258 Vector<Integer> allowedValues);
261 * Native function to set the allowed values of attribute whose value is of
265 * Name of the attribute
266 * @param allowedValues
267 * Allowed values of the attribute
269 public native void setAllowedValuesDouble(String key,
270 Vector<Double> allowedValues);
273 * Native function to set the allowed values of attribute whose value is of
277 * Name of the attribute
278 * @param allowedValues
279 * Allowed values of the attribute
281 public native void setAllowedValuesStringN(String key,
282 Vector<String> allowedValues);
285 * Native function to start the resource level automation. This automation
286 * involves automatically updating all the possible values for all the
287 * attributes sequentially.
289 * @param typeOfAutomation
290 * Indicates whether the automation is one-time or recursive.
292 * Listener to be notified when automation ends.
294 * @return Automation ID using which the automation can be stopped.
296 public native int startResourceAutomation(int typeOfAutomation,
297 IAutomation listener);
300 * Native function to start the attribute level automation. This automation
301 * involves automatically updating all the possible values for a given
302 * attribute sequentially.
305 * Name of the attribute to be automated.
306 * @param typeOfAutomation
307 * Indicates whether the automation is one-time or recursive.
309 * Listener to be notified when automation ends.
311 * @return Automation ID using which the automation can be stopped.
313 public native int startAttributeAutomation(String attrName,
314 int typeOfAutomation, IAutomation listener);
317 * Native function to stop the automation.
319 * @param automationId
320 * Using which a specific automation can be stopped.
322 public native void stopAutomation(int automationId);
325 * Native function to remove an attribute from the resource model.
328 * Name of the attribute to be deleted
330 public native void removeAttribute(String key);
333 * Native function to set the observation callback.
336 * Listener to be notified when clients start/stop observing.
338 public native void setObserverCallback(IObserver observer);
341 * Native function to get the details of a list of observers.
343 * @return An array of {@link ObserverInfo} objects.
345 public native ObserverInfo[] getObserversList();
348 * Native function which sends notification to a specific observer.
353 public native void notifyObserver(int id);
356 * Native function which sends notification to all observers.
358 public native void notifyAllObservers();
361 * Native function to release the memory allocated to the native object for
362 * SimulatorResourceServer.
364 private native void dispose();