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