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 SimulatorResourceServer simulatorResourceServerObj;
51 simulatorResourceServerObj = SimulatorManagerNativeInterface
52 .createResource(configPath, listener);
53 return simulatorResourceServerObj;
57 * API for creating a set of resources from a RAML configuration file whose
58 * path is given as a parameter.
61 * Path to RAML configuration file.
63 * Number of resources to be created.
65 * Listener for receiving notifications whenever there is a
66 * change in the resource model.
68 * @return Returns an array of {@link SimulatorResourceServer} objects one
69 * for each created resource on success, otherwise null.
71 * @throws InvalidArgsException
72 * Thrown if the input parameters are empty.
73 * @throws SimulatorException
74 * Thrown for other errors.
76 public static SimulatorResourceServer[] createResource(String configPath,
77 int count, IResourceModelChangedListener listener)
78 throws InvalidArgsException, SimulatorException {
79 SimulatorResourceServer[] simulatorResourceServers;
80 simulatorResourceServers = SimulatorManagerNativeInterface
81 .createResources(configPath, count, listener);
82 return simulatorResourceServers;
86 * API for deleting a specific resource.
89 * {@link SimulatorResourceServer} object of the resource to be
92 * @throws InvalidArgsException
93 * Thrown if the input parameter is empty.
94 * @throws SimulatorException
95 * Thrown for other errors.
97 public static void deleteResource(SimulatorResourceServer resource)
98 throws InvalidArgsException, SimulatorException {
99 SimulatorManagerNativeInterface.deleteResource(resource);
103 * API for deleting either all the resources or resources of a specific
104 * type. Ex: If resourceType is oic.light, all resources of oic.light type
105 * will be deleted. If resourceType is null, then all of the resources will
108 * @param resourceType
109 * Type of resource to be deleted.
111 * @throws SimulatorException
112 * Thrown for other errors.
114 public static void deleteResources(String resourceType)
115 throws SimulatorException {
116 SimulatorManagerNativeInterface.deleteResources(resourceType);
120 * API for discovering all types of resources in the network. Callback is
121 * called when a resource is discovered in the network.
124 * Interface to receive the discovered remote resources.
126 * @throws InvalidArgsException
127 * Thrown if the input parameter is empty.
128 * @throws SimulatorException
129 * Thrown for other errors.
131 public static void findResource(IFindResourceListener listener)
132 throws InvalidArgsException, SimulatorException {
133 SimulatorManagerNativeInterface.findResource(null, listener);
137 * API for discovering specific type of resources in the network. Callback
138 * is called when a resource is discovered in the network.
140 * @param resourceType
141 * Required resource type
143 * Interface to receive the discovered remote resources.
145 * @throws InvalidArgsException
146 * Thrown if the input parameter is empty.
147 * @throws SimulatorException
148 * Thrown for other errors.
150 public static void findResource(String resourceType,
151 IFindResourceListener listener) throws InvalidArgsException,
153 if (null == resourceType || resourceType.isEmpty()) {
154 throw new InvalidArgsException(
155 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
156 "Resource type is empty");
158 SimulatorManagerNativeInterface.findResource(resourceType, listener);
162 * API to set the listener for receiving log messages.
165 * {@link ILogger} to receive the log messages.
167 public static void setLogger(ILogger logger) {
168 SimulatorManagerNativeInterface.setLogger(logger);
172 * API to set the device information.
175 * Device information.
177 public static void setDeviceInfo(String deviceInfo) {
178 SimulatorManagerNativeInterface.setDeviceInfo(deviceInfo);
182 * API to get the device information asynchronously via callback
183 * using {@link IDeviceInfo}.
186 * Interface for receiving the device information.
188 public static void getDeviceInfo(IDeviceInfo listener) {
189 SimulatorManagerNativeInterface.getDeviceInfo(listener);
193 * API to set the platform information.
195 * @param platformInfo
196 * {@link PlatformInfo} - Platform information.
198 public static void setPlatformInfo(PlatformInfo platformInfo) {
199 SimulatorManagerNativeInterface.setPlatformInfo(platformInfo);
203 * API to get the platform information asynchronously via callback
204 * using {@link IPlatformInfo}..
207 * Interface for receiving the platform information.
209 public static void getPlatformInfo(IPlatformInfo listener) {
210 SimulatorManagerNativeInterface.getPlatformInfo(listener);