d9f502c8a07490e3339bfed9ff12fc9b2aeeb442
[platform/upstream/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / SimulatorManager.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.oic.simulator;
18
19 import org.oic.simulator.clientcontroller.IFindResourceListener;
20 import org.oic.simulator.serviceprovider.IResourceModelChangedListener;
21 import org.oic.simulator.serviceprovider.SimulatorResourceServer;
22
23 /**
24  * This class provides a set of methods for creation, discovery and deletion of
25  * resources.
26  */
27 public class SimulatorManager {
28
29     /**
30      * API for creating a resource from a RAML configuration file whose path is
31      * given as a parameter.
32      *
33      * @param configPath
34      *            Path to RAML configuration file.
35      * @param listener
36      *            Listener for receiving notifications whenever there is a
37      *            change in the resource model.
38      *
39      * @return {@link SimulatorResourceServer} - Created resource on success,
40      *         otherwise null.
41      *
42      * @throws InvalidArgsException
43      *             Thrown if the input parameters are empty.
44      * @throws SimulatorException
45      *             Thrown for other errors.
46      */
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;
54     }
55
56     /**
57      * API for creating a set of resources from a RAML configuration file whose
58      * path is given as a parameter.
59      *
60      * @param configPath
61      *            Path to RAML configuration file.
62      * @param count
63      *            Number of resources to be created.
64      * @param listener
65      *            Listener for receiving notifications whenever there is a
66      *            change in the resource model.
67      *
68      * @return Returns an array of {@link SimulatorResourceServer} objects one
69      *         for each created resource on success, otherwise null.
70      *
71      * @throws InvalidArgsException
72      *             Thrown if the input parameters are empty.
73      * @throws SimulatorException
74      *             Thrown for other errors.
75      */
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;
83     }
84
85     /**
86      * API for deleting a specific resource.
87      *
88      * @param resource
89      *            {@link SimulatorResourceServer} object of the resource to be
90      *            deleted.
91      *
92      * @throws InvalidArgsException
93      *             Thrown if the input parameter is empty.
94      * @throws SimulatorException
95      *             Thrown for other errors.
96      */
97     public static void deleteResource(SimulatorResourceServer resource)
98             throws InvalidArgsException, SimulatorException {
99         SimulatorManagerNativeInterface.deleteResource(resource);
100     }
101
102     /**
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
106      * be deleted.
107      *
108      * @param resourceType
109      *            Type of resource to be deleted.
110      *
111      * @throws SimulatorException
112      *             Thrown for other errors.
113      */
114     public static void deleteResources(String resourceType)
115             throws SimulatorException {
116         SimulatorManagerNativeInterface.deleteResources(resourceType);
117     }
118
119     /**
120      * API for discovering all types of resources in the network. Callback is
121      * called when a resource is discovered in the network.
122      *
123      * @param listener
124      *            Interface to receive the discovered remote resources.
125      *
126      * @throws InvalidArgsException
127      *             Thrown if the input parameter is empty.
128      * @throws SimulatorException
129      *             Thrown for other errors.
130      */
131     public static void findResource(IFindResourceListener listener)
132             throws InvalidArgsException, SimulatorException {
133         SimulatorManagerNativeInterface.findResource(null, listener);
134     }
135
136     /**
137      * API for discovering specific type of resources in the network. Callback
138      * is called when a resource is discovered in the network.
139      *
140      * @param resourceType
141      *            Required resource type
142      * @param listener
143      *            Interface to receive the discovered remote resources.
144      *
145      * @throws InvalidArgsException
146      *             Thrown if the input parameter is empty.
147      * @throws SimulatorException
148      *             Thrown for other errors.
149      */
150     public static void findResource(String resourceType,
151             IFindResourceListener listener) throws InvalidArgsException,
152             SimulatorException {
153         if (null == resourceType || resourceType.isEmpty()) {
154             throw new InvalidArgsException(
155                     SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
156                     "Resource type is empty");
157         }
158         SimulatorManagerNativeInterface.findResource(resourceType, listener);
159     }
160
161     /**
162      * API to set the listener for receiving log messages.
163      *
164      * @param logger
165      *            {@link ILogger} to receive the log messages.
166      */
167     public static void setLogger(ILogger logger) {
168         SimulatorManagerNativeInterface.setLogger(logger);
169     }
170
171     /**
172      * API to set the device information.
173      *
174      * @param deviceInfo
175      *            Device information.
176      */
177     public static void setDeviceInfo(String deviceInfo) {
178         SimulatorManagerNativeInterface.setDeviceInfo(deviceInfo);
179     }
180
181     /**
182      * API to get the device information asynchronously via callback
183      * using {@link IDeviceInfo}.
184      *
185      * @param listener
186      *            Interface for receiving the device information.
187      */
188     public static void getDeviceInfo(IDeviceInfo listener) {
189         SimulatorManagerNativeInterface.getDeviceInfo(listener);
190     }
191
192     /**
193      * API to set the platform information.
194      *
195      * @param platformInfo
196      *            {@link PlatformInfo} - Platform information.
197      */
198     public static void setPlatformInfo(PlatformInfo platformInfo) {
199         SimulatorManagerNativeInterface.setPlatformInfo(platformInfo);
200     }
201
202     /**
203      * API to get the platform information asynchronously via callback
204      * using {@link IPlatformInfo}..
205      *
206      * @param listener
207      *            Interface for receiving the platform information.
208      */
209     public static void getPlatformInfo(IPlatformInfo listener) {
210         SimulatorManagerNativeInterface.getPlatformInfo(listener);
211     }
212 }