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.
337 * @param updateInterval
338 * Interval time in milliseconds for attribute value update automation.
340 * Listener to be notified when automation ends.
342 * @return Automation ID using which the automation can be stopped.
344 * @throws InvalidArgsException
345 * This exception will be thrown if any parameter has invalid
347 * @throws SimulatorException
348 * This exception will be thrown for other errors.
350 public int startResourceAutomation(AutomationType typeOfAutomation,
351 int updateInterval, IAutomation listener) throws InvalidArgsException,
353 return startResourceAutomation(typeOfAutomation.getValue(), updateInterval, listener);
357 * API to start the attribute level automation. This automation
358 * involves automatically updating all the possible values for a given
359 * attribute sequentially.
362 * Name of the attribute to be automated.
363 * @param typeOfAutomation
364 * {@link AutomationType} indicating whether the automation is
365 * one-time or recursive.
366 * @param updateInterval
367 * Interval time in milliseconds for attribute value update automation.
369 * Listener to be notified when automation ends.
371 * @return Automation ID using which the automation can be stopped.
373 * @throws InvalidArgsException
374 * This exception will be thrown if any parameter has invalid
376 * @throws SimulatorException
377 * This exception will be thrown for other errors.
379 public int startAttributeAutomation(String attrName,
380 AutomationType typeOfAutomation, int updateInterval,
381 IAutomation listener)
382 throws InvalidArgsException, SimulatorException {
383 return startAttributeAutomation(attrName, typeOfAutomation.getValue(),
384 updateInterval, listener);
388 * API to stop the automation based on automation id.
390 * @param automationId
391 * Using which a specific automation can be stopped.
393 * @throws SimulatorException
394 * This exception will be thrown for other errors.
396 public native void stopAutomation(int automationId)
397 throws SimulatorException;
400 * API to remove an attribute from the simulated resource.
403 * Name of the attribute to be deleted.
405 * @throws InvalidArgsException
406 * This exception will be thrown either if the parameter has
407 * invalid value or the native resource object does not exist.
408 * @throws SimulatorException
409 * This exception will be thrown for other errors.
411 public native void removeAttribute(String key) throws InvalidArgsException,
415 * API to get observers information.
417 * @return An array of {@link ObserverInfo} objects.
419 * @throws InvalidArgsException
420 * This exception will be thrown if the native resource object
422 * @throws SimulatorException
423 * This exception will be thrown for other errors.
425 public native ObserverInfo[] getObserversList()
426 throws InvalidArgsException, SimulatorException;
429 * API to set callback to receive notifications when observer is added/removed.
432 * Listener to be notified when clients start/stop observing.
434 * @throws InvalidArgsException
435 * This exception will be thrown either if the parameter has
436 * invalid value or the native resource object does not exist.
437 * @throws SimulatorException
438 * This exception will be thrown for other errors.
440 public native void setObserverCallback(IObserver observer)
441 throws InvalidArgsException, SimulatorException;
444 * API to notify simulated resource's state to a specific observer.
449 * @throws InvalidArgsException
450 * This exception will be thrown if the native resource object
452 * @throws SimulatorException
453 * This exception will be thrown for other errors.
455 public native void notifyObserver(int id) throws InvalidArgsException,
459 * API to notify simualted resource's state to all observers.
461 * @throws InvalidArgsException
462 * This exception will be thrown if the native resource object
464 * @throws SimulatorException
465 * This exception will be thrown for other errors.
467 public native void notifyAllObservers() throws InvalidArgsException,
470 private native int startResourceAutomation(int typeOfAutomation,
471 int updateInterval, IAutomation listener) throws InvalidArgsException,
474 private native int startAttributeAutomation(String attrName,
475 int typeOfAutomation, int updateInterval, IAutomation listener)
476 throws InvalidArgsException, SimulatorException;
479 protected void finalize() throws Throwable {
487 private native void dispose();