[IoTivity Simulator] Updated the eclipse plugins to load the
[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 java.util.Vector;
20
21 import org.oic.simulator.client.FindResourceListener;
22 import org.oic.simulator.server.SimulatorResource;
23
24 /**
25  * This class provides a set of methods for creation, discovery and deletion of
26  * resources.
27  */
28 public class SimulatorManager {
29
30     static {
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");
37     }
38
39     /**
40      * API for creating a resource from a RAML configuration file.
41      *
42      * @param configPath
43      *            Path to RAML configuration file.
44      *
45      * @return {@link SimulatorResource} - Created resource on success,
46      *         otherwise null.
47      *
48      * @throws InvalidArgsException
49      *             Thrown if the input parameters are empty.
50      * @throws SimulatorException
51      *             Thrown for other errors.
52      */
53     public static SimulatorResource createResource(String configPath)
54             throws InvalidArgsException, SimulatorException {
55         return nativeCreateResource(configPath);
56     }
57
58     /**
59      * API for creating a set of resources from a RAML configuration file.
60      *
61      * @param configPath
62      *            Path to RAML configuration file.
63      * @param count
64      *            Number of resources to be created.
65      *
66      * @return Returns an array of {@link SimulatorResource} objects one for
67      *         each created resource on success, otherwise null.
68      *
69      * @throws InvalidArgsException
70      *             Thrown if the input parameters are empty.
71      * @throws SimulatorException
72      *             Thrown for other errors.
73      */
74     public static Vector<SimulatorResource> createResource(String configPath,
75             int count) throws InvalidArgsException, SimulatorException {
76         return nativeCreateResources(configPath, count);
77     };
78
79     /**
80      * API for creating a resource either single or collection type.
81      *
82      * @param type
83      *            Indicates whether single or collection type.
84      * @param name
85      *            Resource Name.
86      * @param uri
87      *            Resource URI.
88      * @param resourceType
89      *            Resource Type.
90      *
91      * @return {@link SimulatorResource} - Created resource on success,
92      *         otherwise null.
93      *
94      * @throws InvalidArgsException
95      *             Thrown if the input parameters are empty.
96      * @throws SimulatorException
97      *             Thrown for other errors.
98      */
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);
105         else
106             resource = nativeCreateCollectionResource(name, uri, resourceType);
107         return resource;
108     }
109
110     /**
111      * API for discovering all types of resources in the network. Callback is
112      * called when a resource is discovered in the network.
113      *
114      * @param listener
115      *            Interface to receive the discovered remote resources.
116      *
117      * @throws InvalidArgsException
118      *             Thrown if the input parameter is empty.
119      * @throws SimulatorException
120      *             Thrown for other errors.
121      */
122     public static void findResource(FindResourceListener listener)
123             throws InvalidArgsException, SimulatorException {
124         nativeSearchResource(null, listener);
125     }
126
127     /**
128      * API for discovering specific type of resources in the network. Callback
129      * is called when a resource is discovered in the network.
130      *
131      * @param resourceType
132      *            Required resource type.
133      * @param listener
134      *            Interface to receive the discovered remote resources.
135      *
136      * @throws InvalidArgsException
137      *             Thrown if the input parameter is empty.
138      * @throws SimulatorException
139      *             Thrown for other errors.
140      */
141     public static void findResource(String resourceType,
142             FindResourceListener listener) throws InvalidArgsException,
143             SimulatorException {
144         if (null == resourceType || resourceType.isEmpty()) {
145             throw new InvalidArgsException(
146                     SimulatorResult.SIMULATOR_INVALID_PARAM,
147                     "Invalid resource type!");
148         }
149
150         nativeSearchResource(resourceType, listener);
151     }
152
153     /**
154      * API to set the device information.
155      *
156      * @param deviceInfo
157      *            Device information.
158      *
159      * @throws InvalidArgsException
160      *             Thrown if the input parameter is empty.
161      * @throws SimulatorException
162      *             Thrown for other errors.
163      */
164     public static void setDeviceInfo(String deviceInfo)
165             throws InvalidArgsException, SimulatorException {
166         nativeSetDeviceInfo(deviceInfo);
167     }
168
169     /**
170      * API to search for devices on the given host in the network.
171      *
172      * @param hostUri
173      *            URI of the host device.
174      * @param listener
175      *            Listener for receiving the device information.
176      *
177      * @throws InvalidArgsException
178      *             Thrown if the input parameter is empty.
179      * @throws SimulatorException
180      *             Thrown for other errors.
181      */
182     public static void findDevices(String hostUri, DeviceListener listener)
183             throws InvalidArgsException, SimulatorException {
184         nativeFindDevices(hostUri, listener);
185     }
186
187     /**
188      * API to set the platform information.
189      *
190      * @param platformInfo
191      *            {@link PlatformInfo} - Platform information.
192      *
193      * @throws InvalidArgsException
194      *             Thrown if the input parameter is empty.
195      * @throws SimulatorException
196      *             Thrown for other errors.
197      */
198     public static void setPlatformInfo(PlatformInfo platformInfo)
199             throws InvalidArgsException, SimulatorException {
200         nativeSetPlatformInfo(platformInfo);
201     }
202
203     /**
204      * API to find the platform information of the given host in the network.
205      *
206      * @param hostUri
207      *            URI of the host device.
208      * @param listener
209      *            Listener for receiving the platform information.
210      *
211      * @throws InvalidArgsException
212      *             Thrown if the input parameter is empty.
213      * @throws SimulatorException
214      *             Thrown for other errors.
215      */
216     public static void getPlatformInformation(String hostUri,
217             PlatformListener listener) throws InvalidArgsException,
218             SimulatorException {
219         nativeGetPlatformInformation(hostUri, listener);
220     }
221
222     /**
223      * API to set the listener for receiving log messages.
224      *
225      * @param logger
226      *            {@link ILogger} to receive the log messages.
227      */
228     public static void setLogger(ILogger logger) {
229         nativeSetLogger(logger);
230     }
231
232     private SimulatorManager() {
233     }
234
235     private static native SimulatorResource nativeCreateResource(
236             String configPath);
237
238     private static native Vector<SimulatorResource> nativeCreateResources(
239             String configPath, int count);
240
241     private static native SimulatorResource nativeCreateSingleResource(
242             String name, String uri, String resourceType);
243
244     private static native SimulatorResource nativeCreateCollectionResource(
245             String name, String uri, String resourceType);
246
247     private static native void nativeSearchResource(String resourceType,
248             FindResourceListener listener);
249
250     private static native void nativeSetDeviceInfo(String deviceInfo);
251
252     private static native void nativeFindDevices(String hostUri,
253             DeviceListener listener);
254
255     private static native void nativeSetPlatformInfo(PlatformInfo platformInfo);
256
257     private static native void nativeGetPlatformInformation(String hostUri,
258             PlatformListener listener);
259
260     private static native void nativeSetLogger(ILogger logger);
261 }