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.
157 * Device information.
159 * @throws InvalidArgsException
160 * Thrown if the input parameter is empty.
161 * @throws SimulatorException
162 * Thrown for other errors.
164 public static void setDeviceInfo(String deviceInfo)
165 throws InvalidArgsException, SimulatorException {
166 nativeSetDeviceInfo(deviceInfo);
170 * API to search for devices on the given host in the network.
173 * URI of the host device.
175 * Listener for receiving the device information.
177 * @throws InvalidArgsException
178 * Thrown if the input parameter is empty.
179 * @throws SimulatorException
180 * Thrown for other errors.
182 public static void findDevices(String hostUri, DeviceListener listener)
183 throws InvalidArgsException, SimulatorException {
184 nativeFindDevices(hostUri, listener);
188 * API to set the platform information.
190 * @param platformInfo
191 * {@link PlatformInfo} - Platform information.
193 * @throws InvalidArgsException
194 * Thrown if the input parameter is empty.
195 * @throws SimulatorException
196 * Thrown for other errors.
198 public static void setPlatformInfo(PlatformInfo platformInfo)
199 throws InvalidArgsException, SimulatorException {
200 nativeSetPlatformInfo(platformInfo);
204 * API to find the platform information of the given host in the network.
207 * URI of the host device.
209 * Listener for receiving the platform information.
211 * @throws InvalidArgsException
212 * Thrown if the input parameter is empty.
213 * @throws SimulatorException
214 * Thrown for other errors.
216 public static void getPlatformInformation(String hostUri,
217 PlatformListener listener) throws InvalidArgsException,
219 nativeGetPlatformInformation(hostUri, listener);
223 * API to set the listener for receiving log messages.
226 * {@link ILogger} to receive the log messages.
228 public static void setLogger(ILogger logger) {
229 nativeSetLogger(logger);
232 private SimulatorManager() {
235 private static native SimulatorResource nativeCreateResource(
238 private static native Vector<SimulatorResource> nativeCreateResources(
239 String configPath, int count);
241 private static native SimulatorResource nativeCreateSingleResource(
242 String name, String uri, String resourceType);
244 private static native SimulatorResource nativeCreateCollectionResource(
245 String name, String uri, String resourceType);
247 private static native void nativeSearchResource(String resourceType,
248 FindResourceListener listener);
250 private static native void nativeSetDeviceInfo(String deviceInfo);
252 private static native void nativeFindDevices(String hostUri,
253 DeviceListener listener);
255 private static native void nativeSetPlatformInfo(PlatformInfo platformInfo);
257 private static native void nativeGetPlatformInformation(String hostUri,
258 PlatformListener listener);
260 private static native void nativeSetLogger(ILogger logger);