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 protected void finalize() throws Throwable {
88 * Native function to get the {@link SimulatorResourceModel} of the
89 * corresponding resource.
91 * @return {@link SimulatorResourceModel} object on success, otherwise null.
93 * @throws InvalidArgsException
94 * This exception will be thrown if the native resource object
96 * @throws SimulatorException
97 * This exception will be thrown for other errors.
99 public native SimulatorResourceModel getModel()
100 throws InvalidArgsException, SimulatorException;
103 * Native function to add an attribute whose value is of type int.
106 * Name of the attribute.
108 * Initial value of the attribute.
110 * @throws InvalidArgsException
111 * This exception will be thrown if any parameter has invalid
113 * @throws SimulatorException
114 * This exception will be thrown for other errors.
116 public native void addAttributeInteger(String key, int value)
117 throws InvalidArgsException, SimulatorException;
120 * Native function to add an attribute whose value is of type double.
123 * Name of the attribute.
125 * Initial value of the attribute.
127 * @throws InvalidArgsException
128 * This exception will be thrown if any parameter has invalid
130 * @throws SimulatorException
131 * This exception will be thrown for other errors.
133 public native void addAttributeDouble(String key, double value)
134 throws InvalidArgsException, SimulatorException;
137 * Native function to add an attribute whose value is of type boolean.
140 * Name of the attribute.
142 * Initial value of the attribute.
144 * @throws InvalidArgsException
145 * This exception will be thrown if any parameter has invalid
147 * @throws SimulatorException
148 * This exception will be thrown for other errors.
150 public native void addAttributeBoolean(String key, boolean value)
151 throws InvalidArgsException, SimulatorException;
154 * Native function to add an attribute whose value is of type String.
157 * Name of the attribute.
159 * Initial value of the attribute.
161 * @throws InvalidArgsException
162 * This exception will be thrown if any parameter has invalid
164 * @throws SimulatorException
165 * This exception will be thrown for other errors.
167 public native void addAttributeString(String key, String value)
168 throws InvalidArgsException, SimulatorException;
171 * Native function to update the value of an attribute whose value is of
175 * Name of the attribute.
177 * New value of the attribute.
179 * @throws InvalidArgsException
180 * This exception will be thrown if any parameter has invalid
182 * @throws SimulatorException
183 * This exception will be thrown for other errors.
185 public native void updateAttributeInteger(String key, int value)
186 throws InvalidArgsException, SimulatorException;
189 * Native function to update the value of an attribute whose value is of
193 * Name of the attribute.
195 * New value of the attribute.
197 * @throws InvalidArgsException
198 * This exception will be thrown if any parameter has invalid
200 * @throws SimulatorException
201 * This exception will be thrown for other errors.
203 public native void updateAttributeDouble(String key, double value)
204 throws InvalidArgsException, SimulatorException;
207 * Native function to update the value of an attribute whose value is of
211 * Name of the attribute.
213 * New value of the attribute.
215 * @throws InvalidArgsException
216 * This exception will be thrown if any parameter has invalid
218 * @throws SimulatorException
219 * This exception will be thrown for other errors.
221 public native void updateAttributeBoolean(String key, boolean value)
222 throws InvalidArgsException, SimulatorException;
225 * Native function to update the value of an attribute whose value is of
229 * Name of the attribute.
231 * New value of the attribute.
233 * @throws InvalidArgsException
234 * This exception will be thrown if any parameter has invalid
236 * @throws SimulatorException
237 * This exception will be thrown for other errors.
239 public native void updateAttributeString(String key, String value)
240 throws InvalidArgsException, SimulatorException;
243 * Native function to automatically update the value of an attribute from
244 * its allowed values.
247 * Name of the attribute.
249 * Index of the value in the allowed values.
251 * @throws InvalidArgsException
252 * This exception will be thrown if any parameter has invalid
254 * @throws SimulatorException
255 * This exception will be thrown for other errors.
257 public native void updateAttributeFromAllowedValues(String attrName,
258 int index) throws InvalidArgsException, SimulatorException;
261 * Native function to set the range of allowed values. This function is
262 * intended to be used for integral type attributes.
265 * Name of the attribute.
267 * Minimum value in the range.
269 * Maximum value in the range.
271 * @throws InvalidArgsException
272 * This exception will be thrown if any parameter has invalid
274 * @throws SimulatorException
275 * This exception will be thrown for other errors.
277 public native void setRange(String attrName, int min, int max)
278 throws InvalidArgsException, SimulatorException;
281 * Native function to set the allowed values of attribute whose value is of
285 * Name of the attribute.
286 * @param allowedValues
287 * Allowed values of the attribute.
289 * @throws InvalidArgsException
290 * This exception will be thrown if any parameter has invalid
292 * @throws SimulatorException
293 * This exception will be thrown for other errors.
295 public native void setAllowedValuesInteger(String key,
296 Vector<Integer> allowedValues) throws InvalidArgsException,
300 * Native function to set the allowed values of attribute whose value is of
304 * Name of the attribute.
305 * @param allowedValues
306 * Allowed values of the attribute.
308 * @throws InvalidArgsException
309 * This exception will be thrown if any parameter has invalid
311 * @throws SimulatorException
312 * This exception will be thrown for other errors.
314 public native void setAllowedValuesDouble(String key,
315 Vector<Double> allowedValues) throws InvalidArgsException,
319 * Native function to set the allowed values of attribute whose value is of
323 * Name of the attribute.
324 * @param allowedValues
325 * Allowed values of the attribute.
327 * @throws InvalidArgsException
328 * This exception will be thrown if any parameter has invalid
330 * @throws SimulatorException
331 * This exception will be thrown for other errors.
333 public native void setAllowedValuesString(String key,
334 Vector<String> allowedValues) throws InvalidArgsException,
338 * Native function to start the resource level automation. This automation
339 * involves automatically updating all the possible values for all the
340 * attributes sequentially.
342 * @param typeOfAutomation
343 * {@link AutomationType} indicating whether the automation is
344 * one-time or recursive.
346 * Listener to be notified when automation ends.
348 * @return Automation ID using which the automation can be stopped.
350 * @throws InvalidArgsException
351 * This exception will be thrown if any parameter has invalid
353 * @throws SimulatorException
354 * This exception will be thrown for other errors.
356 public int startResourceAutomation(AutomationType typeOfAutomation,
357 IAutomation listener) throws InvalidArgsException,
359 return startResourceAutomation(typeOfAutomation.getValue(), listener);
362 private native int startResourceAutomation(int typeOfAutomation,
363 IAutomation listener) throws InvalidArgsException,
367 * Native function to start the attribute level automation. This automation
368 * involves automatically updating all the possible values for a given
369 * attribute sequentially.
372 * Name of the attribute to be automated.
373 * @param typeOfAutomation
374 * {@link AutomationType} indicating whether the automation is
375 * one-time or recursive.
377 * Listener to be notified when automation ends.
379 * @return Automation ID using which the automation can be stopped.
381 * @throws InvalidArgsException
382 * This exception will be thrown if any parameter has invalid
384 * @throws SimulatorException
385 * This exception will be thrown for other errors.
387 public int startAttributeAutomation(String attrName,
388 AutomationType typeOfAutomation, IAutomation listener)
389 throws InvalidArgsException, SimulatorException {
390 return startAttributeAutomation(attrName, typeOfAutomation.getValue(),
394 private native int startAttributeAutomation(String attrName,
395 int typeOfAutomation, IAutomation listener)
396 throws InvalidArgsException, SimulatorException;
399 * Native function to stop the automation.
401 * @param automationId
402 * Using which a specific automation can be stopped.
404 * @throws InvalidArgsException
405 * This exception will be thrown if the native resource object
407 * @throws SimulatorException
408 * This exception will be thrown for other errors.
410 public native void stopAutomation(int automationId)
411 throws InvalidArgsException, SimulatorException;
414 * Native function to remove an attribute from the resource model.
417 * Name of the attribute to be deleted.
419 * @throws InvalidArgsException
420 * This exception will be thrown either if the parameter has
421 * invalid value or the native resource object does not exist.
422 * @throws SimulatorException
423 * This exception will be thrown for other errors.
425 public native void removeAttribute(String key) throws InvalidArgsException,
429 * Native function to get the details of a list of observers.
431 * @return An array of {@link ObserverInfo} objects.
433 * @throws InvalidArgsException
434 * This exception will be thrown if the native resource object
436 * @throws SimulatorException
437 * This exception will be thrown for other errors.
439 public native ObserverInfo[] getObserversList()
440 throws InvalidArgsException, SimulatorException;
443 * Native function to set the observation callback.
446 * Listener to be notified when clients start/stop observing.
448 * @throws InvalidArgsException
449 * This exception will be thrown either if the parameter has
450 * invalid value or the native resource object does not exist.
451 * @throws SimulatorException
452 * This exception will be thrown for other errors.
454 public native void setObserverCallback(IObserver observer)
455 throws InvalidArgsException, SimulatorException;
458 * Native function which sends notification to a specific observer.
463 * @throws InvalidArgsException
464 * This exception will be thrown if the native resource object
466 * @throws SimulatorException
467 * This exception will be thrown for other errors.
469 public native void notifyObserver(int id) throws InvalidArgsException,
473 * Native function which sends notification to all observers.
475 * @throws InvalidArgsException
476 * This exception will be thrown if the native resource object
478 * @throws SimulatorException
479 * This exception will be thrown for other errors.
481 public native void notifyAllObservers() throws InvalidArgsException,
485 * Native function to release the memory allocated to the native object for
486 * SimulatorResourceServer.
488 private native void dispose();