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 org.oic.simulator.clientcontroller.IFindResourceListener;
20 import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
21 import org.oic.simulator.serviceprovider.SimulatorResourceServer;
24 * This class provides a set of methods for creation, discovery and deletion of
27 public class SimulatorManager {
30 * API for creating a resource from a RAML configuration file whose path is
31 * given as a parameter.
34 * Path to RAML configuration file.
36 * Listener for receiving notifications whenever there is a
37 * change in the resource model.
39 * @return {@link SimulatorResourceServer} - Created resource on success,
42 * @throws InvalidArgsException
43 * Thrown if the input parameters are empty.
44 * @throws SimulatorException
45 * Thrown for other errors.
47 public static SimulatorResourceServer createResource(String configPath,
48 IResourceModelChangedListener listener)
49 throws InvalidArgsException, SimulatorException {
50 if (configPath.isEmpty() || null == listener)
51 throw new InvalidArgsException(
52 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
53 "Parameter passed in invalid");
54 SimulatorResourceServer simulatorResourceServerObj;
55 simulatorResourceServerObj = SimulatorManagerNativeInterface
56 .createResource(configPath, listener);
57 return simulatorResourceServerObj;
61 * API for creating a set of resources from a RAML configuration file whose
62 * path is given as a parameter.
65 * Path to RAML configuration file.
67 * Number of resources to be created.
69 * Listener for receiving notifications whenever there is a
70 * change in the resource model.
72 * @return Returns an array of {@link SimulatorResourceServer} objects one
73 * for each created resource on success, otherwise null.
75 * @throws InvalidArgsException
76 * Thrown if the input parameters are empty.
77 * @throws SimulatorException
78 * Thrown for other errors.
80 public static SimulatorResourceServer[] createResource(String configPath,
81 int count, IResourceModelChangedListener listener)
82 throws InvalidArgsException, SimulatorException {
83 if (configPath.isEmpty() || count < 0 || null == listener)
84 throw new InvalidArgsException(
85 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
86 "Parameter passed in invalid");
87 SimulatorResourceServer[] simulatorResourceServers;
88 simulatorResourceServers = SimulatorManagerNativeInterface
89 .createResources(configPath, count, listener);
90 return simulatorResourceServers;
94 * API for deleting a specific resource.
97 * {@link SimulatorResourceServer} object of the resource to be
100 * @throws InvalidArgsException
101 * Thrown if the input parameter is empty.
102 * @throws SimulatorException
103 * Thrown for other errors.
105 public static void deleteResource(SimulatorResourceServer resource)
106 throws InvalidArgsException, SimulatorException {
107 SimulatorManagerNativeInterface.deleteResource(resource);
111 * API for deleting either all the resources or resources of a specific
112 * type. Ex: If resourceType is oic.light, all resources of oic.light type
113 * will be deleted. If resourceType is null, then all of the resources will
116 * @param resourceType
117 * Type of resource to be deleted.
119 * @throws SimulatorException
120 * Thrown for other errors.
122 public static void deleteResources(String resourceType)
123 throws SimulatorException {
124 SimulatorManagerNativeInterface.deleteResources(resourceType);
128 * API for discovering all types of resources in the network. Callback is
129 * called when a resource is discovered in the network.
132 * Interface to receive the discovered remote resources.
134 * @throws InvalidArgsException
135 * Thrown if the input parameter is empty.
136 * @throws SimulatorException
137 * Thrown for other errors.
139 public static void findResource(IFindResourceListener listener)
140 throws InvalidArgsException, SimulatorException {
141 SimulatorManagerNativeInterface.findResource(null, listener);
145 * API for discovering specific type of resources in the network. Callback
146 * is called when a resource is discovered in the network.
148 * @param resourceType
149 * Required resource type
151 * Interface to receive the discovered remote resources.
153 * @throws InvalidArgsException
154 * Thrown if the input parameter is empty.
155 * @throws SimulatorException
156 * Thrown for other errors.
158 public static void findResource(String resourceType,
159 IFindResourceListener listener) throws InvalidArgsException,
161 if (null == resourceType || resourceType.isEmpty()) {
162 throw new InvalidArgsException(
163 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
164 "Resource type is empty");
166 SimulatorManagerNativeInterface.findResource(resourceType, listener);
170 * API to set the listener for receiving log messages.
173 * {@link ILogger} to receive the log messages.
175 public static void setLogger(ILogger logger) {
176 SimulatorManagerNativeInterface.setLogger(logger);
180 * API to set the device information.
183 * Device information.
185 public static void setDeviceInfo(String deviceInfo) {
186 SimulatorManagerNativeInterface.setDeviceInfo(deviceInfo);
190 * API to get the device information asynchronously via callback
191 * using {@link IDeviceInfo}.
194 * Interface for receiving the device information.
196 public static void getDeviceInfo(IDeviceInfo listener) {
197 SimulatorManagerNativeInterface.getDeviceInfo(listener);
201 * API to set the platform information.
203 * @param platformInfo
204 * {@link PlatformInfo} - Platform information.
206 public static void setPlatformInfo(PlatformInfo platformInfo) {
207 SimulatorManagerNativeInterface.setPlatformInfo(platformInfo);
211 * API to get the platform information asynchronously via callback
212 * using {@link IPlatformInfo}..
215 * Interface for receiving the platform information.
217 public static void getPlatformInfo(IPlatformInfo listener) {
218 SimulatorManagerNativeInterface.getPlatformInfo(listener);