[IoTivity Simulator] Handling resource interfaces.
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / SimulatorManager.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;
18
19 import java.util.Vector;
20
21 import org.oic.simulator.client.FindResourceListener;
22 import org.oic.simulator.server.SimulatorResource;
23
24 /**
25  * This class provides a set of methods for creation, discovery and deletion of
26  * resources.
27  */
28 public class SimulatorManager {
29
30     private SimulatorManager() {
31     }
32
33     /**
34      * API for creating a resource from a RAML configuration file.
35      *
36      * @param configPath
37      *            Path to RAML configuration file.
38      *
39      * @return {@link SimulatorResource} - Created resource on success,
40      *         otherwise null.
41      *
42      * @throws InvalidArgsException
43      *             Thrown if the input parameters are empty.
44      * @throws SimulatorException
45      *             Thrown for other errors.
46      */
47     public static native SimulatorResource createResource(String configPath)
48             throws InvalidArgsException, SimulatorException;
49
50     /**
51      * API for creating a set of resources from a RAML configuration file.
52      *
53      * @param configPath
54      *            Path to RAML configuration file.
55      * @param count
56      *            Number of resources to be created.
57      *
58      * @return Returns an array of {@link SimulatorResource} objects one for
59      *         each created resource on success, otherwise null.
60      *
61      * @throws InvalidArgsException
62      *             Thrown if the input parameters are empty.
63      * @throws SimulatorException
64      *             Thrown for other errors.
65      */
66     public static Vector<SimulatorResource> createResource(String configPath,
67             int count) throws InvalidArgsException, SimulatorException {
68         return createResources(configPath, count);
69     };
70
71     /**
72      * API for creating a resource either single or collection type.
73      *
74      * @param type
75      *            Indicates whether single or collection type.
76      * @param name
77      *            Resource Name.
78      * @param uri
79      *            Resource URI.
80      * @param resourceType
81      *            Resource Type.
82      *
83      * @return {@link SimulatorResource} - Created resource on success,
84      *         otherwise null.
85      *
86      * @throws InvalidArgsException
87      *             Thrown if the input parameters are empty.
88      * @throws SimulatorException
89      *             Thrown for other errors.
90      */
91     public static SimulatorResource createResource(SimulatorResource.Type type,
92             String name, String uri, String resourceType)
93             throws InvalidArgsException, SimulatorException {
94         SimulatorResource resource = null;
95         if (type == SimulatorResource.Type.SINGLE)
96             resource = createSingleResource(name, uri, resourceType);
97         else
98             resource = createCollectionResource(name, uri, resourceType);
99         return resource;
100     }
101
102     /**
103      * API for discovering all types of resources in the network. Callback is
104      * called when a resource is discovered in the network.
105      *
106      * @param listener
107      *            Interface to receive the discovered remote resources.
108      *
109      * @throws InvalidArgsException
110      *             Thrown if the input parameter is empty.
111      * @throws SimulatorException
112      *             Thrown for other errors.
113      */
114     public static void findResource(FindResourceListener listener)
115             throws InvalidArgsException, SimulatorException {
116         searchResource(null, listener);
117     }
118
119     /**
120      * API for discovering specific type of resources in the network. Callback
121      * is called when a resource is discovered in the network.
122      *
123      * @param resourceType
124      *            Required resource type.
125      * @param listener
126      *            Interface to receive the discovered remote resources.
127      *
128      * @throws InvalidArgsException
129      *             Thrown if the input parameter is empty.
130      * @throws SimulatorException
131      *             Thrown for other errors.
132      */
133     public static void findResource(String resourceType,
134             FindResourceListener listener) throws InvalidArgsException,
135             SimulatorException {
136         if (null == resourceType || resourceType.isEmpty()) {
137             throw new InvalidArgsException(
138                     SimulatorResult.SIMULATOR_INVALID_PARAM,
139                     "Invalid resource type!");
140         }
141
142         searchResource(resourceType, listener);
143     }
144
145     /**
146      * API to set the device information.
147      *
148      * @param deviceInfo
149      *            Device information.
150      *
151      * @throws InvalidArgsException
152      *             Thrown if the input parameter is empty.
153      * @throws SimulatorException
154      *             Thrown for other errors.
155      */
156     public static native void setDeviceInfo(String deviceInfo)
157             throws InvalidArgsException, SimulatorException;
158
159     /**
160      * API to search for devices on the given host in the network.
161      *
162      * @param hostUri
163      *            URI of the host device.
164      * @param listener
165      *            Listener for receiving the device information.
166      *
167      * @throws InvalidArgsException
168      *             Thrown if the input parameter is empty.
169      * @throws SimulatorException
170      *             Thrown for other errors.
171      */
172     public static native void findDevices(String hostUri,
173             DeviceListener listener) throws InvalidArgsException,
174             SimulatorException;
175
176     /**
177      * API to set the platform information.
178      *
179      * @param platformInfo
180      *            {@link PlatformInfo} - Platform information.
181      *
182      * @throws InvalidArgsException
183      *             Thrown if the input parameter is empty.
184      * @throws SimulatorException
185      *             Thrown for other errors.
186      */
187     public static native void setPlatformInfo(PlatformInfo platformInfo)
188             throws InvalidArgsException, SimulatorException;
189
190     /**
191      * API to find the platform information of the given host in the network.
192      *
193      * @param hostUri
194      *            URI of the host device.
195      * @param listener
196      *            Listener for receiving the platform information.
197      *
198      * @throws InvalidArgsException
199      *             Thrown if the input parameter is empty.
200      * @throws SimulatorException
201      *             Thrown for other errors.
202      */
203     public static native void getPlatformInformation(String hostUri,
204             PlatformListener listener) throws InvalidArgsException,
205             SimulatorException;
206
207     /**
208      * API to set the listener for receiving log messages.
209      *
210      * @param logger
211      *            {@link ILogger} to receive the log messages.
212      */
213     public static native void setLogger(ILogger logger);
214
215     private static native Vector<SimulatorResource> createResources(
216             String configPath, int count);
217
218     private static native SimulatorResource createSingleResource(String name,
219             String uri, String resourceType);
220
221     private static native SimulatorResource createCollectionResource(
222             String name, String uri, String resourceType);
223
224     private static native void searchResource(String resourceType,
225             FindResourceListener listener);
226 }