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;
19 import java.util.Vector;
21 import org.oic.simulator.client.FindResourceListener;
22 import org.oic.simulator.server.SimulatorResource;
25 * This class provides a set of methods for creation, discovery and deletion of
28 public class SimulatorManager {
31 System.loadLibrary("connectivity_abstraction");
32 System.loadLibrary("oc_logger");
33 System.loadLibrary("octbstack");
34 System.loadLibrary("oc");
35 System.loadLibrary("RamlParser");
36 System.loadLibrary("SimulatorManager");
40 * API for creating a resource from a RAML configuration file.
43 * Path to RAML configuration file.
45 * @return {@link SimulatorResource} - Created resource on success,
48 * @throws InvalidArgsException
49 * Thrown if the input parameters are empty.
50 * @throws SimulatorException
51 * Thrown for other errors.
53 public static SimulatorResource createResource(String configPath)
54 throws InvalidArgsException, SimulatorException {
55 return nativeCreateResource(configPath);
59 * API for creating a set of resources from a RAML configuration file.
62 * Path to RAML configuration file.
64 * Number of resources to be created.
66 * @return Returns an array of {@link SimulatorResource} objects one for
67 * each created resource on success, otherwise null.
69 * @throws InvalidArgsException
70 * Thrown if the input parameters are empty.
71 * @throws SimulatorException
72 * Thrown for other errors.
74 public static Vector<SimulatorResource> createResource(String configPath,
75 int count) throws InvalidArgsException, SimulatorException {
76 return nativeCreateResources(configPath, count);
80 * API for creating a resource either single or collection type.
83 * Indicates whether single or collection type.
91 * @return {@link SimulatorResource} - Created resource on success,
94 * @throws InvalidArgsException
95 * Thrown if the input parameters are empty.
96 * @throws SimulatorException
97 * Thrown for other errors.
99 public static SimulatorResource createResource(SimulatorResource.Type type,
100 String name, String uri, String resourceType)
101 throws InvalidArgsException, SimulatorException {
102 SimulatorResource resource;
103 if (type == SimulatorResource.Type.SINGLE)
104 resource = nativeCreateSingleResource(name, uri, resourceType);
106 resource = nativeCreateCollectionResource(name, uri, resourceType);
111 * API for discovering all types of resources in the network. Callback is
112 * called when a resource is discovered in the network.
115 * Interface to receive the discovered remote resources.
117 * @throws InvalidArgsException
118 * Thrown if the input parameter is empty.
119 * @throws SimulatorException
120 * Thrown for other errors.
122 public static void findResource(FindResourceListener listener)
123 throws InvalidArgsException, SimulatorException {
124 nativeSearchResource(null, listener);
128 * API for discovering specific type of resources in the network. Callback
129 * is called when a resource is discovered in the network.
131 * @param resourceType
132 * Required resource type.
134 * Interface to receive the discovered remote resources.
136 * @throws InvalidArgsException
137 * Thrown if the input parameter is empty.
138 * @throws SimulatorException
139 * Thrown for other errors.
141 public static void findResource(String resourceType,
142 FindResourceListener listener) throws InvalidArgsException,
144 if (null == resourceType || resourceType.isEmpty()) {
145 throw new InvalidArgsException(
146 SimulatorResult.SIMULATOR_INVALID_PARAM,
147 "Invalid resource type!");
150 nativeSearchResource(resourceType, listener);
154 * API to set the device information.
156 * @deprecated Use setDeviceInfo2 instead.
159 * Device information.
161 * @throws InvalidArgsException
162 * Thrown if the input parameter is empty.
163 * @throws SimulatorException
164 * Thrown for other errors.
166 public static void setDeviceInfo(String deviceInfo)
167 throws InvalidArgsException, SimulatorException {
168 nativeSetDeviceInfo(deviceInfo);
172 * API to set the device information.
175 * Device information.
176 * @param protocolIndependentID
177 * Protocol-independent UUID of the device.
179 * @throws InvalidArgsException
180 * Thrown if the input parameter is empty.
181 * @throws SimulatorException
182 * Thrown for other errors.
184 public static void setDeviceInfo2(String deviceInfo, String protocolIndependentID)
185 throws InvalidArgsException, SimulatorException {
186 nativeSetDeviceInfo2(deviceInfo, protocolIndependentID);
190 * API to search for devices on the given host in the network.
193 * URI of the host device.
195 * Listener for receiving the device information.
197 * @throws InvalidArgsException
198 * Thrown if the input parameter is empty.
199 * @throws SimulatorException
200 * Thrown for other errors.
202 public static void findDevices(String hostUri, DeviceListener listener)
203 throws InvalidArgsException, SimulatorException {
204 nativeFindDevices(hostUri, listener);
208 * API to set the platform information.
210 * @param platformInfo
211 * {@link PlatformInfo} - Platform information.
213 * @throws InvalidArgsException
214 * Thrown if the input parameter is empty.
215 * @throws SimulatorException
216 * Thrown for other errors.
218 public static void setPlatformInfo(PlatformInfo platformInfo)
219 throws InvalidArgsException, SimulatorException {
220 nativeSetPlatformInfo(platformInfo);
224 * API to find the platform information of the given host in the network.
227 * URI of the host device.
229 * Listener for receiving the platform information.
231 * @throws InvalidArgsException
232 * Thrown if the input parameter is empty.
233 * @throws SimulatorException
234 * Thrown for other errors.
236 public static void getPlatformInformation(String hostUri,
237 PlatformListener listener) throws InvalidArgsException,
239 nativeGetPlatformInformation(hostUri, listener);
243 * API to set the listener for receiving log messages.
246 * {@link ILogger} to receive the log messages.
248 public static void setLogger(ILogger logger) {
249 nativeSetLogger(logger);
252 private SimulatorManager() {
255 private static native SimulatorResource nativeCreateResource(
258 private static native Vector<SimulatorResource> nativeCreateResources(
259 String configPath, int count);
261 private static native SimulatorResource nativeCreateSingleResource(
262 String name, String uri, String resourceType);
264 private static native SimulatorResource nativeCreateCollectionResource(
265 String name, String uri, String resourceType);
267 private static native void nativeSearchResource(String resourceType,
268 FindResourceListener listener);
270 private static native void nativeSetDeviceInfo(String deviceInfo);
271 private static native void nativeSetDeviceInfo2(String deviceInfo,
272 String protocolIndependentID);
274 private static native void nativeFindDevices(String hostUri,
275 DeviceListener listener);
277 private static native void nativeSetPlatformInfo(PlatformInfo platformInfo);
279 private static native void nativeGetPlatformInformation(String hostUri,
280 PlatformListener listener);
282 private static native void nativeSetLogger(ILogger logger);