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.
17 package org.oic.simulator.serviceprovider;
19 import java.util.Vector;
21 import org.oic.simulator.IAutomation;
22 import org.oic.simulator.InvalidArgsException;
23 import org.oic.simulator.SimulatorException;
24 import org.oic.simulator.SimulatorResourceModel;
27 * This class represents a resource in the simulator. It provides a set of
28 * native methods for manipulating the simulated resource by adding and removing
29 * attributes to its model, automating the attribute value updates, and changing
30 * the range of acceptable values of the attributes.
32 public class SimulatorResourceServer {
34 private String resourceName;
35 private String resourceURI;
36 private String resourceType;
37 private String interfaceType;
39 private long nativeHandle;
41 private SimulatorResourceServer(long nativeHandle) {
42 this.nativeHandle = nativeHandle;
46 * API to get the resource name. Example: Light, Fan, etc.
48 * @return Resource name.
50 public String getName() {
55 * API to get the resource URI. Example: /oic/light, /oic/fan, etc.
57 * @return Resource URI.
59 public String getURI() {
64 * API to get the resource Type. Example: oic.light, oic.fan, etc.
66 * @return Resource type.
68 public String getResourceType() {
73 * API to get the interface type of the resource. Example: oic.if.baseline,
76 * @return Interface type of the resource.
78 public String getInterfaceType() {
83 * API to get the {@link SimulatorResourceModel} of the
86 * @return {@link SimulatorResourceModel} object on success, otherwise null.
88 * @throws SimulatorException
89 * This exception will be thrown if simulated resource is not proper.
91 public native SimulatorResourceModel getModel()
92 throws SimulatorException;
95 * API to add an attribute whose value is of type int.
98 * Name of the attribute.
100 * Initial value of the attribute.
102 * @throws InvalidArgsException
103 * This exception will be thrown if any parameter has invalid
105 * @throws SimulatorException
106 * This exception will be thrown for other errors.
108 public native void addAttributeInteger(String key, int value)
109 throws InvalidArgsException, SimulatorException;
112 * API to add an attribute whose value is of type double.
115 * Name of the attribute.
117 * Initial value of the attribute.
119 * @throws InvalidArgsException
120 * This exception will be thrown if any parameter has invalid
122 * @throws SimulatorException
123 * This exception will be thrown for other errors.
125 public native void addAttributeDouble(String key, double value)
126 throws InvalidArgsException, SimulatorException;
129 * API to add an attribute whose value is of type boolean.
132 * Name of the attribute.
134 * Initial value of the attribute.
136 * @throws InvalidArgsException
137 * This exception will be thrown if any parameter has invalid
139 * @throws SimulatorException
140 * This exception will be thrown for other errors.
142 public native void addAttributeBoolean(String key, boolean value)
143 throws InvalidArgsException, SimulatorException;
146 * API to add an attribute whose value is of type String.
149 * Name of the attribute.
151 * Initial value of the attribute.
153 * @throws InvalidArgsException
154 * This exception will be thrown if any parameter has invalid
156 * @throws SimulatorException
157 * This exception will be thrown for other errors.
159 public native void addAttributeString(String key, String value)
160 throws InvalidArgsException, SimulatorException;
163 * API to update the value of an attribute whose value is of
167 * Name of the attribute.
169 * New value of the attribute.
171 * @throws InvalidArgsException
172 * This exception will be thrown if any parameter has invalid
174 * @throws SimulatorException
175 * This exception will be thrown for other errors.
177 public native void updateAttributeInteger(String key, int value)
178 throws InvalidArgsException, SimulatorException;
181 * API to update the value of an attribute whose value is of
185 * Name of the attribute.
187 * New value of the attribute.
189 * @throws InvalidArgsException
190 * This exception will be thrown if any parameter has invalid
192 * @throws SimulatorException
193 * This exception will be thrown for other errors.
195 public native void updateAttributeDouble(String key, double value)
196 throws InvalidArgsException, SimulatorException;
199 * API to update the value of an attribute whose value is of
203 * Name of the attribute.
205 * New value of the attribute.
207 * @throws InvalidArgsException
208 * This exception will be thrown if any parameter has invalid
210 * @throws SimulatorException
211 * This exception will be thrown for other errors.
213 public native void updateAttributeBoolean(String key, boolean value)
214 throws InvalidArgsException, SimulatorException;
217 * API to update the value of an attribute whose value is of
221 * Name of the attribute.
223 * New value of the attribute.
225 * @throws InvalidArgsException
226 * This exception will be thrown if any parameter has invalid
228 * @throws SimulatorException
229 * This exception will be thrown for other errors.
231 public native void updateAttributeString(String key, String value)
232 throws InvalidArgsException, SimulatorException;
235 * API to update the value of an attribute from
236 * its allowed values.
239 * Name of the attribute.
241 * Index of the value in the allowed values.
243 * @throws InvalidArgsException
244 * This exception will be thrown if any parameter has invalid
246 * @throws SimulatorException
247 * This exception will be thrown for other errors.
249 public native void updateAttributeFromAllowedValues(String key,
250 int index) throws InvalidArgsException, SimulatorException;
253 * API to set the range of allowed values. This function is
254 * intended to be used for integer type attributes.
257 * Name of the attribute.
259 * Minimum value in the range.
261 * Maximum value in the range.
263 * @throws InvalidArgsException
264 * This exception will be thrown if any parameter has invalid
266 * @throws SimulatorException
267 * This exception will be thrown for other errors.
269 public native void setRange(String key, int min, int max)
270 throws InvalidArgsException, SimulatorException;
273 * API 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 * @throws InvalidArgsException
282 * This exception will be thrown if any parameter has invalid
284 * @throws SimulatorException
285 * This exception will be thrown for other errors.
287 public native void setAllowedValuesInteger(String key,
288 Vector<Integer> allowedValues) throws InvalidArgsException,
292 * API to set the allowed values of attribute whose value is of
296 * Name of the attribute.
297 * @param allowedValues
298 * Allowed values of the attribute.
300 * @throws InvalidArgsException
301 * This exception will be thrown if any parameter has invalid
303 * @throws SimulatorException
304 * This exception will be thrown for other errors.
306 public native void setAllowedValuesDouble(String key,
307 Vector<Double> allowedValues) throws InvalidArgsException,
311 * API to set the allowed values of attribute whose value is of
315 * Name of the attribute.
316 * @param allowedValues
317 * Allowed values of the attribute.
319 * @throws InvalidArgsException
320 * This exception will be thrown if any parameter has invalid
322 * @throws SimulatorException
323 * This exception will be thrown for other errors.
325 public native void setAllowedValuesString(String key,
326 Vector<String> allowedValues) throws InvalidArgsException,
330 * API to start the resource level automation. This automation
331 * involves automatically updating all the possible values for all the
332 * attributes sequentially.
334 * @param typeOfAutomation
335 * {@link AutomationType} indicating whether the automation is
336 * one-time or recursive.
338 * Listener to be notified when automation ends.
340 * @return Automation ID using which the automation can be stopped.
342 * @throws InvalidArgsException
343 * This exception will be thrown if any parameter has invalid
345 * @throws SimulatorException
346 * This exception will be thrown for other errors.
348 public int startResourceAutomation(AutomationType typeOfAutomation,
349 int updateInterval, IAutomation listener) throws InvalidArgsException,
351 return startResourceAutomation(typeOfAutomation.getValue(), updateInterval, listener);
355 * API to start the attribute level automation. This automation
356 * involves automatically updating all the possible values for a given
357 * attribute sequentially.
360 * Name of the attribute to be automated.
361 * @param typeOfAutomation
362 * {@link AutomationType} indicating whether the automation is
363 * one-time or recursive.
365 * Listener to be notified when automation ends.
367 * @return Automation ID using which the automation can be stopped.
369 * @throws InvalidArgsException
370 * This exception will be thrown if any parameter has invalid
372 * @throws SimulatorException
373 * This exception will be thrown for other errors.
375 public int startAttributeAutomation(String attrName,
376 AutomationType typeOfAutomation, int updateInterval,
377 IAutomation listener)
378 throws InvalidArgsException, SimulatorException {
379 return startAttributeAutomation(attrName, typeOfAutomation.getValue(),
380 updateInterval, listener);
384 * API to stop the automation based on automation id.
386 * @param automationId
387 * Using which a specific automation can be stopped.
389 * @throws SimulatorException
390 * This exception will be thrown for other errors.
392 public native void stopAutomation(int automationId)
393 throws SimulatorException;
396 * API to remove an attribute from the simulated resource.
399 * Name of the attribute to be deleted.
401 * @throws InvalidArgsException
402 * This exception will be thrown either if the parameter has
403 * invalid value or the native resource object does not exist.
404 * @throws SimulatorException
405 * This exception will be thrown for other errors.
407 public native void removeAttribute(String key) throws InvalidArgsException,
411 * API to get observers information.
413 * @return An array of {@link ObserverInfo} objects.
415 * @throws InvalidArgsException
416 * This exception will be thrown if the native resource object
418 * @throws SimulatorException
419 * This exception will be thrown for other errors.
421 public native ObserverInfo[] getObserversList()
422 throws InvalidArgsException, SimulatorException;
425 * API to set callback to receive notifications when observer is added/removed.
428 * Listener to be notified when clients start/stop observing.
430 * @throws InvalidArgsException
431 * This exception will be thrown either if the parameter has
432 * invalid value or the native resource object does not exist.
433 * @throws SimulatorException
434 * This exception will be thrown for other errors.
436 public native void setObserverCallback(IObserver observer)
437 throws InvalidArgsException, SimulatorException;
440 * API to notify simulated resource's state to a specific observer.
445 * @throws InvalidArgsException
446 * This exception will be thrown if the native resource object
448 * @throws SimulatorException
449 * This exception will be thrown for other errors.
451 public native void notifyObserver(int id) throws InvalidArgsException,
455 * API to notify simualted resource's state to all observers.
457 * @throws InvalidArgsException
458 * This exception will be thrown if the native resource object
460 * @throws SimulatorException
461 * This exception will be thrown for other errors.
463 public native void notifyAllObservers() throws InvalidArgsException,
466 private native int startResourceAutomation(int typeOfAutomation,
467 int updateInterval, IAutomation listener) throws InvalidArgsException,
470 private native int startAttributeAutomation(String attrName,
471 int typeOfAutomation, int updateInterval, IAutomation listener)
472 throws InvalidArgsException, SimulatorException;
475 protected void finalize() throws Throwable {
478 } catch(Throwable t){
485 private native void dispose();