[IoTivity Simulator] Handling resource interfaces.
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / server / SimulatorSingleResource.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 package org.oic.simulator.server;
18
19 import org.oic.simulator.AttributeValue;
20 import org.oic.simulator.InvalidArgsException;
21 import org.oic.simulator.SimulatorException;
22 import org.oic.simulator.SimulatorResourceAttribute;
23
24 /**
25  * This class represents a single type resource(Non-collection resource). It
26  * provides APIs specific to single resource for manipulating the resource model
27  * by adding/removing the attributes, and updating the attribute values manually
28  * and automatically.
29  */
30 public final class SimulatorSingleResource extends SimulatorResource {
31
32     private SimulatorSingleResource(long nativeHandle) {
33         mNativeHandle = nativeHandle;
34     }
35
36     /**
37      * API to get attribute of resource.
38      *
39      * @param attrName
40      *            Name of the attribute
41      *
42      * @return An object of {@link SimulatorResourceAttribute}, or null if
43      *         resource does not have attribute of this name.
44      *
45      * @throws InvalidArgsException
46      *             This exception will be thrown if the attribute name is
47      *             invalid.
48      * @throws SimulatorException
49      *             This exception will be thrown either if the resource model is
50      *             not found or for some general errors.
51      */
52     public native SimulatorResourceAttribute getAttribute(String attrName)
53             throws InvalidArgsException, SimulatorException;
54
55     /**
56      * API to add an attribute to resource's representation model.
57      *
58      * @param attribute
59      *            Attribute to be added to resource's representation model.
60      *
61      * @throws InvalidArgsException
62      *             This exception will be thrown on invalid input.
63      * @throws SimulatorException
64      *             This exception will be thrown for other errors.
65      */
66     public native void addAttribute(SimulatorResourceAttribute attribute)
67             throws InvalidArgsException, SimulatorException;
68
69     /**
70      * API to update the value of an attribute.
71      *
72      * @param attrName
73      *            Name of the attribute.
74      * @param value
75      *            New value of the attribute.
76      *
77      * @throws InvalidArgsException
78      *             This exception will be thrown on invalid input.
79      * @throws SimulatorException
80      *             This exception will be thrown for other errors.
81      */
82     public native void updateAttribute(String attrName, AttributeValue value)
83             throws InvalidArgsException, SimulatorException;
84
85     /**
86      * API to remove an attribute from the simulated resource.
87      *
88      * @param attrName
89      *            Name of the attribute to be deleted.
90      *
91      * @throws InvalidArgsException
92      *             This exception will be thrown on invalid input.
93      * @throws SimulatorException
94      *             This exception will be thrown for other errors.
95      */
96     public native void removeAttribute(String attrName)
97             throws InvalidArgsException, SimulatorException;
98
99     /**
100      * API to start the resource level automation. This automation involves
101      * automatically updating all the possible values for all the attributes
102      * sequentially.
103      *
104      * @param type
105      *            {@link AutoUpdateType} indicating whether the automation is
106      *            one-time or recursive.
107      * @param interval
108      *            Interval time in milliseconds.
109      * @param listener
110      *            Listener to be notified when automation ends.
111      *
112      * @return Automation ID using which the automation can be stopped.
113      *
114      * @throws InvalidArgsException
115      *             This exception will be thrown on invalid input.
116      * @throws SimulatorException
117      *             This exception will be thrown for other errors.
118      */
119     public native int startResourceUpdation(AutoUpdateType type, int interval,
120             AutoUpdateListener listener) throws InvalidArgsException,
121             SimulatorException;
122
123     /**
124      * API to start the attribute level automation. This automation involves
125      * automatically updating all the possible values for a given attribute
126      * sequentially.
127      *
128      * @param attrName
129      *            Name of the attribute to be automated.
130      * @param type
131      *            {@link AutoUpdateType} indicating whether the automation is
132      *            one-time or recursive.
133      * @param interval
134      *            Interval time in milliseconds.
135      * @param listener
136      *            Listener to be notified when automation ends.
137      *
138      * @return Automation ID using which the automation can be stopped.
139      *
140      * @throws InvalidArgsException
141      *             This exception will be thrown on invalid input.
142      * @throws SimulatorException
143      *             This exception will be thrown for other errors.
144      */
145     public native int startAttributeUpdation(String attrName,
146             AutoUpdateType type, int interval, AutoUpdateListener listener)
147             throws InvalidArgsException, SimulatorException;
148
149     /**
150      * API to stop the automation based on automation id.
151      *
152      * @param id
153      *            Using which a specific automation can be stopped.
154      *
155      * @throws SimulatorException
156      *             This exception will be thrown for general errors.
157      */
158     public native void stopUpdation(int id) throws SimulatorException;
159 }