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("oc_logger");
32 System.loadLibrary("octbstack");
33 System.loadLibrary("oc");
34 System.loadLibrary("RamlParser");
35 System.loadLibrary("SimulatorManager");
39 * API for creating a resource from a RAML configuration file.
42 * Path to RAML configuration file.
44 * @return {@link SimulatorResource} - Created resource on success,
47 * @throws InvalidArgsException
48 * Thrown if the input parameters are empty.
49 * @throws SimulatorException
50 * Thrown for other errors.
52 public static SimulatorResource createResource(String configPath)
53 throws InvalidArgsException, SimulatorException {
54 return nativeCreateResource(configPath);
58 * API for creating a set of resources from a RAML configuration file.
61 * Path to RAML configuration file.
63 * Number of resources to be created.
65 * @return Returns an array of {@link SimulatorResource} objects one for
66 * each created resource on success, otherwise null.
68 * @throws InvalidArgsException
69 * Thrown if the input parameters are empty.
70 * @throws SimulatorException
71 * Thrown for other errors.
73 public static Vector<SimulatorResource> createResource(String configPath,
74 int count) throws InvalidArgsException, SimulatorException {
75 return nativeCreateResources(configPath, count);
79 * API for creating a resource either single or collection type.
82 * Indicates whether single or collection type.
90 * @return {@link SimulatorResource} - Created resource on success,
93 * @throws InvalidArgsException
94 * Thrown if the input parameters are empty.
95 * @throws SimulatorException
96 * Thrown for other errors.
98 public static SimulatorResource createResource(SimulatorResource.Type type,
99 String name, String uri, String resourceType)
100 throws InvalidArgsException, SimulatorException {
101 SimulatorResource resource;
102 if (type == SimulatorResource.Type.SINGLE)
103 resource = nativeCreateSingleResource(name, uri, resourceType);
105 resource = nativeCreateCollectionResource(name, uri, resourceType);
110 * API for discovering all types of resources in the network. Callback is
111 * called when a resource is discovered in the network.
114 * Interface to receive the discovered remote resources.
116 * @throws InvalidArgsException
117 * Thrown if the input parameter is empty.
118 * @throws SimulatorException
119 * Thrown for other errors.
121 public static void findResource(FindResourceListener listener)
122 throws InvalidArgsException, SimulatorException {
123 nativeSearchResource(null, listener);
127 * API for discovering specific type of resources in the network. Callback
128 * is called when a resource is discovered in the network.
130 * @param resourceType
131 * Required resource type.
133 * Interface to receive the discovered remote resources.
135 * @throws InvalidArgsException
136 * Thrown if the input parameter is empty.
137 * @throws SimulatorException
138 * Thrown for other errors.
140 public static void findResource(String resourceType,
141 FindResourceListener listener) throws InvalidArgsException,
143 if (null == resourceType || resourceType.isEmpty()) {
144 throw new InvalidArgsException(
145 SimulatorResult.SIMULATOR_INVALID_PARAM,
146 "Invalid resource type!");
149 nativeSearchResource(resourceType, listener);
153 * API to set the device information.
156 * Device information.
158 * @throws InvalidArgsException
159 * Thrown if the input parameter is empty.
160 * @throws SimulatorException
161 * Thrown for other errors.
163 public static void setDeviceInfo(String deviceInfo)
164 throws InvalidArgsException, SimulatorException {
165 nativeSetDeviceInfo(deviceInfo);
169 * API to search for devices on the given host in the network.
172 * URI of the host device.
174 * Listener for receiving the device information.
176 * @throws InvalidArgsException
177 * Thrown if the input parameter is empty.
178 * @throws SimulatorException
179 * Thrown for other errors.
181 public static void findDevices(String hostUri, DeviceListener listener)
182 throws InvalidArgsException, SimulatorException {
183 nativeFindDevices(hostUri, listener);
187 * API to set the platform information.
189 * @param platformInfo
190 * {@link PlatformInfo} - Platform information.
192 * @throws InvalidArgsException
193 * Thrown if the input parameter is empty.
194 * @throws SimulatorException
195 * Thrown for other errors.
197 public static void setPlatformInfo(PlatformInfo platformInfo)
198 throws InvalidArgsException, SimulatorException {
199 nativeSetPlatformInfo(platformInfo);
203 * API to find the platform information of the given host in the network.
206 * URI of the host device.
208 * Listener for receiving the platform information.
210 * @throws InvalidArgsException
211 * Thrown if the input parameter is empty.
212 * @throws SimulatorException
213 * Thrown for other errors.
215 public static void getPlatformInformation(String hostUri,
216 PlatformListener listener) throws InvalidArgsException,
218 nativeGetPlatformInformation(hostUri, listener);
222 * API to set the listener for receiving log messages.
225 * {@link ILogger} to receive the log messages.
227 public static void setLogger(ILogger logger) {
228 nativeSetLogger(logger);
231 private SimulatorManager() {
234 private static native SimulatorResource nativeCreateResource(
237 private static native Vector<SimulatorResource> nativeCreateResources(
238 String configPath, int count);
240 private static native SimulatorResource nativeCreateSingleResource(
241 String name, String uri, String resourceType);
243 private static native SimulatorResource nativeCreateCollectionResource(
244 String name, String uri, String resourceType);
246 private static native void nativeSearchResource(String resourceType,
247 FindResourceListener listener);
249 private static native void nativeSetDeviceInfo(String deviceInfo);
251 private static native void nativeFindDevices(String hostUri,
252 DeviceListener listener);
254 private static native void nativeSetPlatformInfo(PlatformInfo platformInfo);
256 private static native void nativeGetPlatformInformation(String hostUri,
257 PlatformListener listener);
259 private static native void nativeSetLogger(ILogger logger);